From cb28fa0e26885180391af85bc327f40a33b156e4 Mon Sep 17 00:00:00 2001 From: Ross McFarland Date: Fri, 18 Aug 2023 16:20:53 -0700 Subject: [PATCH] YamlProvider support for shared file, loaded into all zones --- octodns/provider/yaml.py | 13 ++++++++++++- tests/config/split/unit.tests.yaml | 1 - tests/test_octodns_provider_yaml.py | 17 +++++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/octodns/provider/yaml.py b/octodns/provider/yaml.py index 1be77d2..3bba1b6 100644 --- a/octodns/provider/yaml.py +++ b/octodns/provider/yaml.py @@ -57,6 +57,11 @@ class YamlProvider(BaseProvider): # (optional, default False) split_catchall: false + # Optional filename with record data to be included in all zones + # populated by this provider. Has no effect when used as a target. + # (optional, default null) + shared_filename: null + # Disable loading of the zone .yaml files. # (optional, default False) disable_zonefile: false @@ -171,6 +176,7 @@ class YamlProvider(BaseProvider): supports_root_ns=True, split_extension=False, split_catchall=False, + shared_filename=False, disable_zonefile=False, *args, **kwargs, @@ -178,7 +184,7 @@ class YamlProvider(BaseProvider): klass = self.__class__.__name__ self.log = logging.getLogger(f'{klass}[{id}]') self.log.debug( - '__init__: id=%s, directory=%s, default_ttl=%d, enforce_order=%d, populate_should_replace=%s, supports_root_ns=%s, split_extension=%s, split_catchall=%s, disable_zonefile=%s', + '__init__: id=%s, directory=%s, default_ttl=%d, enforce_order=%d, populate_should_replace=%s, supports_root_ns=%s, split_extension=%s, split_catchall=%s, shared_filename=%s, disable_zonefile=%s', id, directory, default_ttl, @@ -187,6 +193,7 @@ class YamlProvider(BaseProvider): supports_root_ns, split_extension, split_catchall, + shared_filename, disable_zonefile, ) super().__init__(id, *args, **kwargs) @@ -197,6 +204,7 @@ class YamlProvider(BaseProvider): self.supports_root_ns = supports_root_ns self.split_extension = split_extension self.split_catchall = split_catchall + self.shared_filename = shared_filename self.disable_zonefile = disable_zonefile def copy(self): @@ -334,6 +342,9 @@ class YamlProvider(BaseProvider): if not self.disable_zonefile: sources.append(self._zone_sources(zone)) + if self.shared_filename: + sources.append(join(self.directory, self.shared_filename)) + # determinstically order our sources sources.sort() diff --git a/tests/config/split/unit.tests.yaml b/tests/config/split/unit.tests.yaml index e249c43..1a25149 100644 --- a/tests/config/split/unit.tests.yaml +++ b/tests/config/split/unit.tests.yaml @@ -2,4 +2,3 @@ only-zone-file: type: TXT value: Only included when zone file processing is enabled - diff --git a/tests/test_octodns_provider_yaml.py b/tests/test_octodns_provider_yaml.py index ae05b8f..0dc46f3 100644 --- a/tests/test_octodns_provider_yaml.py +++ b/tests/test_octodns_provider_yaml.py @@ -511,6 +511,23 @@ class TestSplitYamlProvider(TestCase): self.assertEqual(1, n) source.disable_zonefile = True + # temporarily enable shared file processing, we should see one extra + # record in the zone + source.shared_filename = 'shared.yaml' + zone_shared = Zone('unit.tests.', []) + source.populate(zone_shared) + self.assertEqual(21, len(zone_shared.records)) + n = len([r for r in zone_shared.records if r.name == 'only-shared']) + self.assertEqual(1, n) + dynamic_zone_shared = Zone('dynamic.tests.', []) + source.populate(dynamic_zone_shared) + self.assertEqual(6, len(dynamic_zone_shared.records)) + n = len( + [r for r in dynamic_zone_shared.records if r.name == 'only-shared'] + ) + self.assertEqual(1, n) + source.shared_filename = None + source.populate(dynamic_zone) self.assertEqual(5, len(dynamic_zone.records)) self.assertFalse(