diff --git a/octodns/record/__init__.py b/octodns/record/__init__.py index 0eb9431..384c0a2 100644 --- a/octodns/record/__init__.py +++ b/octodns/record/__init__.py @@ -590,6 +590,11 @@ class _DynamicMixin(object): reasons.append('rule {} missing pool'.format(rule_num)) continue + try: + geos = rule['geos'] + except KeyError: + geos = [] + if not isinstance(pool, string_types): reasons.append('rule {} invalid pool "{}"' .format(rule_num, pool)) @@ -598,15 +603,12 @@ class _DynamicMixin(object): reasons.append('rule {} undefined pool "{}"' .format(rule_num, pool)) pools_seen.add(pool) - elif pool in pools_seen: + elif pool in pools_seen and geos: reasons.append('rule {} invalid, target pool "{}" ' 'reused'.format(rule_num, pool)) pools_seen.add(pool) - try: - geos = rule['geos'] - except KeyError: - geos = [] + if not geos: if seen_default: reasons.append('rule {} duplicate default' .format(rule_num)) diff --git a/tests/test_octodns_record.py b/tests/test_octodns_record.py index 4216c52..f76f593 100644 --- a/tests/test_octodns_record.py +++ b/tests/test_octodns_record.py @@ -3417,6 +3417,7 @@ class TestDynamicRecords(TestCase): 'geos': ['AF'], 'pool': 'one', }, { + 'geos': ['OC'], 'pool': 'one', }], }, @@ -3432,6 +3433,43 @@ class TestDynamicRecords(TestCase): self.assertEquals(['rule 3 invalid, target pool "one" reused'], ctx.exception.reasons) + # Repeated pool is OK if later one is a default + a_data = { + 'dynamic': { + 'pools': { + 'one': { + 'values': [{ + 'value': '3.3.3.3', + }] + }, + 'two': { + 'values': [{ + 'value': '4.4.4.4', + }, { + 'value': '5.5.5.5', + }] + }, + }, + 'rules': [{ + 'geos': ['EU-GB'], + 'pool': 'one', + }, { + 'geos': ['EU'], + 'pool': 'two', + }, { + 'pool': 'one', + }], + }, + 'ttl': 60, + 'type': 'A', + 'values': [ + '1.1.1.1', + '2.2.2.2', + ], + } + # This should be valid, no exception + Record.new(self.zone, 'bad', a_data) + def test_dynamic_lenient(self): # Missing pools a_data = {