From 6f5df26e883b79ce2daf058c05d5086cd53c7d20 Mon Sep 17 00:00:00 2001 From: Viranch Mehta Date: Sun, 4 Jul 2021 23:52:16 -0700 Subject: [PATCH] allow multiple values if all pool values are included --- octodns/provider/azuredns.py | 19 +++++++++++++++---- tests/test_octodns_provider_azuredns.py | 15 +++++++++++---- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/octodns/provider/azuredns.py b/octodns/provider/azuredns.py index 845d4d5..59bd8c3 100644 --- a/octodns/provider/azuredns.py +++ b/octodns/provider/azuredns.py @@ -302,10 +302,21 @@ def _get_monitor(record): def _check_valid_dynamic(record): typ = record._type if typ in ['A', 'AAAA']: - if len(record.values) > 1: - # we don't yet support multi-value defaults - msg = '{} {}: A/AAAA dynamic records can only have a single value' - raise AzureException(msg.format(record.fqdn, record._type)) + defaults = set(record.values) + if len(defaults) > 1: + pools = record.dynamic.pools + vals = set( + v['value'] + for _, pool in pools.items() + for v in pool._data()['values'] + ) + if defaults != vals: + # we don't yet support multi-value defaults, specifying all + # pool values allows for Traffic Manager profile optimization + msg = ('{} {}: Values of A/AAAA dynamic records must either ' + 'have a single value or contain all values from all ' + 'pools') + raise AzureException(msg.format(record.fqdn, record._type)) elif typ != 'CNAME': # dynamic records of unsupported type msg = '{}: Dynamic records in Azure must be of type A/AAAA/CNAME' diff --git a/tests/test_octodns_provider_azuredns.py b/tests/test_octodns_provider_azuredns.py index 85fa572..0af8665 100644 --- a/tests/test_octodns_provider_azuredns.py +++ b/tests/test_octodns_provider_azuredns.py @@ -1873,12 +1873,13 @@ class TestAzureDnsProvider(TestCase): record = Record.new(zone, 'foo', data={ 'type': 'AAAA', 'ttl': 60, - 'values': ['1::1'], + 'values': ['1::1', '2::2'], 'dynamic': { 'pools': { 'one': { 'values': [ {'value': '1::1'}, + {'value': '2::2'}, ], }, }, @@ -1892,16 +1893,22 @@ class TestAzureDnsProvider(TestCase): self.assertEqual(len(profiles), 1) self.assertTrue(_profile_is_match(profiles[0], Profile( name='foo--unit--tests-AAAA', - traffic_routing_method='Geographic', + traffic_routing_method='Weighted', dns_config=DnsConfig( relative_name='foo--unit--tests-aaaa', ttl=record.ttl), monitor_config=_get_monitor(record), endpoints=[ Endpoint( - name='one--default--', + name='one--1--1--default--', type=external, target='1::1', - geo_mapping=['WORLD'], + weight=1, + ), + Endpoint( + name='one--2--2--default--', + type=external, + target='2::2', + weight=1, ), ], )))