Skip to content

Commit

Permalink
[chassis][cli] Fix config chassis module startup/shutdown command for…
Browse files Browse the repository at this point in the history
… fabric module (#3483)

* [chassis][cli] Fix config chassis module starup/shutdown command for fabric module

Signed-off-by: mlok <marty.lok@nokia.com>

* Address review comment: modify UT to test if the run_command parameter type is list

Signed-off-by: mlok <marty.lok@nokia.com>

---------

Signed-off-by: mlok <marty.lok@nokia.com>
  • Loading branch information
mlok-nokia committed Sep 3, 2024
1 parent 4c7e54a commit 9357c45
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
8 changes: 4 additions & 4 deletions config/chassis_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def fabric_module_set_admin_status(db, chassis_module_name, state):
if state == "down":
for asic in asic_list:
click.echo("Stop swss@{} and peer services".format(asic))
clicommon.run_command('sudo systemctl stop swss@{}.service'.format(asic))
clicommon.run_command(['sudo', 'systemctl', 'stop', 'swss@{}.service'.format(asic)])

is_active = subprocess.call(["systemctl", "is-active", "--quiet", "swss@{}.service".format(asic)])

Expand All @@ -89,13 +89,13 @@ def fabric_module_set_admin_status(db, chassis_module_name, state):
# without bring down the hardware
for asic in asic_list:
# To address systemd service restart limit by resetting the count
clicommon.run_command('sudo systemctl reset-failed swss@{}.service'.format(asic))
clicommon.run_command(['sudo', 'systemctl', 'reset-failed', 'swss@{}.service'.format(asic)])
click.echo("Start swss@{} and peer services".format(asic))
clicommon.run_command('sudo systemctl start swss@{}.service'.format(asic))
clicommon.run_command(['sudo', 'systemctl', 'start', 'swss@{}.service'.format(asic)])
elif state == "up":
for asic in asic_list:
click.echo("Start swss@{} and peer services".format(asic))
clicommon.run_command('sudo systemctl start swss@{}.service'.format(asic))
clicommon.run_command(['sudo', 'systemctl', 'start', 'swss@{}.service'.format(asic)])

#
# 'shutdown' subcommand ('config chassis_modules shutdown ...')
Expand Down
8 changes: 7 additions & 1 deletion tests/chassis_modules_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,13 @@


def mock_run_command_side_effect(*args, **kwargs):
return '', 0
print("command: {}".format(*args))
if isinstance(*args, list):
return '', 0
else:
print("Expected type of command is list. Actual type is {}".format(*args))
assert 0
return '', 0


class TestChassisModules(object):
Expand Down

0 comments on commit 9357c45

Please sign in to comment.