Browse Source

Merge branch 'master' into making-changes-info

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

+ 2
- 1
.gitignore View File

@ -5,8 +5,8 @@
*.pyc
.coverage
.env
/config/
/build/
/config/
coverage.xml
dist/
env/
@ -14,4 +14,5 @@ htmlcov/
nosetests.xml
octodns.egg-info/
output/
tests/zones/unit.tests.
tmp/

+ 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'])


+ 25
- 3
tests/test_octodns_source_axfr.py View File

@ -9,6 +9,8 @@ import dns.zone
from dns.exception import DNSException
from mock import patch
from os.path import exists
from shutil import copyfile
from six import text_type
from unittest import TestCase
@ -21,7 +23,7 @@ from octodns.record import ValidationError
class TestAxfrSource(TestCase):
source = AxfrSource('test', 'localhost')
forward_zonefile = dns.zone.from_file('./tests/zones/unit.tests.',
forward_zonefile = dns.zone.from_file('./tests/zones/unit.tests.tst',
'unit.tests', relativize=False)
@patch('dns.zone.from_xfr')
@ -44,15 +46,35 @@ class TestAxfrSource(TestCase):
class TestZoneFileSource(TestCase):
source = ZoneFileSource('test', './tests/zones')
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)
self.assertEquals(1, len(valid.records))
def test_zonefiles_without_extension(self):
# Windows doesn't let files end with a `.` so we add a .tst to them in
# the repo and then try and create the `.` version we need for the
# default case (no extension.)
copyfile('./tests/zones/unit.tests.tst', './tests/zones/unit.tests.')
# Unfortunately copyfile silently works and create the file without
# the `.` so we have to check to see if it did that
if exists('./tests/zones/unit.tests'):
# It did so we need to skip this test, that means windows won't
# have full code coverage, but skipping the test is going out of
# our way enough for a os-specific/oddball case.
self.skipTest('Unable to create unit.tests. (ending with .) so '
'skipping default filename testing.')
source = ZoneFileSource('test', './tests/zones')
# Load zonefiles without a specified file extension
valid = Zone('unit.tests.', [])
source.populate(valid)
self.assertEquals(12, len(valid.records))
def test_populate(self):
# Valid zone file in directory
valid = Zone('unit.tests.', [])


tests/zones/invalid.records. → tests/zones/invalid.records.tst View File


tests/zones/invalid.zone. → tests/zones/invalid.zone.tst View File


tests/zones/unit.tests. → tests/zones/unit.tests.tst View File


Loading…
Cancel
Save