87a48e
From b2c9302e8a4ad1ab7535a557b2f9c9aa49b49629 Mon Sep 17 00:00:00 2001
87a48e
From: Eric Garver <eric@garver.life>
87a48e
Date: Wed, 27 Oct 2021 11:09:39 -0400
87a48e
Subject: [PATCH 43/50] fix(fw_config): zone: on rename remove then add
87a48e
87a48e
Remove the old object before creating the new one. This avoids issues
87a48e
such as conflicting configuration in the objects that check_config() may
87a48e
trip over.
87a48e
87a48e
(cherry picked from commit 3aec1dfe449d0bcb52884341770e4def0de27f56)
87a48e
(cherry picked from commit a58b45d8ee3221309ec0c6f919c266b5cfc6f89a)
87a48e
---
87a48e
 src/firewall/core/fw_config.py | 11 +++++++----
87a48e
 1 file changed, 7 insertions(+), 4 deletions(-)
87a48e
87a48e
diff --git a/src/firewall/core/fw_config.py b/src/firewall/core/fw_config.py
87a48e
index 148ce1b4e32c..a97d0b23a6ac 100644
87a48e
--- a/src/firewall/core/fw_config.py
87a48e
+++ b/src/firewall/core/fw_config.py
87a48e
@@ -984,13 +984,16 @@ class FirewallConfig(object):
87a48e
 
87a48e
     def rename_zone(self, obj, name):
87a48e
         self.check_builtin_zone(obj)
87a48e
-        new_zone = self._copy_zone(obj, name)
87a48e
+        obj_conf = obj.export_config_dict()
87a48e
         self._remove_zone(obj)
87a48e
+        try:
87a48e
+            new_zone = self.new_zone_dict(name, obj_conf)
87a48e
+        except:
87a48e
+            # re-add original if rename failed
87a48e
+            self.new_zone_dict(obj.name, obj_conf)
87a48e
+            raise
87a48e
         return new_zone
87a48e
 
87a48e
-    def _copy_zone(self, obj, name):
87a48e
-        return self.new_zone_dict(name, obj.export_config_dict())
87a48e
-
87a48e
     # policy objects
87a48e
 
87a48e
     def get_policy_objects(self):
87a48e
-- 
87a48e
2.27.0
87a48e