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
8 changes: 8 additions & 0 deletions sonic-chassisd/scripts/chassisd
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,15 @@ class SmartSwitchModuleConfigUpdater(logger.Logger):
self.log_warning("Invalid admin_state value: {}".format(admin_state))

def submit_callback(self, module_index, admin_state):
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.chassis.get_module(module_index).module_pre_shutdown, default=False)

@rameshraghupathy rameshraghupathy May 29, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider avoiding this call for platforms don't require this. Please add a comment just like the HLD, that this will be applicable to platforms that require entire pcie tree rescan and implemented this function. Otherwise it is a no-op.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, Added comment mentioning that no actions will be taken on paltforms which do not have the relevant functions implemented. Please check

try_get(self.chassis.get_module(module_index).set_admin_state, admin_state, default=False)
if admin_state == MODULE_ADMIN_UP:
# This is only valid on platforms which have pci_rescan sensord changes required. If it is not implemented,
# there are no actions taken during this function execution.
try_get(self.chassis.get_module(module_index).module_post_startup, default=False)
pass

#
Expand Down
6 changes: 6 additions & 0 deletions sonic-chassisd/tests/mock_platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ def set_midplane_ip(self):
else:
self.midplane_ip = '192.168.1.{}'.format(self.get_slot())

def module_pre_shutdown(self):
pass

def module_post_startup(self):
pass

def is_midplane_reachable(self):
return self.midplane_access

Expand Down
17 changes: 13 additions & 4 deletions sonic-chassisd/tests/test_chassisd.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,13 +523,22 @@ def test_smartswitch_configupdater_check_admin_state():
chassis.module_list.append(module)

config_updater = SmartSwitchModuleConfigUpdater(SYSLOG_IDENTIFIER, chassis)

# Test setting admin state to down
admin_state = 0
config_updater.module_config_update(name, admin_state)
assert module.get_admin_state() == admin_state
with patch.object(module, 'module_pre_shutdown') as mock_module_pre_shutdown, \
patch.object(module, 'set_admin_state') as mock_set_admin_state:
config_updater.module_config_update(name, admin_state)
mock_module_pre_shutdown.assert_called_once()
mock_set_admin_state.assert_called_once_with(admin_state)

# Test setting admin state to up
admin_state = 1
config_updater.module_config_update(name, admin_state)
assert module.get_admin_state() == admin_state
with patch.object(module, 'set_admin_state') as mock_set_admin_state, \
patch.object(module, 'module_post_startup') as mock_module_post_startup:
config_updater.module_config_update(name, admin_state)
mock_set_admin_state.assert_called_once_with(admin_state)
mock_module_post_startup.assert_called_once()


@patch("your_module.glob.glob")
Expand Down
Loading