Skip to content

Commit 8707098

Browse files
authored
[Smartswitch][chassisd] Addition of pre shutdown and post startup function calls (#619)
The pre shutdown and post startup functions are called on DPU admin state change operations
1 parent 45c1582 commit 8707098

3 files changed

Lines changed: 27 additions & 4 deletions

File tree

sonic-chassisd/scripts/chassisd

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,15 @@ class SmartSwitchModuleConfigUpdater(logger.Logger):
247247
self.log_warning("Invalid admin_state value: {}".format(admin_state))
248248

249249
def submit_callback(self, module_index, admin_state):
250+
if admin_state == MODULE_ADMIN_DOWN:
251+
# This is only valid on platforms which have pci_detach and sensord changes required. If it is not implemented,
252+
# there are no actions taken during this function execution.
253+
try_get(self.chassis.get_module(module_index).module_pre_shutdown, default=False)
250254
try_get(self.chassis.get_module(module_index).set_admin_state, admin_state, default=False)
255+
if admin_state == MODULE_ADMIN_UP:
256+
# This is only valid on platforms which have pci_rescan sensord changes required. If it is not implemented,
257+
# there are no actions taken during this function execution.
258+
try_get(self.chassis.get_module(module_index).module_post_startup, default=False)
251259
pass
252260

253261
#

sonic-chassisd/tests/mock_platform.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ def set_midplane_ip(self):
7272
else:
7373
self.midplane_ip = '192.168.1.{}'.format(self.get_slot())
7474

75+
def module_pre_shutdown(self):
76+
pass
77+
78+
def module_post_startup(self):
79+
pass
80+
7581
def is_midplane_reachable(self):
7682
return self.midplane_access
7783

sonic-chassisd/tests/test_chassisd.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -523,13 +523,22 @@ def test_smartswitch_configupdater_check_admin_state():
523523
chassis.module_list.append(module)
524524

525525
config_updater = SmartSwitchModuleConfigUpdater(SYSLOG_IDENTIFIER, chassis)
526+
527+
# Test setting admin state to down
526528
admin_state = 0
527-
config_updater.module_config_update(name, admin_state)
528-
assert module.get_admin_state() == admin_state
529+
with patch.object(module, 'module_pre_shutdown') as mock_module_pre_shutdown, \
530+
patch.object(module, 'set_admin_state') as mock_set_admin_state:
531+
config_updater.module_config_update(name, admin_state)
532+
mock_module_pre_shutdown.assert_called_once()
533+
mock_set_admin_state.assert_called_once_with(admin_state)
529534

535+
# Test setting admin state to up
530536
admin_state = 1
531-
config_updater.module_config_update(name, admin_state)
532-
assert module.get_admin_state() == admin_state
537+
with patch.object(module, 'set_admin_state') as mock_set_admin_state, \
538+
patch.object(module, 'module_post_startup') as mock_module_post_startup:
539+
config_updater.module_config_update(name, admin_state)
540+
mock_set_admin_state.assert_called_once_with(admin_state)
541+
mock_module_post_startup.assert_called_once()
533542

534543

535544
@patch("your_module.glob.glob")

0 commit comments

Comments
 (0)