From 9357c45f6513a4eddebfece358925d68dab7c159 Mon Sep 17 00:00:00 2001 From: "Marty Y. Lok" <76118573+mlok-nokia@users.noreply.github.com> Date: Tue, 3 Sep 2024 13:51:04 -0400 Subject: [PATCH] [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 * Address review comment: modify UT to test if the run_command parameter type is list Signed-off-by: mlok --------- Signed-off-by: mlok --- config/chassis_modules.py | 8 ++++---- tests/chassis_modules_test.py | 8 +++++++- 2 files changed, 11 insertions(+), 5 deletions(-) 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):