Browse Source

_process_desired_zone after populate, test/enforce order

pull/876/head
Ross McFarland 4 years ago
parent
commit
728ab2af89
No known key found for this signature in database GPG Key ID: 943B179E15D3B22A
2 changed files with 38 additions and 7 deletions
  1. +7
    -7
      octodns/provider/base.py
  2. +31
    -0
      tests/test_octodns_provider_base.py

+ 7
- 7
octodns/provider/base.py View File

@ -168,13 +168,6 @@ class BaseProvider(BaseSource):
def plan(self, desired, processors=[]):
self.log.info('plan: desired=%s', desired.name)
# Make a (shallow) copy of the desired state so that everything from
# now on (in this target) can modify it as they see fit without
# worrying about impacting other targets.
desired = desired.copy()
desired = self._process_desired_zone(desired)
existing = Zone(desired.name, desired.sub_zones)
exists = self.populate(existing, target=True, lenient=True)
if exists is None:
@ -183,6 +176,13 @@ class BaseProvider(BaseSource):
self.log.warning('Provider %s used in target mode did not return '
'exists', self.id)
# Make a (shallow) copy of the desired state so that everything from
# now on (in this target) can modify it as they see fit without
# worrying about impacting other targets.
desired = desired.copy()
desired = self._process_desired_zone(desired)
existing = self._process_existing_zone(existing)
for processor in processors:


+ 31
- 0
tests/test_octodns_provider_base.py View File

@ -277,6 +277,37 @@ class TestBaseProvider(TestCase):
# We filtered out the only change
self.assertFalse(plan)
def test_plan_order_of_operations(self):
class MockProvider(BaseProvider):
log = getLogger('mock-provider')
SUPPORTS = set(('A',))
SUPPORTS_GEO = False
def __init__(self):
super().__init__('mock-provider')
self.calls = []
def populate(self, *args, **kwargs):
self.calls.append('populate')
def _process_desired_zone(self, *args, **kwargs):
self.calls.append('_process_desired_zone')
return super()._process_desired_zone(*args, **kwargs)
def _process_existing_zone(self, *args, **kwargs):
self.calls.append('_process_existing_zone')
return super()._process_existing_zone(*args, **kwargs)
provider = MockProvider()
zone = Zone('unit.tests.', [])
self.assertFalse(provider.plan(zone))
# ensure the calls were made in the expected order, populate comes
# first, then desired, then existing
self.assertEqual(['populate', '_process_desired_zone',
'_process_existing_zone'], provider.calls)
def test_process_desired_zone(self):
provider = HelperProvider('test')


Loading…
Cancel
Save