Skip to content

Commit 7733080

Browse files
authored
modify chassisd to add module to table in STATE_DB only if module is present (#646)
- modify module_db_update function to add module to PHYSICAL_ENTITY_INFO table in STATE_DB only if module is present
1 parent c11af80 commit 7733080

File tree

2 files changed

+53
-8
lines changed

2 files changed

+53
-8
lines changed

sonic-chassisd/scripts/chassisd

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -407,14 +407,18 @@ class ModuleUpdater(logger.Logger):
407407
prev_status = self.get_module_current_status(key)
408408
self.module_table.set(key, fvs)
409409

410-
update_entity_info(self.phy_entity_table,
411-
"chassis {}".format(1),
412-
key,
413-
module_index,
414-
module_info_dict[CHASSIS_MODULE_INFO_SERIAL_FIELD],
415-
module_info_dict[CHASSIS_MODULE_INFO_MODEL_FIELD],
416-
module_info_dict[CHASSIS_MODULE_INFO_REPLACEABLE_FIELD])
417-
410+
if module_info_dict[CHASSIS_MODULE_INFO_PRESENCE_FIELD].lower() == "true":
411+
update_entity_info(self.phy_entity_table,
412+
"chassis {}".format(1),
413+
key,
414+
module_index,
415+
module_info_dict[CHASSIS_MODULE_INFO_SERIAL_FIELD],
416+
module_info_dict[CHASSIS_MODULE_INFO_MODEL_FIELD],
417+
module_info_dict[CHASSIS_MODULE_INFO_REPLACEABLE_FIELD])
418+
else:
419+
if self.phy_entity_table.get(key) is not None:
420+
self.phy_entity_table._del(key)
421+
418422
# Construct key for down_modules dict. Example down_modules key format: LINE-CARD0|<hostname>
419423
fvs = self.hostname_table.get(key)
420424
if isinstance(fvs, list) and fvs[0] is True:

sonic-chassisd/tests/test_chassisd.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,47 @@ def test_moduleupdater_check_phyentity_fields():
136136
assert model == fvs[CHASSIS_MODULE_INFO_MODEL_FIELD]
137137
assert str(replaceable) == fvs[CHASSIS_MODULE_INFO_REPLACEABLE_FIELD]
138138

139+
def test_moduleupdater_check_phyentity_entry_after_fabric_removal():
140+
chassis = MockChassis()
141+
index = 0
142+
name = "FABRIC-CARD0"
143+
desc = "Switch Fabric Module"
144+
slot = 10
145+
serial = "FC1000101"
146+
module_type = ModuleBase.MODULE_TYPE_FABRIC
147+
module = MockModule(index, name, desc, module_type, slot, serial)
148+
replaceable = True
149+
presence = True
150+
model = 'N/A'
151+
parent_name = 'chassis 1'
152+
153+
# Set initial state
154+
status = ModuleBase.MODULE_STATUS_ONLINE
155+
module.set_oper_status(status)
156+
module.set_replaceable(replaceable)
157+
module.set_presence(presence)
158+
module.set_model(model)
159+
160+
chassis.module_list.append(module)
161+
162+
module_updater = ModuleUpdater(SYSLOG_IDENTIFIER, chassis, slot,
163+
module.supervisor_slot)
164+
module_updater.module_db_update()
165+
fvs = module_updater.phy_entity_table.get(name)
166+
if isinstance(fvs, list):
167+
fvs = dict(fvs[-1])
168+
assert str(index) == fvs['position_in_parent']
169+
assert parent_name == fvs['parent_name']
170+
assert serial == fvs[CHASSIS_MODULE_INFO_SERIAL_FIELD]
171+
assert model == fvs[CHASSIS_MODULE_INFO_MODEL_FIELD]
172+
assert str(replaceable) == fvs[CHASSIS_MODULE_INFO_REPLACEABLE_FIELD]
173+
174+
presence = False
175+
module.set_presence(presence)
176+
module_updater.module_db_update()
177+
fvs = module_updater.phy_entity_table.get(name)
178+
assert fvs == None
179+
139180
def test_smartswitch_moduleupdater_check_valid_fields():
140181
chassis = MockSmartSwitchChassis()
141182
index = 0

0 commit comments

Comments
 (0)