Skip to content

[chassisd] update chassisd to write fabric and lc asics on seperate table in chassis state db #311

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 36 additions & 23 deletions sonic-chassisd/scripts/chassisd
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ CHASSIS_MODULE_INFO_NUM_ASICS_FIELD = 'num_asics'
CHASSIS_MODULE_INFO_ASICS = 'asics'

CHASSIS_ASIC_INFO_TABLE = 'CHASSIS_ASIC_TABLE'
CHASSIS_FABRIC_ASIC_INFO_TABLE = 'CHASSIS_FABRIC_ASIC_TABLE'
CHASSIS_ASIC = 'asic'
CHASSIS_ASIC_PCI_ADDRESS_FIELD = 'asic_pci_address'
CHASSIS_ASIC_ID_IN_MODULE_FIELD = 'asic_id_in_module'
Expand Down Expand Up @@ -158,14 +159,16 @@ class ModuleConfigUpdater(logger.Logger):

class ModuleUpdater(logger.Logger):

def __init__(self, log_identifier, chassis):
def __init__(self, log_identifier, chassis, my_slot, supervisor_slot):
"""
Constructor for ModuleUpdater
:param chassis: Object representing a platform chassis
"""
super(ModuleUpdater, self).__init__(log_identifier)

self.chassis = chassis
self.my_slot = my_slot
self.supervisor_slot = supervisor_slot
self.num_modules = chassis.get_num_modules()
# Connect to STATE_DB and create chassis info tables
state_db = daemon_base.db_connect("STATE_DB")
Expand All @@ -177,9 +180,14 @@ class ModuleUpdater(logger.Logger):
CHASSIS_MODULE_INFO_SLOT_FIELD,
CHASSIS_MODULE_INFO_OPERSTATUS_FIELD]

chassis_state_db = daemon_base.db_connect("CHASSIS_STATE_DB")
self.asic_table = swsscommon.Table(chassis_state_db, CHASSIS_ASIC_INFO_TABLE)

self.chassis_state_db = daemon_base.db_connect("CHASSIS_STATE_DB")
if self._is_supervisor():
self.asic_table = swsscommon.Table(self.chassis_state_db,
CHASSIS_FABRIC_ASIC_INFO_TABLE)
else:
self.asic_table = swsscommon.Table(self.chassis_state_db,
CHASSIS_ASIC_INFO_TABLE)
#
self.midplane_initialized = try_get(chassis.init_midplane_switch, default=False)
if not self.midplane_initialized:
self.log_error("Chassisd midplane intialization failed")
Expand Down Expand Up @@ -240,25 +248,28 @@ class ModuleUpdater(logger.Logger):
self.module_table.set(key, fvs)

if module_info_dict[CHASSIS_MODULE_INFO_OPERSTATUS_FIELD] != str(ModuleBase.MODULE_STATUS_ONLINE):
notOnlineModules.append(key)
continue
notOnlineModules.append(key)
continue

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)
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)
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)

# Asics that are on the "not online" modules need to be cleaned up
asics = list(self.asic_table.getKeys())
for asic in asics:
fvs = self.asic_table.get(asic)
if isinstance(fvs, list):
fvs = dict(fvs[-1])
if fvs[CHASSIS_MODULE_INFO_NAME_FIELD] in notOnlineModules:
self.asic_table._del(asic)
fvs = self.asic_table.get(asic)
if isinstance(fvs, list):
fvs = dict(fvs[-1])
if fvs[CHASSIS_MODULE_INFO_NAME_FIELD] in notOnlineModules:
self.asic_table._del(asic)

def _get_module_info(self, module_index):
"""
Expand Down Expand Up @@ -403,15 +414,17 @@ class ChassisdDaemon(daemon_base.DaemonBase):
self.log_error("Failed to load chassis due to {}".format(repr(e)))
sys.exit(CHASSIS_LOAD_ERROR)

# Check if module list is populated
self.module_updater = ModuleUpdater(SYSLOG_IDENTIFIER, platform_chassis)
self.module_updater.modules_num_update()

# Check for valid slot numbers
self.module_updater.my_slot = try_get(platform_chassis.get_my_slot,
my_slot = try_get(platform_chassis.get_my_slot,
default=INVALID_SLOT)
self.module_updater.supervisor_slot = try_get(platform_chassis.get_supervisor_slot,
supervisor_slot = try_get(platform_chassis.get_supervisor_slot,
default=INVALID_SLOT)

# Check if module list is populated
self.module_updater = ModuleUpdater(SYSLOG_IDENTIFIER, platform_chassis, my_slot, supervisor_slot)
self.module_updater.modules_num_update()


if ((self.module_updater.my_slot == INVALID_SLOT) or
(self.module_updater.supervisor_slot == INVALID_SLOT)):
self.log_error("Chassisd not supported for this platform")
Expand Down
27 changes: 17 additions & 10 deletions sonic-chassisd/tests/test_chassisd.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ def test_moduleupdater_check_valid_fields():

chassis.module_list.append(module)

module_updater = ModuleUpdater(SYSLOG_IDENTIFIER, chassis)
module_updater = ModuleUpdater(SYSLOG_IDENTIFIER, chassis, slot,
module.supervisor_slot)
module_updater.module_db_update()
fvs = module_updater.module_table.get(name)
assert desc == fvs[CHASSIS_MODULE_INFO_DESC_FIELD]
Expand All @@ -82,7 +83,8 @@ def test_moduleupdater_check_invalid_name():

chassis.module_list.append(module)

module_updater = ModuleUpdater(SYSLOG_IDENTIFIER, chassis)
module_updater = ModuleUpdater(SYSLOG_IDENTIFIER, chassis, slot,
module.supervisor_slot)
module_updater.module_db_update()
fvs = module_updater.module_table.get(name)
assert fvs == None
Expand All @@ -102,7 +104,8 @@ def test_moduleupdater_check_status_update():
module.set_oper_status(status)
chassis.module_list.append(module)

module_updater = ModuleUpdater(SYSLOG_IDENTIFIER, chassis)
module_updater = ModuleUpdater(SYSLOG_IDENTIFIER, chassis, slot,
module.supervisor_slot)
module_updater.module_db_update()
fvs = module_updater.module_table.get(name)
print('Initial DB-entry {}'.format(fvs))
Expand Down Expand Up @@ -136,7 +139,8 @@ def test_moduleupdater_check_deinit():
module.set_oper_status(status)
chassis.module_list.append(module)

module_updater = ModuleUpdater(SYSLOG_IDENTIFIER, chassis)
module_updater = ModuleUpdater(SYSLOG_IDENTIFIER, chassis, slot,
module.supervisor_slot)
module_updater.modules_num_update()
module_updater.module_db_update()
fvs = module_updater.module_table.get(name)
Expand Down Expand Up @@ -226,7 +230,8 @@ def test_configupdater_check_num_modules():
module = MockModule(index, name, desc, module_type, slot)

# No modules
module_updater = ModuleUpdater(SYSLOG_IDENTIFIER, chassis)
module_updater = ModuleUpdater(SYSLOG_IDENTIFIER, chassis, slot,
module.supervisor_slot)
module_updater.modules_num_update()
fvs = module_updater.chassis_table.get(CHASSIS_INFO_KEY_TEMPLATE.format(1))
assert fvs == None
Expand Down Expand Up @@ -274,7 +279,8 @@ def test_midplane_presence_modules():
chassis.module_list.append(fabric)

#Run on supervisor
module_updater = ModuleUpdater(SYSLOG_IDENTIFIER, chassis)
module_updater = ModuleUpdater(SYSLOG_IDENTIFIER, chassis, slot,
module.supervisor_slot)
module_updater.supervisor_slot = supervisor.get_slot()
module_updater.my_slot = supervisor.get_slot()
module_updater.modules_num_update()
Expand Down Expand Up @@ -338,7 +344,8 @@ def test_midplane_presence_supervisor():
chassis.module_list.append(fabric)

#Run on supervisor
module_updater = ModuleUpdater(SYSLOG_IDENTIFIER, chassis)
module_updater = ModuleUpdater(SYSLOG_IDENTIFIER, chassis, slot,
module.supervisor_slot)
module_updater.supervisor_slot = supervisor.get_slot()
module_updater.my_slot = module.get_slot()
module_updater.modules_num_update()
Expand Down Expand Up @@ -403,9 +410,9 @@ def test_asic_presence():
chassis.module_list.append(fabric)

#Run on supervisor
module_updater = ModuleUpdater(SYSLOG_IDENTIFIER, chassis)
module_updater.supervisor_slot = supervisor.get_slot()
module_updater.my_slot = supervisor.get_slot()
module_updater = ModuleUpdater(SYSLOG_IDENTIFIER, chassis,
module.supervisor_slot,
module.supervisor_slot)
module_updater.modules_num_update()
module_updater.module_db_update()
module_updater.check_midplane_reachability()
Expand Down