From 1ed77d3389ae13e81e392f8e41ed8392f6d1c4ce Mon Sep 17 00:00:00 2001 From: jumao Date: Mon, 22 Apr 2024 19:57:56 -0400 Subject: [PATCH 1/2] Update for the procedures for insertion/hot swap of Switch Fabric Module(SFM) by using "config chassis modules shutdown/startup" commands --- sonic-chassisd/scripts/chassisd | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) mode change 100644 => 100755 sonic-chassisd/scripts/chassisd diff --git a/sonic-chassisd/scripts/chassisd b/sonic-chassisd/scripts/chassisd old mode 100644 new mode 100755 index a9d79903b..51fadd126 --- a/sonic-chassisd/scripts/chassisd +++ b/sonic-chassisd/scripts/chassisd @@ -242,7 +242,7 @@ class ModuleUpdater(logger.Logger): if isinstance(fvs, list) and fvs[0] is True: fvs = dict(fvs[-1]) return fvs[CHASSIS_MODULE_INFO_OPERSTATUS_FIELD] - return ModuleBase.MODULE_STATUS_EMPTY + return ModuleBase.MODULE_STATUS_EMPTY def module_db_update(self): notOnlineModules = [] @@ -302,16 +302,22 @@ class ModuleUpdater(logger.Logger): elif prev_status != ModuleBase.MODULE_STATUS_ONLINE: self.log_notice("Module {} is on-line!".format(key)) - for asic_id, asic in enumerate(module_info_dict[CHASSIS_MODULE_INFO_ASICS]): - asic_global_id, asic_pci_addr = asic - asic_key = "%s%s" % (CHASSIS_ASIC, asic_global_id) - if not self._is_supervisor(): - asic_key = "%s|%s" % (key, asic_key) - - asic_fvs = swsscommon.FieldValuePairs([(CHASSIS_ASIC_PCI_ADDRESS_FIELD, asic_pci_addr), - (CHASSIS_MODULE_INFO_NAME_FIELD, key), - (CHASSIS_ASIC_ID_IN_MODULE_FIELD, str(asic_id))]) - self.asic_table.set(asic_key, asic_fvs) + module_cfg_status = self.get_module_current_status(key) + if module_cfg_status == ModuleBase.MODULE_STATUS_EMPTY: + continue + + #Only populate the related tables when the module configure is down + if module_cfg_status == 'down': + for asic_id, asic in enumerate(module_info_dict[CHASSIS_MODULE_INFO_ASICS]): + asic_global_id, asic_pci_addr = asic + asic_key = "%s%s" % (CHASSIS_ASIC, asic_global_id) + if not self._is_supervisor(): + asic_key = "%s|%s" % (key, asic_key) + + asic_fvs = swsscommon.FieldValuePairs([(CHASSIS_ASIC_PCI_ADDRESS_FIELD, asic_pci_addr), + (CHASSIS_MODULE_INFO_NAME_FIELD, key), + (CHASSIS_ASIC_ID_IN_MODULE_FIELD, str(asic_id))]) + self.asic_table.set(asic_key, asic_fvs) # In line card push the hostname of the module and num_asics to the chassis state db. # The hostname is used as key to access chassis app db entries From 2cd0832a63f08f848a5357d8691576507c991541 Mon Sep 17 00:00:00 2001 From: jumao Date: Thu, 25 Apr 2024 17:54:27 -0400 Subject: [PATCH 2/2] fix based on review comments --- sonic-chassisd/scripts/chassisd | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/sonic-chassisd/scripts/chassisd b/sonic-chassisd/scripts/chassisd index 51fadd126..3997b37ff 100755 --- a/sonic-chassisd/scripts/chassisd +++ b/sonic-chassisd/scripts/chassisd @@ -84,6 +84,7 @@ INVALID_SLOT = ModuleBase.MODULE_INVALID_SLOT INVALID_MODULE_INDEX = -1 INVALID_IP = '0.0.0.0' +CHASSIS_MODULE_ADMIN_STATUS = 'admin_status' MODULE_ADMIN_DOWN = 0 MODULE_ADMIN_UP = 1 @@ -243,7 +244,17 @@ class ModuleUpdater(logger.Logger): fvs = dict(fvs[-1]) return fvs[CHASSIS_MODULE_INFO_OPERSTATUS_FIELD] return ModuleBase.MODULE_STATUS_EMPTY - + + def get_module_admin_status(self, chassis_module_name): + config_db = daemon_base.db_connect("CONFIG_DB") + vtable = swsscommon.Table(config_db, CHASSIS_CFG_TABLE) + fvs = vtable.get(chassis_module_name) + if isinstance(fvs, list) and fvs[0] is True: + fvs = dict(fvs[-1]) + return fvs[CHASSIS_MODULE_ADMIN_STATUS] + else: + return 'up' + def module_db_update(self): notOnlineModules = [] @@ -302,12 +313,10 @@ class ModuleUpdater(logger.Logger): elif prev_status != ModuleBase.MODULE_STATUS_ONLINE: self.log_notice("Module {} is on-line!".format(key)) - module_cfg_status = self.get_module_current_status(key) - if module_cfg_status == ModuleBase.MODULE_STATUS_EMPTY: - continue - - #Only populate the related tables when the module configure is down - if module_cfg_status == 'down': + module_cfg_status = self.get_module_admin_status(key) + + #Only populate the related tables when the module configure is up + if module_cfg_status != 'down': for asic_id, asic in enumerate(module_info_dict[CHASSIS_MODULE_INFO_ASICS]): asic_global_id, asic_pci_addr = asic asic_key = "%s%s" % (CHASSIS_ASIC, asic_global_id)