Browse Source

Fix duplicate endpoints in Azure DNS dynamic records

pull/734/head
Viranch Mehta 5 years ago
parent
commit
d6deabcc52
No known key found for this signature in database GPG Key ID: D83D1392AE9F93B4
2 changed files with 55 additions and 1 deletions
  1. +10
    -1
      octodns/provider/azuredns.py
  2. +45
    -0
      tests/test_octodns_provider_azuredns.py

+ 10
- 1
octodns/provider/azuredns.py View File

@ -922,6 +922,16 @@ class AzureProvider(BaseProvider):
for profile in profiles:
name = profile.name
endpoints = set()
for ep in profile.endpoints:
if not ep.target:
continue
if ep.target in endpoints:
msg = '{} contains duplicate endpoint {}'
raise AzureException(msg.format(name, ep.target))
endpoints.add(ep.target)
if name in seen_profiles:
# exit if a possible collision is detected, even though
# we've tried to ensure unique mapping
@ -1053,7 +1063,6 @@ class AzureProvider(BaseProvider):
while pool_name:
# iterate until we reach end of fallback chain
default_seen = False
pool = pools[pool_name].data
if len(pool['values']) > 1:
# create Weighted profile for multi-value pool


+ 45
- 0
tests/test_octodns_provider_azuredns.py View File

@ -999,6 +999,51 @@ class TestAzureDnsProvider(TestCase):
'Collision in Traffic Manager'
))
@patch(
'octodns.provider.azuredns.AzureProvider._generate_traffic_managers')
def test_extra_changes_non_last_fallback_contains_default(self, mock_gtm):
provider = self._get_provider()
desired = Zone(zone.name, sub_zones=[])
record = Record.new(desired, 'foo', {
'type': 'CNAME',
'ttl': 60,
'value': 'default.unit.tests.',
'dynamic': {
'pools': {
'one': {
'values': [{'value': 'one.unit.tests.'}],
'fallback': 'def',
},
'def': {
'values': [{'value': 'default.unit.tests.'}],
'fallback': 'two',
},
'two': {
'values': [{'value': 'two.unit.tests.'}],
},
},
'rules': [
{'pool': 'one'},
]
}
})
desired.add_record(record)
changes = [Create(record)]
# assert that no exception is raised
provider._extra_changes(zone, desired, changes)
# simulate duplicate endpoint and assert exception
endpoint = Endpoint(target='dup.unit.tests.')
mock_gtm.return_value = [Profile(
name='test-profile',
endpoints=[endpoint, endpoint],
)]
with self.assertRaises(AzureException) as ctx:
provider._extra_changes(zone, desired, changes)
self.assertTrue('duplicate endpoint' in text_type(ctx))
def test_extra_changes_invalid_dynamic_A(self):
provider = self._get_provider()


Loading…
Cancel
Save