From 0f57e6c63e2b1cf269ce9536f79ba6aa861f30f8 Mon Sep 17 00:00:00 2001 From: Ross McFarland Date: Mon, 12 Sep 2022 15:28:51 -0700 Subject: [PATCH] Implement manager.processors for configuring global processors --- octodns/manager.py | 5 ++++- tests/config/processors.yaml | 6 ++++++ tests/helpers.py | 10 ++++++++++ tests/test_octodns_manager.py | 9 ++++++++- 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/octodns/manager.py b/octodns/manager.py index c58074a..d33c960 100644 --- a/octodns/manager.py +++ b/octodns/manager.py @@ -127,6 +127,9 @@ class Manager(object): manager_config, include_meta ) + self.global_processors = manager_config.get('processors', []) + self.log.info('__init__: global_processors=%s', self.global_processors) + providers_config = self.config['providers'] self.providers = self._config_providers(providers_config) @@ -539,7 +542,7 @@ class Manager(object): try: collected = [] - for processor in processors: + for processor in self.global_processors + processors: collected.append(self.processors[processor]) processors = collected except KeyError: diff --git a/tests/config/processors.yaml b/tests/config/processors.yaml index ec50fb3..6fa9e92 100644 --- a/tests/config/processors.yaml +++ b/tests/config/processors.yaml @@ -1,3 +1,7 @@ +manager: + processors: + - global-counter + providers: config: # This helps us get coverage when printing out provider versions @@ -19,6 +23,8 @@ processors: test: # This helps us get coverage when printing out processor versions class: helpers.TestBaseProcessor + global-counter: + class: helpers.CountingProcessor zones: unit.tests.: diff --git a/tests/helpers.py b/tests/helpers.py index 5bb0a86..5eee380 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -131,3 +131,13 @@ class TestYamlProvider(YamlProvider): class TestBaseProcessor(BaseProcessor): pass + + +class CountingProcessor(BaseProcessor): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.count = 0 + + def process_source_zone(self, zone, *args, **kwargs): + self.count += len(zone.records) + return zone diff --git a/tests/test_octodns_manager.py b/tests/test_octodns_manager.py index c0cbfca..2d9e16a 100644 --- a/tests/test_octodns_manager.py +++ b/tests/test_octodns_manager.py @@ -643,9 +643,16 @@ class TestManager(TestCase): def test_processor_config(self): # Smoke test loading a valid config manager = Manager(get_config_filename('processors.yaml')) - self.assertEqual(['noop', 'test'], list(manager.processors.keys())) + self.assertEqual( + ['noop', 'test', 'global-counter'], list(manager.processors.keys()) + ) + # make sure we got the global processor and that it's count is 0 now + self.assertEqual(['global-counter'], manager.global_processors) + self.assertEqual(0, manager.processors['global-counter'].count) # This zone specifies a valid processor manager.sync(['unit.tests.']) + # make sure the global processor ran and counted some records + self.assertTrue(manager.processors['global-counter'].count >= 25) with self.assertRaises(ManagerException) as ctx: # This zone specifies a non-existent processor