Skip to content
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
22 changes: 19 additions & 3 deletions sonic-chassisd/scripts/chassisd
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ class SmartSwitchModuleUpdater(ModuleUpdater):
fvs = dict(fvs[-1])
return fvs[CHASSIS_MODULE_ADMIN_STATUS]
else:
return 'empty'
return ModuleBase.MODULE_STATUS_EMPTY

def clear_transition_flag(self, key):
status, fvs = self.module_table.get(key)
Expand Down Expand Up @@ -1359,7 +1359,19 @@ class ChassisdDaemon(daemon_base.DaemonBase):
# Merge existing fields, preserving all others
fvs_dict = dict(fvs) if fvs else {}

# Update or add transition fields only
# Ensure mandatory fields are present, but only if missing
mandatory_defaults = {
'desc': 'N/A',
'slot': 'N/A',
'serial': 'N/A',
'oper_status': ModuleBase.MODULE_STATUS_EMPTY
}
for field, default in mandatory_defaults.items():
if field not in fvs_dict:
self.log_info(f"{key}: '{field}' missing, setting default '{default}'")
fvs_dict[field] = default

# Update or add transition fields
fvs_dict.update({
'state_transition_in_progress': 'True',
'transition_start_time': get_formatted_time()
Expand All @@ -1369,6 +1381,10 @@ class ChassisdDaemon(daemon_base.DaemonBase):
module_table.set(key, list(fvs_dict.items()))

def submit_dpu_callback(self, module_index, admin_state, module_name):
if admin_state == MODULE_ADMIN_DOWN:
# This is only valid on platforms which have pci_detach and sensord changes required. If it is not implemented,
# there are no actions taken during this function execution.
try_get(self.module_updater.chassis.get_module(module_index).module_pre_shutdown, default=False)
# Set admin_state change in progress using the centralized method
self.set_transition_flag(self.module_updater.module_table, module_name)
try_get(self.module_updater.chassis.get_module(module_index).set_admin_state, admin_state, default=False)
Expand All @@ -1390,7 +1406,7 @@ class ChassisdDaemon(daemon_base.DaemonBase):
try:
# Get admin state of DPU
admin_state = self.module_updater.get_module_admin_status(module_name)
if admin_state == 'empty' and operational_state != ModuleBase.MODULE_STATUS_OFFLINE:
if admin_state == ModuleBase.MODULE_STATUS_EMPTY and operational_state != ModuleBase.MODULE_STATUS_OFFLINE:
# shutdown DPU
op = MODULE_ADMIN_DOWN

Expand Down
2 changes: 1 addition & 1 deletion sonic-chassisd/tests/test_chassisd.py
Original file line number Diff line number Diff line change
Expand Up @@ -1906,7 +1906,7 @@ def test_submit_dpu_callback():
patch.object(module, 'module_post_startup') as mock_post_startup:
daemon_chassisd.submit_dpu_callback(index, MODULE_ADMIN_DOWN, name)
# Verify correct functions are called for admin down
mock_pre_shutdown.assert_not_called()
mock_pre_shutdown.assert_called_once()
mock_set_admin_state.assert_called_once_with(MODULE_ADMIN_DOWN)
mock_post_startup.assert_not_called()

Expand Down
Loading