From 4097a18d0b30b756a3e633377849ad4aea482151 Mon Sep 17 00:00:00 2001 From: Judy Joseph Date: Thu, 9 Jul 2020 00:01:32 -0700 Subject: [PATCH 1/9] platform daemon changes for multi asic platform --- sonic-ledd/scripts/ledd | 33 ++++--- sonic-xcvrd/scripts/xcvrd | 195 ++++++++++++++++++++++++++------------ 2 files changed, 157 insertions(+), 71 deletions(-) diff --git a/sonic-ledd/scripts/ledd b/sonic-ledd/scripts/ledd index f27296ce652e..b89ee4942091 100644 --- a/sonic-ledd/scripts/ledd +++ b/sonic-ledd/scripts/ledd @@ -65,13 +65,18 @@ class DaemonLedd(daemon_base.DaemonBase): self.log_error("Failed to load ledutil: %s" % (str(e)), True) sys.exit(LEDUTIL_LOAD_ERROR) - # Open a handle to the Application database - appl_db = daemon_base.db_connect("APPL_DB") + # Get the namespaces in the platform + namespaces = multi_asic.get_namespaces() # Subscribe to PORT table notifications in the Application DB + appl_db, sst = {}, {} sel = swsscommon.Select() - sst = swsscommon.SubscriberStateTable(appl_db, swsscommon.APP_PORT_TABLE_NAME) - sel.addSelectable(sst) + + for namespace in namespaces: + # Open a handle to the Application database + appl_db[namespace] = daemon_base.db_connect("APPL_DB", namespace=namespace) + sst[namespace] = swsscommon.SubscriberStateTable(appl_db[namespace], swsscommon.APP_PORT_TABLE_NAME) + sel.addSelectable(sst[namespace]) # Listen indefinitely for changes to the PORT table in the Application DB while True: @@ -86,17 +91,19 @@ class DaemonLedd(daemon_base.DaemonBase): self.log_warning("sel.select() did not return swsscommon.Select.OBJECT") continue - (key, op, fvp) = sst.pop() - - # TODO: Once these flag entries have been removed from the DB, - # we can remove this check - if key in ["PortConfigDone", "PortInitDone"]: - continue + for namespace in namespaces: + (key, op, fvp) = sst[namespace].pop() + if fvp: + # TODO: Once these flag entries have been removed from the DB, + # we can remove this check + if key in ["PortConfigDone", "PortInitDone"]: + continue - fvp_dict = dict(fvp) + fvp_dict = dict(fvp) - if op == "SET" and "oper_status" in fvp_dict: - led_control.port_link_state_change(key, fvp_dict["oper_status"]) + if op == "SET" and "oper_status" in fvp_dict: + if not key.startswith(INTERNAL_INTERFACE_PREFIX): + led_control.port_link_state_change(key, fvp_dict["oper_status"]) return 1 diff --git a/sonic-xcvrd/scripts/xcvrd b/sonic-xcvrd/scripts/xcvrd index 3ed032272197..ed6b17dea4fd 100644 --- a/sonic-xcvrd/scripts/xcvrd +++ b/sonic-xcvrd/scripts/xcvrd @@ -95,6 +95,9 @@ platform_chassis = None # by DaemonXcvrd helper_logger = logger.Logger(SYSLOG_IDENTIFIER) +# MultiAsic class instance +multi_asic = multiAsic() + # # Helper functions ============================================================= # @@ -421,14 +424,19 @@ def post_port_dom_info_to_db(logical_port_name, table, stop_event=threading.Even # Update port dom/sfp info in db def post_port_sfp_dom_info_to_db(is_warm_start, stop_event=threading.Event()): # Connect to STATE_DB and create transceiver dom/sfp info tables - transceiver_dict = {} - state_db = daemon_base.db_connect("STATE_DB") - int_tbl = swsscommon.Table(state_db, TRANSCEIVER_INFO_TABLE) - dom_tbl = swsscommon.Table(state_db, TRANSCEIVER_DOM_SENSOR_TABLE) + transceiver_dict, state_db, appl_db, int_tbl, dom_tbl, app_port_tbl = {}, {}, {}, {}, {}, {} - appl_db = daemon_base.db_connect("APPL_DB") - app_port_tbl = swsscommon.ProducerStateTable(appl_db, - swsscommon.APP_PORT_TABLE_NAME) + # Get the namespaces in the platform + namespaces = multi_asic.get_namespaces() + namespaceIDs = multi_asic.get_namespaceIDs() + + for namespace in namespaces: + asic_id = multi_asic.get_asic_id_from_namespace(namespace) + state_db[asic_id] = daemon_base.db_connect("STATE_DB", namespace) + appl_db[asic_id] = daemon_base.db_connect("APPL_DB", namespace) + int_tbl[asic_id] = swsscommon.Table(state_db[asic_id], TRANSCEIVER_INFO_TABLE) + dom_tbl[asic_id] = swsscommon.Table(state_db[asic_id], TRANSCEIVER_DOM_SENSOR_TABLE) + app_port_tbl[asic_id] = swsscommon.ProducerStateTable(appl_db[asic_id], swsscommon.APP_PORT_TABLE_NAME) # Post all the current interface dom/sfp info to STATE_DB logical_port_list = platform_sfputil.logical @@ -436,13 +444,18 @@ def post_port_sfp_dom_info_to_db(is_warm_start, stop_event=threading.Event()): if stop_event.is_set(): break - post_port_sfp_info_to_db(logical_port_name, int_tbl, transceiver_dict, stop_event) - post_port_dom_info_to_db(logical_port_name, dom_tbl, stop_event) - post_port_dom_threshold_info_to_db(logical_port_name, dom_tbl, stop_event) + # Get the asic to which this port belongs + asic_index = platform_sfputil.get_asicId_for_logical_port(logical_port_name) + if asic_index is None or asic_index not in namespaceIDs: + continue + + post_port_sfp_info_to_db(logical_port_name, int_tbl[asic_index], transceiver_dict, stop_event) + post_port_dom_info_to_db(logical_port_name, dom_tbl[asic_index], stop_event) + post_port_dom_threshold_info_to_db(logical_port_name, dom_tbl[asic_index], stop_event) ## Do not notify media settings during warm reboot to avoid dataplane traffic impact if is_warm_start == False: - notify_media_setting(logical_port_name, transceiver_dict, app_port_tbl) + notify_media_setting(logical_port_name, transceiver_dict, app_port_tbl[asic_index]) transceiver_dict.clear() # Delete port dom/sfp info from db @@ -473,16 +486,22 @@ def del_port_sfp_dom_info_from_db(logical_port_name, int_tbl, dom_tbl): sys.exit(NOT_IMPLEMENTED_ERROR) # recover missing sfp table entries if any -def recover_missing_sfp_table_entries(sfp_util, int_tbl, status_tbl, stop_event): +def recover_missing_sfp_table_entries(self, sfp_util, stop_event): transceiver_dict = {} - keys = int_tbl.getKeys() + keys = self.int_tbl.getKeys() logical_port_list = sfp_util.logical for logical_port_name in logical_port_list: if stop_event.is_set(): break - if logical_port_name not in keys and not detect_port_in_error_status(logical_port_name, status_tbl): - post_port_sfp_info_to_db(logical_port_name, int_tbl, transceiver_dict, stop_event) + + # Get the asic to which this port belongs + asic_index = sfp_util.get_asicId_for_logical_port(logical_port_name) + if asic_index is None or asic_index not in namespaceIDs: + continue + + if logical_port_name not in keys and not detect_port_in_error_status(logical_port_name, self.status_tbl[asic_index]): + post_port_sfp_info_to_db(logical_port_name, self.int_tbl[asic_index], transceiver_dict, stop_event) def check_port_in_range(range_str, physical_port): @@ -719,28 +738,41 @@ def detect_port_in_error_status(logical_port_name, status_tbl): # Init TRANSCEIVER_STATUS table def init_port_sfp_status_tbl(stop_event=threading.Event()): # Connect to STATE_DB and create transceiver status table - state_db = daemon_base.db_connect("STATE_DB") - status_tbl = swsscommon.Table(state_db, TRANSCEIVER_STATUS_TABLE) + state_db, status_tbl = {},{} + + # Get the namespaces in the platform + namespaces = multi_asic.get_namespaces() + namespaceIDs = multi_asic.get_namespaceIDs() + + for namespace in namespaces: + asic_id = multi_asic.get_asic_id_from_namespace(namespace) + state_db[asic_id] = daemon_base.db_connect("STATE_DB", namespace) + status_tbl[asic_id] = swsscommon.Table(state_db[asic_id], TRANSCEIVER_STATUS_TABLE) # Init TRANSCEIVER_STATUS table logical_port_list = platform_sfputil.logical for logical_port_name in logical_port_list: if stop_event.is_set(): break + + # Get the asic to which this port belongs + asic_index = platform_sfputil.get_asicId_for_logical_port(logical_port_name) + if asic_index is None or asic_index not in namespaceIDs: + continue + physical_port_list = logical_port_name_to_physical_port_list(logical_port_name) if physical_port_list is None: helper_logger.log_error("No physical ports found for logical port '%s'" % logical_port_name) - update_port_transceiver_status_table(logical_port_name, status_tbl, SFP_STATUS_REMOVED) + update_port_transceiver_status_table(logical_port_name, status_tbl[asic_index], SFP_STATUS_REMOVED) for physical_port in physical_port_list: if stop_event.is_set(): break if not _wrapper_get_presence(physical_port): - update_port_transceiver_status_table(logical_port_name, status_tbl, SFP_STATUS_REMOVED) + update_port_transceiver_status_table(logical_port_name, status_tbl[asic_index], SFP_STATUS_REMOVED) else: - update_port_transceiver_status_table(logical_port_name, status_tbl, SFP_STATUS_INSERTED) - + update_port_transceiver_status_table(logical_port_name, status_tbl[asic_index], SFP_STATUS_INSERTED) # # Helper classes =============================================================== @@ -756,17 +788,30 @@ class DomInfoUpdateTask(object): helper_logger.log_info("Start DOM monitoring loop") # Connect to STATE_DB and create transceiver dom info table - state_db = daemon_base.db_connect("STATE_DB") - dom_tbl = swsscommon.Table(state_db, TRANSCEIVER_DOM_SENSOR_TABLE) - status_tbl = swsscommon.Table(state_db, TRANSCEIVER_STATUS_TABLE) + state_db, dom_tbl, status_tbl = {}, {}, {} + + # Get the namespaces in the platform + namespaces = multi_asic.get_namespaces() + namespaceIDs = multi_asic.get_namespaceIDs() + + for namespace in namespaces: + asic_id = multi_asic.get_asic_id_from_namespace(namespace) + state_db[asic_id] = daemon_base.db_connect("STATE_DB", namespace) + dom_tbl[asic_id] = swsscommon.Table(state_db[asic_id], TRANSCEIVER_DOM_SENSOR_TABLE) + status_tbl[asic_id] = swsscommon.Table(state_db[asic_id], TRANSCEIVER_STATUS_TABLE) # Start loop to update dom info in DB periodically while not self.task_stopping_event.wait(DOM_INFO_UPDATE_PERIOD_SECS): logical_port_list = platform_sfputil.logical for logical_port_name in logical_port_list: - if not detect_port_in_error_status(logical_port_name, status_tbl): - post_port_dom_info_to_db(logical_port_name, dom_tbl, self.task_stopping_event) - post_port_dom_threshold_info_to_db(logical_port_name, dom_tbl, self.task_stopping_event) + # Get the asic to which this port belongs + asic_index = platform_sfputil.get_asicId_for_logical_port(logical_port_name) + if asic_index is None or asic_index not in namespaceIDs: + continue + + if not detect_port_in_error_status(logical_port_name, status_tbl[asic_index]): + post_port_dom_info_to_db(logical_port_name, dom_tbl[asic_index], self.task_stopping_event) + post_port_dom_threshold_info_to_db(logical_port_name, dom_tbl[asic_index], self.task_stopping_event) helper_logger.log_info("Stop DOM monitoring loop") @@ -816,15 +861,22 @@ class SfpStateUpdateTask(object): transceiver_dict = {} # Connect to STATE_DB and create transceiver dom/sfp info tables - state_db = daemon_base.db_connect("STATE_DB") - int_tbl = swsscommon.Table(state_db, TRANSCEIVER_INFO_TABLE) - dom_tbl = swsscommon.Table(state_db, TRANSCEIVER_DOM_SENSOR_TABLE) - status_tbl = swsscommon.Table(state_db, TRANSCEIVER_STATUS_TABLE) + state_db, appl_db, int_tbl, dom_tbl, status_tbl, app_port_tbl = {}, {}, {}, {}, {}, {} + + # Get the namespaces in the platform + namespaces = multi_asic.get_namespaces() + namespaceIDs = multi_asic.get_namespaceIDs() - # Connect to APPL_DB to notify Media notifications - appl_db = daemon_base.db_connect("APPL_DB") - app_port_tbl = swsscommon.ProducerStateTable(appl_db, - swsscommon.APP_PORT_TABLE_NAME) + for namespace in namespaces: + asic_id = multi_asic.get_asic_id_from_namespace(namespace) + state_db[asic_id] = daemon_base.db_connect("STATE_DB", namespace) + int_tbl[asic_id] = swsscommon.Table(state_db[asic_id], TRANSCEIVER_INFO_TABLE) + dom_tbl[asic_id] = swsscommon.Table(state_db[asic_id], TRANSCEIVER_DOM_SENSOR_TABLE) + status_tbl[asic_id] = swsscommon.Table(state_db[asic_id], TRANSCEIVER_STATUS_TABLE) + + # Connect to APPL_DB to notify Media notifications + appl_db[asic_id] = daemon_base.db_connect("APPL_DB", namespace) + app_port_tbl[asic_id] = swsscommon.ProducerStateTable(appl_db[asic_id], swsscommon.APP_PORT_TABLE_NAME) # Start main loop to listen to the SFP change event. # The state migrating sequence: @@ -949,37 +1001,43 @@ class SfpStateUpdateTask(object): helper_logger.log_warning("Got unknown FP port index {}, ignored".format(key)) continue for logical_port in logical_port_list: + + # Get the asic to which this port belongs + asic_index = platform_sfputil.get_asicId_for_logical_port(logical_port) + if asic_index is None or asic_index not in namespaceIDs: + continue + if value == SFP_STATUS_INSERTED: helper_logger.log_info("Got SFP inserted event") # A plugin event will clear the error state. - update_port_transceiver_status_table(logical_port, status_tbl, SFP_STATUS_INSERTED) + update_port_transceiver_status_table(logical_port, status_tbl[asic_index], SFP_STATUS_INSERTED) helper_logger.log_info("receive plug in and update port sfp status table.") - rc = post_port_sfp_info_to_db(logical_port, int_tbl, transceiver_dict) + rc = post_port_sfp_info_to_db(logical_port, int_tbl[asic_index], transceiver_dict) # If we didn't get the sfp info, assuming the eeprom is not ready, give a try again. if rc == SFP_EEPROM_NOT_READY: helper_logger.log_warning("SFP EEPROM is not ready. One more try...") time.sleep(TIME_FOR_SFP_READY_SECS) - post_port_sfp_info_to_db(logical_port, int_tbl, transceiver_dict) - post_port_dom_info_to_db(logical_port, dom_tbl) - post_port_dom_threshold_info_to_db(logical_port, dom_tbl) - notify_media_setting(logical_port, transceiver_dict, app_port_tbl) + post_port_sfp_info_to_db(logical_port, int_tbl[asic_index], transceiver_dict) + post_port_dom_info_to_db(logical_port, dom_tbl[asic_index]) + post_port_dom_threshold_info_to_db(logical_port, dom_tbl[asic_index]) + notify_media_setting(logical_port, transceiver_dict, app_port_tbl[asic_index]) transceiver_dict.clear() elif value == SFP_STATUS_REMOVED: helper_logger.log_info("Got SFP removed event") - update_port_transceiver_status_table(logical_port, status_tbl, SFP_STATUS_REMOVED) + update_port_transceiver_status_table(logical_port, status_tbl[asic_index], SFP_STATUS_REMOVED) helper_logger.log_info("receive plug out and pdate port sfp status table.") - del_port_sfp_dom_info_from_db(logical_port, int_tbl, dom_tbl) + del_port_sfp_dom_info_from_db(logical_port, int_tbl[asic_index], dom_tbl[asic_index]) elif value in errors_block_eeprom_reading: helper_logger.log_info("Got SFP Error event") # Add port to error table to stop accessing eeprom of it # If the port already in the error table, the stored error code will # be updated to the new one. - update_port_transceiver_status_table(logical_port, status_tbl, value) + update_port_transceiver_status_table(logical_port, status_tbl[asic_index], value) helper_logger.log_info("receive error update port sfp status table.") # In this case EEPROM is not accessible, so remove the DOM info # since it will be outdated if long time no update. # but will keep the interface info in the DB since it static. - del_port_sfp_dom_info_from_db(logical_port, None, dom_tbl) + del_port_sfp_dom_info_from_db(logical_port, None, dom_tbl[asic_index]) else: # SFP return unkown event, just ignore for now. @@ -1042,6 +1100,7 @@ class DaemonXcvrd(daemon_base.DaemonBase): super(DaemonXcvrd, self).__init__(log_identifier) self.timeout = XCVRD_MAIN_THREAD_SLEEP_SECS + self.num_asics = multi_asic.get_num_asics() self.stop_event = threading.Event() self.sfp_error_event = multiprocessing.Event() @@ -1059,9 +1118,9 @@ class DaemonXcvrd(daemon_base.DaemonBase): self.log_warning("Caught unhandled signal '" + sig + "'") # Wait for port config is done - def wait_for_port_config_done(self): + def wait_for_port_config_done(self, namespace): # Connect to APPL_DB and subscribe to PORT table notifications - appl_db = daemon_base.db_connect("APPL_DB") + appl_db = daemon_base.db_connect("APPL_DB", namespace=namespace) sel = swsscommon.Select() sst = swsscommon.SubscriberStateTable(appl_db, swsscommon.APP_PORT_TABLE_NAME) @@ -1126,17 +1185,31 @@ class DaemonXcvrd(daemon_base.DaemonBase): # Load port info try: - port_config_file_path = device_info.get_path_to_port_config_file() - platform_sfputil.read_porttab_mappings(port_config_file_path) - except Exception as e: + if multi_asic.is_multi_asic(): + # For multi ASIC platforms we pass DIR of port_config_file_path and the number of asics + (platform_path, hwsku_path) = device_info.get_path_to_platform_and_hwsku() + platform_sfputil.read_all_porttab_mappings(hwsku_path, self.num_asics) + else: + # For single ASIC platforms we pass port_config_file_path and the asic_inst as 0 + port_config_file_path = device_info.get_path_to_port_config_file() + platform_sfputil.read_porttab_mappings(port_config_file_path, 0) + except Exception, e: self.log_error("Failed to read port info: %s" % (str(e)), True) sys.exit(PORT_CONFIG_LOAD_ERROR) # Connect to STATE_DB and create transceiver dom/sfp info tables - state_db = daemon_base.db_connect("STATE_DB") - self.int_tbl = swsscommon.Table(state_db, TRANSCEIVER_INFO_TABLE) - self.dom_tbl = swsscommon.Table(state_db, TRANSCEIVER_DOM_SENSOR_TABLE) - self.status_tbl = swsscommon.Table(state_db, TRANSCEIVER_STATUS_TABLE) + state_db, self.int_tbl, self.dom_tbl, self.status_tbl = {}, {}, {}, {} + + # Get the namespaces in the platform + namespaces = multi_asic.get_namespaces() + namespaceIDs = multi_asic.get_namespaceIDs() + + for namespace in namespaces: + asic_id = multi_asic.get_asic_id_from_namespace(namespace) + state_db[asic_id] = daemon_base.db_connect("STATE_DB", namespace) + self.int_tbl[asic_id] = swsscommon.Table(state_db[asic_id], TRANSCEIVER_INFO_TABLE) + self.dom_tbl[asic_id] = swsscommon.Table(state_db[asic_id], TRANSCEIVER_DOM_SENSOR_TABLE) + self.status_tbl[asic_id] = swsscommon.Table(state_db[asic_id], TRANSCEIVER_STATUS_TABLE) self.load_media_settings() warmstart = swsscommon.WarmStart() @@ -1146,7 +1219,8 @@ class DaemonXcvrd(daemon_base.DaemonBase): # Make sure this daemon started after all port configured self.log_info("Wait for port config is done") - self.wait_for_port_config_done() + for namespace in namespaces: + self.wait_for_port_config_done(namespace) # Post all the current interface dom/sfp info to STATE_DB self.log_info("Post all port DOM/SFP info to DB") @@ -1163,8 +1237,13 @@ class DaemonXcvrd(daemon_base.DaemonBase): # Delete all the information from DB and then exit logical_port_list = platform_sfputil.logical for logical_port_name in logical_port_list: - del_port_sfp_dom_info_from_db(logical_port_name, self.int_tbl, self.dom_tbl) - delete_port_from_status_table(logical_port_name, self.status_tbl) + # Get the asic to which this port belongs + asic_index = platform_sfputil.get_asicId_for_logical_port(logical_port_name) + if asic_index is None: + continue + + del_port_sfp_dom_info_from_db(logical_port_name, self.int_tbl[asic_index], self.dom_tbl[asic_index]) + delete_port_from_status_table(logical_port_name, self.status_tbl[asic_index]) # Run daemon def run(self): @@ -1186,7 +1265,7 @@ class DaemonXcvrd(daemon_base.DaemonBase): while not self.stop_event.wait(self.timeout): # Check the integrity of the sfp info table and recover the missing entries if any - recover_missing_sfp_table_entries(platform_sfputil, self.int_tbl, self.status_tbl, self.stop_event) + recover_missing_sfp_table_entries(self, platform_sfputil, self.stop_event) self.log_info("Stop daemon main loop") From 3d3c9ed3a5c2ca90b02e432c21d0228e225cf1bb Mon Sep 17 00:00:00 2001 From: Judy Joseph Date: Thu, 9 Jul 2020 23:35:59 -0700 Subject: [PATCH 2/9] Updates to initial commit --- sonic-ledd/scripts/ledd | 6 +++--- sonic-xcvrd/scripts/xcvrd | 27 +++++++++++---------------- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/sonic-ledd/scripts/ledd b/sonic-ledd/scripts/ledd index b89ee4942091..8c356b3b8872 100644 --- a/sonic-ledd/scripts/ledd +++ b/sonic-ledd/scripts/ledd @@ -73,12 +73,12 @@ class DaemonLedd(daemon_base.DaemonBase): sel = swsscommon.Select() for namespace in namespaces: - # Open a handle to the Application database + # Open a handle to the Application database, in all namespaces appl_db[namespace] = daemon_base.db_connect("APPL_DB", namespace=namespace) sst[namespace] = swsscommon.SubscriberStateTable(appl_db[namespace], swsscommon.APP_PORT_TABLE_NAME) sel.addSelectable(sst[namespace]) - # Listen indefinitely for changes to the PORT table in the Application DB + # Listen indefinitely for changes to the PORT table in the Application DB's while True: # Use timeout to prevent ignoring the signals we want to handle # in signal_handler() (e.g. SIGTERM for graceful shutdown) @@ -102,7 +102,7 @@ class DaemonLedd(daemon_base.DaemonBase): fvp_dict = dict(fvp) if op == "SET" and "oper_status" in fvp_dict: - if not key.startswith(INTERNAL_INTERFACE_PREFIX): + if not key.startswith(daemon_base.get_internal_interface_prefix()): led_control.port_link_state_change(key, fvp_dict["oper_status"]) return 1 diff --git a/sonic-xcvrd/scripts/xcvrd b/sonic-xcvrd/scripts/xcvrd index ed6b17dea4fd..881fa4fee405 100644 --- a/sonic-xcvrd/scripts/xcvrd +++ b/sonic-xcvrd/scripts/xcvrd @@ -428,8 +428,6 @@ def post_port_sfp_dom_info_to_db(is_warm_start, stop_event=threading.Event()): # Get the namespaces in the platform namespaces = multi_asic.get_namespaces() - namespaceIDs = multi_asic.get_namespaceIDs() - for namespace in namespaces: asic_id = multi_asic.get_asic_id_from_namespace(namespace) state_db[asic_id] = daemon_base.db_connect("STATE_DB", namespace) @@ -446,9 +444,9 @@ def post_port_sfp_dom_info_to_db(is_warm_start, stop_event=threading.Event()): # Get the asic to which this port belongs asic_index = platform_sfputil.get_asicId_for_logical_port(logical_port_name) - if asic_index is None or asic_index not in namespaceIDs: + if asic_index is None: + logger.log_warning("Got invalid asic index for {}, ignored".format(logical_port_name)) continue - post_port_sfp_info_to_db(logical_port_name, int_tbl[asic_index], transceiver_dict, stop_event) post_port_dom_info_to_db(logical_port_name, dom_tbl[asic_index], stop_event) post_port_dom_threshold_info_to_db(logical_port_name, dom_tbl[asic_index], stop_event) @@ -497,7 +495,8 @@ def recover_missing_sfp_table_entries(self, sfp_util, stop_event): # Get the asic to which this port belongs asic_index = sfp_util.get_asicId_for_logical_port(logical_port_name) - if asic_index is None or asic_index not in namespaceIDs: + if asic_index is None: + logger.log_warning("Got invalid asic index for {}, ignored".format(logical_port_name)) continue if logical_port_name not in keys and not detect_port_in_error_status(logical_port_name, self.status_tbl[asic_index]): @@ -742,8 +741,6 @@ def init_port_sfp_status_tbl(stop_event=threading.Event()): # Get the namespaces in the platform namespaces = multi_asic.get_namespaces() - namespaceIDs = multi_asic.get_namespaceIDs() - for namespace in namespaces: asic_id = multi_asic.get_asic_id_from_namespace(namespace) state_db[asic_id] = daemon_base.db_connect("STATE_DB", namespace) @@ -757,7 +754,8 @@ def init_port_sfp_status_tbl(stop_event=threading.Event()): # Get the asic to which this port belongs asic_index = platform_sfputil.get_asicId_for_logical_port(logical_port_name) - if asic_index is None or asic_index not in namespaceIDs: + if asic_index is None: + logger.log_warning("Got invalid asic index for {}, ignored".format(logical_port_name)) continue physical_port_list = logical_port_name_to_physical_port_list(logical_port_name) @@ -792,8 +790,6 @@ class DomInfoUpdateTask(object): # Get the namespaces in the platform namespaces = multi_asic.get_namespaces() - namespaceIDs = multi_asic.get_namespaceIDs() - for namespace in namespaces: asic_id = multi_asic.get_asic_id_from_namespace(namespace) state_db[asic_id] = daemon_base.db_connect("STATE_DB", namespace) @@ -806,7 +802,8 @@ class DomInfoUpdateTask(object): for logical_port_name in logical_port_list: # Get the asic to which this port belongs asic_index = platform_sfputil.get_asicId_for_logical_port(logical_port_name) - if asic_index is None or asic_index not in namespaceIDs: + if asic_index is None: + logger.log_warning("Got invalid asic index for {}, ignored".format(logical_port_name)) continue if not detect_port_in_error_status(logical_port_name, status_tbl[asic_index]): @@ -865,8 +862,6 @@ class SfpStateUpdateTask(object): # Get the namespaces in the platform namespaces = multi_asic.get_namespaces() - namespaceIDs = multi_asic.get_namespaceIDs() - for namespace in namespaces: asic_id = multi_asic.get_asic_id_from_namespace(namespace) state_db[asic_id] = daemon_base.db_connect("STATE_DB", namespace) @@ -1004,7 +999,8 @@ class SfpStateUpdateTask(object): # Get the asic to which this port belongs asic_index = platform_sfputil.get_asicId_for_logical_port(logical_port) - if asic_index is None or asic_index not in namespaceIDs: + if asic_index is None: + logger.log_warning("Got invalid asic index for {}, ignored".format(logical_port)) continue if value == SFP_STATUS_INSERTED: @@ -1202,8 +1198,6 @@ class DaemonXcvrd(daemon_base.DaemonBase): # Get the namespaces in the platform namespaces = multi_asic.get_namespaces() - namespaceIDs = multi_asic.get_namespaceIDs() - for namespace in namespaces: asic_id = multi_asic.get_asic_id_from_namespace(namespace) state_db[asic_id] = daemon_base.db_connect("STATE_DB", namespace) @@ -1240,6 +1234,7 @@ class DaemonXcvrd(daemon_base.DaemonBase): # Get the asic to which this port belongs asic_index = platform_sfputil.get_asicId_for_logical_port(logical_port_name) if asic_index is None: + logger.log_warning("Got invalid asic index for {}, ignored".format(logical_port_name)) continue del_port_sfp_dom_info_from_db(logical_port_name, self.int_tbl[asic_index], self.dom_tbl[asic_index]) From 81dddf17bae21bd674f00a13d317898685fce238 Mon Sep 17 00:00:00 2001 From: Judy Joseph Date: Tue, 14 Jul 2020 00:41:51 -0700 Subject: [PATCH 3/9] Updates for review comments. --- sonic-xcvrd/scripts/xcvrd | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/sonic-xcvrd/scripts/xcvrd b/sonic-xcvrd/scripts/xcvrd index 881fa4fee405..5aa70a9f08a6 100644 --- a/sonic-xcvrd/scripts/xcvrd +++ b/sonic-xcvrd/scripts/xcvrd @@ -96,7 +96,7 @@ platform_chassis = None helper_logger = logger.Logger(SYSLOG_IDENTIFIER) # MultiAsic class instance -multi_asic = multiAsic() +multi_asic = MultiAsic() # # Helper functions ============================================================= @@ -443,7 +443,7 @@ def post_port_sfp_dom_info_to_db(is_warm_start, stop_event=threading.Event()): break # Get the asic to which this port belongs - asic_index = platform_sfputil.get_asicId_for_logical_port(logical_port_name) + asic_index = platform_sfputil.get_asic_id_for_logical_port(logical_port_name) if asic_index is None: logger.log_warning("Got invalid asic index for {}, ignored".format(logical_port_name)) continue @@ -484,23 +484,23 @@ def del_port_sfp_dom_info_from_db(logical_port_name, int_tbl, dom_tbl): sys.exit(NOT_IMPLEMENTED_ERROR) # recover missing sfp table entries if any -def recover_missing_sfp_table_entries(self, sfp_util, stop_event): +def recover_missing_sfp_table_entries(sfp_util, int_tbl, status_tbl, stop_event): transceiver_dict = {} - keys = self.int_tbl.getKeys() + keys = int_tbl.getKeys() logical_port_list = sfp_util.logical for logical_port_name in logical_port_list: if stop_event.is_set(): break # Get the asic to which this port belongs - asic_index = sfp_util.get_asicId_for_logical_port(logical_port_name) + asic_index = sfp_util.get_asic_id_for_logical_port(logical_port_name) if asic_index is None: logger.log_warning("Got invalid asic index for {}, ignored".format(logical_port_name)) continue - if logical_port_name not in keys and not detect_port_in_error_status(logical_port_name, self.status_tbl[asic_index]): - post_port_sfp_info_to_db(logical_port_name, self.int_tbl[asic_index], transceiver_dict, stop_event) + if logical_port_name not in keys and not detect_port_in_error_status(logical_port_name, status_tbl[asic_index]): + post_port_sfp_info_to_db(logical_port_name, int_tbl[asic_index], transceiver_dict, stop_event) def check_port_in_range(range_str, physical_port): @@ -753,7 +753,7 @@ def init_port_sfp_status_tbl(stop_event=threading.Event()): break # Get the asic to which this port belongs - asic_index = platform_sfputil.get_asicId_for_logical_port(logical_port_name) + asic_index = platform_sfputil.get_asic_id_for_logical_port(logical_port_name) if asic_index is None: logger.log_warning("Got invalid asic index for {}, ignored".format(logical_port_name)) continue @@ -801,7 +801,7 @@ class DomInfoUpdateTask(object): logical_port_list = platform_sfputil.logical for logical_port_name in logical_port_list: # Get the asic to which this port belongs - asic_index = platform_sfputil.get_asicId_for_logical_port(logical_port_name) + asic_index = platform_sfputil.get_asic_id_for_logical_port(logical_port_name) if asic_index is None: logger.log_warning("Got invalid asic index for {}, ignored".format(logical_port_name)) continue @@ -998,7 +998,7 @@ class SfpStateUpdateTask(object): for logical_port in logical_port_list: # Get the asic to which this port belongs - asic_index = platform_sfputil.get_asicId_for_logical_port(logical_port) + asic_index = platform_sfputil.get_asic_id_for_logical_port(logical_port) if asic_index is None: logger.log_warning("Got invalid asic index for {}, ignored".format(logical_port)) continue @@ -1232,7 +1232,7 @@ class DaemonXcvrd(daemon_base.DaemonBase): logical_port_list = platform_sfputil.logical for logical_port_name in logical_port_list: # Get the asic to which this port belongs - asic_index = platform_sfputil.get_asicId_for_logical_port(logical_port_name) + asic_index = platform_sfputil.get_asic_id_for_logical_port(logical_port_name) if asic_index is None: logger.log_warning("Got invalid asic index for {}, ignored".format(logical_port_name)) continue @@ -1260,7 +1260,7 @@ class DaemonXcvrd(daemon_base.DaemonBase): while not self.stop_event.wait(self.timeout): # Check the integrity of the sfp info table and recover the missing entries if any - recover_missing_sfp_table_entries(self, platform_sfputil, self.stop_event) + recover_missing_sfp_table_entries(platform_sfputil, self.int_tbl, self.status_tbl, self.stop_event) self.log_info("Stop daemon main loop") From 0e70e2f83bd3203e798b7edf33451d5f6fbf880f Mon Sep 17 00:00:00 2001 From: Judy Joseph Date: Mon, 20 Jul 2020 23:49:01 -0700 Subject: [PATCH 4/9] Updates in ledd daemon to get the namespace from selector object. --- sonic-ledd/scripts/ledd | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/sonic-ledd/scripts/ledd b/sonic-ledd/scripts/ledd index 8c356b3b8872..87cbc51d2373 100644 --- a/sonic-ledd/scripts/ledd +++ b/sonic-ledd/scripts/ledd @@ -91,19 +91,20 @@ class DaemonLedd(daemon_base.DaemonBase): self.log_warning("sel.select() did not return swsscommon.Select.OBJECT") continue - for namespace in namespaces: - (key, op, fvp) = sst[namespace].pop() - if fvp: - # TODO: Once these flag entries have been removed from the DB, - # we can remove this check - if key in ["PortConfigDone", "PortInitDone"]: - continue - - fvp_dict = dict(fvp) - - if op == "SET" and "oper_status" in fvp_dict: - if not key.startswith(daemon_base.get_internal_interface_prefix()): - led_control.port_link_state_change(key, fvp_dict["oper_status"]) + # Get the namespace from the selectable object and use it to index the SubscriberStateTable handle. + ns=c.getDbNamespace() + (key, op, fvp) = sst[ns].pop() + if fvp: + # TODO: Once these flag entries have been removed from the DB, + # we can remove this check + if key in ["PortConfigDone", "PortInitDone"]: + continue + + fvp_dict = dict(fvp) + + if op == "SET" and "oper_status" in fvp_dict: + if not key.startswith(daemon_base.get_internal_interface_prefix()): + led_control.port_link_state_change(key, fvp_dict["oper_status"]) return 1 From 332dfff9711ba2d8673131934601c257c30b7ff2 Mon Sep 17 00:00:00 2001 From: Judy Joseph Date: Sun, 9 Aug 2020 15:37:32 -0700 Subject: [PATCH 5/9] Updated based on sonic-py-common --- sonic-ledd/scripts/ledd | 18 +++++++++++--- sonic-xcvrd/scripts/xcvrd | 49 ++++++++++++++++++++++++++++----------- 2 files changed, 51 insertions(+), 16 deletions(-) diff --git a/sonic-ledd/scripts/ledd b/sonic-ledd/scripts/ledd index 87cbc51d2373..9c9b6c5d7cca 100644 --- a/sonic-ledd/scripts/ledd +++ b/sonic-ledd/scripts/ledd @@ -10,6 +10,8 @@ try: import sys from sonic_py_common import daemon_base + from sonic_py_common import multi_asic + from sonic_py_common.interface import backplane_prefix from swsscommon import swsscommon except ImportError as e: raise ImportError (str(e) + " - required module not found") @@ -35,6 +37,9 @@ SELECT_TIMEOUT = 1000 LEDUTIL_LOAD_ERROR = 1 +# The empty namespace refers to linux host namespace. +EMPTY_NAMESPACE = '' + class DaemonLedd(daemon_base.DaemonBase): # Run daemon @@ -65,8 +70,15 @@ class DaemonLedd(daemon_base.DaemonBase): self.log_error("Failed to load ledutil: %s" % (str(e)), True) sys.exit(LEDUTIL_LOAD_ERROR) - # Get the namespaces in the platform - namespaces = multi_asic.get_namespaces() + # Load the namespace details first from the database_global.json file. + swsscommon.SonicDBConfig.initializeGlobalConfig() + + # Get the namespaces in the platform. For multi-asic devices we get the namespaces + # of front-end ascis which have front-panel interfaces. + namespaces = [EMPTY_NAMESPACE] + if multi_asic.is_multi_asic(): + ns_list = multi_asic.get_all_namespaces() + namespaces = ns_list['front_ns'] # Subscribe to PORT table notifications in the Application DB appl_db, sst = {}, {} @@ -103,7 +115,7 @@ class DaemonLedd(daemon_base.DaemonBase): fvp_dict = dict(fvp) if op == "SET" and "oper_status" in fvp_dict: - if not key.startswith(daemon_base.get_internal_interface_prefix()): + if not key.startswith(backplane_prefix()): led_control.port_link_state_change(key, fvp_dict["oper_status"]) return 1 diff --git a/sonic-xcvrd/scripts/xcvrd b/sonic-xcvrd/scripts/xcvrd index 5aa70a9f08a6..30a1ee6c0709 100644 --- a/sonic-xcvrd/scripts/xcvrd +++ b/sonic-xcvrd/scripts/xcvrd @@ -19,7 +19,8 @@ try: from enum import Enum from sonic_py_common import daemon_base, device_info, logger from swsscommon import swsscommon -except ImportError as e: + from sonic_py_common import multi_asic +except ImportError, e: raise ImportError (str(e) + " - required module not found") # @@ -95,13 +96,32 @@ platform_chassis = None # by DaemonXcvrd helper_logger = logger.Logger(SYSLOG_IDENTIFIER) -# MultiAsic class instance -multi_asic = MultiAsic() +# The empty namespace refers to linux host namespace. +EMPTY_NAMESPACE = '' # # Helper functions ============================================================= # +# Get namespaces, for single ASIC platform namespace is EMPTY_NAMESPACE +def get_front_end_namesapces(): + # Get the namespaces in the platform. For multi-asic devices we get the namespaces + # of front-end ascis which have front-panel interfaces. + namespaces = [EMPTY_NAMESPACE] + if multi_asic.is_multi_asic(): + ns_list = multi_asic.get_all_namespaces() + namespaces = ns_list['front_ns'] + + return namespaces + +# Get asic index from the namespace name +# With single ASIC platform, namespace is EMPTY_NAMESPACE, return index 0 +def get_asic_id_from_namespace(namespace): + if namespace == EMPTY_NAMESPACE: + return 0 + else: + return multi_asic.get_asic_id_from_name(namespace) + # Find out the underneath physical port list by logical name def logical_port_name_to_physical_port_list(port_name): if port_name.startswith("Ethernet"): @@ -427,9 +447,9 @@ def post_port_sfp_dom_info_to_db(is_warm_start, stop_event=threading.Event()): transceiver_dict, state_db, appl_db, int_tbl, dom_tbl, app_port_tbl = {}, {}, {}, {}, {}, {} # Get the namespaces in the platform - namespaces = multi_asic.get_namespaces() + namespaces = get_front_end_namesapces() for namespace in namespaces: - asic_id = multi_asic.get_asic_id_from_namespace(namespace) + asic_id = get_asic_id_from_namespace(namespace) state_db[asic_id] = daemon_base.db_connect("STATE_DB", namespace) appl_db[asic_id] = daemon_base.db_connect("APPL_DB", namespace) int_tbl[asic_id] = swsscommon.Table(state_db[asic_id], TRANSCEIVER_INFO_TABLE) @@ -740,9 +760,9 @@ def init_port_sfp_status_tbl(stop_event=threading.Event()): state_db, status_tbl = {},{} # Get the namespaces in the platform - namespaces = multi_asic.get_namespaces() + namespaces = get_front_end_namesapces() for namespace in namespaces: - asic_id = multi_asic.get_asic_id_from_namespace(namespace) + asic_id = get_asic_id_from_namespace(namespace) state_db[asic_id] = daemon_base.db_connect("STATE_DB", namespace) status_tbl[asic_id] = swsscommon.Table(state_db[asic_id], TRANSCEIVER_STATUS_TABLE) @@ -789,9 +809,9 @@ class DomInfoUpdateTask(object): state_db, dom_tbl, status_tbl = {}, {}, {} # Get the namespaces in the platform - namespaces = multi_asic.get_namespaces() + namespaces = get_front_end_namesapces() for namespace in namespaces: - asic_id = multi_asic.get_asic_id_from_namespace(namespace) + asic_id = get_asic_id_from_namespace(namespace) state_db[asic_id] = daemon_base.db_connect("STATE_DB", namespace) dom_tbl[asic_id] = swsscommon.Table(state_db[asic_id], TRANSCEIVER_DOM_SENSOR_TABLE) status_tbl[asic_id] = swsscommon.Table(state_db[asic_id], TRANSCEIVER_STATUS_TABLE) @@ -861,9 +881,9 @@ class SfpStateUpdateTask(object): state_db, appl_db, int_tbl, dom_tbl, status_tbl, app_port_tbl = {}, {}, {}, {}, {}, {} # Get the namespaces in the platform - namespaces = multi_asic.get_namespaces() + namespaces = get_front_end_namesapces() for namespace in namespaces: - asic_id = multi_asic.get_asic_id_from_namespace(namespace) + asic_id = get_asic_id_from_namespace(namespace) state_db[asic_id] = daemon_base.db_connect("STATE_DB", namespace) int_tbl[asic_id] = swsscommon.Table(state_db[asic_id], TRANSCEIVER_INFO_TABLE) dom_tbl[asic_id] = swsscommon.Table(state_db[asic_id], TRANSCEIVER_DOM_SENSOR_TABLE) @@ -1179,6 +1199,9 @@ class DaemonXcvrd(daemon_base.DaemonBase): self.log_error("Failed to load sfputil: %s" % (str(e)), True) sys.exit(SFPUTIL_LOAD_ERROR) + # Load the namespace details first from the database_global.json file. + swsscommon.SonicDBConfig.initializeGlobalConfig() + # Load port info try: if multi_asic.is_multi_asic(): @@ -1197,9 +1220,9 @@ class DaemonXcvrd(daemon_base.DaemonBase): state_db, self.int_tbl, self.dom_tbl, self.status_tbl = {}, {}, {}, {} # Get the namespaces in the platform - namespaces = multi_asic.get_namespaces() + namespaces = get_front_end_namesapces() for namespace in namespaces: - asic_id = multi_asic.get_asic_id_from_namespace(namespace) + asic_id = get_asic_id_from_namespace(namespace) state_db[asic_id] = daemon_base.db_connect("STATE_DB", namespace) self.int_tbl[asic_id] = swsscommon.Table(state_db[asic_id], TRANSCEIVER_INFO_TABLE) self.dom_tbl[asic_id] = swsscommon.Table(state_db[asic_id], TRANSCEIVER_DOM_SENSOR_TABLE) From 37cec198e763f6c070c5066bae1c045487c487da Mon Sep 17 00:00:00 2001 From: Judy Joseph Date: Fri, 14 Aug 2020 10:45:01 -0700 Subject: [PATCH 6/9] Invoke initializeGlobalConfig() in the SfpUpdate/DomInfoUpdate processes as well. --- sonic-xcvrd/scripts/xcvrd | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sonic-xcvrd/scripts/xcvrd b/sonic-xcvrd/scripts/xcvrd index 30a1ee6c0709..ee86de041a33 100644 --- a/sonic-xcvrd/scripts/xcvrd +++ b/sonic-xcvrd/scripts/xcvrd @@ -802,6 +802,9 @@ class DomInfoUpdateTask(object): self.task_thread = None self.task_stopping_event = threading.Event() + # Load the namespace details first from the database_global.json file. + swsscommon.SonicDBConfig.initializeGlobalConfig() + def task_worker(self): helper_logger.log_info("Start DOM monitoring loop") @@ -849,6 +852,9 @@ class SfpStateUpdateTask(object): self.task_process = None self.task_stopping_event = multiprocessing.Event() + # Load the namespace details first from the database_global.json file. + swsscommon.SonicDBConfig.initializeGlobalConfig() + def _mapping_event_from_change_event(self, status, port_dict): """ mapping from what get_transceiver_change_event returns to event defined in the state machine From 9323fa05787fb21ebeef26f9058d7d9557554be3 Mon Sep 17 00:00:00 2001 From: Judy Joseph Date: Wed, 19 Aug 2020 16:45:21 -0700 Subject: [PATCH 7/9] Fixes in xcvrd. --- sonic-xcvrd/scripts/xcvrd | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/sonic-xcvrd/scripts/xcvrd b/sonic-xcvrd/scripts/xcvrd index ee86de041a33..53e11f9e08de 100644 --- a/sonic-xcvrd/scripts/xcvrd +++ b/sonic-xcvrd/scripts/xcvrd @@ -117,10 +117,13 @@ def get_front_end_namesapces(): # Get asic index from the namespace name # With single ASIC platform, namespace is EMPTY_NAMESPACE, return index 0 def get_asic_id_from_namespace(namespace): - if namespace == EMPTY_NAMESPACE: - return 0 - else: - return multi_asic.get_asic_id_from_name(namespace) + asic_id_string = multi_asic.get_asic_id_from_name(namespace) + if asic_id_string is not None: + return int(asic_id_string) + + # Default we return back 0, handles single asic platform and check when the func + # get_asic_id_from_name() returns back None. + return 0 # Find out the underneath physical port list by logical name def logical_port_name_to_physical_port_list(port_name): @@ -1212,7 +1215,7 @@ class DaemonXcvrd(daemon_base.DaemonBase): try: if multi_asic.is_multi_asic(): # For multi ASIC platforms we pass DIR of port_config_file_path and the number of asics - (platform_path, hwsku_path) = device_info.get_path_to_platform_and_hwsku() + (platform_path, hwsku_path) = device_info.get_paths_to_platform_and_hwsku_dirs() platform_sfputil.read_all_porttab_mappings(hwsku_path, self.num_asics) else: # For single ASIC platforms we pass port_config_file_path and the asic_inst as 0 From 17572dead98a7d4549d0b86b840d1afc1103b8e6 Mon Sep 17 00:00:00 2001 From: Judy Joseph Date: Thu, 20 Aug 2020 19:41:50 -0700 Subject: [PATCH 8/9] Use common API's to get asic index and get namespaces with front-panel interfaces. --- sonic-ledd/scripts/ledd | 5 +---- sonic-xcvrd/scripts/xcvrd | 42 ++++++++++----------------------------- 2 files changed, 11 insertions(+), 36 deletions(-) diff --git a/sonic-ledd/scripts/ledd b/sonic-ledd/scripts/ledd index 9c9b6c5d7cca..52812dbaac29 100644 --- a/sonic-ledd/scripts/ledd +++ b/sonic-ledd/scripts/ledd @@ -75,10 +75,7 @@ class DaemonLedd(daemon_base.DaemonBase): # Get the namespaces in the platform. For multi-asic devices we get the namespaces # of front-end ascis which have front-panel interfaces. - namespaces = [EMPTY_NAMESPACE] - if multi_asic.is_multi_asic(): - ns_list = multi_asic.get_all_namespaces() - namespaces = ns_list['front_ns'] + namespaces = multi_asic.get_front_end_namespaces() # Subscribe to PORT table notifications in the Application DB appl_db, sst = {}, {} diff --git a/sonic-xcvrd/scripts/xcvrd b/sonic-xcvrd/scripts/xcvrd index 53e11f9e08de..533f97fff4eb 100644 --- a/sonic-xcvrd/scripts/xcvrd +++ b/sonic-xcvrd/scripts/xcvrd @@ -103,28 +103,6 @@ EMPTY_NAMESPACE = '' # Helper functions ============================================================= # -# Get namespaces, for single ASIC platform namespace is EMPTY_NAMESPACE -def get_front_end_namesapces(): - # Get the namespaces in the platform. For multi-asic devices we get the namespaces - # of front-end ascis which have front-panel interfaces. - namespaces = [EMPTY_NAMESPACE] - if multi_asic.is_multi_asic(): - ns_list = multi_asic.get_all_namespaces() - namespaces = ns_list['front_ns'] - - return namespaces - -# Get asic index from the namespace name -# With single ASIC platform, namespace is EMPTY_NAMESPACE, return index 0 -def get_asic_id_from_namespace(namespace): - asic_id_string = multi_asic.get_asic_id_from_name(namespace) - if asic_id_string is not None: - return int(asic_id_string) - - # Default we return back 0, handles single asic platform and check when the func - # get_asic_id_from_name() returns back None. - return 0 - # Find out the underneath physical port list by logical name def logical_port_name_to_physical_port_list(port_name): if port_name.startswith("Ethernet"): @@ -450,9 +428,9 @@ def post_port_sfp_dom_info_to_db(is_warm_start, stop_event=threading.Event()): transceiver_dict, state_db, appl_db, int_tbl, dom_tbl, app_port_tbl = {}, {}, {}, {}, {}, {} # Get the namespaces in the platform - namespaces = get_front_end_namesapces() + namespaces = multi_asic.get_front_end_namespaces() for namespace in namespaces: - asic_id = get_asic_id_from_namespace(namespace) + asic_id = multi_asic.get_asic_index_from_namespace(namespace) state_db[asic_id] = daemon_base.db_connect("STATE_DB", namespace) appl_db[asic_id] = daemon_base.db_connect("APPL_DB", namespace) int_tbl[asic_id] = swsscommon.Table(state_db[asic_id], TRANSCEIVER_INFO_TABLE) @@ -763,9 +741,9 @@ def init_port_sfp_status_tbl(stop_event=threading.Event()): state_db, status_tbl = {},{} # Get the namespaces in the platform - namespaces = get_front_end_namesapces() + namespaces = multi_asic.get_front_end_namespaces() for namespace in namespaces: - asic_id = get_asic_id_from_namespace(namespace) + asic_id = multi_asic.get_asic_index_from_namespace(namespace) state_db[asic_id] = daemon_base.db_connect("STATE_DB", namespace) status_tbl[asic_id] = swsscommon.Table(state_db[asic_id], TRANSCEIVER_STATUS_TABLE) @@ -815,9 +793,9 @@ class DomInfoUpdateTask(object): state_db, dom_tbl, status_tbl = {}, {}, {} # Get the namespaces in the platform - namespaces = get_front_end_namesapces() + namespaces = multi_asic.get_front_end_namespaces() for namespace in namespaces: - asic_id = get_asic_id_from_namespace(namespace) + asic_id = multi_asic.get_asic_index_from_namespace(namespace) state_db[asic_id] = daemon_base.db_connect("STATE_DB", namespace) dom_tbl[asic_id] = swsscommon.Table(state_db[asic_id], TRANSCEIVER_DOM_SENSOR_TABLE) status_tbl[asic_id] = swsscommon.Table(state_db[asic_id], TRANSCEIVER_STATUS_TABLE) @@ -890,9 +868,9 @@ class SfpStateUpdateTask(object): state_db, appl_db, int_tbl, dom_tbl, status_tbl, app_port_tbl = {}, {}, {}, {}, {}, {} # Get the namespaces in the platform - namespaces = get_front_end_namesapces() + namespaces = multi_asic.get_front_end_namespaces() for namespace in namespaces: - asic_id = get_asic_id_from_namespace(namespace) + asic_id = multi_asic.get_asic_index_from_namespace(namespace) state_db[asic_id] = daemon_base.db_connect("STATE_DB", namespace) int_tbl[asic_id] = swsscommon.Table(state_db[asic_id], TRANSCEIVER_INFO_TABLE) dom_tbl[asic_id] = swsscommon.Table(state_db[asic_id], TRANSCEIVER_DOM_SENSOR_TABLE) @@ -1229,9 +1207,9 @@ class DaemonXcvrd(daemon_base.DaemonBase): state_db, self.int_tbl, self.dom_tbl, self.status_tbl = {}, {}, {}, {} # Get the namespaces in the platform - namespaces = get_front_end_namesapces() + namespaces = multi_asic.get_front_end_namespaces() for namespace in namespaces: - asic_id = get_asic_id_from_namespace(namespace) + asic_id = multi_asic.get_asic_index_from_namespace(namespace) state_db[asic_id] = daemon_base.db_connect("STATE_DB", namespace) self.int_tbl[asic_id] = swsscommon.Table(state_db[asic_id], TRANSCEIVER_INFO_TABLE) self.dom_tbl[asic_id] = swsscommon.Table(state_db[asic_id], TRANSCEIVER_DOM_SENSOR_TABLE) From 710689f01ace8f2a159ecc92a5f1d2f10dce5077 Mon Sep 17 00:00:00 2001 From: Judy Joseph Date: Mon, 24 Aug 2020 08:19:54 -0700 Subject: [PATCH 9/9] Fix the space in initialization. --- sonic-xcvrd/scripts/xcvrd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sonic-xcvrd/scripts/xcvrd b/sonic-xcvrd/scripts/xcvrd index 533f97fff4eb..b59acdbc33a8 100644 --- a/sonic-xcvrd/scripts/xcvrd +++ b/sonic-xcvrd/scripts/xcvrd @@ -738,7 +738,7 @@ def detect_port_in_error_status(logical_port_name, status_tbl): # Init TRANSCEIVER_STATUS table def init_port_sfp_status_tbl(stop_event=threading.Event()): # Connect to STATE_DB and create transceiver status table - state_db, status_tbl = {},{} + state_db, status_tbl = {}, {} # Get the namespaces in the platform namespaces = multi_asic.get_front_end_namespaces()