From c5d00ae4b8430aac81cf078ba79224096815686c Mon Sep 17 00:00:00 2001 From: Neetha John Date: Thu, 24 Jun 2021 17:09:45 -0700 Subject: [PATCH] [pfcwd] Fix the return code in invalid case (#1691) Signed-off-by: Neetha John Fixes #1690 What I did Set the correct return code when pfcwd command is specified with invalid options How to verify it Modified the unit test to check for the correct return code and ran them and they passed --- pfcwd/main.py | 2 +- tests/pfcwd_test.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pfcwd/main.py b/pfcwd/main.py index 1f8ec2293e..c3b92fd223 100644 --- a/pfcwd/main.py +++ b/pfcwd/main.py @@ -242,7 +242,7 @@ def start(self, action, restoration_time, ports, detection_time): click.echo("Failed to run command, invalid options:") for opt in invalid_ports: click.echo(opt) - exit() + exit(1) self.start_cmd(action, restoration_time, ports, detection_time) diff --git a/tests/pfcwd_test.py b/tests/pfcwd_test.py index b0af050233..c150c0568b 100644 --- a/tests/pfcwd_test.py +++ b/tests/pfcwd_test.py @@ -255,7 +255,7 @@ def test_pfcwd_start_ports_invalid(self): obj=db ) print(result.output) - assert result.exit_code == 0 + assert result.exit_code == 1 assert result.output == pfcwd_show_start_config_output_fail @classmethod @@ -447,7 +447,7 @@ def test_pfcwd_start_ports_masic_invalid(self): obj=db ) print(result.output) - assert result.exit_code == 0 + assert result.exit_code == 1 assert result.output == show_pfc_config_start_fail # get config after the command, config shouldn't change @@ -500,4 +500,4 @@ def teardown_class(cls): import mock_tables.mock_single_asic importlib.reload(mock_tables.mock_single_asic) import pfcwd.main - importlib.reload(pfcwd.main) \ No newline at end of file + importlib.reload(pfcwd.main)