Skip to content

Commit 91c8ff3

Browse files
committed
[GCU] protect loopback0 from deletion
1 parent 1b21201 commit 91c8ff3

File tree

2 files changed

+47
-6
lines changed

2 files changed

+47
-6
lines changed

generic_config_updater/gu_common.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,14 @@ def validate_field_operation(self, old_config, target_config):
149149
patch = jsonpatch.JsonPatch.from_diff(old_config, target_config)
150150

151151
# illegal_operations_to_fields_map['remove'] yields a list of fields for which `remove` is an illegal operation
152-
illegal_operations_to_fields_map = {'add':[],
153-
'replace': [],
154-
'remove': ['/PFC_WD/GLOBAL/POLL_INTERVAL', '/PFC_WD/GLOBAL']}
152+
illegal_operations_to_fields_map = {
153+
'add':[],
154+
'replace': [],
155+
'remove': [
156+
'/PFC_WD/GLOBAL/POLL_INTERVAL',
157+
'/PFC_WD/GLOBAL',
158+
'/LOOPBACK_INTERFACE/Loopback0']
159+
}
155160
for operation, field_list in illegal_operations_to_fields_map.items():
156161
for field in field_list:
157162
if any(op['op'] == operation and field == op['path'] for op in patch):

tests/generic_config_updater/gu_common_test.py

+39-3
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,54 @@ def setUp(self):
6969
self.config_wrapper_mock = gu_common.ConfigWrapper()
7070
self.config_wrapper_mock.get_config_db_as_json=MagicMock(return_value=Files.CONFIG_DB_AS_JSON)
7171

72-
def test_validate_field_operation_legal(self):
72+
def test_validate_field_operation_legal__pfcwd(self):
7373
old_config = {"PFC_WD": {"GLOBAL": {"POLL_INTERVAL": "60"}}}
7474
target_config = {"PFC_WD": {"GLOBAL": {"POLL_INTERVAL": "40"}}}
7575
config_wrapper = gu_common.ConfigWrapper()
7676
config_wrapper.validate_field_operation(old_config, target_config)
77-
78-
def test_validate_field_operation_illegal(self):
77+
78+
def test_validate_field_operation_legal__loopback0(self):
79+
old_config = {
80+
"LOOPBACK_INTERFACE": {
81+
"Loopback0": {},
82+
"Loopback0|10.1.0.32/32": {},
83+
"Loopback1": {},
84+
"Loopback1|10.1.0.33/32": {}
85+
}
86+
}
87+
target_config = {
88+
"LOOPBACK_INTERFACE": {
89+
"Loopback0": {},
90+
"Loopback0|10.1.0.32/32": {}
91+
}
92+
}
93+
config_wrapper = gu_common.ConfigWrapper()
94+
config_wrapper.validate_field_operation(old_config, target_config)
95+
96+
def test_validate_field_operation_illegal__pfcwd(self):
7997
old_config = {"PFC_WD": {"GLOBAL": {"POLL_INTERVAL": 60}}}
8098
target_config = {"PFC_WD": {"GLOBAL": {}}}
8199
config_wrapper = gu_common.ConfigWrapper()
82100
self.assertRaises(gu_common.IllegalPatchOperationError, config_wrapper.validate_field_operation, old_config, target_config)
83101

102+
def test_validate_field_operation_illegal__loopback0(self):
103+
old_config = {
104+
"LOOPBACK_INTERFACE": {
105+
"Loopback0": {},
106+
"Loopback0|10.1.0.32/32": {},
107+
"Loopback1": {},
108+
"Loopback1|10.1.0.33/32": {}
109+
}
110+
}
111+
target_config = {
112+
"LOOPBACK_INTERFACE": {
113+
"Loopback1": {},
114+
"Loopback1|10.1.0.33/32": {}
115+
}
116+
}
117+
config_wrapper = gu_common.ConfigWrapper()
118+
self.assertRaises(gu_common.IllegalPatchOperationError, config_wrapper.validate_field_operation, old_config, target_config)
119+
84120
def test_ctor__default_values_set(self):
85121
config_wrapper = gu_common.ConfigWrapper()
86122

0 commit comments

Comments
 (0)