Browse Source

Include sources only if they exist

pull/1067/head
Viranch Mehta 2 years ago
parent
commit
0181158953
No known key found for this signature in database GPG Key ID: D83D1392AE9F93B4
5 changed files with 44 additions and 3 deletions
  1. +14
    -3
      octodns/provider/yaml.py
  2. +4
    -0
      tests/config/hybrid/one.test.yaml
  3. +4
    -0
      tests/config/hybrid/two.test./$two.test.yaml
  4. +4
    -0
      tests/config/hybrid/two.test./split-zone-file.yaml
  5. +18
    -0
      tests/test_octodns_provider_yaml.py

+ 14
- 3
octodns/provider/yaml.py View File

@ -278,8 +278,10 @@ class YamlProvider(BaseProvider):
f'Both UTF-8 "{utf8}" and IDNA "{idna}" exist for {zone.decoded_name}'
)
directory = utf8
else:
elif isdir(idna):
directory = idna
else:
return []
for filename in listdir(directory):
if filename.endswith('.yaml'):
@ -294,8 +296,10 @@ class YamlProvider(BaseProvider):
f'Both UTF-8 "{utf8}" and IDNA "{idna}" exist for {zone.decoded_name}'
)
return utf8
elif isfile(idna):
return idna
return idna
return None
def _populate_from_file(self, filename, zone, lenient):
with open(filename, 'r') as fh:
@ -341,11 +345,18 @@ class YamlProvider(BaseProvider):
sources.extend(self._split_sources(zone))
if not self.disable_zonefile:
sources.append(self._zone_sources(zone))
source = self._zone_sources(zone)
if source:
sources.append(self._zone_sources(zone))
if self.shared_filename:
sources.append(join(self.directory, self.shared_filename))
if not sources:
self.log.info(
'populate: no YAMLs found for %s', zone.decoded_name
)
# determinstically order our sources
sources.sort()


+ 4
- 0
tests/config/hybrid/one.test.yaml View File

@ -0,0 +1,4 @@
---
flat-zone-file:
type: TXT
value: non-split flat zone file

+ 4
- 0
tests/config/hybrid/two.test./$two.test.yaml View File

@ -0,0 +1,4 @@
---
'':
type: TXT
value: root TXT

+ 4
- 0
tests/config/hybrid/two.test./split-zone-file.yaml View File

@ -0,0 +1,4 @@
---
split-zone-file:
type: TXT
value: split zone file

+ 18
- 0
tests/test_octodns_provider_yaml.py View File

@ -760,6 +760,24 @@ class TestSplitYamlProvider(TestCase):
sorted(provider.list_zones()),
)
def test_hybrid_directory(self):
source = YamlProvider(
'test',
join(dirname(__file__), 'config/hybrid'),
split_extension='.',
strict_supports=False,
)
# flat zone file only
zone = Zone('one.test.', [])
source.populate(zone)
self.assertEqual(1, len(zone.records))
# split zone only
zone = Zone('two.test.', [])
source.populate(zone)
self.assertEqual(2, len(zone.records))
class TestOverridingYamlProvider(TestCase):
def test_provider(self):


Loading…
Cancel
Save