From 973f88510f6e09fcc29592bfb8273e1b6741c854 Mon Sep 17 00:00:00 2001 From: Viranch Mehta Date: Wed, 17 Nov 2021 17:09:45 -0800 Subject: [PATCH] Fix geo comparison in Azure DNS traffic manager profiles --- octodns/provider/azuredns.py | 33 ++++++++++++++++--------- tests/test_octodns_provider_azuredns.py | 10 ++++++++ 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/octodns/provider/azuredns.py b/octodns/provider/azuredns.py index bbc6973..c78af8f 100644 --- a/octodns/provider/azuredns.py +++ b/octodns/provider/azuredns.py @@ -377,29 +377,39 @@ def _profile_is_match(have, desired): for have_endpoint, desired_endpoint in endpoints: have_status = have_endpoint.endpoint_status or 'Enabled' desired_status = desired_endpoint.endpoint_status or 'Enabled' + + # compare basic attributes if have_endpoint.name != desired_endpoint.name or \ have_endpoint.type != desired_endpoint.type or \ have_status != desired_status: return false(have_endpoint, desired_endpoint, have.name) + + # compare geos + if method == 'Geographic': + have_geos = sorted(have_endpoint.geo_mapping) + desired_geos = sorted(desired_endpoint.geo_mapping) + if have_geos != desired_geos: + return false(have_endpoint, desired_endpoint, have.name) + + # compare priorities + if method == 'Priority' and \ + have_endpoint.priority != desired_endpoint.priority: + return false(have_endpoint, desired_endpoint, have.name) + + # compare weights + if method == 'Weighted' and \ + have_endpoint.weight != desired_endpoint.weight: + return false(have_endpoint, desired_endpoint, have.name) + + # compare targets target_type = have_endpoint.type.split('/')[-1] if target_type == 'externalEndpoints': - # compare value, weight, priority if have_endpoint.target != desired_endpoint.target: return false(have_endpoint, desired_endpoint, have.name) - if method == 'Weighted' and \ - have_endpoint.weight != desired_endpoint.weight: - return false(have_endpoint, desired_endpoint, have.name) elif target_type == 'nestedEndpoints': - # compare targets if have_endpoint.target_resource_id != \ desired_endpoint.target_resource_id: return false(have_endpoint, desired_endpoint, have.name) - # compare geos - if method == 'Geographic': - have_geos = sorted(have_endpoint.geo_mapping) - desired_geos = sorted(desired_endpoint.geo_mapping) - if have_geos != desired_geos: - return false(have_endpoint, desired_endpoint, have.name) else: # unexpected, give up return False @@ -913,6 +923,7 @@ class AzureProvider(BaseProvider): if value['status'] == 'up': # Azure only supports obey and down, not up up_pools.append(name) + break if not up_pools: continue diff --git a/tests/test_octodns_provider_azuredns.py b/tests/test_octodns_provider_azuredns.py index 64bd3ec..02dec2f 100644 --- a/tests/test_octodns_provider_azuredns.py +++ b/tests/test_octodns_provider_azuredns.py @@ -516,6 +516,16 @@ class Test_ProfileIsMatch(TestCase): ) self.assertFalse(is_match(profile(), profile(target_id='rsrc/id2'))) self.assertFalse(is_match(profile(), profile(geos=['IN']))) + self.assertFalse(is_match( + profile(endpoint_type='profile/externalEndpoints'), + profile( + endpoint_type='profile/externalEndpoints', + geos=['IN'] + ) + )) + self.assertFalse(is_match(profile(method='Priority'), profile( + method='Priority', priority=2 + ))) def wprofile(**kwargs): kwargs['method'] = 'Weighted'