Skip to content

Commit

Permalink
Add serial field to chassis module table (#363)
Browse files Browse the repository at this point in the history
Add support for serial field to into STATE_DB CHASSIS_MODULE_TABLE
  • Loading branch information
amulyan7 authored Jun 7, 2023
1 parent 37f0c36 commit e98a850
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 19 deletions.
7 changes: 6 additions & 1 deletion sonic-chassisd/scripts/chassisd
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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

Expand Down
6 changes: 5 additions & 1 deletion sonic-chassisd/tests/mock_platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 = []
Expand Down
53 changes: 36 additions & 17 deletions sonic-chassisd/tests/test_chassisd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
Expand All @@ -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():
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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)

Expand All @@ -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)

Expand All @@ -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
Expand Down Expand Up @@ -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)

Expand All @@ -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)

Expand All @@ -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
Expand Down Expand Up @@ -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)

Expand All @@ -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)

Expand All @@ -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
Expand Down

0 comments on commit e98a850

Please sign in to comment.