Skip to content

Commit 4fc3bb4

Browse files
wen587Ubuntu
authored and
Ubuntu
committed
[GCU] protect loopback0 from deletion (sonic-net#2638)
What I did Refer to sonic-net/sonic-buildimage#11171, protect loopback0 from deletion How I did it Add patch checker to fail the validation when remove loopback0 How to verify it Unit test
1 parent 506dd7a commit 4fc3bb4

File tree

2 files changed

+45
-4
lines changed

2 files changed

+45
-4
lines changed

generic_config_updater/gu_common.py

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

155155
# illegal_operations_to_fields_map['remove'] yields a list of fields for which `remove` is an illegal operation
156-
illegal_operations_to_fields_map = {'add':[],
157-
'replace': [],
158-
'remove': ['/PFC_WD/GLOBAL/POLL_INTERVAL', '/PFC_WD/GLOBAL']}
156+
illegal_operations_to_fields_map = {
157+
'add':[],
158+
'replace': [],
159+
'remove': [
160+
'/PFC_WD/GLOBAL/POLL_INTERVAL',
161+
'/PFC_WD/GLOBAL',
162+
'/LOOPBACK_INTERFACE/Loopback0']
163+
}
159164
for operation, field_list in illegal_operations_to_fields_map.items():
160165
for field in field_list:
161166
if any(op['op'] == operation and field == op['path'] for op in patch):

tests/generic_config_updater/gu_common_test.py

+37-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,25 @@ def test_validate_field_operation_legal__pfcwd(self):
7777
target_config = {"PFC_WD": {"GLOBAL": {"POLL_INTERVAL": "40"}}}
7878
config_wrapper = gu_common.ConfigWrapper()
7979
config_wrapper.validate_field_operation(old_config, target_config)
80-
80+
81+
def test_validate_field_operation_legal__rm_loopback1(self):
82+
old_config = {
83+
"LOOPBACK_INTERFACE": {
84+
"Loopback0": {},
85+
"Loopback0|10.1.0.32/32": {},
86+
"Loopback1": {},
87+
"Loopback1|10.1.0.33/32": {}
88+
}
89+
}
90+
target_config = {
91+
"LOOPBACK_INTERFACE": {
92+
"Loopback0": {},
93+
"Loopback0|10.1.0.32/32": {}
94+
}
95+
}
96+
config_wrapper = gu_common.ConfigWrapper()
97+
config_wrapper.validate_field_operation(old_config, target_config)
98+
8199
def test_validate_field_operation_illegal__pfcwd(self):
82100
old_config = {"PFC_WD": {"GLOBAL": {"POLL_INTERVAL": "60"}}}
83101
target_config = {"PFC_WD": {"GLOBAL": {}}}
@@ -91,6 +109,24 @@ def test_validate_field_modification_illegal__pfcwd(self):
91109
config_wrapper = gu_common.ConfigWrapper()
92110
self.assertRaises(gu_common.IllegalPatchOperationError, config_wrapper.validate_field_operation, old_config, target_config)
93111

112+
def test_validate_field_operation_illegal__rm_loopback0(self):
113+
old_config = {
114+
"LOOPBACK_INTERFACE": {
115+
"Loopback0": {},
116+
"Loopback0|10.1.0.32/32": {},
117+
"Loopback1": {},
118+
"Loopback1|10.1.0.33/32": {}
119+
}
120+
}
121+
target_config = {
122+
"LOOPBACK_INTERFACE": {
123+
"Loopback1": {},
124+
"Loopback1|10.1.0.33/32": {}
125+
}
126+
}
127+
config_wrapper = gu_common.ConfigWrapper()
128+
self.assertRaises(gu_common.IllegalPatchOperationError, config_wrapper.validate_field_operation, old_config, target_config)
129+
94130
def test_ctor__default_values_set(self):
95131
config_wrapper = gu_common.ConfigWrapper()
96132

0 commit comments

Comments
 (0)