Browse Source

dump output_provider testing

pull/898/head
Ross McFarland 4 years ago
parent
commit
0d606e0728
No known key found for this signature in database GPG Key ID: 943B179E15D3B22A
4 changed files with 93 additions and 4 deletions
  1. +2
    -2
      octodns/manager.py
  2. +2
    -1
      tests/config/simple.yaml
  3. +62
    -1
      tests/test_octodns_manager.py
  4. +27
    -0
      tests/test_octodns_provider_yaml.py

+ 2
- 2
octodns/manager.py View File

@ -572,12 +572,12 @@ class Manager(object):
raise ManagerException(f'Unknown output_provider: {e.args[0]}') raise ManagerException(f'Unknown output_provider: {e.args[0]}')
if not hasattr(target, 'directory'): if not hasattr(target, 'directory'):
msg = f'output_provider={output_provider}, does not support ' \ msg = f'output_provider={output_provider}, does not support ' \
'directory'
'directory property'
raise ManagerException(msg) raise ManagerException(msg)
if target.directory != output_dir: if target.directory != output_dir:
if not hasattr(target, 'copy'): if not hasattr(target, 'copy'):
msg = f'output_provider={output_provider}, does not ' \ msg = f'output_provider={output_provider}, does not ' \
'support copy'
'support copy method'
raise ManagerException(msg) raise ManagerException(msg)
target = target.copy() target = target.copy()
self.log.info('dump: setting directory of output_provider ' self.log.info('dump: setting directory of output_provider '


+ 2
- 1
tests/config/simple.yaml View File

@ -8,12 +8,13 @@ providers:
dump: dump:
class: octodns.provider.yaml.YamlProvider class: octodns.provider.yaml.YamlProvider
directory: env/YAML_TMP_DIR directory: env/YAML_TMP_DIR
default_ttl: 999
supports_root_ns: False supports_root_ns: False
# This is sort of ugly, but it shouldn't hurt anything. It'll just write out # 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 # the target file twice where it and dump are both used
dump2: dump2:
class: octodns.provider.yaml.YamlProvider class: octodns.provider.yaml.YamlProvider
directory: env/YAML_TMP_DIR
directory: env/YAML_TMP_DIR2
supports_root_ns: False supports_root_ns: False
simple: simple:
class: helpers.SimpleProvider class: helpers.SimpleProvider


+ 62
- 1
tests/test_octodns_manager.py View File

@ -6,7 +6,7 @@ from __future__ import absolute_import, division, print_function, \
unicode_literals unicode_literals
from os import environ from os import environ
from os.path import dirname, join
from os.path import dirname, isfile, join
from octodns import __VERSION__ from octodns import __VERSION__
from octodns.manager import _AggregateTarget, MainThreadExecutor, Manager, \ from octodns.manager import _AggregateTarget, MainThreadExecutor, Manager, \
@ -111,6 +111,7 @@ class TestManager(TestCase):
def test_always_dry_run(self): def test_always_dry_run(self):
with TemporaryDirectory() as tmpdir: with TemporaryDirectory() as tmpdir:
environ['YAML_TMP_DIR'] = tmpdir.dirname environ['YAML_TMP_DIR'] = tmpdir.dirname
environ['YAML_TMP_DIR2'] = tmpdir.dirname
tc = Manager(get_config_filename('always-dry-run.yaml')) \ tc = Manager(get_config_filename('always-dry-run.yaml')) \
.sync(dry_run=False) .sync(dry_run=False)
# only the stuff from subzone, unit.tests. is always-dry-run # only the stuff from subzone, unit.tests. is always-dry-run
@ -119,6 +120,7 @@ class TestManager(TestCase):
def test_simple(self): def test_simple(self):
with TemporaryDirectory() as tmpdir: with TemporaryDirectory() as tmpdir:
environ['YAML_TMP_DIR'] = tmpdir.dirname environ['YAML_TMP_DIR'] = tmpdir.dirname
environ['YAML_TMP_DIR2'] = tmpdir.dirname
tc = Manager(get_config_filename('simple.yaml')) \ tc = Manager(get_config_filename('simple.yaml')) \
.sync(dry_run=False) .sync(dry_run=False)
self.assertEqual(26, tc) self.assertEqual(26, tc)
@ -157,6 +159,7 @@ class TestManager(TestCase):
def test_eligible_sources(self): def test_eligible_sources(self):
with TemporaryDirectory() as tmpdir: with TemporaryDirectory() as tmpdir:
environ['YAML_TMP_DIR'] = tmpdir.dirname environ['YAML_TMP_DIR'] = tmpdir.dirname
environ['YAML_TMP_DIR2'] = tmpdir.dirname
# Only allow a target that doesn't exist # Only allow a target that doesn't exist
tc = Manager(get_config_filename('simple.yaml')) \ tc = Manager(get_config_filename('simple.yaml')) \
.sync(eligible_sources=['foo']) .sync(eligible_sources=['foo'])
@ -165,6 +168,7 @@ class TestManager(TestCase):
def test_eligible_targets(self): def test_eligible_targets(self):
with TemporaryDirectory() as tmpdir: with TemporaryDirectory() as tmpdir:
environ['YAML_TMP_DIR'] = tmpdir.dirname environ['YAML_TMP_DIR'] = tmpdir.dirname
environ['YAML_TMP_DIR2'] = tmpdir.dirname
# Only allow a target that doesn't exist # Only allow a target that doesn't exist
tc = Manager(get_config_filename('simple.yaml')) \ tc = Manager(get_config_filename('simple.yaml')) \
.sync(eligible_targets=['foo']) .sync(eligible_targets=['foo'])
@ -173,6 +177,7 @@ class TestManager(TestCase):
def test_aliases(self): def test_aliases(self):
with TemporaryDirectory() as tmpdir: with TemporaryDirectory() as tmpdir:
environ['YAML_TMP_DIR'] = tmpdir.dirname environ['YAML_TMP_DIR'] = tmpdir.dirname
environ['YAML_TMP_DIR2'] = tmpdir.dirname
# Alias zones with a valid target. # Alias zones with a valid target.
tc = Manager(get_config_filename('simple-alias-zone.yaml')) \ tc = Manager(get_config_filename('simple-alias-zone.yaml')) \
.sync() .sync()
@ -205,6 +210,7 @@ class TestManager(TestCase):
def test_compare(self): def test_compare(self):
with TemporaryDirectory() as tmpdir: with TemporaryDirectory() as tmpdir:
environ['YAML_TMP_DIR'] = tmpdir.dirname environ['YAML_TMP_DIR'] = tmpdir.dirname
environ['YAML_TMP_DIR2'] = tmpdir.dirname
manager = Manager(get_config_filename('simple.yaml')) manager = Manager(get_config_filename('simple.yaml'))
# make sure this was pulled in from the config # make sure this was pulled in from the config
@ -280,6 +286,7 @@ class TestManager(TestCase):
def test_dump(self): def test_dump(self):
with TemporaryDirectory() as tmpdir: with TemporaryDirectory() as tmpdir:
environ['YAML_TMP_DIR'] = tmpdir.dirname environ['YAML_TMP_DIR'] = tmpdir.dirname
environ['YAML_TMP_DIR2'] = tmpdir.dirname
manager = Manager(get_config_filename('simple.yaml')) manager = Manager(get_config_filename('simple.yaml'))
with self.assertRaises(ManagerException) as ctx: with self.assertRaises(ManagerException) as ctx:
@ -299,6 +306,7 @@ class TestManager(TestCase):
def test_dump_empty(self): def test_dump_empty(self):
with TemporaryDirectory() as tmpdir: with TemporaryDirectory() as tmpdir:
environ['YAML_TMP_DIR'] = tmpdir.dirname environ['YAML_TMP_DIR'] = tmpdir.dirname
environ['YAML_TMP_DIR2'] = tmpdir.dirname
manager = Manager(get_config_filename('simple.yaml')) manager = Manager(get_config_filename('simple.yaml'))
manager.dump(zone='empty.', output_dir=tmpdir.dirname, manager.dump(zone='empty.', output_dir=tmpdir.dirname,
@ -308,9 +316,60 @@ class TestManager(TestCase):
data = safe_load(fh, False) data = safe_load(fh, False)
self.assertFalse(data) self.assertFalse(data)
def test_dump_output_provider(self):
with TemporaryDirectory() as tmpdir:
environ['YAML_TMP_DIR'] = tmpdir.dirname
# this time we'll use seperate tmp dirs
with TemporaryDirectory() as tmpdir2:
environ['YAML_TMP_DIR2'] = tmpdir2.dirname
manager = Manager(get_config_filename('simple.yaml'))
# we're going to tell it to use dump2 to do the dumping, but a
# copy should be made and directory set to tmpdir.dirname
# rather than 2's tmpdir2.dirname
manager.dump(zone='unit.tests.', output_dir=tmpdir.dirname,
output_provider='dump2', sources=['in'])
self.assertTrue(isfile(join(tmpdir.dirname,
'unit.tests.yaml')))
self.assertFalse(isfile(join(tmpdir2.dirname,
'unit.tests.yaml')))
# let's run that again, this time telling it to use tmpdir2 and
# dump2 which should allow it to skip the copying
manager.dump(zone='unit.tests.', output_dir=tmpdir2.dirname,
output_provider='dump2', sources=['in'])
self.assertTrue(isfile(join(tmpdir2.dirname,
'unit.tests.yaml')))
# tell it to use an output_provider that doesn't exist
with self.assertRaises(ManagerException) as ctx:
manager.dump(zone='unit.tests.', output_dir=tmpdir.dirname,
output_provider='nope', sources=['in'])
self.assertEqual('Unknown output_provider: nope',
str(ctx.exception))
# tell it to use an output_provider that doesn't support
# directory
with self.assertRaises(ManagerException) as ctx:
manager.dump(zone='unit.tests.', output_dir=tmpdir.dirname,
output_provider='simple', sources=['in'])
self.assertEqual('output_provider=simple, does not support '
'directory property', str(ctx.exception))
# hack a directory property onto the simple provider so that
# it'll pass that check and fail the copy one instead
manager.providers['simple'].directory = 42
with self.assertRaises(ManagerException) as ctx:
manager.dump(zone='unit.tests.', output_dir=tmpdir.dirname,
output_provider='simple', sources=['in'])
self.assertEqual('output_provider=simple, does not support '
'copy method', str(ctx.exception))
def test_dump_split(self): def test_dump_split(self):
with TemporaryDirectory() as tmpdir: with TemporaryDirectory() as tmpdir:
environ['YAML_TMP_DIR'] = tmpdir.dirname environ['YAML_TMP_DIR'] = tmpdir.dirname
environ['YAML_TMP_DIR2'] = tmpdir.dirname
manager = Manager(get_config_filename('simple-split.yaml')) manager = Manager(get_config_filename('simple-split.yaml'))
with self.assertRaises(ManagerException) as ctx: with self.assertRaises(ManagerException) as ctx:
@ -376,6 +435,7 @@ class TestManager(TestCase):
def test_populate_lenient_fallback(self): def test_populate_lenient_fallback(self):
with TemporaryDirectory() as tmpdir: with TemporaryDirectory() as tmpdir:
environ['YAML_TMP_DIR'] = tmpdir.dirname environ['YAML_TMP_DIR'] = tmpdir.dirname
environ['YAML_TMP_DIR2'] = tmpdir.dirname
# Only allow a target that doesn't exist # Only allow a target that doesn't exist
manager = Manager(get_config_filename('simple.yaml')) manager = Manager(get_config_filename('simple.yaml'))
@ -401,6 +461,7 @@ class TestManager(TestCase):
def test_plan_processors_fallback(self): def test_plan_processors_fallback(self):
with TemporaryDirectory() as tmpdir: with TemporaryDirectory() as tmpdir:
environ['YAML_TMP_DIR'] = tmpdir.dirname environ['YAML_TMP_DIR'] = tmpdir.dirname
environ['YAML_TMP_DIR2'] = tmpdir.dirname
# Only allow a target that doesn't exist # Only allow a target that doesn't exist
manager = Manager(get_config_filename('simple.yaml')) manager = Manager(get_config_filename('simple.yaml'))


+ 27
- 0
tests/test_octodns_provider_yaml.py View File

@ -398,6 +398,33 @@ class TestSplitYamlProvider(TestCase):
self.assertEqual('Record www.sub.unit.tests. is under a managed ' self.assertEqual('Record www.sub.unit.tests. is under a managed '
'subzone', str(ctx.exception)) 'subzone', str(ctx.exception))
def test_copy(self):
# going to put some sentinal values in here to ensure, these aren't
# valid, but we shouldn't hit any code that cares during this test
source = YamlProvider('test', 42, default_ttl=43, enforce_order=44,
populate_should_replace=45, supports_root_ns=46)
copy = source.copy()
self.assertEqual(source.directory, copy.directory)
self.assertEqual(source.default_ttl, copy.default_ttl)
self.assertEqual(source.enforce_order, copy.enforce_order)
self.assertEqual(source.populate_should_replace,
copy.populate_should_replace)
self.assertEqual(source.supports_root_ns, copy.supports_root_ns)
# same for split
source = SplitYamlProvider('test', 42, extension=42.5, default_ttl=43,
enforce_order=44,
populate_should_replace=45,
supports_root_ns=46)
copy = source.copy()
self.assertEqual(source.directory, copy.directory)
self.assertEqual(source.extension, copy.extension)
self.assertEqual(source.default_ttl, copy.default_ttl)
self.assertEqual(source.enforce_order, copy.enforce_order)
self.assertEqual(source.populate_should_replace,
copy.populate_should_replace)
self.assertEqual(source.supports_root_ns, copy.supports_root_ns)
class TestOverridingYamlProvider(TestCase): class TestOverridingYamlProvider(TestCase):


Loading…
Cancel
Save