diff --git a/octodns/provider/base.py b/octodns/provider/base.py index 88f40b1..51cda9e 100644 --- a/octodns/provider/base.py +++ b/octodns/provider/base.py @@ -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: diff --git a/tests/test_octodns_provider_base.py b/tests/test_octodns_provider_base.py index fbe4cf7..128372e 100644 --- a/tests/test_octodns_provider_base.py +++ b/tests/test_octodns_provider_base.py @@ -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')