Browse Source

Remove the rest of the . ending files, clean up code and tests for better coverage

pull/665/head
Ross McFarland 5 years ago
parent
commit
4ce2563d2e
No known key found for this signature in database GPG Key ID: 61C10C4FC8FE4A89
32 changed files with 30 additions and 23 deletions
  1. +4
    -2
      octodns/provider/yaml.py
  2. +2
    -7
      octodns/source/axfr.py
  3. +3
    -0
      tests/config/simple-split.yaml
  4. +0
    -0
      tests/config/split/dynamic.tests.tst/a.yaml
  5. +0
    -0
      tests/config/split/dynamic.tests.tst/aaaa.yaml
  6. +0
    -0
      tests/config/split/dynamic.tests.tst/cname.yaml
  7. +0
    -0
      tests/config/split/dynamic.tests.tst/real-ish-a.yaml
  8. +0
    -0
      tests/config/split/dynamic.tests.tst/simple-weighted.yaml
  9. +0
    -0
      tests/config/split/empty.tst/.gitkeep
  10. +0
    -0
      tests/config/split/subzone.unit.tests.tst/12.yaml
  11. +0
    -0
      tests/config/split/subzone.unit.tests.tst/2.yaml
  12. +0
    -0
      tests/config/split/subzone.unit.tests.tst/test.yaml
  13. +0
    -0
      tests/config/split/unit.tests.tst/$unit.tests.yaml
  14. +0
    -0
      tests/config/split/unit.tests.tst/_srv._tcp.yaml
  15. +0
    -0
      tests/config/split/unit.tests.tst/aaaa.yaml
  16. +0
    -0
      tests/config/split/unit.tests.tst/cname.yaml
  17. +0
    -0
      tests/config/split/unit.tests.tst/dname.yaml
  18. +0
    -0
      tests/config/split/unit.tests.tst/excluded.yaml
  19. +0
    -0
      tests/config/split/unit.tests.tst/ignored.yaml
  20. +0
    -0
      tests/config/split/unit.tests.tst/included.yaml
  21. +0
    -0
      tests/config/split/unit.tests.tst/mx.yaml
  22. +0
    -0
      tests/config/split/unit.tests.tst/naptr.yaml
  23. +0
    -0
      tests/config/split/unit.tests.tst/ptr.yaml
  24. +0
    -0
      tests/config/split/unit.tests.tst/spf.yaml
  25. +0
    -0
      tests/config/split/unit.tests.tst/sub.yaml
  26. +0
    -0
      tests/config/split/unit.tests.tst/txt.yaml
  27. +0
    -0
      tests/config/split/unit.tests.tst/www.sub.yaml
  28. +0
    -0
      tests/config/split/unit.tests.tst/www.yaml
  29. +0
    -0
      tests/config/split/unordered.tst/abc.yaml
  30. +0
    -0
      tests/config/split/unordered.tst/xyz.yaml
  31. +19
    -12
      tests/test_octodns_provider_yaml.py
  32. +2
    -2
      tests/test_octodns_source_axfr.py

+ 4
- 2
octodns/provider/yaml.py View File

@ -239,11 +239,13 @@ class SplitYamlProvider(YamlProvider):
# instead of a file matching the record name.
CATCHALL_RECORD_NAMES = ('*', '')
def __init__(self, id, directory, *args, **kwargs):
def __init__(self, id, directory, extension='.', *args, **kwargs):
super(SplitYamlProvider, self).__init__(id, directory, *args, **kwargs)
self.extension = extension
def _zone_directory(self, zone):
return join(self.directory, zone.name)
filename = '{}{}'.format(zone.name[:-1], self.extension)
return join(self.directory, filename)
def populate(self, zone, target=False, lenient=False):
self.log.debug('populate: name=%s, target=%s, lenient=%s', zone.name,


+ 2
- 7
octodns/source/axfr.py View File

@ -216,7 +216,7 @@ class ZoneFileSource(AxfrBaseSource):
# (optional, default true)
check_origin: false
'''
def __init__(self, id, directory, file_extension=None, check_origin=True):
def __init__(self, id, directory, file_extension='.', check_origin=True):
self.log = logging.getLogger('ZoneFileSource[{}]'.format(id))
self.log.debug('__init__: id=%s, directory=%s, file_extension=%s, '
'check_origin=%s', id,
@ -229,12 +229,7 @@ class ZoneFileSource(AxfrBaseSource):
self._zone_records = {}
def _load_zone_file(self, zone_name):
zone_filename = zone_name
if self.file_extension:
zone_filename = '{}{}'.format(zone_name,
self.file_extension.lstrip('.'))
zone_filename = '{}{}'.format(zone_name[:-1], self.file_extension)
zonefiles = listdir(self.directory)
if zone_filename in zonefiles:
try:


+ 3
- 0
tests/config/simple-split.yaml View File

@ -4,14 +4,17 @@ providers:
in:
class: octodns.provider.yaml.SplitYamlProvider
directory: tests/config/split
extension: .tst
dump:
class: octodns.provider.yaml.SplitYamlProvider
directory: env/YAML_TMP_DIR
extension: .tst
# This is sort of ugly, but it shouldn't hurt anything. It'll just write out
# the target file twice where it and dump are both used
dump2:
class: octodns.provider.yaml.SplitYamlProvider
directory: env/YAML_TMP_DIR
extension: .tst
simple:
class: helpers.SimpleProvider
geo:


tests/config/split/dynamic.tests./a.yaml → tests/config/split/dynamic.tests.tst/a.yaml View File


tests/config/split/dynamic.tests./aaaa.yaml → tests/config/split/dynamic.tests.tst/aaaa.yaml View File


tests/config/split/dynamic.tests./cname.yaml → tests/config/split/dynamic.tests.tst/cname.yaml View File


tests/config/split/dynamic.tests./real-ish-a.yaml → tests/config/split/dynamic.tests.tst/real-ish-a.yaml View File


tests/config/split/dynamic.tests./simple-weighted.yaml → tests/config/split/dynamic.tests.tst/simple-weighted.yaml View File


tests/config/split/empty./.gitkeep → tests/config/split/empty.tst/.gitkeep View File


tests/config/split/subzone.unit.tests./12.yaml → tests/config/split/subzone.unit.tests.tst/12.yaml View File


tests/config/split/subzone.unit.tests./2.yaml → tests/config/split/subzone.unit.tests.tst/2.yaml View File


tests/config/split/subzone.unit.tests./test.yaml → tests/config/split/subzone.unit.tests.tst/test.yaml View File


tests/config/split/unit.tests./$unit.tests.yaml → tests/config/split/unit.tests.tst/$unit.tests.yaml View File


tests/config/split/unit.tests./_srv._tcp.yaml → tests/config/split/unit.tests.tst/_srv._tcp.yaml View File


tests/config/split/unit.tests./aaaa.yaml → tests/config/split/unit.tests.tst/aaaa.yaml View File


tests/config/split/unit.tests./cname.yaml → tests/config/split/unit.tests.tst/cname.yaml View File


tests/config/split/unit.tests./dname.yaml → tests/config/split/unit.tests.tst/dname.yaml View File


tests/config/split/unit.tests./excluded.yaml → tests/config/split/unit.tests.tst/excluded.yaml View File


tests/config/split/unit.tests./ignored.yaml → tests/config/split/unit.tests.tst/ignored.yaml View File


tests/config/split/unit.tests./included.yaml → tests/config/split/unit.tests.tst/included.yaml View File


tests/config/split/unit.tests./mx.yaml → tests/config/split/unit.tests.tst/mx.yaml View File


tests/config/split/unit.tests./naptr.yaml → tests/config/split/unit.tests.tst/naptr.yaml View File


tests/config/split/unit.tests./ptr.yaml → tests/config/split/unit.tests.tst/ptr.yaml View File


tests/config/split/unit.tests./spf.yaml → tests/config/split/unit.tests.tst/spf.yaml View File


tests/config/split/unit.tests./sub.yaml → tests/config/split/unit.tests.tst/sub.yaml View File


tests/config/split/unit.tests./txt.yaml → tests/config/split/unit.tests.tst/txt.yaml View File


tests/config/split/unit.tests./www.sub.yaml → tests/config/split/unit.tests.tst/www.sub.yaml View File


tests/config/split/unit.tests./www.yaml → tests/config/split/unit.tests.tst/www.yaml View File


tests/config/split/unordered./abc.yaml → tests/config/split/unordered.tst/abc.yaml View File


tests/config/split/unordered./xyz.yaml → tests/config/split/unordered.tst/xyz.yaml View File


+ 19
- 12
tests/test_octodns_provider_yaml.py View File

@ -207,18 +207,20 @@ class TestSplitYamlProvider(TestCase):
def test_zone_directory(self):
source = SplitYamlProvider(
'test', join(dirname(__file__), 'config/split'))
'test', join(dirname(__file__), 'config/split'),
extension='.tst')
zone = Zone('unit.tests.', [])
self.assertEqual(
join(dirname(__file__), 'config/split/unit.tests.'),
join(dirname(__file__), 'config/split/unit.tests.tst'),
source._zone_directory(zone))
def test_apply_handles_existing_zone_directory(self):
with TemporaryDirectory() as td:
provider = SplitYamlProvider('test', join(td.dirname, 'config'))
makedirs(join(td.dirname, 'config', 'does.exist.'))
provider = SplitYamlProvider('test', join(td.dirname, 'config'),
extension='.tst')
makedirs(join(td.dirname, 'config', 'does.exist.tst'))
zone = Zone('does.exist.', [])
self.assertTrue(isdir(provider._zone_directory(zone)))
@ -227,7 +229,8 @@ class TestSplitYamlProvider(TestCase):
def test_provider(self):
source = SplitYamlProvider(
'test', join(dirname(__file__), 'config/split'))
'test', join(dirname(__file__), 'config/split'),
extension='.tst')
zone = Zone('unit.tests.', [])
dynamic_zone = Zone('dynamic.tests.', [])
@ -246,9 +249,10 @@ class TestSplitYamlProvider(TestCase):
with TemporaryDirectory() as td:
# Add some subdirs to make sure that it can create them
directory = join(td.dirname, 'sub', 'dir')
zone_dir = join(directory, 'unit.tests.')
dynamic_zone_dir = join(directory, 'dynamic.tests.')
target = SplitYamlProvider('test', directory)
zone_dir = join(directory, 'unit.tests.tst')
dynamic_zone_dir = join(directory, 'dynamic.tests.tst')
target = SplitYamlProvider('test', directory,
extension='.tst')
# We add everything
plan = target.plan(zone)
@ -335,7 +339,8 @@ class TestSplitYamlProvider(TestCase):
def test_empty(self):
source = SplitYamlProvider(
'test', join(dirname(__file__), 'config/split'))
'test', join(dirname(__file__), 'config/split'),
extension='.tst')
zone = Zone('empty.', [])
@ -345,7 +350,8 @@ class TestSplitYamlProvider(TestCase):
def test_unsorted(self):
source = SplitYamlProvider(
'test', join(dirname(__file__), 'config/split'))
'test', join(dirname(__file__), 'config/split'),
extension='.tst')
zone = Zone('unordered.', [])
@ -356,14 +362,15 @@ class TestSplitYamlProvider(TestCase):
source = SplitYamlProvider(
'test', join(dirname(__file__), 'config/split'),
enforce_order=False)
extension='.tst', enforce_order=False)
# no exception
source.populate(zone)
self.assertEqual(2, len(zone.records))
def test_subzone_handling(self):
source = SplitYamlProvider(
'test', join(dirname(__file__), 'config/split'))
'test', join(dirname(__file__), 'config/split'),
extension='.tst')
# If we add `sub` as a sub-zone we'll reject `www.sub`
zone = Zone('unit.tests.', ['sub'])


+ 2
- 2
tests/test_octodns_source_axfr.py View File

@ -46,10 +46,10 @@ class TestAxfrSource(TestCase):
class TestZoneFileSource(TestCase):
source = ZoneFileSource('test', './tests/zones', file_extension='tst')
source = ZoneFileSource('test', './tests/zones', file_extension='.tst')
def test_zonefiles_with_extension(self):
source = ZoneFileSource('test', './tests/zones', 'extension')
source = ZoneFileSource('test', './tests/zones', '.extension')
# Load zonefiles with a specified file extension
valid = Zone('ext.unit.tests.', [])
source.populate(valid)


Loading…
Cancel
Save