From 8ec75dc194d3cd3440869c3fd8ce878275c19153 Mon Sep 17 00:00:00 2001 From: Ross McFarland Date: Mon, 17 Apr 2023 10:39:07 -0700 Subject: [PATCH] fix issue in OwnershipProcessor when last change is removed --- CHANGELOG.md | 1 + octodns/processor/ownership.py | 4 +++- tests/test_octodns_processor_ownership.py | 21 +++++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a38abb..3bccc0f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ * Added simple IgnoreRootNsFilter * Minor refactor on YamlProvider to add get_filenames making it a bit easier to create specialized providers inheriting from it +* Fixed bug in OwnershipProcessor when all changes were removed from plans ## v0.9.21 - 2022-10-16 - Last of the oughts diff --git a/octodns/processor/ownership.py b/octodns/processor/ownership.py index 590d792..3323019 100644 --- a/octodns/processor/ownership.py +++ b/octodns/processor/ownership.py @@ -90,7 +90,9 @@ class OwnershipProcessor(BaseProcessor): # change is we should do filtered_changes.append(change) - if plan.changes != filtered_changes: + if not filtered_changes: + return None + elif plan.changes != filtered_changes: return Plan( plan.existing, plan.desired, diff --git a/tests/test_octodns_processor_ownership.py b/tests/test_octodns_processor_ownership.py index e7211a7..bd0a630 100644 --- a/tests/test_octodns_processor_ownership.py +++ b/tests/test_octodns_processor_ownership.py @@ -7,6 +7,7 @@ from unittest import TestCase from helpers import PlannableProvider from octodns.processor.ownership import OwnershipProcessor +from octodns.provider.plan import Plan from octodns.record import Delete, Record from octodns.zone import Zone @@ -119,3 +120,23 @@ class TestOwnershipProcessor(TestCase): self.assertTrue(got) self.assertEqual(plan, got) self.assertEqual(len(plan.changes), len(got.changes)) + + def test_remove_last_change(self): + ownership = OwnershipProcessor('ownership') + + record = Record.new( + zone, 'a', {'ttl': 30, 'type': 'A', 'value': '4.4.4.4'} + ) + + existing = Zone('unit.tests.', []) + existing.add_record(record) + desired = Zone('unit.tests.', []) + + change = Delete(record) + + plan = Plan( + existing=existing, desired=desired, changes=[change], exists=True + ) + self.assertEqual(1, len(plan.changes)) + plan = ownership.process_plan(plan) + self.assertFalse(plan)