Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GCU] protect loopback0 from deletion #2638

Merged
merged 2 commits into from
Feb 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions generic_config_updater/gu_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,14 @@ def validate_field_operation(self, old_config, target_config):
patch = jsonpatch.JsonPatch.from_diff(old_config, target_config)

# illegal_operations_to_fields_map['remove'] yields a list of fields for which `remove` is an illegal operation
illegal_operations_to_fields_map = {'add':[],
'replace': [],
'remove': ['/PFC_WD/GLOBAL/POLL_INTERVAL', '/PFC_WD/GLOBAL']}
illegal_operations_to_fields_map = {
'add':[],
'replace': [],
'remove': [
'/PFC_WD/GLOBAL/POLL_INTERVAL',
'/PFC_WD/GLOBAL',
'/LOOPBACK_INTERFACE/Loopback0']
}
for operation, field_list in illegal_operations_to_fields_map.items():
for field in field_list:
if any(op['op'] == operation and field == op['path'] for op in patch):
Expand Down
42 changes: 39 additions & 3 deletions tests/generic_config_updater/gu_common_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,54 @@ def setUp(self):
self.config_wrapper_mock = gu_common.ConfigWrapper()
self.config_wrapper_mock.get_config_db_as_json=MagicMock(return_value=Files.CONFIG_DB_AS_JSON)

def test_validate_field_operation_legal(self):
def test_validate_field_operation_legal__pfcwd(self):
old_config = {"PFC_WD": {"GLOBAL": {"POLL_INTERVAL": "60"}}}
target_config = {"PFC_WD": {"GLOBAL": {"POLL_INTERVAL": "40"}}}
config_wrapper = gu_common.ConfigWrapper()
config_wrapper.validate_field_operation(old_config, target_config)

def test_validate_field_operation_illegal(self):

def test_validate_field_operation_legal__loopback0(self):
old_config = {
"LOOPBACK_INTERFACE": {
"Loopback0": {},
"Loopback0|10.1.0.32/32": {},
"Loopback1": {},
"Loopback1|10.1.0.33/32": {}
}
}
target_config = {
"LOOPBACK_INTERFACE": {
"Loopback0": {},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Loopback0

Seem you are testing removing Loopback1. Do you intent to removing Loopback0?

"Loopback0|10.1.0.32/32": {}
}
}
config_wrapper = gu_common.ConfigWrapper()
config_wrapper.validate_field_operation(old_config, target_config)

def test_validate_field_operation_illegal__pfcwd(self):
old_config = {"PFC_WD": {"GLOBAL": {"POLL_INTERVAL": 60}}}
target_config = {"PFC_WD": {"GLOBAL": {}}}
config_wrapper = gu_common.ConfigWrapper()
self.assertRaises(gu_common.IllegalPatchOperationError, config_wrapper.validate_field_operation, old_config, target_config)

def test_validate_field_operation_illegal__loopback0(self):
old_config = {
"LOOPBACK_INTERFACE": {
"Loopback0": {},
"Loopback0|10.1.0.32/32": {},
"Loopback1": {},
"Loopback1|10.1.0.33/32": {}
}
}
target_config = {
"LOOPBACK_INTERFACE": {
"Loopback1": {},
"Loopback1|10.1.0.33/32": {}
}
}
config_wrapper = gu_common.ConfigWrapper()
self.assertRaises(gu_common.IllegalPatchOperationError, config_wrapper.validate_field_operation, old_config, target_config)

def test_ctor__default_values_set(self):
config_wrapper = gu_common.ConfigWrapper()

Expand Down