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]Remove GCU unique lane check for duplicate lanes platforms #2343

Merged
merged 9 commits into from
Sep 20, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
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
26 changes: 15 additions & 11 deletions generic_config_updater/gu_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ def validate_config_db_config(self, config_db_as_json):
# TODO: Move these validators to YANG models
supplemental_yang_validators = [self.validate_bgp_peer_group,
self.validate_lanes]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
self.validate_lanes]
lambda c: return self.validate_lanes(c, False)]

validators_params = [(config_db_as_json,),
(config_db_as_json, False)]

try:
tmp_config_db_as_json = copy.deepcopy(config_db_as_json)
Expand All @@ -124,16 +126,17 @@ def validate_config_db_config(self, config_db_as_json):

sy.validate_data_tree()

for supplemental_yang_validator in supplemental_yang_validators:
success, error = supplemental_yang_validator(config_db_as_json)
for supplemental_yang_validator, validator_params in \
zip(supplemental_yang_validators, validators_params):
success, error = supplemental_yang_validator(*validator_params)
Copy link
Contributor

@qiluo-msft qiluo-msft Sep 2, 2022

Choose a reason for hiding this comment

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

supplemental_yang_validator

To make code more readable, you may use lambda in supplemental_yang_validators, and no need to zip with another array validators_params. #Closed

if not success:
return success, error
except sonic_yang.SonicYangException as ex:
return False, ex

return True, None

def validate_lanes(self, config_db):
def validate_lanes(self, config_db, unique_lanes=True):
if "PORT" not in config_db:
return True, None

Expand All @@ -154,14 +157,15 @@ def validate_lanes(self, config_db):
return False, f"PORT '{port}' has an invalid lane '{lane}'"
port_to_lanes_map[port] = lanes

# Validate lanes are unique
existing = {}
for port in port_to_lanes_map:
lanes = port_to_lanes_map[port]
for lane in lanes:
if lane in existing:
return False, f"'{lane}' lane is used multiple times in PORT: {set([port, existing[lane]])}"
existing[lane] = port
if unique_lanes:
# Validate lanes are unique
existing = {}
for port in port_to_lanes_map:
lanes = port_to_lanes_map[port]
for lane in lanes:
if lane in existing:
return False, f"'{lane}' lane is used multiple times in PORT: {set([port, existing[lane]])}"
existing[lane] = port
return True, None

def validate_bgp_peer_group(self, config_db):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6157,4 +6157,4 @@
]
]
}
}
}
3 changes: 3 additions & 0 deletions tests/generic_config_updater/patch_sorter_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3034,6 +3034,9 @@ def test_patch_sorter_success(self):
data = Files.PATCH_SORTER_TEST_SUCCESS
skip_exact_change_list_match = False
for test_case_name in data:
# DPB_1_TO_4__SUCCESS will fail when unique_lanes is set to False
Copy link
Contributor

@qiluo-msft qiluo-msft Sep 2, 2022

Choose a reason for hiding this comment

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

fail

Why one less validator will make original passing testcase fail? #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You can check above sorting output here #2343 (comment)
When lane validator is removed, the sorting order is changed. That's why it fails.

if test_case_name == "DPB_1_TO_4__SUCCESS":
continue
with self.subTest(name=test_case_name):
self.run_single_success_case(data[test_case_name], skip_exact_change_list_match)

Expand Down