Browse Source

YamlProvider support for shared file, loaded into all zones

pull/1048/head
Ross McFarland 2 years ago
parent
commit
cb28fa0e26
No known key found for this signature in database GPG Key ID: 943B179E15D3B22A
3 changed files with 29 additions and 2 deletions
  1. +12
    -1
      octodns/provider/yaml.py
  2. +0
    -1
      tests/config/split/unit.tests.yaml
  3. +17
    -0
      tests/test_octodns_provider_yaml.py

+ 12
- 1
octodns/provider/yaml.py View File

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


+ 0
- 1
tests/config/split/unit.tests.yaml View File

@ -2,4 +2,3 @@
only-zone-file:
type: TXT
value: Only included when zone file processing is enabled

+ 17
- 0
tests/test_octodns_provider_yaml.py View File

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


Loading…
Cancel
Save