Skip to content

Commit 9357c45

Browse files
authored
[chassis][cli] Fix config chassis module startup/shutdown command for fabric module (#3483)
* [chassis][cli] Fix config chassis module starup/shutdown command for fabric module Signed-off-by: mlok <[email protected]> * Address review comment: modify UT to test if the run_command parameter type is list Signed-off-by: mlok <[email protected]> --------- Signed-off-by: mlok <[email protected]>
1 parent 4c7e54a commit 9357c45

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

config/chassis_modules.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def fabric_module_set_admin_status(db, chassis_module_name, state):
7272
if state == "down":
7373
for asic in asic_list:
7474
click.echo("Stop swss@{} and peer services".format(asic))
75-
clicommon.run_command('sudo systemctl stop swss@{}.service'.format(asic))
75+
clicommon.run_command(['sudo', 'systemctl', 'stop', 'swss@{}.service'.format(asic)])
7676

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

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

100100
#
101101
# 'shutdown' subcommand ('config chassis_modules shutdown ...')

tests/chassis_modules_test.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,13 @@
126126

127127

128128
def mock_run_command_side_effect(*args, **kwargs):
129-
return '', 0
129+
print("command: {}".format(*args))
130+
if isinstance(*args, list):
131+
return '', 0
132+
else:
133+
print("Expected type of command is list. Actual type is {}".format(*args))
134+
assert 0
135+
return '', 0
130136

131137

132138
class TestChassisModules(object):

0 commit comments

Comments
 (0)