Browse Source

Restore Manager.sync's eligible_zones parameter as it's useful for cases like octodsn-api

zone-config-cleanup
Ross McFarland 2 months ago
parent
commit
425e34e27c
No known key found for this signature in database GPG Key ID: 943B179E15D3B22A
2 changed files with 43 additions and 4 deletions
  1. +15
    -4
      octodns/manager.py
  2. +28
    -0
      tests/test_octodns_manager.py

+ 15
- 4
octodns/manager.py View File

@ -703,24 +703,35 @@ class Manager(object):
return sources
def sync(
self, dry_run=True, force=False, plan_output_fh=stdout, checksum=None
self,
dry_run=True,
force=False,
plan_output_fh=stdout,
checksum=None,
eligible_zones=None,
):
self.log.info(
'sync: dry_run=%s, force=%s, plan_output_fh=%s, checksum=%s',
'sync: dry_run=%s, force=%s, plan_output_fh=%s, checksum=%s, eligible_zones=%s',
dry_run,
force,
getattr(plan_output_fh, 'name', plan_output_fh.__class__.__name__),
checksum,
eligible_zones,
)
zones = self.zones
if eligible_zones:
zones = IdnaDict({n: zones.get(n) for n in eligible_zones})
includes_arpa = any(e.endswith('arpa.') for e in zones.keys())
if self.auto_arpa and includes_arpa:
# it's not safe to mess with auto_arpa when we don't have a complete
# picture of records, so if any filtering is happening while arpa
# zones are in play we need to abort
if any(e.endswith('arpa.') for e in (self.active_zones or [])):
# zones are in play we need to abort. If eligible or active are present
# we are filtering.
target_zones = eligible_zones or self.active_zones or []
if any(e.endswith('arpa.') for e in target_zones):
raise ManagerException(
'ARPA zones cannot be synced during partial runs when auto_arpa is enabled'
)


+ 28
- 0
tests/test_octodns_manager.py View File

@ -311,6 +311,15 @@ class TestManager(TestCase):
).sync()
self.assertEqual(0, tc)
def test_eligible_zones(self):
with TemporaryDirectory() as tmpdir:
environ['YAML_TMP_DIR'] = tmpdir.dirname
environ['YAML_TMP_DIR2'] = tmpdir.dirname
# Test eligible_zones parameter for runtime filtering
manager = Manager(get_config_filename('simple.yaml'))
tc = manager.sync(eligible_zones=['unit.tests.'], dry_run=False)
self.assertEqual(22, tc)
def test_aliases(self):
with TemporaryDirectory() as tmpdir:
environ['YAML_TMP_DIR'] = tmpdir.dirname
@ -1094,6 +1103,25 @@ class TestManager(TestCase):
str(ctx.exception),
)
# same for eligible_zones parameter
reset(tmpdir.dirname)
manager.active_zones = None
manager.active_sources = None
manager.active_targets = None
manager._zones = None
tc = manager.sync(eligible_zones=['unit.tests.'], dry_run=False)
self.assertEqual(22, tc)
# can't do partial syncs that include arpa zones via eligible_zones
with self.assertRaises(ManagerException) as ctx:
manager.sync(
eligible_zones=['unit.tests.', '3.2.2.in-addr.arpa.'],
dry_run=False,
)
self.assertEqual(
'ARPA zones cannot be synced during partial runs when auto_arpa is enabled',
str(ctx.exception),
)
# full sync with arpa is fine, 2 extra records from it
reset(tmpdir.dirname)
manager.active_zones = None


Loading…
Cancel
Save