diff --git a/config/chassis_modules.py b/config/chassis_modules.py index 4e7fd8096b..5f70ef404a 100755 --- a/config/chassis_modules.py +++ b/config/chassis_modules.py @@ -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)]) @@ -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 ...') diff --git a/tests/chassis_modules_test.py b/tests/chassis_modules_test.py index 681e3d2c13..f59341a487 100755 --- a/tests/chassis_modules_test.py +++ b/tests/chassis_modules_test.py @@ -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):