From e98a850b0589f9013588a97e840d581ba4c73d08 Mon Sep 17 00:00:00 2001 From: amulyan7 <98349131+amulyan7@users.noreply.github.com> Date: Wed, 7 Jun 2023 12:44:15 -0700 Subject: [PATCH] Add serial field to chassis module table (#363) Add support for serial field to into STATE_DB CHASSIS_MODULE_TABLE --- sonic-chassisd/scripts/chassisd | 7 +++- sonic-chassisd/tests/mock_platform.py | 6 ++- sonic-chassisd/tests/test_chassisd.py | 53 ++++++++++++++++++--------- 3 files changed, 47 insertions(+), 19 deletions(-) diff --git a/sonic-chassisd/scripts/chassisd b/sonic-chassisd/scripts/chassisd index fea1853d4..64206297b 100644 --- a/sonic-chassisd/scripts/chassisd +++ b/sonic-chassisd/scripts/chassisd @@ -49,6 +49,7 @@ CHASSIS_MODULE_INFO_SLOT_FIELD = 'slot' CHASSIS_MODULE_INFO_OPERSTATUS_FIELD = 'oper_status' CHASSIS_MODULE_INFO_NUM_ASICS_FIELD = 'num_asics' CHASSIS_MODULE_INFO_ASICS = 'asics' +CHASSIS_MODULE_INFO_SERIAL_FIELD = 'serial' CHASSIS_ASIC_INFO_TABLE = 'CHASSIS_ASIC_TABLE' CHASSIS_FABRIC_ASIC_INFO_TABLE = 'CHASSIS_FABRIC_ASIC_TABLE' @@ -178,6 +179,7 @@ class ModuleUpdater(logger.Logger): self.info_dict_keys = [CHASSIS_MODULE_INFO_NAME_FIELD, CHASSIS_MODULE_INFO_DESC_FIELD, CHASSIS_MODULE_INFO_SLOT_FIELD, + CHASSIS_MODULE_INFO_SERIAL_FIELD, CHASSIS_MODULE_INFO_OPERSTATUS_FIELD] self.chassis_state_db = daemon_base.db_connect("CHASSIS_STATE_DB") @@ -245,7 +247,8 @@ class ModuleUpdater(logger.Logger): (CHASSIS_MODULE_INFO_SLOT_FIELD, module_info_dict[CHASSIS_MODULE_INFO_SLOT_FIELD]), (CHASSIS_MODULE_INFO_OPERSTATUS_FIELD, module_info_dict[CHASSIS_MODULE_INFO_OPERSTATUS_FIELD]), - (CHASSIS_MODULE_INFO_NUM_ASICS_FIELD, str(len(module_info_dict[CHASSIS_MODULE_INFO_ASICS])))]) + (CHASSIS_MODULE_INFO_NUM_ASICS_FIELD, str(len(module_info_dict[CHASSIS_MODULE_INFO_ASICS]))), + (CHASSIS_MODULE_INFO_SERIAL_FIELD, module_info_dict[CHASSIS_MODULE_INFO_SERIAL_FIELD])]) self.module_table.set(key, fvs) if module_info_dict[CHASSIS_MODULE_INFO_OPERSTATUS_FIELD] != str(ModuleBase.MODULE_STATUS_ONLINE): @@ -285,12 +288,14 @@ class ModuleUpdater(logger.Logger): default=ModuleBase.MODULE_STATUS_OFFLINE) asics = try_get(self.chassis.get_module(module_index).get_all_asics, default=[]) + serial = try_get(self.chassis.get_module(module_index).get_serial) module_info_dict[CHASSIS_MODULE_INFO_NAME_FIELD] = name module_info_dict[CHASSIS_MODULE_INFO_DESC_FIELD] = str(desc) module_info_dict[CHASSIS_MODULE_INFO_SLOT_FIELD] = str(slot) module_info_dict[CHASSIS_MODULE_INFO_OPERSTATUS_FIELD] = str(status) module_info_dict[CHASSIS_MODULE_INFO_ASICS] = asics + module_info_dict[CHASSIS_MODULE_INFO_SERIAL_FIELD] = str(serial) return module_info_dict diff --git a/sonic-chassisd/tests/mock_platform.py b/sonic-chassisd/tests/mock_platform.py index a1ab20530..0e6b7f36f 100644 --- a/sonic-chassisd/tests/mock_platform.py +++ b/sonic-chassisd/tests/mock_platform.py @@ -20,7 +20,7 @@ def get_serial(self): class MockModule(MockDevice): def __init__(self, module_index, module_name, module_desc, module_type, module_slot, - asic_list=[]): + module_serial, asic_list=[]): self.module_index = module_index self.module_name = module_name self.module_desc = module_desc @@ -31,6 +31,7 @@ def __init__(self, module_index, module_name, module_desc, module_type, module_s self.supervisor_slot = 16 self.midplane_access = False self.asic_list = asic_list + self.module_serial = module_serial def get_name(self): return self.module_name @@ -74,6 +75,9 @@ def set_midplane_reachable(self, up): def get_all_asics(self): return self.asic_list + def get_serial(self): + return self.module_serial + class MockChassis: def __init__(self): self.module_list = [] diff --git a/sonic-chassisd/tests/test_chassisd.py b/sonic-chassisd/tests/test_chassisd.py index 6986059be..5b073af50 100644 --- a/sonic-chassisd/tests/test_chassisd.py +++ b/sonic-chassisd/tests/test_chassisd.py @@ -32,6 +32,7 @@ CHASSIS_MODULE_INFO_DESC_FIELD = 'desc' CHASSIS_MODULE_INFO_SLOT_FIELD = 'slot' CHASSIS_MODULE_INFO_OPERSTATUS_FIELD = 'oper_status' +CHASSIS_MODULE_INFO_SERIAL_FIELD = 'serial' CHASSIS_INFO_KEY_TEMPLATE = 'CHASSIS {}' CHASSIS_INFO_CARD_NUM_FIELD = 'module_num' @@ -55,8 +56,9 @@ def test_moduleupdater_check_valid_fields(): name = "FABRIC-CARD0" desc = "Switch Fabric Module" slot = 10 + serial = "FC1000101" module_type = ModuleBase.MODULE_TYPE_FABRIC - module = MockModule(index, name, desc, module_type, slot) + module = MockModule(index, name, desc, module_type, slot, serial) # Set initial state status = ModuleBase.MODULE_STATUS_ONLINE @@ -71,6 +73,7 @@ def test_moduleupdater_check_valid_fields(): assert desc == fvs[CHASSIS_MODULE_INFO_DESC_FIELD] assert slot == int(fvs[CHASSIS_MODULE_INFO_SLOT_FIELD]) assert status == fvs[CHASSIS_MODULE_INFO_OPERSTATUS_FIELD] + assert serial == fvs[CHASSIS_MODULE_INFO_SERIAL_FIELD] def test_moduleupdater_check_invalid_name(): @@ -79,8 +82,9 @@ def test_moduleupdater_check_invalid_name(): name = "TEST-CARD0" desc = "36 port 400G card" slot = 2 + serial = "TS1000101" module_type = ModuleBase.MODULE_TYPE_LINE - module = MockModule(index, name, desc, module_type, slot) + module = MockModule(index, name, desc, module_type, slot, serial) # Set initial state status = ModuleBase.MODULE_STATUS_PRESENT @@ -101,8 +105,9 @@ def test_moduleupdater_check_status_update(): name = "LINE-CARD0" desc = "36 port 400G card" slot = 1 + serial = "LC1000101" module_type = ModuleBase.MODULE_TYPE_LINE - module = MockModule(index, name, desc, module_type, slot) + module = MockModule(index, name, desc, module_type, slot, serial) # Set initial state status = ModuleBase.MODULE_STATUS_ONLINE @@ -136,8 +141,9 @@ def test_moduleupdater_check_deinit(): name = "LINE-CARD0" desc = "36 port 400G card" slot = 1 + serial = "LC1000101" module_type = ModuleBase.MODULE_TYPE_LINE - module = MockModule(index, name, desc, module_type, slot) + module = MockModule(index, name, desc, module_type, slot, serial) # Set initial state status = ModuleBase.MODULE_STATUS_ONLINE @@ -163,8 +169,9 @@ def test_configupdater_check_valid_names(): name = "TEST-CARD0" desc = "36 port 400G card" slot = 1 + serial = "TC1000101" module_type = ModuleBase.MODULE_TYPE_LINE - module = MockModule(index, name, desc, module_type, slot) + module = MockModule(index, name, desc, module_type, slot, serial) # Set initial state status = ModuleBase.MODULE_STATUS_ONLINE @@ -185,8 +192,9 @@ def test_configupdater_check_valid_index(): name = "LINE-CARD0" desc = "36 port 400G card" slot = 1 + serial = "LC1000101" module_type = ModuleBase.MODULE_TYPE_LINE - module = MockModule(index, name, desc, module_type, slot) + module = MockModule(index, name, desc, module_type, slot, serial) # Set initial state status = ModuleBase.MODULE_STATUS_ONLINE @@ -207,8 +215,9 @@ def test_configupdater_check_admin_state(): name = "LINE-CARD0" desc = "36 port 400G card" slot = 1 + serial = "LC1000101" module_type = ModuleBase.MODULE_TYPE_LINE - module = MockModule(index, name, desc, module_type, slot) + module = MockModule(index, name, desc, module_type, slot, serial) # Set initial state status = ModuleBase.MODULE_STATUS_ONLINE @@ -231,8 +240,9 @@ def test_configupdater_check_num_modules(): name = "LINE-CARD0" desc = "36 port 400G card" slot = 1 + serial = "LC1000101" module_type = ModuleBase.MODULE_TYPE_LINE - module = MockModule(index, name, desc, module_type, slot) + module = MockModule(index, name, desc, module_type, slot, serial) # No modules module_updater = ModuleUpdater(SYSLOG_IDENTIFIER, chassis, slot, @@ -259,8 +269,9 @@ def test_midplane_presence_modules(): name = "SUPERVISOR0" desc = "Supervisor card" slot = 16 + serial = "RP1000101" module_type = ModuleBase.MODULE_TYPE_SUPERVISOR - supervisor = MockModule(index, name, desc, module_type, slot) + supervisor = MockModule(index, name, desc, module_type, slot, serial) supervisor.set_midplane_ip() chassis.module_list.append(supervisor) @@ -269,8 +280,9 @@ def test_midplane_presence_modules(): name = "LINE-CARD0" desc = "36 port 400G card" slot = 1 + serial = "LC1000101" module_type = ModuleBase.MODULE_TYPE_LINE - module = MockModule(index, name, desc, module_type, slot) + module = MockModule(index, name, desc, module_type, slot, serial) module.set_midplane_ip() chassis.module_list.append(module) @@ -279,8 +291,9 @@ def test_midplane_presence_modules(): name = "FABRIC-CARD0" desc = "Switch fabric card" slot = 17 + serial = "FC1000101" module_type = ModuleBase.MODULE_TYPE_FABRIC - fabric = MockModule(index, name, desc, module_type, slot) + fabric = MockModule(index, name, desc, module_type, slot, serial) chassis.module_list.append(fabric) #Run on supervisor @@ -324,8 +337,9 @@ def test_midplane_presence_supervisor(): name = "SUPERVISOR0" desc = "Supervisor card" slot = 16 + serial = "RP1000101" module_type = ModuleBase.MODULE_TYPE_SUPERVISOR - supervisor = MockModule(index, name, desc, module_type, slot) + supervisor = MockModule(index, name, desc, module_type, slot, serial) supervisor.set_midplane_ip() chassis.module_list.append(supervisor) @@ -334,8 +348,9 @@ def test_midplane_presence_supervisor(): name = "LINE-CARD0" desc = "36 port 400G card" slot = 1 + serial = "LC1000101" module_type = ModuleBase.MODULE_TYPE_LINE - module = MockModule(index, name, desc, module_type, slot) + module = MockModule(index, name, desc, module_type, slot, serial) module.set_midplane_ip() chassis.module_list.append(module) @@ -344,8 +359,9 @@ def test_midplane_presence_supervisor(): name = "FABRIC-CARD0" desc = "Switch fabric card" slot = 17 + serial = "FC1000101" module_type = ModuleBase.MODULE_TYPE_FABRIC - fabric = MockModule(index, name, desc, module_type, slot) + fabric = MockModule(index, name, desc, module_type, slot, serial) chassis.module_list.append(fabric) #Run on supervisor @@ -389,8 +405,9 @@ def test_asic_presence(): name = "SUPERVISOR0" desc = "Supervisor card" slot = 16 + serial = "RP1000101" module_type = ModuleBase.MODULE_TYPE_SUPERVISOR - supervisor = MockModule(index, name, desc, module_type, slot) + supervisor = MockModule(index, name, desc, module_type, slot, serial) supervisor.set_midplane_ip() chassis.module_list.append(supervisor) @@ -399,8 +416,9 @@ def test_asic_presence(): name = "LINE-CARD0" desc = "36 port 400G card" slot = 1 + serial = "LC1000101" module_type = ModuleBase.MODULE_TYPE_LINE - module = MockModule(index, name, desc, module_type, slot) + module = MockModule(index, name, desc, module_type, slot, serial) module.set_midplane_ip() chassis.module_list.append(module) @@ -409,9 +427,10 @@ def test_asic_presence(): name = "FABRIC-CARD0" desc = "Switch fabric card" slot = 17 + serial = "FC1000101" module_type = ModuleBase.MODULE_TYPE_FABRIC fabric_asic_list = [("4", "0000:04:00.0"), ("5", "0000:05:00.0")] - fabric = MockModule(index, name, desc, module_type, slot, fabric_asic_list) + fabric = MockModule(index, name, desc, module_type, slot, serial, fabric_asic_list) chassis.module_list.append(fabric) #Run on supervisor