From 2e9c99e89fb84b6d7c6f519cf67ff2f6a60890b9 Mon Sep 17 00:00:00 2001 From: Jing Zhang Date: Fri, 28 Apr 2023 14:17:16 -0700 Subject: [PATCH] [show][muxcable] fix `show mux hwmode muxdirection` RC (#2812) What I did show mux hwmode muxdirection always has rc==1. Fixed the issue below: get_grpc_cached_version_mux_direction_per_port has reverted TRUE/FALSE return value compared to get_hwmode_mux_direction_port. The former is used to get results for active-active ports, the latter is used to get results for active-standby ports. Use sys.exit() instead of return rc. CLI rc is different from function return value. Fixed show mux grpc muxdirection as well. sign-off: Jing Zhang How to verify it Tested on DUTs to verify rc. Run commands for single port and all ports, with and without --json. Passed all UTs. --- show/muxcable.py | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/show/muxcable.py b/show/muxcable.py index 2d82cedf72..fd70dcd72d 100644 --- a/show/muxcable.py +++ b/show/muxcable.py @@ -1370,13 +1370,14 @@ def muxdirection(db, port, json_output): headers = ['Port', 'Direction', 'Presence'] click.echo(tabulate(body, headers=headers)) - return rc + rc_exit = EXIT_SUCCESS if rc==0 else EXIT_FAIL + sys.exit(rc_exit) else: logical_port_list = platform_sfputil_helper.get_logical_list() - rc_exit = True + rc_exit = EXIT_SUCCESS body = [] active_active = False if json_output: @@ -1425,8 +1426,9 @@ def muxdirection(db, port, json_output): active_active = True else: rc = create_active_standby_mux_direction_result(body, port, db) - if rc != 0: - rc_exit = False + + if rc != 0: + rc_exit = EXIT_FAIL @@ -1440,8 +1442,7 @@ def muxdirection(db, port, json_output): headers = ['Port', 'Direction', 'Presence'] click.echo(tabulate(body, headers=headers)) - if rc_exit == False: - sys.exit(EXIT_FAIL) + sys.exit(rc_exit) @hwmode.command() @@ -2116,7 +2117,7 @@ def get_grpc_cached_version_mux_direction_per_port(db, port): mux_info_dict = {} mux_info_full_dict = {} trans_info_full_dict = {} - mux_info_dict["rc"] = False + mux_info_dict["rc"] = 1 # Getting all front asic namespace and correspding config and state DB connector @@ -2158,7 +2159,7 @@ def get_grpc_cached_version_mux_direction_per_port(db, port): mux_info_dict["presence"] = presence - mux_info_dict["rc"] = True + mux_info_dict["rc"] = 0 return mux_info_dict @@ -2198,14 +2199,15 @@ def muxdirection(db, port, json_output): rc = create_active_active_mux_direction_result(body, port, db) click.echo(tabulate(body, headers=headers)) - return rc + rc_exit = EXIT_SUCCESS if rc==0 else EXIT_FAIL + sys.exit(rc_exit) else: logical_port_list = platform_sfputil_helper.get_logical_list() - rc_exit = True + rc_exit = EXIT_SUCCESS body = [] if json_output: result = {} @@ -2242,8 +2244,8 @@ def muxdirection(db, port, json_output): else: rc = create_active_active_mux_direction_result(body, port, db) - if rc != True: - rc_exit = False + if rc != 0: + rc_exit = EXIT_FAIL if json_output: click.echo("{}".format(json.dumps(result, indent=4))) @@ -2252,7 +2254,6 @@ def muxdirection(db, port, json_output): click.echo(tabulate(body, headers=headers)) - if rc_exit == False: - sys.exit(EXIT_FAIL) + sys.exit(rc_exit)