Skip to content

Commit 1490b79

Browse files
authored
chassisd: add fabric module information to STATE_DB (#601)
Add Fabric Card Module information to STATE_DB. This information is necessary as in the tests we expect for fans under fabric cards, their parent information (i.e fabric cards) is also present in the PHYSICAL_ENTITY_INFO of STATE_DB. Rather than storing a module by its index, store it by its name. This makes it easier to refer to modules as sometimes index/position of module may change, but it's name remains consistent.
1 parent 90246a5 commit 1490b79

File tree

4 files changed

+102
-3
lines changed

4 files changed

+102
-3
lines changed

sonic-chassisd/scripts/chassisd

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ CHASSIS_MODULE_INFO_OPERSTATUS_FIELD = 'oper_status'
5656
CHASSIS_MODULE_INFO_NUM_ASICS_FIELD = 'num_asics'
5757
CHASSIS_MODULE_INFO_ASICS = 'asics'
5858
CHASSIS_MODULE_INFO_SERIAL_FIELD = 'serial'
59+
CHASSIS_MODULE_INFO_PRESENCE_FIELD = 'presence'
60+
CHASSIS_MODULE_INFO_MODEL_FIELD = 'model'
61+
CHASSIS_MODULE_INFO_REPLACEABLE_FIELD = 'is_replaceable'
5962

6063
CHASSIS_ASIC_INFO_TABLE = 'CHASSIS_ASIC_TABLE'
6164
CHASSIS_FABRIC_ASIC_INFO_TABLE = 'CHASSIS_FABRIC_ASIC_TABLE'
@@ -80,6 +83,8 @@ DEFAULT_DPU_REBOOT_TIMEOUT = 360
8083
PLATFORM_ENV_CONF_FILE = "/usr/share/sonic/platform/platform_env.conf"
8184
PLATFORM_JSON_FILE = "/usr/share/sonic/platform/platform.json"
8285

86+
PHYSICAL_ENTITY_INFO_TABLE = 'PHYSICAL_ENTITY_INFO'
87+
8388
CHASSIS_INFO_UPDATE_PERIOD_SECS = 10
8489
CHASSIS_DB_CLEANUP_MODULE_DOWN_PERIOD = 30 # Minutes
8590

@@ -146,6 +151,15 @@ def get_formatted_time(datetimeobj=None, op_format=None):
146151
date_obj = datetimeobj if datetimeobj else datetime.now(timezone.utc)
147152
return date_obj.strftime(op_format if op_format else "%a %b %d %I:%M:%S %p UTC %Y")
148153

154+
def update_entity_info(table, parent_name, key, index, serial, model, is_replaceable):
155+
fvs = swsscommon.FieldValuePairs(
156+
[('position_in_parent', str(index)),
157+
('parent_name', parent_name),
158+
('serial', serial),
159+
('model', model),
160+
('is_replaceable', is_replaceable)])
161+
table.set(key, fvs)
162+
149163
#
150164
# Module Config Updater ========================================================
151165
#
@@ -259,6 +273,7 @@ class ModuleUpdater(logger.Logger):
259273
self.chassis_table = swsscommon.Table(state_db, CHASSIS_INFO_TABLE)
260274
self.module_table = swsscommon.Table(state_db, CHASSIS_MODULE_INFO_TABLE)
261275
self.midplane_table = swsscommon.Table(state_db, CHASSIS_MIDPLANE_INFO_TABLE)
276+
self.phy_entity_table = swsscommon.Table(state_db, PHYSICAL_ENTITY_INFO_TABLE)
262277
self.info_dict_keys = [CHASSIS_MODULE_INFO_NAME_FIELD,
263278
CHASSIS_MODULE_INFO_DESC_FIELD,
264279
CHASSIS_MODULE_INFO_SLOT_FIELD,
@@ -301,6 +316,8 @@ class ModuleUpdater(logger.Logger):
301316
self.module_table._del(name)
302317
if self.midplane_table.get(name) is not None:
303318
self.midplane_table._del(name)
319+
if self.phy_entity_table.get(name) is not None:
320+
self.phy_entity_table._del(name)
304321

305322
if self.chassis_table is not None:
306323
self.chassis_table._del(CHASSIS_INFO_KEY_TEMPLATE.format(1))
@@ -365,10 +382,23 @@ class ModuleUpdater(logger.Logger):
365382
str(module_info_dict[CHASSIS_MODULE_INFO_SLOT_FIELD])),
366383
(CHASSIS_MODULE_INFO_OPERSTATUS_FIELD, module_info_dict[CHASSIS_MODULE_INFO_OPERSTATUS_FIELD]),
367384
(CHASSIS_MODULE_INFO_NUM_ASICS_FIELD, str(len(module_info_dict[CHASSIS_MODULE_INFO_ASICS]))),
368-
(CHASSIS_MODULE_INFO_SERIAL_FIELD, module_info_dict[CHASSIS_MODULE_INFO_SERIAL_FIELD])])
385+
(CHASSIS_MODULE_INFO_SERIAL_FIELD, module_info_dict[CHASSIS_MODULE_INFO_SERIAL_FIELD]),
386+
(CHASSIS_MODULE_INFO_PRESENCE_FIELD, module_info_dict[CHASSIS_MODULE_INFO_PRESENCE_FIELD]),
387+
(CHASSIS_MODULE_INFO_REPLACEABLE_FIELD, module_info_dict[CHASSIS_MODULE_INFO_REPLACEABLE_FIELD]),
388+
(CHASSIS_MODULE_INFO_MODEL_FIELD, module_info_dict[CHASSIS_MODULE_INFO_MODEL_FIELD])])
389+
390+
369391
prev_status = self.get_module_current_status(key)
370392
self.module_table.set(key, fvs)
371393

394+
update_entity_info(self.phy_entity_table,
395+
"chassis {}".format(1),
396+
key,
397+
module_index,
398+
module_info_dict[CHASSIS_MODULE_INFO_SERIAL_FIELD],
399+
module_info_dict[CHASSIS_MODULE_INFO_MODEL_FIELD],
400+
module_info_dict[CHASSIS_MODULE_INFO_REPLACEABLE_FIELD])
401+
372402
# Construct key for down_modules dict. Example down_modules key format: LINE-CARD0|<hostname>
373403
fvs = self.hostname_table.get(key)
374404
if isinstance(fvs, list) and fvs[0] is True:
@@ -452,13 +482,19 @@ class ModuleUpdater(logger.Logger):
452482
asics = try_get(self.chassis.get_module(module_index).get_all_asics,
453483
default=[])
454484
serial = try_get(self.chassis.get_module(module_index).get_serial)
485+
presence = try_get(self.chassis.get_module(module_index).get_presence)
486+
replaceable = try_get(self.chassis.get_module(module_index).is_replaceable)
487+
model = try_get(self.chassis.get_module(module_index).get_model)
455488

456489
module_info_dict[CHASSIS_MODULE_INFO_NAME_FIELD] = name
457490
module_info_dict[CHASSIS_MODULE_INFO_DESC_FIELD] = str(desc)
458491
module_info_dict[CHASSIS_MODULE_INFO_SLOT_FIELD] = slot
459492
module_info_dict[CHASSIS_MODULE_INFO_OPERSTATUS_FIELD] = str(status)
460493
module_info_dict[CHASSIS_MODULE_INFO_ASICS] = asics
461494
module_info_dict[CHASSIS_MODULE_INFO_SERIAL_FIELD] = str(serial)
495+
module_info_dict[CHASSIS_MODULE_INFO_PRESENCE_FIELD] = str(presence)
496+
module_info_dict[CHASSIS_MODULE_INFO_REPLACEABLE_FIELD] = str(replaceable)
497+
module_info_dict[CHASSIS_MODULE_INFO_MODEL_FIELD] = str(model)
462498

463499
return module_info_dict
464500

sonic-chassisd/tests/mock_platform.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ def __init__(self):
44
self.presence = True
55
self.model = 'Module Model'
66
self.serial = 'Module Serial'
7+
self.replaceable = True
78

89
def get_name(self):
910
return self.name
@@ -17,10 +18,13 @@ def get_model(self):
1718
def get_serial(self):
1819
return self.serial
1920

21+
def is_replaceable(self):
22+
return self.replaceable
2023

2124
class MockModule(MockDevice):
2225
def __init__(self, module_index, module_name, module_desc, module_type, module_slot,
2326
module_serial, asic_list=[]):
27+
super(MockModule, self).__init__()
2428
self.module_index = module_index
2529
self.module_name = module_name
2630
self.module_desc = module_desc
@@ -32,7 +36,7 @@ def __init__(self, module_index, module_name, module_desc, module_type, module_s
3236
self.midplane_access = False
3337
self.asic_list = asic_list
3438
self.module_serial = module_serial
35-
39+
3640
def get_name(self):
3741
return self.module_name
3842

@@ -83,6 +87,18 @@ def get_reboot_cause(self):
8387
def get_serial(self):
8488
return self.module_serial
8589

90+
def set_serial(self, serial):
91+
self.serial = serial
92+
93+
def set_replaceable(self, replaceable):
94+
self.replaceable = replaceable
95+
96+
def set_model(self, model):
97+
self.model = model
98+
99+
def set_presence(self, presence):
100+
self.presence = presence
101+
86102
class MockChassis:
87103
def __init__(self):
88104
self.module_list = []

sonic-chassisd/tests/test_chassisd.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939
CHASSIS_MODULE_INFO_SLOT_FIELD = 'slot'
4040
CHASSIS_MODULE_INFO_OPERSTATUS_FIELD = 'oper_status'
4141
CHASSIS_MODULE_INFO_SERIAL_FIELD = 'serial'
42+
CHASSIS_MODULE_INFO_PRESENCE_FIELD = 'presence'
43+
CHASSIS_MODULE_INFO_MODEL_FIELD = 'model'
44+
CHASSIS_MODULE_INFO_REPLACEABLE_FIELD = 'is_replaceable'
4245

4346
CHASSIS_INFO_KEY_TEMPLATE = 'CHASSIS {}'
4447
CHASSIS_INFO_CARD_NUM_FIELD = 'module_num'
@@ -71,10 +74,16 @@ def test_moduleupdater_check_valid_fields():
7174
serial = "FC1000101"
7275
module_type = ModuleBase.MODULE_TYPE_FABRIC
7376
module = MockModule(index, name, desc, module_type, slot, serial)
77+
replaceable = True
78+
presence = True
79+
model = 'N/A'
7480

7581
# Set initial state
7682
status = ModuleBase.MODULE_STATUS_ONLINE
7783
module.set_oper_status(status)
84+
module.set_replaceable(replaceable)
85+
module.set_presence(presence)
86+
module.set_model(model)
7887

7988
chassis.module_list.append(module)
8089

@@ -87,6 +96,44 @@ def test_moduleupdater_check_valid_fields():
8796
assert desc == fvs[CHASSIS_MODULE_INFO_DESC_FIELD]
8897
assert status == fvs[CHASSIS_MODULE_INFO_OPERSTATUS_FIELD]
8998
assert serial == fvs[CHASSIS_MODULE_INFO_SERIAL_FIELD]
99+
assert model == fvs[CHASSIS_MODULE_INFO_MODEL_FIELD]
100+
assert str(replaceable) == fvs[CHASSIS_MODULE_INFO_REPLACEABLE_FIELD]
101+
assert str(presence) == fvs[CHASSIS_MODULE_INFO_PRESENCE_FIELD]
102+
103+
def test_moduleupdater_check_phyentity_fields():
104+
chassis = MockChassis()
105+
index = 0
106+
name = "FABRIC-CARD0"
107+
desc = "Switch Fabric Module"
108+
slot = 10
109+
serial = "FC1000101"
110+
module_type = ModuleBase.MODULE_TYPE_FABRIC
111+
module = MockModule(index, name, desc, module_type, slot, serial)
112+
replaceable = True
113+
presence = True
114+
model = 'N/A'
115+
parent_name = 'chassis 1'
116+
117+
# Set initial state
118+
status = ModuleBase.MODULE_STATUS_ONLINE
119+
module.set_oper_status(status)
120+
module.set_replaceable(replaceable)
121+
module.set_presence(presence)
122+
module.set_model(model)
123+
124+
chassis.module_list.append(module)
125+
126+
module_updater = ModuleUpdater(SYSLOG_IDENTIFIER, chassis, slot,
127+
module.supervisor_slot)
128+
module_updater.module_db_update()
129+
fvs = module_updater.phy_entity_table.get(name)
130+
if isinstance(fvs, list):
131+
fvs = dict(fvs[-1])
132+
assert str(index) == fvs['position_in_parent']
133+
assert parent_name == fvs['parent_name']
134+
assert serial == fvs[CHASSIS_MODULE_INFO_SERIAL_FIELD]
135+
assert model == fvs[CHASSIS_MODULE_INFO_MODEL_FIELD]
136+
assert str(replaceable) == fvs[CHASSIS_MODULE_INFO_REPLACEABLE_FIELD]
90137

91138
def test_smartswitch_moduleupdater_check_valid_fields():
92139
chassis = MockSmartSwitchChassis()

sonic-thermalctld/scripts/thermalctld

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ class FanUpdater(logger.Logger):
299299
if fan_type == FanType.PSU:
300300
parent_name = 'PSU {}'.format(parent_index + 1)
301301
elif fan_type == FanType.MODULE:
302-
parent_name = 'Module {}'.format(parent_index + 1)
302+
parent_name = try_get(parent.get_name, default='Module {}'.format(parent_index + 1))
303303
else:
304304
parent_name = drawer_name if drawer_name != NOT_AVAILABLE else CHASSIS_INFO_KEY
305305
fan_name = try_get(fan.get_name, '{} fan {}'.format(parent_name, fan_index + 1))

0 commit comments

Comments
 (0)