From c2ac376dc9f863e004f40b75dad9c6fdad7e5269 Mon Sep 17 00:00:00 2001 From: tshalvi Date: Wed, 11 Oct 2023 17:23:45 +0000 Subject: [PATCH] Refactoring for the function get_cmis_application_desired() --- sonic-xcvrd/xcvrd/xcvrd.py | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/sonic-xcvrd/xcvrd/xcvrd.py b/sonic-xcvrd/xcvrd/xcvrd.py index 8db0b4858..7418a17f2 100644 --- a/sonic-xcvrd/xcvrd/xcvrd.py +++ b/sonic-xcvrd/xcvrd/xcvrd.py @@ -132,23 +132,15 @@ def get_cmis_application_desired(api, host_lane_count, speed): if speed == 0 or host_lane_count == 0: return None - appl_code = None - app_found = False - if is_cmis_api(api): - appl_dict = api.get_application_advertisement() - for index in appl_dict.keys(): - app_info = appl_dict[index] - if app_info.get('host_lane_count') != host_lane_count: - continue - if get_interface_speed(app_info.get('host_electrical_interface_id')) != speed: - continue - appl_code = index - app_found = True - break + if not is_cmis_api(api): + return None + + appl_dict = api.get_application_advertisement() + for index, app_info in appl_dict.items(): + if (app_info.get('host_lane_count') == host_lane_count and + get_interface_speed(app_info.get('host_electrical_interface_id')) == speed): + return (index & 0xf) - if app_found: - return (appl_code & 0xf) - return None