Skip to content

Commit 7b347c6

Browse files
Fix for #23205 [Smartswitch] Issues caused due to introduction of the chassisd/sonic-utiltiies changes for consecutive admin state changes (#645)
1 parent b431dad commit 7b347c6

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

sonic-chassisd/scripts/chassisd

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,7 @@ class SmartSwitchModuleUpdater(ModuleUpdater):
765765
fvs = dict(fvs[-1])
766766
return fvs[CHASSIS_MODULE_ADMIN_STATUS]
767767
else:
768-
return 'empty'
768+
return ModuleBase.MODULE_STATUS_EMPTY
769769

770770
def retrieve_dpu_reboot_info(self, module):
771771
"""
@@ -1404,7 +1404,19 @@ class ChassisdDaemon(daemon_base.DaemonBase):
14041404
# Merge existing fields, preserving all others
14051405
fvs_dict = dict(fvs) if fvs else {}
14061406

1407-
# Update or add transition fields only
1407+
# Ensure mandatory fields are present, but only if missing
1408+
mandatory_defaults = {
1409+
'desc': 'N/A',
1410+
'slot': 'N/A',
1411+
'serial': 'N/A',
1412+
'oper_status': ModuleBase.MODULE_STATUS_EMPTY
1413+
}
1414+
for field, default in mandatory_defaults.items():
1415+
if field not in fvs_dict:
1416+
self.log_info(f"{key}: '{field}' missing, setting default '{default}'")
1417+
fvs_dict[field] = default
1418+
1419+
# Update or add transition fields
14081420
fvs_dict.update({
14091421
'state_transition_in_progress': 'True',
14101422
'transition_start_time': get_formatted_time()
@@ -1414,6 +1426,10 @@ class ChassisdDaemon(daemon_base.DaemonBase):
14141426
module_table.set(key, list(fvs_dict.items()))
14151427

14161428
def submit_dpu_callback(self, module_index, admin_state, module_name):
1429+
if admin_state == MODULE_ADMIN_DOWN:
1430+
# This is only valid on platforms which have pci_detach and sensord changes required. If it is not implemented,
1431+
# there are no actions taken during this function execution.
1432+
try_get(self.module_updater.chassis.get_module(module_index).module_pre_shutdown, default=False)
14171433
# Set admin_state change in progress using the centralized method
14181434
self.set_transition_flag(self.module_updater.module_table, module_name)
14191435
try_get(self.module_updater.chassis.get_module(module_index).set_admin_state, admin_state, default=False)
@@ -1435,7 +1451,7 @@ class ChassisdDaemon(daemon_base.DaemonBase):
14351451
try:
14361452
# Get admin state of DPU
14371453
admin_state = self.module_updater.get_module_admin_status(module_name)
1438-
if admin_state == 'empty' and operational_state != ModuleBase.MODULE_STATUS_OFFLINE:
1454+
if admin_state == ModuleBase.MODULE_STATUS_EMPTY and operational_state != ModuleBase.MODULE_STATUS_OFFLINE:
14391455
# shutdown DPU
14401456
op = MODULE_ADMIN_DOWN
14411457

sonic-chassisd/tests/test_chassisd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1998,7 +1998,7 @@ def test_submit_dpu_callback():
19981998
patch.object(module, 'module_post_startup') as mock_post_startup:
19991999
daemon_chassisd.submit_dpu_callback(index, MODULE_ADMIN_DOWN, name)
20002000
# Verify correct functions are called for admin down
2001-
mock_pre_shutdown.assert_not_called()
2001+
mock_pre_shutdown.assert_called_once()
20022002
mock_set_admin_state.assert_called_once_with(MODULE_ADMIN_DOWN)
20032003
mock_post_startup.assert_not_called()
20042004

0 commit comments

Comments
 (0)