mirror of
https://github.com/github/octodns.git
synced 2024-05-11 05:55:00 +00:00
Include sources only if they exist
This commit is contained in:
@@ -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
tests/config/hybrid/one.test.yaml
Normal file
4
tests/config/hybrid/one.test.yaml
Normal file
@@ -0,0 +1,4 @@
|
||||
---
|
||||
flat-zone-file:
|
||||
type: TXT
|
||||
value: non-split flat zone file
|
||||
4
tests/config/hybrid/two.test./$two.test.yaml
Normal file
4
tests/config/hybrid/two.test./$two.test.yaml
Normal file
@@ -0,0 +1,4 @@
|
||||
---
|
||||
'':
|
||||
type: TXT
|
||||
value: root TXT
|
||||
4
tests/config/hybrid/two.test./split-zone-file.yaml
Normal file
4
tests/config/hybrid/two.test./split-zone-file.yaml
Normal file
@@ -0,0 +1,4 @@
|
||||
---
|
||||
split-zone-file:
|
||||
type: TXT
|
||||
value: split zone 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):
|
||||
|
||||
Reference in New Issue
Block a user