mirror of
https://github.com/github/octodns.git
synced 2024-05-11 05:55:00 +00:00
Merge pull request #689 from cfunkhouser/handles-output-a-little-more-nicely
Capture plan output in File as argument to sync
This commit is contained in:
@@ -9,6 +9,7 @@ from concurrent.futures import ThreadPoolExecutor
|
||||
from importlib import import_module
|
||||
from os import environ
|
||||
from six import text_type
|
||||
from sys import stdout
|
||||
import logging
|
||||
|
||||
from .provider.base import BaseProvider
|
||||
@@ -267,16 +268,19 @@ class Manager(object):
|
||||
return plans, zone
|
||||
|
||||
def sync(self, eligible_zones=[], eligible_sources=[], eligible_targets=[],
|
||||
dry_run=True, force=False):
|
||||
self.log.info('sync: eligible_zones=%s, eligible_targets=%s, '
|
||||
'dry_run=%s, force=%s', eligible_zones, eligible_targets,
|
||||
dry_run, force)
|
||||
dry_run=True, force=False, plan_output_fh=stdout):
|
||||
|
||||
self.log.info(
|
||||
'sync: eligible_zones=%s, eligible_targets=%s, dry_run=%s, '
|
||||
'force=%s, plan_output_fh=%s',
|
||||
eligible_zones, eligible_targets, dry_run, force,
|
||||
getattr(plan_output_fh, 'name', plan_output_fh.__class__.__name__))
|
||||
|
||||
zones = self.config['zones'].items()
|
||||
if eligible_zones:
|
||||
zones = [z for z in zones if z[0] in eligible_zones]
|
||||
|
||||
aliased_zones = {}
|
||||
aliased_zones = {}
|
||||
futures = []
|
||||
for zone_name, config in zones:
|
||||
self.log.info('sync: zone=%s', zone_name)
|
||||
@@ -402,7 +406,7 @@ class Manager(object):
|
||||
plans.sort(key=self._plan_keyer, reverse=True)
|
||||
|
||||
for output in self.plan_outputs.values():
|
||||
output.run(plans=plans, log=self.log)
|
||||
output.run(plans=plans, log=self.log, fh=plan_output_fh)
|
||||
|
||||
if not force:
|
||||
self.log.debug('sync: checking safety')
|
||||
|
6
tests/config/plan-output-filehandle.yaml
Normal file
6
tests/config/plan-output-filehandle.yaml
Normal file
@@ -0,0 +1,6 @@
|
||||
manager:
|
||||
plan_outputs:
|
||||
"doesntexist":
|
||||
class: octodns.provider.plan.DoesntExist
|
||||
providers: {}
|
||||
zones: {}
|
@@ -8,7 +8,6 @@ from __future__ import absolute_import, division, print_function, \
|
||||
from os import environ
|
||||
from os.path import dirname, join
|
||||
from six import text_type
|
||||
from unittest import TestCase
|
||||
|
||||
from octodns.record import Record
|
||||
from octodns.manager import _AggregateTarget, MainThreadExecutor, Manager, \
|
||||
@@ -16,6 +15,9 @@ from octodns.manager import _AggregateTarget, MainThreadExecutor, Manager, \
|
||||
from octodns.yaml import safe_load
|
||||
from octodns.zone import Zone
|
||||
|
||||
from mock import MagicMock, patch
|
||||
from unittest import TestCase
|
||||
|
||||
from helpers import DynamicProvider, GeoProvider, NoSshFpProvider, \
|
||||
SimpleProvider, TemporaryDirectory
|
||||
|
||||
@@ -371,6 +373,24 @@ class TestManager(TestCase):
|
||||
with self.assertRaises(TypeError):
|
||||
manager._populate_and_plan('unit.tests.', [NoZone()], [])
|
||||
|
||||
@patch('octodns.manager.Manager._get_named_class')
|
||||
def test_sync_passes_file_handle(self, mock):
|
||||
plan_output_mock = MagicMock()
|
||||
plan_output_class_mock = MagicMock()
|
||||
plan_output_class_mock.return_value = plan_output_mock
|
||||
mock.return_value = plan_output_class_mock
|
||||
fh_mock = MagicMock()
|
||||
|
||||
Manager(get_config_filename('plan-output-filehandle.yaml')
|
||||
).sync(plan_output_fh=fh_mock)
|
||||
|
||||
# Since we only care about the fh kwarg, and different _PlanOutputs are
|
||||
# are free to require arbitrary kwargs anyway, we concern ourselves
|
||||
# with checking the value of fh only.
|
||||
plan_output_mock.run.assert_called()
|
||||
_, kwargs = plan_output_mock.run.call_args
|
||||
self.assertEqual(fh_mock, kwargs.get('fh'))
|
||||
|
||||
|
||||
class TestMainThreadExecutor(TestCase):
|
||||
|
||||
|
Reference in New Issue
Block a user