Skip to content

Commit 707a720

Browse files
authored
[chassisd] update chassisd to write fabric and lc asics on sep erate table (sonic-net#311)
Signed-off-by: Arvindsrinivasan Lakshmi Narasimhan <[email protected]> Description The following changes are done in chassisd Change the ModuleUpdater init changed to include slot and supervisor as argument. Add logic to in ModuleUpdater to update the asic_info in CHASSIS_FABRIC_ASIC_INFO for the supervisor and CHASSIS_ASIC_TABLE for the linecard asics respectively. Add the linecard name is the key of the CHASSIS_ASIC_TABLE update the UT Motivation and Context Fixes sonic-net#12575 and sonic-net#12575 How Has This Been Tested? Update the pmon on the supervisor and linecard and verify the CHASSIS_STATE_DB is update properly admin@str2-sonic-sup-1:~$ redis-cli -h redis_chassis.server -p 6380 -n 13 keys *ASIC* 1) "CHASSIS_ASIC_TABLE|LINE-CARD4|asic0" 2) "CHASSIS_FABRIC_ASIC_TABLE|asic1" 3) "CHASSIS_FABRIC_ASIC_TABLE|asic8" 4) "CHASSIS_FABRIC_ASIC_TABLE|asic10" 5) "CHASSIS_ASIC_TABLE|LINE-CARD0|asic0" 6) "CHASSIS_FABRIC_ASIC_TABLE|asic6" 7) "CHASSIS_FABRIC_ASIC_TABLE|asic9" 8) "CHASSIS_FABRIC_ASIC_TABLE|asic5" 9) "CHASSIS_FABRIC_ASIC_TABLE|asic3" 10) "CHASSIS_ASIC_TABLE|LINE-CARD3|asic0" 11) "CHASSIS_FABRIC_ASIC_TABLE|asic2" 12) "CHASSIS_ASIC_TABLE|LINE-CARD2|asic0" 13) "CHASSIS_ASIC_TABLE|LINE-CARD2|asic1" 14) "CHASSIS_FABRIC_ASIC_TABLE|asic11" 15) "CHASSIS_FABRIC_ASIC_TABLE|asic0" 16) "CHASSIS_FABRIC_ASIC_TABLE|asic4" 17) "CHASSIS_FABRIC_ASIC_TABLE|asic7" admin@str2-sonic-sup-1:~$
1 parent e8c5657 commit 707a720

File tree

2 files changed

+53
-33
lines changed

2 files changed

+53
-33
lines changed

sonic-chassisd/scripts/chassisd

+36-23
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ CHASSIS_MODULE_INFO_NUM_ASICS_FIELD = 'num_asics'
5151
CHASSIS_MODULE_INFO_ASICS = 'asics'
5252

5353
CHASSIS_ASIC_INFO_TABLE = 'CHASSIS_ASIC_TABLE'
54+
CHASSIS_FABRIC_ASIC_INFO_TABLE = 'CHASSIS_FABRIC_ASIC_TABLE'
5455
CHASSIS_ASIC = 'asic'
5556
CHASSIS_ASIC_PCI_ADDRESS_FIELD = 'asic_pci_address'
5657
CHASSIS_ASIC_ID_IN_MODULE_FIELD = 'asic_id_in_module'
@@ -158,14 +159,16 @@ class ModuleConfigUpdater(logger.Logger):
158159

159160
class ModuleUpdater(logger.Logger):
160161

161-
def __init__(self, log_identifier, chassis):
162+
def __init__(self, log_identifier, chassis, my_slot, supervisor_slot):
162163
"""
163164
Constructor for ModuleUpdater
164165
:param chassis: Object representing a platform chassis
165166
"""
166167
super(ModuleUpdater, self).__init__(log_identifier)
167168

168169
self.chassis = chassis
170+
self.my_slot = my_slot
171+
self.supervisor_slot = supervisor_slot
169172
self.num_modules = chassis.get_num_modules()
170173
# Connect to STATE_DB and create chassis info tables
171174
state_db = daemon_base.db_connect("STATE_DB")
@@ -177,9 +180,14 @@ class ModuleUpdater(logger.Logger):
177180
CHASSIS_MODULE_INFO_SLOT_FIELD,
178181
CHASSIS_MODULE_INFO_OPERSTATUS_FIELD]
179182

180-
chassis_state_db = daemon_base.db_connect("CHASSIS_STATE_DB")
181-
self.asic_table = swsscommon.Table(chassis_state_db, CHASSIS_ASIC_INFO_TABLE)
182-
183+
self.chassis_state_db = daemon_base.db_connect("CHASSIS_STATE_DB")
184+
if self._is_supervisor():
185+
self.asic_table = swsscommon.Table(self.chassis_state_db,
186+
CHASSIS_FABRIC_ASIC_INFO_TABLE)
187+
else:
188+
self.asic_table = swsscommon.Table(self.chassis_state_db,
189+
CHASSIS_ASIC_INFO_TABLE)
190+
#
183191
self.midplane_initialized = try_get(chassis.init_midplane_switch, default=False)
184192
if not self.midplane_initialized:
185193
self.log_error("Chassisd midplane intialization failed")
@@ -240,25 +248,28 @@ class ModuleUpdater(logger.Logger):
240248
self.module_table.set(key, fvs)
241249

242250
if module_info_dict[CHASSIS_MODULE_INFO_OPERSTATUS_FIELD] != str(ModuleBase.MODULE_STATUS_ONLINE):
243-
notOnlineModules.append(key)
244-
continue
251+
notOnlineModules.append(key)
252+
continue
245253

246254
for asic_id, asic in enumerate(module_info_dict[CHASSIS_MODULE_INFO_ASICS]):
247-
asic_global_id, asic_pci_addr = asic
248-
asic_key = "%s%s" % (CHASSIS_ASIC, asic_global_id)
249-
asic_fvs = swsscommon.FieldValuePairs([(CHASSIS_ASIC_PCI_ADDRESS_FIELD, asic_pci_addr),
250-
(CHASSIS_MODULE_INFO_NAME_FIELD, key),
251-
(CHASSIS_ASIC_ID_IN_MODULE_FIELD, str(asic_id))])
252-
self.asic_table.set(asic_key, asic_fvs)
255+
asic_global_id, asic_pci_addr = asic
256+
asic_key = "%s%s" % (CHASSIS_ASIC, asic_global_id)
257+
if not self._is_supervisor():
258+
asic_key = "%s|%s" % (key, asic_key)
259+
260+
asic_fvs = swsscommon.FieldValuePairs([(CHASSIS_ASIC_PCI_ADDRESS_FIELD, asic_pci_addr),
261+
(CHASSIS_MODULE_INFO_NAME_FIELD, key),
262+
(CHASSIS_ASIC_ID_IN_MODULE_FIELD, str(asic_id))])
263+
self.asic_table.set(asic_key, asic_fvs)
253264

254265
# Asics that are on the "not online" modules need to be cleaned up
255266
asics = list(self.asic_table.getKeys())
256267
for asic in asics:
257-
fvs = self.asic_table.get(asic)
258-
if isinstance(fvs, list):
259-
fvs = dict(fvs[-1])
260-
if fvs[CHASSIS_MODULE_INFO_NAME_FIELD] in notOnlineModules:
261-
self.asic_table._del(asic)
268+
fvs = self.asic_table.get(asic)
269+
if isinstance(fvs, list):
270+
fvs = dict(fvs[-1])
271+
if fvs[CHASSIS_MODULE_INFO_NAME_FIELD] in notOnlineModules:
272+
self.asic_table._del(asic)
262273

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

406-
# Check if module list is populated
407-
self.module_updater = ModuleUpdater(SYSLOG_IDENTIFIER, platform_chassis)
408-
self.module_updater.modules_num_update()
409-
410417
# Check for valid slot numbers
411-
self.module_updater.my_slot = try_get(platform_chassis.get_my_slot,
418+
my_slot = try_get(platform_chassis.get_my_slot,
412419
default=INVALID_SLOT)
413-
self.module_updater.supervisor_slot = try_get(platform_chassis.get_supervisor_slot,
420+
supervisor_slot = try_get(platform_chassis.get_supervisor_slot,
414421
default=INVALID_SLOT)
422+
423+
# Check if module list is populated
424+
self.module_updater = ModuleUpdater(SYSLOG_IDENTIFIER, platform_chassis, my_slot, supervisor_slot)
425+
self.module_updater.modules_num_update()
426+
427+
415428
if ((self.module_updater.my_slot == INVALID_SLOT) or
416429
(self.module_updater.supervisor_slot == INVALID_SLOT)):
417430
self.log_error("Chassisd not supported for this platform")

sonic-chassisd/tests/test_chassisd.py

+17-10
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ def test_moduleupdater_check_valid_fields():
5959

6060
chassis.module_list.append(module)
6161

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

8384
chassis.module_list.append(module)
8485

85-
module_updater = ModuleUpdater(SYSLOG_IDENTIFIER, chassis)
86+
module_updater = ModuleUpdater(SYSLOG_IDENTIFIER, chassis, slot,
87+
module.supervisor_slot)
8688
module_updater.module_db_update()
8789
fvs = module_updater.module_table.get(name)
8890
assert fvs == None
@@ -102,7 +104,8 @@ def test_moduleupdater_check_status_update():
102104
module.set_oper_status(status)
103105
chassis.module_list.append(module)
104106

105-
module_updater = ModuleUpdater(SYSLOG_IDENTIFIER, chassis)
107+
module_updater = ModuleUpdater(SYSLOG_IDENTIFIER, chassis, slot,
108+
module.supervisor_slot)
106109
module_updater.module_db_update()
107110
fvs = module_updater.module_table.get(name)
108111
print('Initial DB-entry {}'.format(fvs))
@@ -136,7 +139,8 @@ def test_moduleupdater_check_deinit():
136139
module.set_oper_status(status)
137140
chassis.module_list.append(module)
138141

139-
module_updater = ModuleUpdater(SYSLOG_IDENTIFIER, chassis)
142+
module_updater = ModuleUpdater(SYSLOG_IDENTIFIER, chassis, slot,
143+
module.supervisor_slot)
140144
module_updater.modules_num_update()
141145
module_updater.module_db_update()
142146
fvs = module_updater.module_table.get(name)
@@ -226,7 +230,8 @@ def test_configupdater_check_num_modules():
226230
module = MockModule(index, name, desc, module_type, slot)
227231

228232
# No modules
229-
module_updater = ModuleUpdater(SYSLOG_IDENTIFIER, chassis)
233+
module_updater = ModuleUpdater(SYSLOG_IDENTIFIER, chassis, slot,
234+
module.supervisor_slot)
230235
module_updater.modules_num_update()
231236
fvs = module_updater.chassis_table.get(CHASSIS_INFO_KEY_TEMPLATE.format(1))
232237
assert fvs == None
@@ -274,7 +279,8 @@ def test_midplane_presence_modules():
274279
chassis.module_list.append(fabric)
275280

276281
#Run on supervisor
277-
module_updater = ModuleUpdater(SYSLOG_IDENTIFIER, chassis)
282+
module_updater = ModuleUpdater(SYSLOG_IDENTIFIER, chassis, slot,
283+
module.supervisor_slot)
278284
module_updater.supervisor_slot = supervisor.get_slot()
279285
module_updater.my_slot = supervisor.get_slot()
280286
module_updater.modules_num_update()
@@ -338,7 +344,8 @@ def test_midplane_presence_supervisor():
338344
chassis.module_list.append(fabric)
339345

340346
#Run on supervisor
341-
module_updater = ModuleUpdater(SYSLOG_IDENTIFIER, chassis)
347+
module_updater = ModuleUpdater(SYSLOG_IDENTIFIER, chassis, slot,
348+
module.supervisor_slot)
342349
module_updater.supervisor_slot = supervisor.get_slot()
343350
module_updater.my_slot = module.get_slot()
344351
module_updater.modules_num_update()
@@ -403,9 +410,9 @@ def test_asic_presence():
403410
chassis.module_list.append(fabric)
404411

405412
#Run on supervisor
406-
module_updater = ModuleUpdater(SYSLOG_IDENTIFIER, chassis)
407-
module_updater.supervisor_slot = supervisor.get_slot()
408-
module_updater.my_slot = supervisor.get_slot()
413+
module_updater = ModuleUpdater(SYSLOG_IDENTIFIER, chassis,
414+
module.supervisor_slot,
415+
module.supervisor_slot)
409416
module_updater.modules_num_update()
410417
module_updater.module_db_update()
411418
module_updater.check_midplane_reachability()

0 commit comments

Comments
 (0)