diff --git a/octodns/provider/dyn.py b/octodns/provider/dyn.py index 1832759..7846bbb 100644 --- a/octodns/provider/dyn.py +++ b/octodns/provider/dyn.py @@ -1258,31 +1258,33 @@ class DynProvider(BaseProvider): if new.geo: # New record is a geo record self.log.info('_mod_dynamic_Update: %s to geo', new.fqdn) - # Convert the TD over to a geo + # Convert the TD over to a geo and we're done self._mod_geo_Update(dyn_zone, change) else: # New record doesn't have dynamic, we're going from a TD to a # regular record self.log.info('_mod_dynamic_Update: %s to plain', new.fqdn) + # Create the regular record self._mod_Create(dyn_zone, change) + # Delete the dynamic self._mod_dynamic_Delete(dyn_zone, change) return try: + # We'll be dynamic going forward, see if we have one already td = self.traffic_directors[new.fqdn][new._type] - self.log.debug('_mod_dynamic_Update: %s existing', new.fqdn) + if change.existing.geo: + self.log.info('_mod_dynamic_Update: %s from geo', new.fqdn) + else: + self.log.debug('_mod_dynamic_Update: %s existing', new.fqdn) + # If we're here we do, we'll just update it down below except KeyError: # There's no td, this is actually a create, we must be going from a # non-dynamic to dynamic record # First create the dynamic record + self.log.info('_mod_dynamic_Update: %s from regular', new.fqdn) self._mod_dynamic_Create(dyn_zone, change) - if change.existing.geo: - # From a geo, so remove the old geo - self.log.info('_mod_dynamic_Update: %s from geo', new.fqdn) - self._mod_geo_Delete(dyn_zone, change) - else: - # From a generic so remove the old generic - self.log.info('_mod_dynamic_Update: %s from plain', new.fqdn) - self._mod_Delete(dyn_zone, change) + # From a generic so remove the old generic + self._mod_Delete(dyn_zone, change) return # IF we're here it's actually an update, sync up rules diff --git a/tests/test_octodns_provider_dyn.py b/tests/test_octodns_provider_dyn.py index 328cc69..8fcf80b 100644 --- a/tests/test_octodns_provider_dyn.py +++ b/tests/test_octodns_provider_dyn.py @@ -2411,8 +2411,8 @@ class TestDynProviderDynamic(TestCase): # mock _mod_dynamic_rulesets provider._mod_dynamic_rulesets = MagicMock() - geo = self.dynamic_a_record - change = Update(geo, geo) + dyn = self.dynamic_a_record + change = Update(dyn, dyn) provider._mod_dynamic_Update(None, change) # still in cache self.assertTrue('A' in provider.traffic_directors['unit.tests.']) @@ -2457,15 +2457,21 @@ class TestDynProviderDynamic(TestCase): # convert a geo record to a dynamic td - provider._mod_dynamic_Create = MagicMock() - provider._mod_geo_Delete = MagicMock() + # pre-populate the cache with our mock td + provider._traffic_directors = { + 'unit.tests.': { + 'A': 42, + } + } + # mock _mod_dynamic_rulesets + provider._mod_dynamic_rulesets = MagicMock() change = Update(self.geo_a_record, self.dynamic_a_record) - provider._mod_dynamic_Update(42, change) - # should have seen a call to create the new geo record - provider._mod_dynamic_Create.assert_called_once_with(42, change) - # should have seen a call to delete the old geo record - provider._mod_geo_Delete.assert_called_once_with(42, change) + provider._mod_dynamic_Update(None, change) + # still in cache + self.assertTrue('A' in provider.traffic_directors['unit.tests.']) + # should have seen 1 gen call + provider._mod_dynamic_rulesets.assert_called_once_with(42, change) @patch('dyn.core.SessionEngine.execute') def test_mod_dynamic_update_regular_dynamic(self, _):