Browse Source

Validate that dynamic rule goes are not reused

pull/992/head
Ross McFarland 3 years ago
parent
commit
ae5c6bdd52
No known key found for this signature in database GPG Key ID: 943B179E15D3B22A
2 changed files with 19 additions and 1 deletions
  1. +5
    -1
      octodns/record/dynamic.py
  2. +14
    -0
      tests/test_octodns_record_dynamic.py

+ 5
- 1
octodns/record/dynamic.py View File

@ -271,7 +271,11 @@ class _DynamicMixin(object):
# currently looking at, e.g. geo=NA-US and there was a
# previous rule with NA
for seen, where in geos_seen.items():
if geo.startswith(seen):
if geo == seen:
reasons.append(
f'rule {rule_num} targets geo {geo} which has previously been seen in rule {where}'
)
elif geo.startswith(seen):
reasons.append(
f'rule {rule_num} targets geo {geo} which is more specific than the previously seen {seen} in rule {where}'
)


+ 14
- 0
tests/test_octodns_record_dynamic.py View File

@ -1299,6 +1299,7 @@ class TestRecordDynamic(TestCase):
self.assertFalse(reasons)
self.assertEqual({'sfo', 'iad'}, pools_seen)
# this one targets NA in rule 0 and then NA-Ca in rule 1
pools = {'iad', 'sfo'}
rules = [
{'geos': ('AS', 'NA'), 'pool': 'sfo'},
@ -1312,6 +1313,7 @@ class TestRecordDynamic(TestCase):
reasons,
)
# this one targets NA and NA-US in rule 0
pools = {'sfo'}
rules = [{'geos': ('AS', 'NA-US', 'NA'), 'pool': 'sfo'}]
reasons, pools_seen = _DynamicMixin._validate_rules(pools, rules)
@ -1321,3 +1323,15 @@ class TestRecordDynamic(TestCase):
],
reasons,
)
# this one targets the same geo in multiple rules
pools = {'iad', 'sfo'}
rules = [
{'geos': ('AS', 'NA'), 'pool': 'sfo'},
{'geos': ('EU', 'NA'), 'pool': 'iad'},
]
reasons, pools_seen = _DynamicMixin._validate_rules(pools, rules)
self.assertEqual(
['rule 2 targets geo NA which has previously been seen in rule 1'],
reasons,
)

Loading…
Cancel
Save