Skip to content

Commit 28302d4

Browse files
authored
Update for the procedures for insertion/hot swap of Switch Fabric Module (SFM) by using "config chassis modules shutdown/startup" commands (sonic-net#491)
* Update for the procedures for insertion/hot swap of Switch Fabric Module(SFM) by using "config chassis modules shutdown/startup" commands
1 parent 9ffce20 commit 28302d4

File tree

1 file changed

+28
-13
lines changed

1 file changed

+28
-13
lines changed

sonic-chassisd/scripts/chassisd

100644100755
+28-13
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ INVALID_SLOT = ModuleBase.MODULE_INVALID_SLOT
9090
INVALID_MODULE_INDEX = -1
9191
INVALID_IP = '0.0.0.0'
9292

93+
CHASSIS_MODULE_ADMIN_STATUS = 'admin_status'
9394
MODULE_ADMIN_DOWN = 0
9495
MODULE_ADMIN_UP = 1
9596

@@ -257,8 +258,18 @@ class ModuleUpdater(logger.Logger):
257258
if isinstance(fvs, list) and fvs[0] is True:
258259
fvs = dict(fvs[-1])
259260
return fvs[CHASSIS_MODULE_INFO_OPERSTATUS_FIELD]
260-
return ModuleBase.MODULE_STATUS_EMPTY
261-
261+
return ModuleBase.MODULE_STATUS_EMPTY
262+
263+
def get_module_admin_status(self, chassis_module_name):
264+
config_db = daemon_base.db_connect("CONFIG_DB")
265+
vtable = swsscommon.Table(config_db, CHASSIS_CFG_TABLE)
266+
fvs = vtable.get(chassis_module_name)
267+
if isinstance(fvs, list) and fvs[0] is True:
268+
fvs = dict(fvs[-1])
269+
return fvs[CHASSIS_MODULE_ADMIN_STATUS]
270+
else:
271+
return 'up'
272+
262273
def module_db_update(self):
263274
notOnlineModules = []
264275

@@ -317,16 +328,20 @@ class ModuleUpdater(logger.Logger):
317328
elif prev_status != ModuleBase.MODULE_STATUS_ONLINE:
318329
self.log_notice("Module {} is on-line!".format(key))
319330

320-
for asic_id, asic in enumerate(module_info_dict[CHASSIS_MODULE_INFO_ASICS]):
321-
asic_global_id, asic_pci_addr = asic
322-
asic_key = "%s%s" % (CHASSIS_ASIC, asic_global_id)
323-
if not self._is_supervisor():
324-
asic_key = "%s|%s" % (key, asic_key)
331+
module_cfg_status = self.get_module_admin_status(key)
332+
333+
#Only populate the related tables when the module configure is up
334+
if module_cfg_status != 'down':
335+
for asic_id, asic in enumerate(module_info_dict[CHASSIS_MODULE_INFO_ASICS]):
336+
asic_global_id, asic_pci_addr = asic
337+
asic_key = "%s%s" % (CHASSIS_ASIC, asic_global_id)
338+
if not self._is_supervisor():
339+
asic_key = "%s|%s" % (key, asic_key)
325340

326-
asic_fvs = swsscommon.FieldValuePairs([(CHASSIS_ASIC_PCI_ADDRESS_FIELD, asic_pci_addr),
327-
(CHASSIS_MODULE_INFO_NAME_FIELD, key),
328-
(CHASSIS_ASIC_ID_IN_MODULE_FIELD, str(asic_id))])
329-
self.asic_table.set(asic_key, asic_fvs)
341+
asic_fvs = swsscommon.FieldValuePairs([(CHASSIS_ASIC_PCI_ADDRESS_FIELD, asic_pci_addr),
342+
(CHASSIS_MODULE_INFO_NAME_FIELD, key),
343+
(CHASSIS_ASIC_ID_IN_MODULE_FIELD, str(asic_id))])
344+
self.asic_table.set(asic_key, asic_fvs)
330345

331346
# In line card push the hostname of the module and num_asics to the chassis state db.
332347
# The hostname is used as key to access chassis app db entries
@@ -518,9 +533,9 @@ class ModuleUpdater(logger.Logger):
518533
asic = CHASSIS_ASIC+str(asic_id)
519534

520535
# Cleanup the chassis app db entries using lua script
521-
redis_cmd = 'redis-cli -h redis_chassis.server -p 6380 -n 12 EVALSHA ' + self.chassis_app_db_clean_sha + ' 0 ' + lc + ' ' + asic
536+
redis_cmd = ['redis-cli', '-h', 'redis_chassis.server', '-p', '6380', '-n', '12', 'EVALSHA', self.chassis_app_db_clean_sha, '0', lc, asic]
522537
try:
523-
subp = subprocess.Popen(redis_cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
538+
subp = subprocess.Popen(redis_cmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
524539
subp.communicate()
525540
self.log_notice("Cleaned up chassis app db entries for {}({})/{}".format(module, lc, asic))
526541
except Exception:

0 commit comments

Comments
 (0)