Validate that dynamic rule goes are not reused

This commit is contained in:
Ross McFarland
2023-03-28 10:53:44 -07:00
parent 14668d8f94
commit ae5c6bdd52
2 changed files with 19 additions and 1 deletions
+5 -1
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
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,
)