diff --git a/octodns/provider/route53.py b/octodns/provider/route53.py index ee9d05d..85d35e6 100644 --- a/octodns/provider/route53.py +++ b/octodns/provider/route53.py @@ -500,6 +500,10 @@ class Route53Provider(BaseProvider): # use expected_re = re.compile(r'^\d\d\d\d:{}:{}:' .format(record._type, record.name)) + # Until the v1.0 release we'll clean out the previous version of + # Route53 health checks as best as we can. + expected_legacy_host = record.fqdn[:-1] + expected_legacy = '0000:{}:'.format(record._type) for id, health_check in self.health_checks.items(): ref = health_check['CallerReference'] if expected_re.match(ref) and id not in in_use: @@ -507,6 +511,12 @@ class Route53Provider(BaseProvider): # planning to use going forward self.log.info('_gc_health_checks: deleting id=%s', id) self._conn.delete_health_check(HealthCheckId=id) + elif ref.startswith(expected_legacy): + config = health_check['HealthCheckConfig'] + if expected_legacy_host == config['FullyQualifiedDomainName']: + self.log.info('_gc_health_checks: deleting legacy id=%s', + id) + self._conn.delete_health_check(HealthCheckId=id) def _gen_records(self, record, creating=False): ''' diff --git a/tests/test_octodns_provider_route53.py b/tests/test_octodns_provider_route53.py index 7ec0d34..5d34f50 100644 --- a/tests/test_octodns_provider_route53.py +++ b/tests/test_octodns_provider_route53.py @@ -18,6 +18,12 @@ from octodns.zone import Zone from helpers import GeoProvider +class DummyR53Record(object): + + def __init__(self, health_check_id): + self.health_check_id = health_check_id + + class TestOctalReplace(TestCase): def test_basic(self): @@ -807,18 +813,13 @@ class TestRoute53Provider(TestCase): } }) - class DummyRecord(object): - - def __init__(self, health_check_id): - self.health_check_id = health_check_id - # gc no longer in_use records (directly) stubber.add_response('delete_health_check', {}, { 'HealthCheckId': '44', }) provider._gc_health_checks(record, [ - DummyRecord('42'), - DummyRecord('43'), + DummyR53Record('42'), + DummyR53Record('43'), ]) stubber.assert_no_pending_responses() @@ -866,6 +867,71 @@ class TestRoute53Provider(TestCase): provider._gc_health_checks(record, []) stubber.assert_no_pending_responses() + def test_legacy_health_check_gc(self): + provider, stubber = self._get_stubbed_provider() + + old_caller_ref = '0000:A:3333' + health_checks = [{ + 'Id': '42', + 'CallerReference': self.caller_ref, + 'HealthCheckConfig': { + 'Type': 'HTTPS', + 'FullyQualifiedDomainName': 'unit.tests', + 'IPAddress': '4.2.3.4', + 'ResourcePath': '/_dns', + }, + 'HealthCheckVersion': 2, + }, { + 'Id': '43', + 'CallerReference': old_caller_ref, + 'HealthCheckConfig': { + 'Type': 'HTTPS', + 'FullyQualifiedDomainName': 'unit.tests', + 'IPAddress': '4.2.3.4', + 'ResourcePath': '/_dns', + }, + 'HealthCheckVersion': 2, + }, { + 'Id': '44', + 'CallerReference': old_caller_ref, + 'HealthCheckConfig': { + 'Type': 'HTTPS', + 'FullyQualifiedDomainName': 'other.unit.tests', + 'IPAddress': '4.2.3.4', + 'ResourcePath': '/_dns', + }, + 'HealthCheckVersion': 2, + }] + + stubber.add_response('list_health_checks', { + 'HealthChecks': health_checks, + 'IsTruncated': False, + 'MaxItems': '100', + 'Marker': '', + }) + + # No changes to the record itself + record = Record.new(self.expected, '', { + 'ttl': 61, + 'type': 'A', + 'values': ['2.2.3.4', '3.2.3.4'], + 'geo': { + 'AF': ['4.2.3.4'], + 'NA-US': ['5.2.3.4', '6.2.3.4'], + 'NA-US-CA': ['7.2.3.4'] + } + }) + + # Expect to delete the legacy hc for our record, but not touch the new + # one or the other legacy record + stubber.add_response('delete_health_check', {}, { + 'HealthCheckId': '43', + }) + + provider._gc_health_checks(record, [ + DummyR53Record('42'), + ]) + def test_no_extra_changes(self): provider, stubber = self._get_stubbed_provider()