From d6deabcc522f8a18cfdef39acf0c02abc377f818 Mon Sep 17 00:00:00 2001 From: Viranch Mehta Date: Fri, 25 Jun 2021 10:52:35 -0700 Subject: [PATCH 1/2] Fix duplicate endpoints in Azure DNS dynamic records --- octodns/provider/azuredns.py | 11 +++++- tests/test_octodns_provider_azuredns.py | 45 +++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/octodns/provider/azuredns.py b/octodns/provider/azuredns.py index 4551c6c..c69c723 100644 --- a/octodns/provider/azuredns.py +++ b/octodns/provider/azuredns.py @@ -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 diff --git a/tests/test_octodns_provider_azuredns.py b/tests/test_octodns_provider_azuredns.py index eb74007..13c1bf4 100644 --- a/tests/test_octodns_provider_azuredns.py +++ b/tests/test_octodns_provider_azuredns.py @@ -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() From 4848246712d56268b7f074e151466846533c5639 Mon Sep 17 00:00:00 2001 From: Viranch Mehta Date: Fri, 25 Jun 2021 13:58:00 -0700 Subject: [PATCH 2/2] Fix partially re-used fallback chain --- octodns/provider/azuredns.py | 4 ++-- tests/test_octodns_provider_azuredns.py | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/octodns/provider/azuredns.py b/octodns/provider/azuredns.py index c69c723..87bbef0 100644 --- a/octodns/provider/azuredns.py +++ b/octodns/provider/azuredns.py @@ -837,8 +837,8 @@ class AzureProvider(BaseProvider): pool['fallback'] = pool_name if pool_name in pools: - # we've already populated the pool - continue + # we've already populated this and subsequent pools + break # populate the pool from Weighted profile # these should be leaf node entries with no further nesting diff --git a/tests/test_octodns_provider_azuredns.py b/tests/test_octodns_provider_azuredns.py index 13c1bf4..e09de28 100644 --- a/tests/test_octodns_provider_azuredns.py +++ b/tests/test_octodns_provider_azuredns.py @@ -1687,6 +1687,12 @@ class TestAzureDnsProvider(TestCase): 'value': 'default.unit.tests.', 'dynamic': { 'pools': { + 'sto': { + 'values': [ + {'value': 'sto.unit.tests.'}, + ], + 'fallback': 'iad', + }, 'iad': { 'values': [ {'value': 'iad.unit.tests.'}, @@ -1702,13 +1708,14 @@ class TestAzureDnsProvider(TestCase): 'rules': [ {'geos': ['EU'], 'pool': 'iad'}, {'geos': ['EU-GB'], 'pool': 'lhr'}, + {'geos': ['EU-SE'], 'pool': 'sto'}, {'pool': 'lhr'}, ], } }) profiles = provider._generate_traffic_managers(record) - self.assertEqual(len(profiles), 3) + self.assertEqual(len(profiles), 4) self.assertTrue(_profile_is_match(profiles[-1], Profile( name='foo--unit--tests', traffic_routing_method='Geographic', @@ -1728,6 +1735,12 @@ class TestAzureDnsProvider(TestCase): target_resource_id=profiles[1].id, geo_mapping=['GB', 'WORLD'], ), + Endpoint( + name='rule-sto', + type=nested, + target_resource_id=profiles[2].id, + geo_mapping=['SE'], + ), ], )))