1
0
mirror of https://github.com/github/octodns.git synced 2024-05-11 05:55:00 +00:00

Plumb hosted_zone_id through to _Route53Record

This commit is contained in:
Ross McFarland
2019-04-01 09:33:56 -07:00
parent f83eeb0a9c
commit ed152ce0f3
2 changed files with 18 additions and 14 deletions

View File

@@ -29,7 +29,7 @@ def _octal_replace(s):
class _Route53Record(object): class _Route53Record(object):
@classmethod @classmethod
def new(self, provider, record, creating): def new(self, provider, record, hosted_zone_id, creating):
ret = set() ret = set()
if getattr(record, 'geo', False): if getattr(record, 'geo', False):
ret.add(_Route53GeoDefault(provider, record, creating)) ret.add(_Route53GeoDefault(provider, record, creating))
@@ -698,25 +698,26 @@ class Route53Provider(BaseProvider):
id) id)
self._conn.delete_health_check(HealthCheckId=id) self._conn.delete_health_check(HealthCheckId=id)
def _gen_records(self, record, creating=False): def _gen_records(self, record, zone_id, creating=False):
''' '''
Turns an octodns.Record into one or more `_Route53*`s Turns an octodns.Record into one or more `_Route53*`s
''' '''
return _Route53Record.new(self, record, creating) return _Route53Record.new(self, record, zone_id, creating)
def _mod_Create(self, change): def _mod_Create(self, change, zone_id):
# New is the stuff that needs to be created # New is the stuff that needs to be created
new_records = self._gen_records(change.new, creating=True) new_records = self._gen_records(change.new, zone_id, creating=True)
# Now is a good time to clear out any unused health checks since we # Now is a good time to clear out any unused health checks since we
# know what we'll be using going forward # know what we'll be using going forward
self._gc_health_checks(change.new, new_records) self._gc_health_checks(change.new, new_records)
return self._gen_mods('CREATE', new_records) return self._gen_mods('CREATE', new_records)
def _mod_Update(self, change): def _mod_Update(self, change, zone_id):
# See comments in _Route53Record for how the set math is made to do our # See comments in _Route53Record for how the set math is made to do our
# bidding here. # bidding here.
existing_records = self._gen_records(change.existing, creating=False) existing_records = self._gen_records(change.existing, zone_id,
new_records = self._gen_records(change.new, creating=True) creating=False)
new_records = self._gen_records(change.new, zone_id, creating=True)
# Now is a good time to clear out any unused health checks since we # Now is a good time to clear out any unused health checks since we
# know what we'll be using going forward # know what we'll be using going forward
self._gc_health_checks(change.new, new_records) self._gc_health_checks(change.new, new_records)
@@ -738,9 +739,10 @@ class Route53Provider(BaseProvider):
self._gen_mods('CREATE', creates) + \ self._gen_mods('CREATE', creates) + \
self._gen_mods('UPSERT', upserts) self._gen_mods('UPSERT', upserts)
def _mod_Delete(self, change): def _mod_Delete(self, change, zone_id):
# Existing is the thing that needs to be deleted # Existing is the thing that needs to be deleted
existing_records = self._gen_records(change.existing, creating=False) existing_records = self._gen_records(change.existing, zone_id,
creating=False)
# Now is a good time to clear out all the health checks since we know # Now is a good time to clear out all the health checks since we know
# we're done with them # we're done with them
self._gc_health_checks(change.existing, []) self._gc_health_checks(change.existing, [])
@@ -822,7 +824,9 @@ class Route53Provider(BaseProvider):
batch_rs_count = 0 batch_rs_count = 0
zone_id = self._get_zone_id(desired.name, True) zone_id = self._get_zone_id(desired.name, True)
for c in changes: for c in changes:
mods = getattr(self, '_mod_{}'.format(c.__class__.__name__))(c) # Generate the mods for this change
mod_type = getattr(self, '_mod_{}'.format(c.__class__.__name__))
mods = mod_type(c, zone_id)
mods_rs_count = sum( mods_rs_count = sum(
[len(m['ResourceRecordSet']['ResourceRecords']) for m in mods] [len(m['ResourceRecordSet']['ResourceRecords']) for m in mods]
) )

View File

@@ -1010,7 +1010,7 @@ class TestRoute53Provider(TestCase):
'HealthCheckId': '44', 'HealthCheckId': '44',
}) })
change = Create(record) change = Create(record)
provider._mod_Create(change) provider._mod_Create(change, 'z43')
stubber.assert_no_pending_responses() stubber.assert_no_pending_responses()
# gc through _mod_Update # gc through _mod_Update
@@ -1019,7 +1019,7 @@ class TestRoute53Provider(TestCase):
}) })
# first record is ignored for our purposes, we have to pass something # first record is ignored for our purposes, we have to pass something
change = Update(record, record) change = Update(record, record)
provider._mod_Create(change) provider._mod_Create(change, 'z43')
stubber.assert_no_pending_responses() stubber.assert_no_pending_responses()
# gc through _mod_Delete, expect 3 to go away, can't check order # gc through _mod_Delete, expect 3 to go away, can't check order
@@ -1034,7 +1034,7 @@ class TestRoute53Provider(TestCase):
'HealthCheckId': ANY, 'HealthCheckId': ANY,
}) })
change = Delete(record) change = Delete(record)
provider._mod_Delete(change) provider._mod_Delete(change, 'z43')
stubber.assert_no_pending_responses() stubber.assert_no_pending_responses()
# gc only AAAA, leave the A's alone # gc only AAAA, leave the A's alone