From 8177ee6926648bb8dd69788374167b3bf97b4020 Mon Sep 17 00:00:00 2001 From: Ross McFarland Date: Tue, 29 Aug 2023 12:59:38 -0700 Subject: [PATCH] Revert "yaml provider is either split or zonefile, not both" This reverts commit 6f39fcc5f7f29d83c8cb6e59904829c89454e032. --- octodns/provider/yaml.py | 24 +++++++++++---- tests/test_octodns_provider_yaml.py | 46 +++++++++++++++++++++++++++-- 2 files changed, 62 insertions(+), 8 deletions(-) diff --git a/octodns/provider/yaml.py b/octodns/provider/yaml.py index 2d4ee81..d340bc6 100644 --- a/octodns/provider/yaml.py +++ b/octodns/provider/yaml.py @@ -58,6 +58,10 @@ class YamlProvider(BaseProvider): # (optional, default True) split_catchall: true + # Disable loading of the zone .yaml files. + # (optional, default False) + disable_zonefile: false + Split Details ------------- @@ -168,13 +172,14 @@ class YamlProvider(BaseProvider): supports_root_ns=True, split_extension=False, split_catchall=True, + disable_zonefile=False, *args, **kwargs, ): 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', + '__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', id, directory, default_ttl, @@ -183,6 +188,7 @@ class YamlProvider(BaseProvider): supports_root_ns, split_extension, split_catchall, + disable_zonefile, ) super().__init__(id, *args, **kwargs) self.directory = directory @@ -192,6 +198,7 @@ class YamlProvider(BaseProvider): self.supports_root_ns = supports_root_ns self.split_extension = split_extension self.split_catchall = split_catchall + self.disable_zonefile = disable_zonefile def copy(self): kwargs = dict(self.__dict__) @@ -239,7 +246,7 @@ class YamlProvider(BaseProvider): dirname = dirname[:-trim] zones.add(dirname) - if not self.split_extension: + if not self.disable_zonefile: self.log.debug('list_zones: looking for zone files') for filename in listdir(self.directory): not_ends_with = not filename.endswith('.yaml') @@ -325,7 +332,7 @@ class YamlProvider(BaseProvider): if split_extension: sources.extend(self._split_sources(zone)) - if not self.split_extension: + if not self.disable_zonefile: sources.append(self._zone_sources(zone)) # determinstically order our sources @@ -425,13 +432,20 @@ class SplitYamlProvider(YamlProvider): # extension is configured as split_extension split_extension: . split_catchall: true + disable_zonefile: true TO BE REMOVED: 2.0 ''' def __init__(self, id, directory, *args, extension='.', **kwargs): - kwargs.update({'split_extension': extension, 'split_catchall': True}) + kwargs.update( + { + 'split_extension': extension, + 'split_catchall': True, + 'disable_zonefile': True, + } + ) super().__init__(id, directory, *args, **kwargs) self.log.warning( - '__init__: DEPRECATED use YamlProvider with split_extension and split_catchall instead, will go away in v2.0' + '__init__: DEPRECATED use YamlProvider with split_extension, split_catchall, and disable_zonefile instead, will go away in v2.0' ) diff --git a/tests/test_octodns_provider_yaml.py b/tests/test_octodns_provider_yaml.py index 814eb81..a41a417 100644 --- a/tests/test_octodns_provider_yaml.py +++ b/tests/test_octodns_provider_yaml.py @@ -348,20 +348,50 @@ xn--dj-kia8a: list(provider.list_zones()), ) - # split only . + # include stuff with . AND basic provider.split_extension = '.' self.assertEqual( - ['both.tld.', 'other.split.', 'split.test.', 'sub.split.test.'], + [ + 'both.tld.', + 'other.split.', + 'other.tld.', + 'split.test.', + 'sub.split.test.', + 'sub.unit.test.', + 'unit.test.', + ], list(provider.list_zones()), ) - # only .tst + # include stuff with .tst AND basic provider.split_extension = '.tst' + self.assertEqual( + [ + 'both.tld.', + 'other-ext.split.', + 'other.tld.', + 'split-ext.test.', + 'sub.split-ext.test.', + 'sub.unit.test.', + 'unit.test.', + ], + list(provider.list_zones()), + ) + + # only .tst + provider.disable_zonefile = True self.assertEqual( ['other-ext.split.', 'split-ext.test.', 'sub.split-ext.test.'], list(provider.list_zones()), ) + # only . (and both zone) + provider.split_extension = '.' + self.assertEqual( + ['both.tld.', 'other.split.', 'split.test.', 'sub.split.test.'], + list(provider.list_zones()), + ) + def test_split_sources(self): with TemporaryDirectory() as td: directory = join(td.dirname) @@ -474,6 +504,16 @@ class TestSplitYamlProvider(TestCase): self.assertEqual(20, len(zone.records)) self.assertFalse([r for r in zone.records if r.name.startswith('only')]) + # temporarily enable zone file processing too, we should see one extra + # record that came from unit.tests. + source.disable_zonefile = False + zone_both = Zone('unit.tests.', []) + source.populate(zone_both) + self.assertEqual(21, len(zone_both.records)) + n = len([r for r in zone_both.records if r.name == 'only-zone-file']) + self.assertEqual(1, n) + source.disable_zonefile = True + source.populate(dynamic_zone) self.assertEqual(5, len(dynamic_zone.records)) self.assertFalse(