Browse Source

Merge pull request #934 from octodns/global-processors

Global processors support
pull/936/head
Ross McFarland 3 years ago
committed by GitHub
parent
commit
00f0123b97
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 30 additions and 2 deletions
  1. +2
    -0
      CHANGELOG.md
  2. +4
    -1
      octodns/manager.py
  3. +6
    -0
      tests/config/processors.yaml
  4. +10
    -0
      tests/helpers.py
  5. +8
    -1
      tests/test_octodns_manager.py

+ 2
- 0
CHANGELOG.md View File

@ -11,6 +11,8 @@
decoded form. Both forms should be accepted in command line arguments. decoded form. Both forms should be accepted in command line arguments.
Providers may need to be updated to display the decoded form in their logs, Providers may need to be updated to display the decoded form in their logs,
until then they'd display the IDNA version. until then they'd display the IDNA version.
* Support for configuring global processors that apply to all zones with
`manager.processors`
#### Stuff #### Stuff


+ 4
- 1
octodns/manager.py View File

@ -127,6 +127,9 @@ class Manager(object):
manager_config, include_meta 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'] providers_config = self.config['providers']
self.providers = self._config_providers(providers_config) self.providers = self._config_providers(providers_config)
@ -539,7 +542,7 @@ class Manager(object):
try: try:
collected = [] collected = []
for processor in processors:
for processor in self.global_processors + processors:
collected.append(self.processors[processor]) collected.append(self.processors[processor])
processors = collected processors = collected
except KeyError: except KeyError:


+ 6
- 0
tests/config/processors.yaml View File

@ -1,3 +1,7 @@
manager:
processors:
- global-counter
providers: providers:
config: config:
# This helps us get coverage when printing out provider versions # This helps us get coverage when printing out provider versions
@ -19,6 +23,8 @@ processors:
test: test:
# This helps us get coverage when printing out processor versions # This helps us get coverage when printing out processor versions
class: helpers.TestBaseProcessor class: helpers.TestBaseProcessor
global-counter:
class: helpers.CountingProcessor
zones: zones:
unit.tests.: unit.tests.:


+ 10
- 0
tests/helpers.py View File

@ -131,3 +131,13 @@ class TestYamlProvider(YamlProvider):
class TestBaseProcessor(BaseProcessor): class TestBaseProcessor(BaseProcessor):
pass 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

+ 8
- 1
tests/test_octodns_manager.py View File

@ -643,9 +643,16 @@ class TestManager(TestCase):
def test_processor_config(self): def test_processor_config(self):
# Smoke test loading a valid config # Smoke test loading a valid config
manager = Manager(get_config_filename('processors.yaml')) 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 # This zone specifies a valid processor
manager.sync(['unit.tests.']) 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: with self.assertRaises(ManagerException) as ctx:
# This zone specifies a non-existent processor # This zone specifies a non-existent processor


Loading…
Cancel
Save