Browse Source

Revert "yaml provider is either split or zonefile, not both"

This reverts commit 6f39fcc5f7.
pull/1044/head
Ross McFarland 2 years ago
parent
commit
8177ee6926
No known key found for this signature in database GPG Key ID: 943B179E15D3B22A
2 changed files with 62 additions and 8 deletions
  1. +19
    -5
      octodns/provider/yaml.py
  2. +43
    -3
      tests/test_octodns_provider_yaml.py

+ 19
- 5
octodns/provider/yaml.py View File

@ -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'
)

+ 43
- 3
tests/test_octodns_provider_yaml.py View File

@ -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(


Loading…
Cancel
Save