Add zone specific threshold config

This commit is contained in:
Matt Cholick
2024-04-10 11:44:37 -07:00
parent e594f227c1
commit 2bb2d5643b
7 changed files with 175 additions and 6 deletions
+28
View File
@@ -0,0 +1,28 @@
manager:
max_workers: 2
providers:
in:
class: octodns.provider.yaml.YamlProvider
directory: tests/config
strict_supports: False
dump:
class: octodns.provider.yaml.YamlProvider
directory: env/YAML_TMP_DIR
supports_root_ns: False
strict_supports: False
zones:
unit.tests.:
update_pcent_threshold: 0.2
delete_pcent_threshold: 0.1
sources:
- in
targets:
- dump
subzone.unit.tests.:
update_pcent_threshold: 0.02
delete_pcent_threshold: 0.01
sources:
- in
targets:
- dump
+17
View File
@@ -1294,6 +1294,23 @@ class TestManager(TestCase):
requires_dummy.fetch(':hello', None),
)
def test_zone_threshold(self):
with TemporaryDirectory() as tmpdir:
environ['YAML_TMP_DIR'] = tmpdir.dirname
manager = Manager(get_config_filename('zone-threshold.yaml'))
zone = manager.get_zone('unit.tests.')
self.assertEqual(0.2, zone.update_pcent_threshold)
self.assertEqual(0.1, zone.delete_pcent_threshold)
# subzone has different threshold
subzone = manager.get_zone('subzone.unit.tests.')
self.assertEqual(0.02, subzone.update_pcent_threshold)
self.assertEqual(0.01, subzone.delete_pcent_threshold)
class TestMainThreadExecutor(TestCase):
def test_success(self):
+88 -2
View File
@@ -165,8 +165,27 @@ class TestPlanSafety(TestCase):
record_4 = Record.new(
existing, '4', data={'type': 'A', 'ttl': 42, 'value': '1.2.3.4'}
)
record_5 = Record.new(
existing, '5', data={'type': 'A', 'ttl': 42, 'value': '1.2.3.4'}
)
record_6 = Record.new(
existing, '6', data={'type': 'A', 'ttl': 42, 'value': '1.2.3.4'}
)
record_7 = Record.new(
existing, '7', data={'type': 'A', 'ttl': 42, 'value': '1.2.3.4'}
)
record_8 = Record.new(
existing, '8', data={'type': 'A', 'ttl': 42, 'value': '1.2.3.4'}
)
def test_too_many_updates(self):
# manager loads the zone's config, so existing also holds providers & other config
update_threshold = 0.2
delete_threshold = 0.1
existing_with_thresholds = Zone(
'cautious.tests.', [], update_threshold, delete_threshold
)
def test_too_many_provider_updates(self):
existing = self.existing.copy()
changes = []
@@ -206,7 +225,46 @@ class TestPlanSafety(TestCase):
plan = HelperPlan(existing, None, changes, True, min_existing=10)
plan.raise_if_unsafe()
def test_too_many_deletes(self):
def test_too_many_zone_updates(self):
existing = self.existing_with_thresholds.copy()
changes = []
# No records, no changes, we're good
plan = HelperPlan(existing, None, changes, True)
plan.raise_if_unsafe()
# Setup quite a few records, so that
# zone can be more cautious than provider's default
existing.add_record(self.record_1)
existing.add_record(self.record_2)
existing.add_record(self.record_3)
existing.add_record(self.record_4)
existing.add_record(self.record_5)
existing.add_record(self.record_6)
existing.add_record(self.record_7)
existing.add_record(self.record_8)
plan = HelperPlan(existing, None, changes, True)
plan.raise_if_unsafe()
# One update is ok: 12.5% < 20%
changes.append(Update(self.record_1, self.record_1))
plan = HelperPlan(existing, None, changes, True)
plan.raise_if_unsafe()
# Still ok, zone takes precedence
plan = HelperPlan(
existing, None, changes, True, update_pcent_threshold=0
)
plan.raise_if_unsafe()
# Two exceeds threshold, 25% > 20%
changes.append(Update(self.record_2, self.record_2))
plan = HelperPlan(existing, None, changes, True)
with self.assertRaises(TooMuchChange) as ctx:
plan.raise_if_unsafe()
self.assertTrue('Too many updates', str(ctx.exception))
def test_too_many_provider_deletes(self):
existing = self.existing.copy()
changes = []
@@ -246,6 +304,34 @@ class TestPlanSafety(TestCase):
plan = HelperPlan(existing, None, changes, True, min_existing=10)
plan.raise_if_unsafe()
def test_too_many_zone_deletes(self):
existing = self.existing_with_thresholds.copy()
changes = []
# No records, no changes, we're good
plan = HelperPlan(existing, None, changes, True)
plan.raise_if_unsafe()
# Setup quite a few records, so that
# zone can be more cautious than provider's default
existing.add_record(self.record_1)
existing.add_record(self.record_2)
existing.add_record(self.record_3)
existing.add_record(self.record_4)
existing.add_record(self.record_5)
existing.add_record(self.record_6)
existing.add_record(self.record_7)
existing.add_record(self.record_8)
plan = HelperPlan(existing, None, changes, True)
plan.raise_if_unsafe()
# One delete exceeds Zone threshold
changes.append(Delete(self.record_1))
plan = HelperPlan(existing, None, changes, True)
with self.assertRaises(TooMuchChange) as ctx:
plan.raise_if_unsafe()
self.assertTrue('Too many deletes', str(ctx.exception))
def test_root_ns_change(self):
existing = self.existing.copy()
changes = []