Browse Source

add conditional and test for zone not exists by name

pull/783/head
slandry 4 years ago
parent
commit
da1b732f29
2 changed files with 43 additions and 5 deletions
  1. +6
    -5
      octodns/provider/route53.py
  2. +37
    -0
      tests/test_octodns_provider_route53.py

+ 6
- 5
octodns/provider/route53.py View File

@ -669,11 +669,12 @@ class Route53Provider(BaseProvider):
response = self._conn.list_hosted_zones_by_name(
DNSName=name, MaxItems="1"
)
if len(response['HostedZones']) == 1:
# if there is a single response
id = response['HostedZones'][0]['Id']
self.log.debug(id)
return id
if len(response['HostedZones']) != 0:
# if there is a response that starts with the name
if response['HostedZones'][0]['Name'].startswith(name):
id = response['HostedZones'][0]['Id']
self.log.debug('get_zones_by_name: id=%s', id)
return id
elif name in self.r53_zones:
id = self.r53_zones[name]
self.log.debug('_get_zone_id: id=%s', id)


+ 37
- 0
tests/test_octodns_provider_route53.py View File

@ -1782,6 +1782,43 @@ class TestRoute53Provider(TestCase):
self.assertEquals([], extra)
stubber.assert_no_pending_responses()
def test_zone_not_found_get_zones_by_name(self):
provider = Route53Provider(
'test', 'abc', '123', get_zones_by_name=True)
# Use the stubber
stubber = Stubber(provider._conn)
stubber.activate()
list_hosted_zones_by_name_resp = {
'HostedZones': [{
'Id': 'z43',
'Name': 'bad.tests.',
'CallerReference': 'abc',
'Config': {
'Comment': 'string',
'PrivateZone': False
},
'ResourceRecordSetCount': 123,
}, ],
'DNSName': 'unit.tests.',
'HostedZoneId': 'z42',
'IsTruncated': False,
'MaxItems': 'string'
}
stubber.add_response(
'list_hosted_zones_by_name',
list_hosted_zones_by_name_resp,
{'DNSName': 'unit.tests.', 'MaxItems': '1'}
)
# empty is empty
desired = Zone('unit.tests.', [])
extra = provider._extra_changes(desired=desired, changes=[])
self.assertEquals([], extra)
stubber.assert_no_pending_responses()
def test_plan_with_get_zones_by_name(self):
provider = Route53Provider(
'test', 'abc', '123', get_zones_by_name=True)


Loading…
Cancel
Save