mirror of
https://github.com/github/octodns.git
synced 2024-05-11 05:55:00 +00:00
add conditional and test for zone not exists by name
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user