mirror of
https://github.com/github/octodns.git
synced 2024-05-11 05:55:00 +00:00
Force order of Delete() -> Create() -> Update() in Cloudflare provider
Addresses issues with changing between A, AAAA and CNAME records in both directions with the Cloudflare API See also: github/octodns#507 See also: github/octodns#586 See also: github/octodns#587
This commit is contained in:
@@ -143,6 +143,11 @@ class CloudflareProvider(BaseProvider):
|
|||||||
resp.raise_for_status()
|
resp.raise_for_status()
|
||||||
return resp.json()
|
return resp.json()
|
||||||
|
|
||||||
|
def _change_keyer(self, change):
|
||||||
|
key = change.__class__.__name__
|
||||||
|
order = {'Delete': 0, 'Create': 1, 'Update': 2}
|
||||||
|
return order[key]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def zones(self):
|
def zones(self):
|
||||||
if self._zones is None:
|
if self._zones is None:
|
||||||
@@ -660,6 +665,11 @@ class CloudflareProvider(BaseProvider):
|
|||||||
self.zones[name] = zone_id
|
self.zones[name] = zone_id
|
||||||
self._zone_records[name] = {}
|
self._zone_records[name] = {}
|
||||||
|
|
||||||
|
# Force the operation order to be Delete() -> Create() -> Update()
|
||||||
|
# This will help avoid problems in updating a CNAME record into an
|
||||||
|
# A record and vice-versa
|
||||||
|
changes.sort(key=self._change_keyer)
|
||||||
|
|
||||||
for change in changes:
|
for change in changes:
|
||||||
class_name = change.__class__.__name__
|
class_name = change.__class__.__name__
|
||||||
getattr(self, '_apply_{}'.format(class_name))(change)
|
getattr(self, '_apply_{}'.format(class_name))(change)
|
||||||
|
|||||||
@@ -340,6 +340,10 @@ class TestCloudflareProvider(TestCase):
|
|||||||
self.assertTrue(plan.exists)
|
self.assertTrue(plan.exists)
|
||||||
# creates a the new value and then deletes all the old
|
# creates a the new value and then deletes all the old
|
||||||
provider._request.assert_has_calls([
|
provider._request.assert_has_calls([
|
||||||
|
call('DELETE', '/zones/ff12ab34cd5611334422ab3322997650/'
|
||||||
|
'dns_records/fc12ab34cd5611334422ab3322997653'),
|
||||||
|
call('DELETE', '/zones/ff12ab34cd5611334422ab3322997650/'
|
||||||
|
'dns_records/fc12ab34cd5611334422ab3322997654'),
|
||||||
call('PUT', '/zones/42/dns_records/'
|
call('PUT', '/zones/42/dns_records/'
|
||||||
'fc12ab34cd5611334422ab3322997655', data={
|
'fc12ab34cd5611334422ab3322997655', data={
|
||||||
'content': '3.2.3.4',
|
'content': '3.2.3.4',
|
||||||
@@ -347,11 +351,7 @@ class TestCloudflareProvider(TestCase):
|
|||||||
'name': 'ttl.unit.tests',
|
'name': 'ttl.unit.tests',
|
||||||
'proxied': False,
|
'proxied': False,
|
||||||
'ttl': 300
|
'ttl': 300
|
||||||
}),
|
})
|
||||||
call('DELETE', '/zones/ff12ab34cd5611334422ab3322997650/'
|
|
||||||
'dns_records/fc12ab34cd5611334422ab3322997653'),
|
|
||||||
call('DELETE', '/zones/ff12ab34cd5611334422ab3322997650/'
|
|
||||||
'dns_records/fc12ab34cd5611334422ab3322997654')
|
|
||||||
])
|
])
|
||||||
|
|
||||||
def test_update_add_swap(self):
|
def test_update_add_swap(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user