From 68e1178ac772d73d0cd9c124ee5f3db092e2a5fd Mon Sep 17 00:00:00 2001 From: Martin Frausing Date: Fri, 5 Jan 2024 13:59:49 +0100 Subject: [PATCH] Add list_zones to AutoArpa - This makes it possible to use dynamic zone config with AutoArpa - Document what gotchas that entails - Add tests both with another source (for generating zones to populate) and without (no zones to populate) --- docs/auto_arpa.md | 19 ++++++++++++ octodns/processor/arpa.py | 3 ++ .../config/dynamic-arpa-no-normal-source.yaml | 29 ++++++++++++++++++ tests/config/dynamic-arpa.yaml | 30 +++++++++++++++++++ .../dynamic-arpa/3.2.2.in-addr.arpa.yaml | 0 ....2.e.0.0.5.0.4.4.6.0.1.0.6.2.ip6.arpa.yaml | 0 tests/config/dynamic-arpa/unit.tests.yaml | 17 +++++++++++ tests/test_octodns_manager.py | 20 +++++++++++++ 8 files changed, 118 insertions(+) create mode 100644 tests/config/dynamic-arpa-no-normal-source.yaml create mode 100644 tests/config/dynamic-arpa.yaml create mode 100644 tests/config/dynamic-arpa/3.2.2.in-addr.arpa.yaml create mode 100644 tests/config/dynamic-arpa/b.e.f.f.f.d.1.8.f.2.6.0.1.2.e.0.0.5.0.4.4.6.0.1.0.6.2.ip6.arpa.yaml create mode 100644 tests/config/dynamic-arpa/unit.tests.yaml diff --git a/docs/auto_arpa.md b/docs/auto_arpa.md index a8cb00a..5539a29 100644 --- a/docs/auto_arpa.md +++ b/docs/auto_arpa.md @@ -100,3 +100,22 @@ fileserver: ### Notes Automatic `PTR` generation requires a "complete" picture of records and thus cannot be done during partial syncs. Thus syncing `arpa.` zones will throw an error any time filtering of zones, targets, or sources is being done. + +#### AutoArpa and Dynamic Zone Config + +The AutoArpa provider works with Dynamic Zone Config, but only in the sense that it doesn't stop it from working. It requires another provider to actually generate the list of zones. It could be the Yaml provider like so: + +```yaml +example.com.: + sources: + - config + targets: + - ... +"*.arpa.": + sources: + - config + - auto-arpa + targets: + - ... +``` +That would take all the relevant records from example.com and add them as PTR records for the arpa zones in the same place as the 'config' source specifies. diff --git a/octodns/processor/arpa.py b/octodns/processor/arpa.py index 7de4c1c..960fb55 100644 --- a/octodns/processor/arpa.py +++ b/octodns/processor/arpa.py @@ -72,3 +72,6 @@ class AutoArpa(BaseProcessor): self.log.info( 'populate: found %s records', len(zone.records) - before ) + + def list_zones(self): + return set() diff --git a/tests/config/dynamic-arpa-no-normal-source.yaml b/tests/config/dynamic-arpa-no-normal-source.yaml new file mode 100644 index 0000000..170a823 --- /dev/null +++ b/tests/config/dynamic-arpa-no-normal-source.yaml @@ -0,0 +1,29 @@ +manager: + max_workers: 2 + auto_arpa: + populate_should_replace: True + ttl: 1800 + +providers: + in: + class: octodns.provider.yaml.YamlProvider + directory: tests/config/dynamic-arpa + supports_root_ns: False + strict_supports: False + dump: + class: octodns.provider.yaml.YamlProvider + directory: env/YAML_TMP_DIR + default_ttl: 999 + supports_root_ns: False + strict_supports: False +zones: + unit.tests.: + sources: + - in + targets: + - dump + "*.arpa.": + sources: + - auto-arpa + targets: + - dump diff --git a/tests/config/dynamic-arpa.yaml b/tests/config/dynamic-arpa.yaml new file mode 100644 index 0000000..f57d259 --- /dev/null +++ b/tests/config/dynamic-arpa.yaml @@ -0,0 +1,30 @@ +manager: + max_workers: 2 + auto_arpa: + populate_should_replace: True + ttl: 1800 + +providers: + in: + class: octodns.provider.yaml.YamlProvider + directory: tests/config/dynamic-arpa + supports_root_ns: False + strict_supports: False + dump: + class: octodns.provider.yaml.YamlProvider + directory: env/YAML_TMP_DIR + default_ttl: 999 + supports_root_ns: False + strict_supports: False +zones: + unit.tests.: + sources: + - in + targets: + - dump + "*.arpa.": + sources: + - in + - auto-arpa + targets: + - dump diff --git a/tests/config/dynamic-arpa/3.2.2.in-addr.arpa.yaml b/tests/config/dynamic-arpa/3.2.2.in-addr.arpa.yaml new file mode 100644 index 0000000..e69de29 diff --git a/tests/config/dynamic-arpa/b.e.f.f.f.d.1.8.f.2.6.0.1.2.e.0.0.5.0.4.4.6.0.1.0.6.2.ip6.arpa.yaml b/tests/config/dynamic-arpa/b.e.f.f.f.d.1.8.f.2.6.0.1.2.e.0.0.5.0.4.4.6.0.1.0.6.2.ip6.arpa.yaml new file mode 100644 index 0000000..e69de29 diff --git a/tests/config/dynamic-arpa/unit.tests.yaml b/tests/config/dynamic-arpa/unit.tests.yaml new file mode 100644 index 0000000..952e319 --- /dev/null +++ b/tests/config/dynamic-arpa/unit.tests.yaml @@ -0,0 +1,17 @@ +--- +aaaa: + ttl: 600 + type: AAAA + value: 2601:644:500:e210:62f8:1dff:feb8:947a +not-a-zone-file: + ttl: 300 + type: A + value: 3.3.3.6 +www: + ttl: 300 + type: A + value: 2.2.3.6 +www.sub: + ttl: 300 + type: A + value: 2.2.3.7 diff --git a/tests/test_octodns_manager.py b/tests/test_octodns_manager.py index a369b1b..5283769 100644 --- a/tests/test_octodns_manager.py +++ b/tests/test_octodns_manager.py @@ -1099,6 +1099,26 @@ class TestManager(TestCase): # should sync everything across all zones, total of 32 records self.assertEqual(32, manager.sync(dry_run=False)) + def test_dynamic_config_with_arpa(self): + with TemporaryDirectory() as tmpdir: + environ['YAML_TMP_DIR'] = tmpdir.dirname + manager = Manager(get_config_filename('dynamic-arpa.yaml')) + + # should sync everything across all zones, total of 7 records + # 4 normal records and 3 arpa records generated + self.assertEqual(4 + 3, manager.sync(dry_run=False)) + + def test_dynamic_config_with_arpa_no_normal_source(self): + with TemporaryDirectory() as tmpdir: + environ['YAML_TMP_DIR'] = tmpdir.dirname + manager = Manager( + get_config_filename('dynamic-arpa-no-normal-source.yaml') + ) + + # should sync everything across all zones, total of 4 records + # 4 normal records and 0 arpa records generated since no zones to populate was found + self.assertEqual(4, manager.sync(dry_run=False)) + def test_dynamic_config_unsupported_zone(self): manager = Manager( get_config_filename('dynamic-config-no-list-zones.yaml')