Skip to content

Commit c61323f

Browse files
authored
[chassisd] Address the chassisd crash issue and add UT for it (#573)
Description On Nokia platform, slot name of Supervisor is string "A" instead of a number. Using "int" to convert it could cause issue backtrace. We should use slot value to any checking without any conversion. This will fixes sonic-net/sonic-buildimage#21131 Motivation and Context Modify the _get_module_info not to convert "slot" to a string value. And also modify the code not to convert slot value to an to do any checking. Just directly use the returned value of get_slot(). Also add UT test_moduleupdater_check_slot_string() to valid it. How Has This Been Tested? Tested on 202405 branch Signed-off-by: mlok <[email protected]>
1 parent 0d79916 commit c61323f

File tree

2 files changed

+52
-4
lines changed

2 files changed

+52
-4
lines changed

sonic-chassisd/scripts/chassisd

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ class ModuleUpdater(logger.Logger):
335335

336336
for module_index in range(0, self.num_modules):
337337
module_info_dict = self._get_module_info(module_index)
338-
if self.my_slot == int(module_info_dict['slot']):
338+
if self.my_slot == module_info_dict['slot']:
339339
my_index = module_index
340340

341341
if module_info_dict is not None:
@@ -352,7 +352,7 @@ class ModuleUpdater(logger.Logger):
352352

353353
fvs = swsscommon.FieldValuePairs([(CHASSIS_MODULE_INFO_DESC_FIELD, module_info_dict[CHASSIS_MODULE_INFO_DESC_FIELD]),
354354
(CHASSIS_MODULE_INFO_SLOT_FIELD,
355-
module_info_dict[CHASSIS_MODULE_INFO_SLOT_FIELD]),
355+
str(module_info_dict[CHASSIS_MODULE_INFO_SLOT_FIELD])),
356356
(CHASSIS_MODULE_INFO_OPERSTATUS_FIELD, module_info_dict[CHASSIS_MODULE_INFO_OPERSTATUS_FIELD]),
357357
(CHASSIS_MODULE_INFO_NUM_ASICS_FIELD, str(len(module_info_dict[CHASSIS_MODULE_INFO_ASICS]))),
358358
(CHASSIS_MODULE_INFO_SERIAL_FIELD, module_info_dict[CHASSIS_MODULE_INFO_SERIAL_FIELD])])
@@ -409,8 +409,8 @@ class ModuleUpdater(logger.Logger):
409409

410410
# In line card push the hostname of the module and num_asics to the chassis state db.
411411
# The hostname is used as key to access chassis app db entries
412-
module_info_dict = self._get_module_info(my_index)
413412
if not self._is_supervisor():
413+
module_info_dict = self._get_module_info(my_index)
414414
hostname_key = "{}{}".format(ModuleBase.MODULE_TYPE_LINE, int(self.my_slot) - 1)
415415
hostname = try_get(device_info.get_hostname, default="None")
416416
hostname_fvs = swsscommon.FieldValuePairs([(CHASSIS_MODULE_INFO_SLOT_FIELD, str(self.my_slot)),
@@ -445,7 +445,7 @@ class ModuleUpdater(logger.Logger):
445445

446446
module_info_dict[CHASSIS_MODULE_INFO_NAME_FIELD] = name
447447
module_info_dict[CHASSIS_MODULE_INFO_DESC_FIELD] = str(desc)
448-
module_info_dict[CHASSIS_MODULE_INFO_SLOT_FIELD] = str(slot)
448+
module_info_dict[CHASSIS_MODULE_INFO_SLOT_FIELD] = slot
449449
module_info_dict[CHASSIS_MODULE_INFO_OPERSTATUS_FIELD] = str(status)
450450
module_info_dict[CHASSIS_MODULE_INFO_ASICS] = asics
451451
module_info_dict[CHASSIS_MODULE_INFO_SERIAL_FIELD] = str(serial)

sonic-chassisd/tests/test_chassisd.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,54 @@ def test_configupdater_check_num_modules():
631631
fvs = module_updater.chassis_table.get(CHASSIS_INFO_KEY_TEMPLATE.format(1))
632632
assert fvs == None
633633

634+
def test_moduleupdater_check_string_slot():
635+
chassis = MockChassis()
636+
637+
#Supervisor
638+
index = 0
639+
name = "SUPERVISOR0"
640+
desc = "Supervisor card"
641+
slot = "A"
642+
serial = "RP1000101"
643+
module_type = ModuleBase.MODULE_TYPE_SUPERVISOR
644+
supervisor = MockModule(index, name, desc, module_type, slot, serial)
645+
supervisor.set_midplane_ip()
646+
chassis.module_list.append(supervisor)
647+
648+
#Linecard
649+
index = 1
650+
name = "LINE-CARD0"
651+
desc = "36 port 400G card"
652+
slot = "1"
653+
serial = "LC1000101"
654+
module_type = ModuleBase.MODULE_TYPE_LINE
655+
module = MockModule(index, name, desc, module_type, slot, serial)
656+
module.set_midplane_ip()
657+
chassis.module_list.append(module)
658+
659+
#Fabric-card
660+
index = 1
661+
name = "FABRIC-CARD0"
662+
desc = "Switch fabric card"
663+
slot = "17"
664+
serial = "FC1000101"
665+
module_type = ModuleBase.MODULE_TYPE_FABRIC
666+
fabric = MockModule(index, name, desc, module_type, slot, serial)
667+
chassis.module_list.append(fabric)
668+
669+
#Run on supervisor
670+
module_updater = ModuleUpdater(SYSLOG_IDENTIFIER, chassis, slot,
671+
module.supervisor_slot)
672+
module_updater.supervisor_slot = supervisor.get_slot()
673+
module_updater.my_slot = supervisor.get_slot()
674+
module_updater.modules_num_update()
675+
module_updater.module_db_update()
676+
module_updater.check_midplane_reachability()
677+
678+
midplane_table = module_updater.midplane_table
679+
#Check only one entry in database
680+
assert 1 == midplane_table.size()
681+
634682
def test_midplane_presence_modules():
635683
chassis = MockChassis()
636684

0 commit comments

Comments
 (0)