From 02d89d6fcb0463cd46146bf6ca6433dbf61f18fa Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Mon, 25 Jan 2021 23:42:49 +0000 Subject: [PATCH 01/16] [sonic-utilities] add changes for cli support for ber eye info, configure prbs and loopback Signed-off-by: vaibhav-dahiya --- config/muxcable.py | 28 ++++++++++++++++++++++++++++ show/muxcable.py | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/config/muxcable.py b/config/muxcable.py index 2418284692..b6cbc82d29 100644 --- a/config/muxcable.py +++ b/config/muxcable.py @@ -5,6 +5,7 @@ import click import utilities_common.cli as clicommon from sonic_py_common import multi_asic +from sonic_y_cable import y_cable from swsssdk import ConfigDBConnector from swsscommon import swsscommon from tabulate import tabulate @@ -188,3 +189,30 @@ def mode(state, port, json_output): click.echo(tabulate(data, headers=headers)) sys.exit(CONFIG_SUCCESSFUL) + +@muxcable.command() +@click.argument('port', required=True, default=None, type= click.INT) +@click.argument('target', required=True, default=None, type = click.INT) +@click.argument('mode_value', required=True, default=None, type= click.INT) +@click.argument('lane_map', required=True, default=None, type = click.INT) +def prbs(port, target, mode_value, lane_map): + + res = y_cable.enable_prbs_mode(port, target, mode_value, lane_map) + if res != True: + click.echo("PRBS config unsuccesful") + sys.exit(CONFIG_FAIL) + click.echo("PRBS config sucessful") + sys.exit(0) + +@muxcable.command() +@click.argument('port', required=True, default=None, type= click.INT) +@click.argument('target', required=True, default=None, type = click.INT) +@click.argument('lane_map', required=True, default=None, type = click.INT) +def loopback(port, target, lane_map): + + res = y_cable.enable_loopback_mode(port, target, lane_map) + if res != True: + click.echo("loopback config unsuccesful") + sys.exit(CONFIG_FAIL) + click.echo("loopback config sucessful") + sys.exit(0) diff --git a/show/muxcable.py b/show/muxcable.py index 3b65e4b638..c49708a7eb 100644 --- a/show/muxcable.py +++ b/show/muxcable.py @@ -1,9 +1,11 @@ import json +import os import sys import click import utilities_common.cli as clicommon from sonic_py_common import multi_asic +from sonic_y_cable import y_cable from swsscommon import swsscommon from swsssdk import ConfigDBConnector from tabulate import tabulate @@ -336,3 +338,38 @@ def config(port, json_output): click.echo(tabulate(print_data, headers=headers)) sys.exit(CONFIG_SUCCESSFUL) + +@muxcable.command() +@click.argument('port', required=True, default=None, type= click.INT) +@click.argument('target', required=True, default=None, type = click.INT) +def berinfo(port, target): + + if os.geteuid() != 0: + click.echo("Root privileges are required for this operation") + sys.exit(CONFIG_FAIL) + res = y_cable.get_ber_info(port, target) + if res == False or res == -1: + click.echo("Unable to fetch ber info") + sys.exit(CONFIG_FAIL) + #res1 = y_cable.get_eye_info(port, target) + headers = ['Lane1', 'Lane2'] + lane_data = [] + lane_data.append(res) + click.echo(tabulate(lane_data, headers=headers)) + +@muxcable.command() +@click.argument('port', required=True, default=None, type= click.INT) +@click.argument('target', required=True, default=None, type = click.INT) +def eyeinfo(port, target): + + if os.geteuid() != 0: + click.echo("Root privileges are required for this operation") + sys.exit(CONFIG_FAIL) + res = y_cable.get_eye_info(port, target) + if res == False or res == -1: + click.echo("Unable to fetch eye info") + sys.exit(CONFIG_FAIL) + headers = ['Lane1', 'Lane2'] + lane_data = [] + lane_data.append(res) + click.echo(tabulate(lane_data, headers=headers)) From 8b88c5a2438566079905bf3fcd0c72c25f9c7145 Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Wed, 27 Jan 2021 01:39:18 +0000 Subject: [PATCH 02/16] fix comments Signed-off-by: vaibhav-dahiya --- config/muxcable.py | 20 +++++++++++--------- setup.py | 1 + show/muxcable.py | 10 ++++++---- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/config/muxcable.py b/config/muxcable.py index b6cbc82d29..9e0110aaf9 100644 --- a/config/muxcable.py +++ b/config/muxcable.py @@ -72,7 +72,7 @@ def lookup_statedb_and_update_configdb(per_npu_statedb, config_db, port, state_c ipv6_value = get_value_for_key_in_config_tbl(config_db, port, "server_ipv6", "MUX_CABLE") state = get_value_for_key_in_dict(muxcable_statedb_dict, port, "state", "MUX_CABLE_TABLE") - if (state == "active" and configdb_state == "active") or (state == "standby" and configdb_state == "active") or (state == "unknown" and configdb_state == "active") : + if (state == "active" and configdb_state == "active") or (state == "standby" and configdb_state == "active") or (state == "unknown" and configdb_state == "active"): if state_cfg_val == "active": # status is already active, so right back error port_status_dict[port] = 'OK' @@ -91,7 +91,7 @@ def lookup_statedb_and_update_configdb(per_npu_statedb, config_db, port, state_c # dont write anything to db, write OK to user port_status_dict[port] = 'OK' - elif (state == "standby" and configdb_state == "auto") or (state == "unknown" and configdb_state == "auto"): + elif (state == "standby" and configdb_state == "auto") or (state == "unknown" and configdb_state == "auto"): if state_cfg_val == "active": # make the state active config_db.set_entry("MUX_CABLE", port, {"state": "active", @@ -190,11 +190,12 @@ def mode(state, port, json_output): sys.exit(CONFIG_SUCCESSFUL) + @muxcable.command() -@click.argument('port', required=True, default=None, type= click.INT) -@click.argument('target', required=True, default=None, type = click.INT) -@click.argument('mode_value', required=True, default=None, type= click.INT) -@click.argument('lane_map', required=True, default=None, type = click.INT) +@click.argument('port', required=True, default=None, type=click.INT) +@click.argument('target', required=True, default=None, type=click.INT) +@click.argument('mode_value', required=True, default=None, type=click.INT) +@click.argument('lane_map', required=True, default=None, type=click.INT) def prbs(port, target, mode_value, lane_map): res = y_cable.enable_prbs_mode(port, target, mode_value, lane_map) @@ -204,10 +205,11 @@ def prbs(port, target, mode_value, lane_map): click.echo("PRBS config sucessful") sys.exit(0) + @muxcable.command() -@click.argument('port', required=True, default=None, type= click.INT) -@click.argument('target', required=True, default=None, type = click.INT) -@click.argument('lane_map', required=True, default=None, type = click.INT) +@click.argument('port', required=True, default=None, type=click.INT) +@click.argument('target', required=True, default=None, type=click.INT) +@click.argument('lane_map', required=True, default=None, type=click.INT) def loopback(port, target, lane_map): res = y_cable.enable_loopback_mode(port, target, lane_map) diff --git a/setup.py b/setup.py index adb725727b..8df45f8487 100644 --- a/setup.py +++ b/setup.py @@ -155,6 +155,7 @@ 'netifaces==0.10.7', 'pexpect==4.8.0', 'requests==2.25.0', + 'sonic-platform-common', 'sonic-py-common', 'sonic-yang-mgmt', 'swsssdk>=2.0.1', diff --git a/show/muxcable.py b/show/muxcable.py index c49708a7eb..45f307d271 100644 --- a/show/muxcable.py +++ b/show/muxcable.py @@ -339,9 +339,10 @@ def config(port, json_output): sys.exit(CONFIG_SUCCESSFUL) + @muxcable.command() -@click.argument('port', required=True, default=None, type= click.INT) -@click.argument('target', required=True, default=None, type = click.INT) +@click.argument('port', required=True, default=None, type=click.INT) +@click.argument('target', required=True, default=None, type=click.INT) def berinfo(port, target): if os.geteuid() != 0: @@ -357,9 +358,10 @@ def berinfo(port, target): lane_data.append(res) click.echo(tabulate(lane_data, headers=headers)) + @muxcable.command() -@click.argument('port', required=True, default=None, type= click.INT) -@click.argument('target', required=True, default=None, type = click.INT) +@click.argument('port', required=True, default=None, type=click.INT) +@click.argument('target', required=True, default=None, type=click.INT) def eyeinfo(port, target): if os.geteuid() != 0: From f60129b4f9da453c02f51da395e41b7b3dd790f3 Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Wed, 27 Jan 2021 01:59:37 +0000 Subject: [PATCH 03/16] fix some more comments Signed-off-by: vaibhav-dahiya --- config/muxcable.py | 2 +- show/muxcable.py | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/config/muxcable.py b/config/muxcable.py index 9e0110aaf9..b9f8ce7b63 100644 --- a/config/muxcable.py +++ b/config/muxcable.py @@ -217,4 +217,4 @@ def loopback(port, target, lane_map): click.echo("loopback config unsuccesful") sys.exit(CONFIG_FAIL) click.echo("loopback config sucessful") - sys.exit(0) + sys.exit(CONFIG_SUCCESSFUL) diff --git a/show/muxcable.py b/show/muxcable.py index 45f307d271..a3f6a25a05 100644 --- a/show/muxcable.py +++ b/show/muxcable.py @@ -352,7 +352,6 @@ def berinfo(port, target): if res == False or res == -1: click.echo("Unable to fetch ber info") sys.exit(CONFIG_FAIL) - #res1 = y_cable.get_eye_info(port, target) headers = ['Lane1', 'Lane2'] lane_data = [] lane_data.append(res) From e865ee8f139db554599fe9f36f6c51c6ffe9dbf1 Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Fri, 29 Jan 2021 01:32:55 +0000 Subject: [PATCH 04/16] updating command_refernce.md and fixing comments Signed-off-by: vaibhav-dahiya --- config/muxcable.py | 2 +- doc/Command-Reference.md | 108 ++++++++++++++++++++++++++++++++++++++- show/muxcable.py | 10 ++-- 3 files changed, 113 insertions(+), 7 deletions(-) diff --git a/config/muxcable.py b/config/muxcable.py index b9f8ce7b63..070f19e1d2 100644 --- a/config/muxcable.py +++ b/config/muxcable.py @@ -203,7 +203,7 @@ def prbs(port, target, mode_value, lane_map): click.echo("PRBS config unsuccesful") sys.exit(CONFIG_FAIL) click.echo("PRBS config sucessful") - sys.exit(0) + sys.exit(CONFIG_SUCCESSFUL) @muxcable.command() diff --git a/doc/Command-Reference.md b/doc/Command-Reference.md index 3088b6db61..9a25b56120 100644 --- a/doc/Command-Reference.md +++ b/doc/Command-Reference.md @@ -4734,6 +4734,54 @@ While displaying the muxcable configuration, users can configure the following f } ``` +**show muxcable ber-info** + +This command displays the ber(Bit error rate) of the port user provides on the target user provides. The target provided as an integer corresponds to actual target as. +0 -> local +1 -> tor 1 +2 -> tor 2 +3 -> nic + +- Usage: + ``` + Usage: show muxcable ber-info [OPTIONS] PORT TARGET + ``` + + +- PORT required - Port number should be a valid port +- TARGET required - the actual target to get the ber info of. + +- Example: + ``` + admin@sonic:~$ show muxcable ber-info 1 1 + Lane1 Lane2 + ------- ------- + 0 0 + ``` + +**show muxcable ber-info** + +This command displays the eye info in mv(milli volts) of the port user provides on the target user provides. The target provided as an integer corresponds to actual target as. +0 -> local +1 -> tor 1 +2 -> tor 2 +3 -> nic + +- Usage: + ``` + Usage: show muxcable eye-info [OPTIONS] PORT TARGET + ``` + +- PORT required - Port number should be a valid port +- TARGET required - the actual target to get the eye info of. + +- Example: + ``` + admin@sonic:~$ show muxcable ber-info 1 1 + Lane1 Lane2 + ------- ------- + 632 622 + ``` ### Muxcable Config commands @@ -4769,7 +4817,6 @@ While configuring the muxcable, users needs to configure the following fields fo "Ethernet0": "OK" } ``` - ``` admin@sonic:~$ sudo config muxcable mode active all port state @@ -4785,8 +4832,65 @@ While configuring the muxcable, users needs to configure the following fields fo "Ethernet32": "INPROGRESS", "Ethernet0": "OK" } - ``` + ``` +**config muxcable prbs** +This command is used for setting the configuration of prbs on a port user provides. In addition to port the user also needs to provides the target, prbs mode and lane map on which the user intends to run prbs on. + +- Usage: + ``` + config muxcable prbs [OPTIONS] PORT TARGET MODE_VALUE LANE_MAP + ``` + +While configuring the muxcable, users needs to configure the following fields for the operation + +- PORT required - Port number should be a valid port +- TARGET required - the actual target to run the prbs on + 0 -> local side, + 1 -> TOR 1 + 2 -> TOR 2 + 3 -> NIC +- MODE_VALUE required - the mode/type for configuring the PRBS mode. + 0x00 = PRBS 9, 0x01 = PRBS 15, 0x02 = PRBS 23, 0x03 = PRBS 31 +- LANE_MAP required - an integer representing the lane_map to be run PRBS on + 0bit for lane 0, 1bit for lane1 and so on. + for example 3 -> 0b'0011 , means running on lane0 and lane1 +- Example: + ``` + admin@sonic:~$ sudo config muxcable prbs 1 1 3 3 + PRBS config sucessful + ``` + +**config muxcable loopback** + +This command is used for setting the configuration of loopback on a port user provides. In addition to port the user also needs to provides the target and lane map on which the user intends to run loopback on. + +- Usage: + ``` + config muxcable loopback [OPTIONS] PORT TARGET LANE_MAP + ``` + +While configuring the muxcable, users needs to configure the following fields for the operation + +- PORT required - Port number should be a valid port +- TARGET required - the actual target to run the loopback on + 0 -> local side, + 1 -> TOR 1 + 2 -> TOR 2 + 3 -> NIC +- LANE_MAP required - an integer representing the lane_map to be run loopback on + 0bit for lane 0, 1bit for lane1 and so on. + for example 3 -> 0b'0011 , means running on lane0 and lane1 + +- Example: + ``` + admin@sonic:~$ sudo config muxcable loopback 1 1 3 + loopback config sucessful + ``` + +Go Back To [Beginning of the document](#) or [Beginning of this section](#muxcable) + +## Mirroring Go Back To [Beginning of the document](#) or [Beginning of this section](#muxcable) ## Mirroring diff --git a/show/muxcable.py b/show/muxcable.py index a3f6a25a05..bfbc13cf99 100644 --- a/show/muxcable.py +++ b/show/muxcable.py @@ -17,6 +17,8 @@ CONFIG_SUCCESSFUL = 101 CONFIG_FAIL = 1 +BER_CONFIG_FAIL = 1 +EYE_CONFIG_FAIL = 1 STATUS_FAIL = 1 STATUS_SUCCESSFUL = 102 @@ -347,11 +349,11 @@ def berinfo(port, target): if os.geteuid() != 0: click.echo("Root privileges are required for this operation") - sys.exit(CONFIG_FAIL) + sys.exit(BER_CONFIG_FAIL) res = y_cable.get_ber_info(port, target) if res == False or res == -1: click.echo("Unable to fetch ber info") - sys.exit(CONFIG_FAIL) + sys.exit(BER_CONFIG_FAIL) headers = ['Lane1', 'Lane2'] lane_data = [] lane_data.append(res) @@ -365,11 +367,11 @@ def eyeinfo(port, target): if os.geteuid() != 0: click.echo("Root privileges are required for this operation") - sys.exit(CONFIG_FAIL) + sys.exit(EYE_CONFIG_FAIL) res = y_cable.get_eye_info(port, target) if res == False or res == -1: click.echo("Unable to fetch eye info") - sys.exit(CONFIG_FAIL) + sys.exit(EYE_CONFIG_FAIL) headers = ['Lane1', 'Lane2'] lane_data = [] lane_data.append(res) From 6f940bf886c06822834b642d0a4bc101024b0f4e Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Fri, 29 Jan 2021 01:40:58 +0000 Subject: [PATCH 05/16] fixing comments Signed-off-by: vaibhav-dahiya --- show/muxcable.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/show/muxcable.py b/show/muxcable.py index bfbc13cf99..ec99e6d673 100644 --- a/show/muxcable.py +++ b/show/muxcable.py @@ -17,8 +17,8 @@ CONFIG_SUCCESSFUL = 101 CONFIG_FAIL = 1 -BER_CONFIG_FAIL = 1 -EYE_CONFIG_FAIL = 1 +EXIT_FAIL = 1 +EXIT_SUCCESS = 0 STATUS_FAIL = 1 STATUS_SUCCESSFUL = 102 @@ -349,11 +349,11 @@ def berinfo(port, target): if os.geteuid() != 0: click.echo("Root privileges are required for this operation") - sys.exit(BER_CONFIG_FAIL) + sys.exit(EXIT_FAIL) res = y_cable.get_ber_info(port, target) if res == False or res == -1: click.echo("Unable to fetch ber info") - sys.exit(BER_CONFIG_FAIL) + sys.exit(EXIT_FAIL) headers = ['Lane1', 'Lane2'] lane_data = [] lane_data.append(res) @@ -367,11 +367,11 @@ def eyeinfo(port, target): if os.geteuid() != 0: click.echo("Root privileges are required for this operation") - sys.exit(EYE_CONFIG_FAIL) + sys.exit(EXIT_FAIL) res = y_cable.get_eye_info(port, target) if res == False or res == -1: click.echo("Unable to fetch eye info") - sys.exit(EYE_CONFIG_FAIL) + sys.exit(EXIT_FAIL) headers = ['Lane1', 'Lane2'] lane_data = [] lane_data.append(res) From 4447d4add9c323c9a4a90c383e00c6329b373136 Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Fri, 29 Jan 2021 01:52:23 +0000 Subject: [PATCH 06/16] fix extra lines yanked Signed-off-by: vaibhav-dahiya --- doc/Command-Reference.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/doc/Command-Reference.md b/doc/Command-Reference.md index 9a25b56120..2f8ade8edc 100644 --- a/doc/Command-Reference.md +++ b/doc/Command-Reference.md @@ -4890,9 +4890,6 @@ While configuring the muxcable, users needs to configure the following fields fo Go Back To [Beginning of the document](#) or [Beginning of this section](#muxcable) -## Mirroring -Go Back To [Beginning of the document](#) or [Beginning of this section](#muxcable) - ## Mirroring ### Mirroring Show commands From 0aa3910fcb9f0e8f70c783c7eed036f1666f2d35 Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Sat, 30 Jan 2021 05:52:27 +0000 Subject: [PATCH 07/16] add unit tests for new apis Signed-off-by: vaibhav-dahiya --- config/muxcable.py | 37 ++++++++++++++++--- show/muxcable.py | 9 +++-- tests/muxcable_test.py | 83 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 121 insertions(+), 8 deletions(-) diff --git a/config/muxcable.py b/config/muxcable.py index 070f19e1d2..7c295156a9 100644 --- a/config/muxcable.py +++ b/config/muxcable.py @@ -5,7 +5,6 @@ import click import utilities_common.cli as clicommon from sonic_py_common import multi_asic -from sonic_y_cable import y_cable from swsssdk import ConfigDBConnector from swsscommon import swsscommon from tabulate import tabulate @@ -196,25 +195,53 @@ def mode(state, port, json_output): @click.argument('target', required=True, default=None, type=click.INT) @click.argument('mode_value', required=True, default=None, type=click.INT) @click.argument('lane_map', required=True, default=None, type=click.INT) -def prbs(port, target, mode_value, lane_map): +def enable_prbs(port, target, mode_value, lane_map): - res = y_cable.enable_prbs_mode(port, target, mode_value, lane_map) + import sonic_y_cable.y_cable + res = sonic_y_cable.y_cable.enable_prbs_mode(port, target, mode_value, lane_map) if res != True: click.echo("PRBS config unsuccesful") sys.exit(CONFIG_FAIL) click.echo("PRBS config sucessful") sys.exit(CONFIG_SUCCESSFUL) +@muxcable.command() +@click.argument('port', required=True, default=None, type=click.INT) +@click.argument('target', required=True, default=None, type=click.INT) +def disable_prbs(port, target): + + import sonic_y_cable.y_cable + res = sonic_y_cable.y_cable.disable_prbs_mode(port, target) + if res != True: + click.echo("PRBS disable unsuccesful") + sys.exit(CONFIG_FAIL) + click.echo("PRBS disbale sucessful") + sys.exit(CONFIG_SUCCESSFUL) + @muxcable.command() @click.argument('port', required=True, default=None, type=click.INT) @click.argument('target', required=True, default=None, type=click.INT) @click.argument('lane_map', required=True, default=None, type=click.INT) -def loopback(port, target, lane_map): +def enable_loopback(port, target, lane_map): - res = y_cable.enable_loopback_mode(port, target, lane_map) + import sonic_y_cable.y_cable + res = sonic_y_cable.y_cable.enable_loopback_mode(port, target, lane_map) if res != True: click.echo("loopback config unsuccesful") sys.exit(CONFIG_FAIL) click.echo("loopback config sucessful") sys.exit(CONFIG_SUCCESSFUL) + +@muxcable.command() +@click.argument('port', required=True, default=None, type=click.INT) +@click.argument('target', required=True, default=None, type=click.INT) +def disable_loopback(port, target): + + import sonic_y_cable.y_cable + res = sonic_y_cable.y_cable.disable_loopback_mode(port, target) + if res != True: + click.echo("loopback disable unsuccesful") + sys.exit(CONFIG_FAIL) + click.echo("loopback disable sucessful") + sys.exit(CONFIG_SUCCESSFUL) diff --git a/show/muxcable.py b/show/muxcable.py index ec99e6d673..af5a9488a6 100644 --- a/show/muxcable.py +++ b/show/muxcable.py @@ -5,7 +5,6 @@ import click import utilities_common.cli as clicommon from sonic_py_common import multi_asic -from sonic_y_cable import y_cable from swsscommon import swsscommon from swsssdk import ConfigDBConnector from tabulate import tabulate @@ -350,7 +349,8 @@ def berinfo(port, target): if os.geteuid() != 0: click.echo("Root privileges are required for this operation") sys.exit(EXIT_FAIL) - res = y_cable.get_ber_info(port, target) + import sonic_y_cable.y_cable + res = sonic_y_cable.y_cable.get_ber_info(port, target) if res == False or res == -1: click.echo("Unable to fetch ber info") sys.exit(EXIT_FAIL) @@ -358,6 +358,7 @@ def berinfo(port, target): lane_data = [] lane_data.append(res) click.echo(tabulate(lane_data, headers=headers)) + sys.exit(EXIT_SUCCESS) @muxcable.command() @@ -368,7 +369,8 @@ def eyeinfo(port, target): if os.geteuid() != 0: click.echo("Root privileges are required for this operation") sys.exit(EXIT_FAIL) - res = y_cable.get_eye_info(port, target) + import sonic_y_cable.y_cable + res = sonic_y_cable.y_cable.get_eye_info(port, target) if res == False or res == -1: click.echo("Unable to fetch eye info") sys.exit(EXIT_FAIL) @@ -376,3 +378,4 @@ def eyeinfo(port, target): lane_data = [] lane_data.append(res) click.echo(tabulate(lane_data, headers=headers)) + sys.exit(EXIT_SUCCESS) diff --git a/tests/muxcable_test.py b/tests/muxcable_test.py index 7fad557f4a..2c1ebec47c 100644 --- a/tests/muxcable_test.py +++ b/tests/muxcable_test.py @@ -10,6 +10,11 @@ sys.modules['sonic_platform_base'] = mock.Mock() sys.modules['sonic_platform_base.sonic_sfp'] = mock.Mock() sys.modules['sonic_platform_base.sonic_sfp.sfputilhelper'] = mock.Mock() +sys.modules['sonic_y_cable'] = mock.Mock() +sys.modules['y_cable'] = mock.Mock() +sys.modules['sonic_y_cable.y_cable'] = mock.Mock() +#sys.modules['os'] = mock.Mock() +#sys.modules['os.geteuid'] = mock.Mock() #sys.modules['platform_sfputil'] = mock.Mock() import config.main as config import show.main as show @@ -416,6 +421,84 @@ def test_config_muxcable_tabular_port_with_incorrect_port(self): assert(result.exit_code == 1) + def test_show_muxcable_eye_info(self): + runner = CliRunner() + db = Db() + + with mock.patch('os.geteuid') as patched_util_outer: + os.geteuid.return_value = 0 + with mock.patch('sonic_y_cable.y_cable') as patched_util: + patched_util.get_eye_info.return_value = [0, 0] + result = runner.invoke(show.cli.commands["muxcable"].commands["eyeinfo"], [ + "0", "0"], obj=db) + + assert(result.exit_code == 0) + + def test_show_muxcable_ber_info(self): + runner = CliRunner() + db = Db() + + with mock.patch('os.geteuid') as patched_util_outer: + os.geteuid.return_value = 0 + with mock.patch('sonic_y_cable.y_cable') as patched_util: + patched_util.get_ber_info.return_value = [0, 0] + result = runner.invoke(show.cli.commands["muxcable"].commands["berinfo"], [ + "0", "0"], obj=db) + + assert(result.exit_code == 0) + + def test_config_muxcable_enable_prbs(self): + runner = CliRunner() + db = Db() + + with mock.patch('os.geteuid') as patched_util_outer: + os.geteuid.return_value = 0 + with mock.patch('sonic_y_cable.y_cable') as patched_util: + patched_util.enable_prbs_mode.return_value = 1 + result = runner.invoke(config.config.commands["muxcable"].commands["enable-prbs"], [ + "0", "0", "0", "0"], obj=db) + + assert(result.exit_code == 100) + + def test_config_muxcable_enable_loopback(self): + runner = CliRunner() + db = Db() + + with mock.patch('os.geteuid') as patched_util_outer: + os.geteuid.return_value = 0 + with mock.patch('sonic_y_cable.y_cable') as patched_util: + patched_util.enable_loopback_mode.return_value = 1 + result = runner.invoke(config.config.commands["muxcable"].commands["enable-loopback"], [ + "0", "0", "0"], obj=db) + + assert(result.exit_code == 100) + + def test_config_muxcable_disble_prbs(self): + runner = CliRunner() + db = Db() + + with mock.patch('os.geteuid') as patched_util_outer: + os.geteuid.return_value = 0 + with mock.patch('sonic_y_cable.y_cable') as patched_util: + patched_util.disable_prbs_mode.return_value = 1 + result = runner.invoke(config.config.commands["muxcable"].commands["disable-prbs"], [ + "0", "0"], obj=db) + + assert(result.exit_code == 100) + + def test_config_muxcable_disable_loopback(self): + runner = CliRunner() + db = Db() + + with mock.patch('os.geteuid') as patched_util_outer: + os.geteuid.return_value = 0 + with mock.patch('sonic_y_cable.y_cable') as patched_util: + patched_util.disable_loopback_mode.return_value = 1 + result = runner.invoke(config.config.commands["muxcable"].commands["disable-loopback"], [ + "0", "0"], obj=db) + + assert(result.exit_code == 100) + @classmethod def teardown_class(cls): os.environ['UTILITIES_UNIT_TESTING'] = "0" From 2724acc367851cbc5c03a0b4a5ad2cc707c6e1e1 Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Tue, 2 Feb 2021 05:12:02 +0000 Subject: [PATCH 08/16] adding subgroups Signed-off-by: vaibhav-dahiya --- config/muxcable.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/config/muxcable.py b/config/muxcable.py index 7c295156a9..4683f66482 100644 --- a/config/muxcable.py +++ b/config/muxcable.py @@ -189,13 +189,17 @@ def mode(state, port, json_output): sys.exit(CONFIG_SUCCESSFUL) +@muxcable.group(cls=clicommon.AbbreviationGroup) +def prbs(): + """Enable prbs on a port""" + pass -@muxcable.command() +@prbs.command() @click.argument('port', required=True, default=None, type=click.INT) @click.argument('target', required=True, default=None, type=click.INT) @click.argument('mode_value', required=True, default=None, type=click.INT) @click.argument('lane_map', required=True, default=None, type=click.INT) -def enable_prbs(port, target, mode_value, lane_map): +def enable(port, target, mode_value, lane_map): import sonic_y_cable.y_cable res = sonic_y_cable.y_cable.enable_prbs_mode(port, target, mode_value, lane_map) @@ -205,10 +209,10 @@ def enable_prbs(port, target, mode_value, lane_map): click.echo("PRBS config sucessful") sys.exit(CONFIG_SUCCESSFUL) -@muxcable.command() +@prbs.command() @click.argument('port', required=True, default=None, type=click.INT) @click.argument('target', required=True, default=None, type=click.INT) -def disable_prbs(port, target): +def disable(port, target): import sonic_y_cable.y_cable res = sonic_y_cable.y_cable.disable_prbs_mode(port, target) @@ -218,12 +222,17 @@ def disable_prbs(port, target): click.echo("PRBS disbale sucessful") sys.exit(CONFIG_SUCCESSFUL) +@muxcable.group(cls=clicommon.AbbreviationGroup) +def loopback(): + """Enable loopback on a port""" + pass -@muxcable.command() + +@loopback.command() @click.argument('port', required=True, default=None, type=click.INT) @click.argument('target', required=True, default=None, type=click.INT) @click.argument('lane_map', required=True, default=None, type=click.INT) -def enable_loopback(port, target, lane_map): +def enable(port, target, lane_map): import sonic_y_cable.y_cable res = sonic_y_cable.y_cable.enable_loopback_mode(port, target, lane_map) @@ -233,10 +242,10 @@ def enable_loopback(port, target, lane_map): click.echo("loopback config sucessful") sys.exit(CONFIG_SUCCESSFUL) -@muxcable.command() +@loopback.command() @click.argument('port', required=True, default=None, type=click.INT) @click.argument('target', required=True, default=None, type=click.INT) -def disable_loopback(port, target): +def disable(port, target): import sonic_y_cable.y_cable res = sonic_y_cable.y_cable.disable_loopback_mode(port, target) From c30edc6d690583f9acbcd45251696604c1e966ca Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Tue, 2 Feb 2021 05:17:00 +0000 Subject: [PATCH 09/16] fixing test cases Signed-off-by: vaibhav-dahiya --- tests/muxcable_test.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/muxcable_test.py b/tests/muxcable_test.py index 2c1ebec47c..c455640f1f 100644 --- a/tests/muxcable_test.py +++ b/tests/muxcable_test.py @@ -455,7 +455,7 @@ def test_config_muxcable_enable_prbs(self): os.geteuid.return_value = 0 with mock.patch('sonic_y_cable.y_cable') as patched_util: patched_util.enable_prbs_mode.return_value = 1 - result = runner.invoke(config.config.commands["muxcable"].commands["enable-prbs"], [ + result = runner.invoke(config.config.commands["muxcable"].commands["prbs"].commands["enable"], [ "0", "0", "0", "0"], obj=db) assert(result.exit_code == 100) @@ -468,7 +468,7 @@ def test_config_muxcable_enable_loopback(self): os.geteuid.return_value = 0 with mock.patch('sonic_y_cable.y_cable') as patched_util: patched_util.enable_loopback_mode.return_value = 1 - result = runner.invoke(config.config.commands["muxcable"].commands["enable-loopback"], [ + result = runner.invoke(config.config.commands["muxcable"].commands["loopback"].commands["enable"], [ "0", "0", "0"], obj=db) assert(result.exit_code == 100) @@ -481,7 +481,7 @@ def test_config_muxcable_disble_prbs(self): os.geteuid.return_value = 0 with mock.patch('sonic_y_cable.y_cable') as patched_util: patched_util.disable_prbs_mode.return_value = 1 - result = runner.invoke(config.config.commands["muxcable"].commands["disable-prbs"], [ + result = runner.invoke(config.config.commands["muxcable"].commands["prbs"].commands["enable"], [ "0", "0"], obj=db) assert(result.exit_code == 100) @@ -494,7 +494,7 @@ def test_config_muxcable_disable_loopback(self): os.geteuid.return_value = 0 with mock.patch('sonic_y_cable.y_cable') as patched_util: patched_util.disable_loopback_mode.return_value = 1 - result = runner.invoke(config.config.commands["muxcable"].commands["disable-loopback"], [ + result = runner.invoke(config.config.commands["muxcable"].commands["prbs"].commands["disbale"], [ "0", "0"], obj=db) assert(result.exit_code == 100) From 4fa4b56103cf06e3397dae01b5373f1253e86fd3 Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Tue, 2 Feb 2021 05:30:09 +0000 Subject: [PATCH 10/16] fixing test cases Signed-off-by: vaibhav-dahiya --- tests/muxcable_test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/muxcable_test.py b/tests/muxcable_test.py index c455640f1f..9ddc0c7c43 100644 --- a/tests/muxcable_test.py +++ b/tests/muxcable_test.py @@ -481,7 +481,7 @@ def test_config_muxcable_disble_prbs(self): os.geteuid.return_value = 0 with mock.patch('sonic_y_cable.y_cable') as patched_util: patched_util.disable_prbs_mode.return_value = 1 - result = runner.invoke(config.config.commands["muxcable"].commands["prbs"].commands["enable"], [ + result = runner.invoke(config.config.commands["muxcable"].commands["prbs"].commands["disable"], [ "0", "0"], obj=db) assert(result.exit_code == 100) @@ -494,7 +494,7 @@ def test_config_muxcable_disable_loopback(self): os.geteuid.return_value = 0 with mock.patch('sonic_y_cable.y_cable') as patched_util: patched_util.disable_loopback_mode.return_value = 1 - result = runner.invoke(config.config.commands["muxcable"].commands["prbs"].commands["disbale"], [ + result = runner.invoke(config.config.commands["muxcable"].commands["loopback"].commands["disable"], [ "0", "0"], obj=db) assert(result.exit_code == 100) From 4853899c2471dbd9c8ded10a4811490c8b24c2bb Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Tue, 2 Feb 2021 16:14:11 +0000 Subject: [PATCH 11/16] fixing the patch indents Signed-off-by: vaibhav-dahiya --- tests/muxcable_test.py | 60 +++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 36 deletions(-) diff --git a/tests/muxcable_test.py b/tests/muxcable_test.py index 9ddc0c7c43..4ab7a79347 100644 --- a/tests/muxcable_test.py +++ b/tests/muxcable_test.py @@ -421,81 +421,69 @@ def test_config_muxcable_tabular_port_with_incorrect_port(self): assert(result.exit_code == 1) + @mock.patch('os.geteuid', mock.MagicMock(return_value=0)) + @mock.patch('sonic_y_cable.y_cable.get_eye_info', mock.MagicMock(return_value=[0, 0])) def test_show_muxcable_eye_info(self): runner = CliRunner() db = Db() - with mock.patch('os.geteuid') as patched_util_outer: - os.geteuid.return_value = 0 - with mock.patch('sonic_y_cable.y_cable') as patched_util: - patched_util.get_eye_info.return_value = [0, 0] - result = runner.invoke(show.cli.commands["muxcable"].commands["eyeinfo"], [ - "0", "0"], obj=db) + result = runner.invoke(show.cli.commands["muxcable"].commands["eyeinfo"], [ + "0", "0"], obj=db) assert(result.exit_code == 0) + @mock.patch('os.geteuid', mock.MagicMock(return_value=0)) + @mock.patch('sonic_y_cable.y_cable.get_ber_info', mock.MagicMock(return_value=[0, 0])) def test_show_muxcable_ber_info(self): runner = CliRunner() db = Db() - with mock.patch('os.geteuid') as patched_util_outer: - os.geteuid.return_value = 0 - with mock.patch('sonic_y_cable.y_cable') as patched_util: - patched_util.get_ber_info.return_value = [0, 0] - result = runner.invoke(show.cli.commands["muxcable"].commands["berinfo"], [ - "0", "0"], obj=db) + result = runner.invoke(show.cli.commands["muxcable"].commands["berinfo"], [ + "0", "0"], obj=db) assert(result.exit_code == 0) + @mock.patch('os.geteuid', mock.MagicMock(return_value=0)) + @mock.patch('sonic_y_cable.y_cable.enable_prbs_mode', mock.MagicMock(return_value=1)) def test_config_muxcable_enable_prbs(self): runner = CliRunner() db = Db() - with mock.patch('os.geteuid') as patched_util_outer: - os.geteuid.return_value = 0 - with mock.patch('sonic_y_cable.y_cable') as patched_util: - patched_util.enable_prbs_mode.return_value = 1 - result = runner.invoke(config.config.commands["muxcable"].commands["prbs"].commands["enable"], [ - "0", "0", "0", "0"], obj=db) + result = runner.invoke(config.config.commands["muxcable"].commands["prbs"].commands["enable"], [ + "0", "0", "0", "0"], obj=db) assert(result.exit_code == 100) + @mock.patch('os.geteuid', mock.MagicMock(return_value=0)) + @mock.patch('sonic_y_cable.y_cable.enable_loopback_mode', mock.MagicMock(return_value=1)) def test_config_muxcable_enable_loopback(self): runner = CliRunner() db = Db() - with mock.patch('os.geteuid') as patched_util_outer: - os.geteuid.return_value = 0 - with mock.patch('sonic_y_cable.y_cable') as patched_util: - patched_util.enable_loopback_mode.return_value = 1 - result = runner.invoke(config.config.commands["muxcable"].commands["loopback"].commands["enable"], [ - "0", "0", "0"], obj=db) + result = runner.invoke(config.config.commands["muxcable"].commands["loopback"].commands["enable"], [ + "0", "0", "0"], obj=db) assert(result.exit_code == 100) + @mock.patch('os.geteuid', mock.MagicMock(return_value=0)) + @mock.patch('sonic_y_cable.y_cable.disable_prbs_mode', mock.MagicMock(return_value=1)) def test_config_muxcable_disble_prbs(self): runner = CliRunner() db = Db() - with mock.patch('os.geteuid') as patched_util_outer: - os.geteuid.return_value = 0 - with mock.patch('sonic_y_cable.y_cable') as patched_util: - patched_util.disable_prbs_mode.return_value = 1 - result = runner.invoke(config.config.commands["muxcable"].commands["prbs"].commands["disable"], [ - "0", "0"], obj=db) + result = runner.invoke(config.config.commands["muxcable"].commands["prbs"].commands["disable"], [ + "0", "0"], obj=db) assert(result.exit_code == 100) + @mock.patch('os.geteuid', mock.MagicMock(return_value=0)) + @mock.patch('sonic_y_cable.y_cable.disable_loopback_mode', mock.MagicMock(return_value=1)) def test_config_muxcable_disable_loopback(self): runner = CliRunner() db = Db() - with mock.patch('os.geteuid') as patched_util_outer: - os.geteuid.return_value = 0 - with mock.patch('sonic_y_cable.y_cable') as patched_util: - patched_util.disable_loopback_mode.return_value = 1 - result = runner.invoke(config.config.commands["muxcable"].commands["loopback"].commands["disable"], [ - "0", "0"], obj=db) + result = runner.invoke(config.config.commands["muxcable"].commands["loopback"].commands["disable"], [ + "0", "0"], obj=db) assert(result.exit_code == 100) From a5f3f1467520d1f57c78eb2b1be8cd1bb7216eb8 Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Wed, 3 Feb 2021 18:50:35 +0000 Subject: [PATCH 12/16] fixing comments Signed-off-by: vaibhav-dahiya --- config/muxcable.py | 10 +++++++--- doc/Command-Reference.md | 22 ++++++++++++++-------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/config/muxcable.py b/config/muxcable.py index 4683f66482..52a8065d44 100644 --- a/config/muxcable.py +++ b/config/muxcable.py @@ -191,7 +191,7 @@ def mode(state, port, json_output): @muxcable.group(cls=clicommon.AbbreviationGroup) def prbs(): - """Enable prbs on a port""" + """Enable/disable PRBS mode on a port""" pass @prbs.command() @@ -200,6 +200,7 @@ def prbs(): @click.argument('mode_value', required=True, default=None, type=click.INT) @click.argument('lane_map', required=True, default=None, type=click.INT) def enable(port, target, mode_value, lane_map): + """Enable PRBS mode on a port""" import sonic_y_cable.y_cable res = sonic_y_cable.y_cable.enable_prbs_mode(port, target, mode_value, lane_map) @@ -213,18 +214,19 @@ def enable(port, target, mode_value, lane_map): @click.argument('port', required=True, default=None, type=click.INT) @click.argument('target', required=True, default=None, type=click.INT) def disable(port, target): + """Disable PRBS mode on a port""" import sonic_y_cable.y_cable res = sonic_y_cable.y_cable.disable_prbs_mode(port, target) if res != True: click.echo("PRBS disable unsuccesful") sys.exit(CONFIG_FAIL) - click.echo("PRBS disbale sucessful") + click.echo("PRBS disable sucessful") sys.exit(CONFIG_SUCCESSFUL) @muxcable.group(cls=clicommon.AbbreviationGroup) def loopback(): - """Enable loopback on a port""" + """Enable/disable loopback mode on a port""" pass @@ -233,6 +235,7 @@ def loopback(): @click.argument('target', required=True, default=None, type=click.INT) @click.argument('lane_map', required=True, default=None, type=click.INT) def enable(port, target, lane_map): + """Enable loopback mode on a port""" import sonic_y_cable.y_cable res = sonic_y_cable.y_cable.enable_loopback_mode(port, target, lane_map) @@ -246,6 +249,7 @@ def enable(port, target, lane_map): @click.argument('port', required=True, default=None, type=click.INT) @click.argument('target', required=True, default=None, type=click.INT) def disable(port, target): + """Disable loopback mode on a port""" import sonic_y_cable.y_cable res = sonic_y_cable.y_cable.disable_loopback_mode(port, target) diff --git a/doc/Command-Reference.md b/doc/Command-Reference.md index 2f8ade8edc..0b81d89167 100644 --- a/doc/Command-Reference.md +++ b/doc/Command-Reference.md @@ -4833,13 +4833,14 @@ While configuring the muxcable, users needs to configure the following fields fo "Ethernet0": "OK" } ``` -**config muxcable prbs** +**config muxcable prbs enable/disable** -This command is used for setting the configuration of prbs on a port user provides. In addition to port the user also needs to provides the target, prbs mode and lane map on which the user intends to run prbs on. +This command is used for setting the configuration and enable/diable of prbs on a port user provides. While enabling in addition to port the user also needs to provides the target, prbs mode and lane map on which the user intends to run prbs on. The target reflects where the enable/dsiable will happen. - Usage: ``` - config muxcable prbs [OPTIONS] PORT TARGET MODE_VALUE LANE_MAP + config muxcable prbs enable [OPTIONS] PORT TARGET MODE_VALUE LANE_MAP + config muxcable prbs disable [OPTIONS] PORT TARGET ``` While configuring the muxcable, users needs to configure the following fields for the operation @@ -4857,17 +4858,20 @@ While configuring the muxcable, users needs to configure the following fields fo for example 3 -> 0b'0011 , means running on lane0 and lane1 - Example: ``` - admin@sonic:~$ sudo config muxcable prbs 1 1 3 3 + admin@sonic:~$ sudo config muxcable prbs enable 1 1 3 3 PRBS config sucessful + admin@sonic:~$ sudo config muxcable prbs disable 1 0 + PRBS disable sucessful ``` -**config muxcable loopback** +**config muxcable loopback enable/disable** -This command is used for setting the configuration of loopback on a port user provides. In addition to port the user also needs to provides the target and lane map on which the user intends to run loopback on. +This command is used for setting the configuration and enable/disable of loopback on a port user provides. While enabling in addition to port the user also needs to provides the target and lane map on which the user intends to run loopback on. The target reflects where the enable/dsiable will happen. - Usage: ``` - config muxcable loopback [OPTIONS] PORT TARGET LANE_MAP + config muxcable loopback enable [OPTIONS] PORT TARGET LANE_MAP + config muxcable loopback disable [OPTIONS] PORT TARGET ``` While configuring the muxcable, users needs to configure the following fields for the operation @@ -4884,8 +4888,10 @@ While configuring the muxcable, users needs to configure the following fields fo - Example: ``` - admin@sonic:~$ sudo config muxcable loopback 1 1 3 + admin@sonic:~$ sudo config muxcable loopback enable 1 1 3 loopback config sucessful + admin@sonic:~$ sudo config muxcable loopback disable 1 0 + loopback disable sucessfull ``` Go Back To [Beginning of the document](#) or [Beginning of this section](#muxcable) From e409cc18685ea68006286581208d7a68640e0d13 Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Wed, 3 Feb 2021 21:03:36 +0000 Subject: [PATCH 13/16] fix comments Signed-off-by: vaibhav-dahiya --- doc/Command-Reference.md | 4 ++-- tests/muxcable_test.py | 24 ++++++++++++------------ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/doc/Command-Reference.md b/doc/Command-Reference.md index 0b81d89167..b2015fb51a 100644 --- a/doc/Command-Reference.md +++ b/doc/Command-Reference.md @@ -4859,7 +4859,7 @@ While configuring the muxcable, users needs to configure the following fields fo - Example: ``` admin@sonic:~$ sudo config muxcable prbs enable 1 1 3 3 - PRBS config sucessful + PRBS config sucessful admin@sonic:~$ sudo config muxcable prbs disable 1 0 PRBS disable sucessful ``` @@ -4889,7 +4889,7 @@ While configuring the muxcable, users needs to configure the following fields fo - Example: ``` admin@sonic:~$ sudo config muxcable loopback enable 1 1 3 - loopback config sucessful + loopback config sucessful admin@sonic:~$ sudo config muxcable loopback disable 1 0 loopback disable sucessfull ``` diff --git a/tests/muxcable_test.py b/tests/muxcable_test.py index 4ab7a79347..3fa94e50cd 100644 --- a/tests/muxcable_test.py +++ b/tests/muxcable_test.py @@ -427,8 +427,8 @@ def test_show_muxcable_eye_info(self): runner = CliRunner() db = Db() - result = runner.invoke(show.cli.commands["muxcable"].commands["eyeinfo"], [ - "0", "0"], obj=db) + result = runner.invoke(show.cli.commands["muxcable"].commands["eyeinfo"], + ["0", "0"], obj=db) assert(result.exit_code == 0) @@ -438,8 +438,8 @@ def test_show_muxcable_ber_info(self): runner = CliRunner() db = Db() - result = runner.invoke(show.cli.commands["muxcable"].commands["berinfo"], [ - "0", "0"], obj=db) + result = runner.invoke(show.cli.commands["muxcable"].commands["berinfo"], + ["0", "0"], obj=db) assert(result.exit_code == 0) @@ -449,8 +449,8 @@ def test_config_muxcable_enable_prbs(self): runner = CliRunner() db = Db() - result = runner.invoke(config.config.commands["muxcable"].commands["prbs"].commands["enable"], [ - "0", "0", "0", "0"], obj=db) + result = runner.invoke(config.config.commands["muxcable"].commands["prbs"].commands["enable"], + ["0", "0", "0", "0"], obj=db) assert(result.exit_code == 100) @@ -460,8 +460,8 @@ def test_config_muxcable_enable_loopback(self): runner = CliRunner() db = Db() - result = runner.invoke(config.config.commands["muxcable"].commands["loopback"].commands["enable"], [ - "0", "0", "0"], obj=db) + result = runner.invoke(config.config.commands["muxcable"].commands["loopback"].commands["enable"], + ["0", "0", "0"], obj=db) assert(result.exit_code == 100) @@ -471,8 +471,8 @@ def test_config_muxcable_disble_prbs(self): runner = CliRunner() db = Db() - result = runner.invoke(config.config.commands["muxcable"].commands["prbs"].commands["disable"], [ - "0", "0"], obj=db) + result = runner.invoke(config.config.commands["muxcable"].commands["prbs"].commands["disable"], + ["0", "0"], obj=db) assert(result.exit_code == 100) @@ -482,8 +482,8 @@ def test_config_muxcable_disable_loopback(self): runner = CliRunner() db = Db() - result = runner.invoke(config.config.commands["muxcable"].commands["loopback"].commands["disable"], [ - "0", "0"], obj=db) + result = runner.invoke(config.config.commands["muxcable"].commands["loopback"].commands["disable"], + ["0", "0"], obj=db) assert(result.exit_code == 100) From 0ce3b87dda5739d06b33a978fdef3dd890695384 Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Wed, 3 Feb 2021 23:46:04 +0000 Subject: [PATCH 14/16] fixing some more comments Signed-off-by: vaibhav-dahiya --- show/muxcable.py | 2 ++ tests/muxcable_test.py | 78 +++++++++++++++++++++--------------------- 2 files changed, 41 insertions(+), 39 deletions(-) diff --git a/show/muxcable.py b/show/muxcable.py index af5a9488a6..f1664a566e 100644 --- a/show/muxcable.py +++ b/show/muxcable.py @@ -345,6 +345,7 @@ def config(port, json_output): @click.argument('port', required=True, default=None, type=click.INT) @click.argument('target', required=True, default=None, type=click.INT) def berinfo(port, target): + """Show muxcable ber (bit error rate) information""" if os.geteuid() != 0: click.echo("Root privileges are required for this operation") @@ -365,6 +366,7 @@ def berinfo(port, target): @click.argument('port', required=True, default=None, type=click.INT) @click.argument('target', required=True, default=None, type=click.INT) def eyeinfo(port, target): + """Show muxcable eye information""" if os.geteuid() != 0: click.echo("Root privileges are required for this operation") diff --git a/tests/muxcable_test.py b/tests/muxcable_test.py index 3fa94e50cd..0639fca7aa 100644 --- a/tests/muxcable_test.py +++ b/tests/muxcable_test.py @@ -165,8 +165,8 @@ def test_muxcable_status(self): db = Db() result = runner.invoke(show.cli.commands["muxcable"].commands["status"], obj=db) - assert(result.exit_code == 102) - assert(result.output == tabular_data_status_output_expected) + assert result.exit_code == 102 + assert result.output == tabular_data_status_output_expected def test_muxcable_status_json(self): runner = CliRunner() @@ -174,8 +174,8 @@ def test_muxcable_status_json(self): result = runner.invoke(show.cli.commands["muxcable"].commands["status"], ["--json"], obj=db) - assert(result.exit_code == 102) - assert(result.output == json_data_status_output_expected) + assert result.exit_code == 102 + assert result.output == json_data_status_output_expected def test_muxcable_status_config(self): runner = CliRunner() @@ -183,8 +183,8 @@ def test_muxcable_status_config(self): result = runner.invoke(show.cli.commands["muxcable"].commands["config"], obj=db) - assert(result.exit_code == 101) - assert(result.output == tabular_data_config_output_expected) + assert result.exit_code == 101 + assert result.output == tabular_data_config_output_expected def test_muxcable_status_config_json(self): runner = CliRunner() @@ -192,8 +192,8 @@ def test_muxcable_status_config_json(self): result = runner.invoke(show.cli.commands["muxcable"].commands["config"], ["--json"], obj=db) - assert(result.exit_code == 101) - assert(result.output == json_data_status_config_output_expected) + assert result.exit_code == 101 + assert result.output == json_data_status_config_output_expected def test_muxcable_config_json_with_incorrect_port(self): runner = CliRunner() @@ -201,7 +201,7 @@ def test_muxcable_config_json_with_incorrect_port(self): result = runner.invoke(show.cli.commands["muxcable"].commands["config"], ["Ethernet33", "--json"], obj=db) - assert(result.exit_code == 1) + assert result.exit_code == 1 def test_muxcable_status_json_with_correct_port(self): runner = CliRunner() @@ -210,7 +210,7 @@ def test_muxcable_status_json_with_correct_port(self): patched_util.SfpUtilHelper.return_value.get_asic_id_for_logical_port.return_value = 0 result = runner.invoke(show.cli.commands["muxcable"].commands["status"], ["Ethernet0", "--json"], obj=db) - assert(result.exit_code == 102) + assert result.exit_code == 102 def test_muxcable_status_json_port_incorrect_index(self): runner = CliRunner() @@ -219,7 +219,7 @@ def test_muxcable_status_json_port_incorrect_index(self): patched_util.SfpUtilHelper.return_value.get_asic_id_for_logical_port.return_value = 1 result = runner.invoke(show.cli.commands["muxcable"].commands["status"], ["Ethernet0", "--json"], obj=db) - assert(result.exit_code == 1) + assert result.exit_code == 1 def test_muxcable_status_with_patch(self): runner = CliRunner() @@ -234,7 +234,7 @@ def test_muxcable_status_json_with_incorrect_port(self): patched_util.SfpUtilHelper.return_value.get_asic_id_for_logical_port.return_value = 0 result = runner.invoke(show.cli.commands["muxcable"].commands["status"], ["Ethernet33", "--json"], obj=db) - assert(result.exit_code == 1) + assert result.exit_code == 1 def test_muxcable_config_with_correct_port(self): runner = CliRunner() @@ -243,7 +243,7 @@ def test_muxcable_config_with_correct_port(self): patched_util.SfpUtilHelper.return_value.get_asic_id_for_logical_port.return_value = 0 result = runner.invoke(show.cli.commands["muxcable"].commands["config"], ["Ethernet0"], obj=db) - assert(result.exit_code == 101) + assert result.exit_code == 101 def test_muxcable_config_json_with_correct_port(self): runner = CliRunner() @@ -252,7 +252,7 @@ def test_muxcable_config_json_with_correct_port(self): patched_util.SfpUtilHelper.return_value.get_asic_id_for_logical_port.return_value = 0 result = runner.invoke(show.cli.commands["muxcable"].commands["config"], ["Ethernet0", "--json"], obj=db) - assert(result.exit_code == 101) + assert result.exit_code == 101 def test_muxcable_config_json_port_with_incorrect_index(self): runner = CliRunner() @@ -261,7 +261,7 @@ def test_muxcable_config_json_port_with_incorrect_index(self): patched_util.SfpUtilHelper.return_value.get_asic_id_for_logical_port.return_value = 1 result = runner.invoke(show.cli.commands["muxcable"].commands["config"], ["Ethernet0", "--json"], obj=db) - assert(result.exit_code == 101) + assert result.exit_code == 101 def test_muxcable_config_json_with_incorrect_port_patch(self): runner = CliRunner() @@ -270,7 +270,7 @@ def test_muxcable_config_json_with_incorrect_port_patch(self): patched_util.SfpUtilHelper.return_value.get_asic_id_for_logical_port.return_value = 0 result = runner.invoke(show.cli.commands["muxcable"].commands["config"], ["Ethernet33", "--json"], obj=db) - assert(result.exit_code == 1) + assert result.exit_code == 1 def test_muxcable_status_json_port_eth0(self): runner = CliRunner() @@ -279,7 +279,7 @@ def test_muxcable_status_json_port_eth0(self): patched_util.SfpUtilHelper.return_value.get_asic_id_for_logical_port.return_value = 0 result = runner.invoke(show.cli.commands["muxcable"].commands["status"], ["Ethernet0"], obj=db) - assert(result.exit_code == 102) + assert result.exit_code == 102 def test_config_muxcable_tabular_port_Ethernet8_active(self): runner = CliRunner() @@ -289,7 +289,7 @@ def test_config_muxcable_tabular_port_Ethernet8_active(self): patched_util.SfpUtilHelper.return_value.get_asic_id_for_logical_port.return_value = 0 result = runner.invoke(config.config.commands["muxcable"].commands["mode"], ["active", "Ethernet8"], obj=db) - assert(result.exit_code == 100) + assert result.exit_code == 100 def test_config_muxcable_tabular_port_Ethernet8_auto(self): runner = CliRunner() @@ -299,7 +299,7 @@ def test_config_muxcable_tabular_port_Ethernet8_auto(self): patched_util.SfpUtilHelper.return_value.get_asic_id_for_logical_port.return_value = 0 result = runner.invoke(config.config.commands["muxcable"].commands["mode"], ["auto", "Ethernet8"], obj=db) - assert(result.exit_code == 100) + assert result.exit_code == 100 def test_config_muxcable_mode_auto_json(self): runner = CliRunner() @@ -307,8 +307,8 @@ def test_config_muxcable_mode_auto_json(self): result = runner.invoke(config.config.commands["muxcable"].commands["mode"], ["auto", "all", "--json"], obj=db) - assert(result.exit_code == 100) - assert(result.output == json_data_config_output_auto_expected) + assert result.exit_code == 100 + assert result.output == json_data_config_output_auto_expected def test_config_muxcable_mode_active_json(self): runner = CliRunner() @@ -318,8 +318,8 @@ def test_config_muxcable_mode_active_json(self): f = open("newfile1", "w") f.write(result.output) - assert(result.exit_code == 100) - assert(result.output == json_data_config_output_active_expected) + assert result.exit_code == 100 + assert result.output == json_data_config_output_active_expected def test_config_muxcable_json_port_auto_Ethernet0(self): runner = CliRunner() @@ -330,7 +330,7 @@ def test_config_muxcable_json_port_auto_Ethernet0(self): result = runner.invoke(config.config.commands["muxcable"].commands["mode"], [ "auto", "Ethernet0", "--json"], obj=db) - assert(result.exit_code == 100) + assert result.exit_code == 100 def test_config_muxcable_json_port_active_Ethernet0(self): runner = CliRunner() @@ -341,13 +341,13 @@ def test_config_muxcable_json_port_active_Ethernet0(self): result = runner.invoke(config.config.commands["muxcable"].commands["mode"], [ "active", "Ethernet0", "--json"], obj=db) - assert(result.exit_code == 100) + assert result.exit_code == 100 def test_config_muxcable_mode_auto_tabular(self): runner = CliRunner() db = Db() result = runner.invoke(config.config.commands["muxcable"].commands["mode"], ["auto", "all"], obj=db) - assert(result.exit_code == 100) + assert result.exit_code == 100 def test_config_muxcable_mode_active_tabular(self): runner = CliRunner() @@ -357,7 +357,7 @@ def test_config_muxcable_mode_active_tabular(self): f = open("newfile", "w") f.write(result.output) - assert(result.exit_code == 100) + assert result.exit_code == 100 def test_config_muxcable_tabular_port(self): runner = CliRunner() @@ -367,7 +367,7 @@ def test_config_muxcable_tabular_port(self): patched_util.SfpUtilHelper.return_value.get_asic_id_for_logical_port.return_value = 0 result = runner.invoke(config.config.commands["muxcable"].commands["mode"], ["active", "Ethernet0"], obj=db) - assert(result.exit_code == 100) + assert result.exit_code == 100 def test_config_muxcable_tabular_port_Ethernet4_active(self): runner = CliRunner() @@ -377,7 +377,7 @@ def test_config_muxcable_tabular_port_Ethernet4_active(self): patched_util.SfpUtilHelper.return_value.get_asic_id_for_logical_port.return_value = 0 result = runner.invoke(config.config.commands["muxcable"].commands["mode"], ["active", "Ethernet4"], obj=db) - assert(result.exit_code == 100) + assert result.exit_code == 100 def test_config_muxcable_tabular_port_Ethernet4_auto(self): runner = CliRunner() @@ -387,7 +387,7 @@ def test_config_muxcable_tabular_port_Ethernet4_auto(self): patched_util.SfpUtilHelper.return_value.get_asic_id_for_logical_port.return_value = 0 result = runner.invoke(config.config.commands["muxcable"].commands["mode"], ["auto", "Ethernet4"], obj=db) - assert(result.exit_code == 100) + assert result.exit_code == 100 def test_config_muxcable_tabular_port_with_incorrect_index(self): runner = CliRunner() @@ -397,7 +397,7 @@ def test_config_muxcable_tabular_port_with_incorrect_index(self): patched_util.SfpUtilHelper.return_value.get_asic_id_for_logical_port.return_value = 2 result = runner.invoke(config.config.commands["muxcable"].commands["mode"], ["active", "Ethernet0"], obj=db) - assert(result.exit_code == 1) + assert result.exit_code == 1 def test_config_muxcable_tabular_port_with_incorrect_port_index(self): runner = CliRunner() @@ -408,7 +408,7 @@ def test_config_muxcable_tabular_port_with_incorrect_port_index(self): result = runner.invoke(config.config.commands["muxcable"].commands["mode"], [ "active", "Ethernet33"], obj=db) - assert(result.exit_code == 1) + assert result.exit_code == 1 def test_config_muxcable_tabular_port_with_incorrect_port(self): runner = CliRunner() @@ -419,7 +419,7 @@ def test_config_muxcable_tabular_port_with_incorrect_port(self): result = runner.invoke(config.config.commands["muxcable"].commands["mode"], [ "active", "Ethernet33"], obj=db) - assert(result.exit_code == 1) + assert result.exit_code == 1 @mock.patch('os.geteuid', mock.MagicMock(return_value=0)) @mock.patch('sonic_y_cable.y_cable.get_eye_info', mock.MagicMock(return_value=[0, 0])) @@ -430,7 +430,7 @@ def test_show_muxcable_eye_info(self): result = runner.invoke(show.cli.commands["muxcable"].commands["eyeinfo"], ["0", "0"], obj=db) - assert(result.exit_code == 0) + assert result.exit_code == 0 @mock.patch('os.geteuid', mock.MagicMock(return_value=0)) @mock.patch('sonic_y_cable.y_cable.get_ber_info', mock.MagicMock(return_value=[0, 0])) @@ -441,7 +441,7 @@ def test_show_muxcable_ber_info(self): result = runner.invoke(show.cli.commands["muxcable"].commands["berinfo"], ["0", "0"], obj=db) - assert(result.exit_code == 0) + assert result.exit_code == 0 @mock.patch('os.geteuid', mock.MagicMock(return_value=0)) @mock.patch('sonic_y_cable.y_cable.enable_prbs_mode', mock.MagicMock(return_value=1)) @@ -452,7 +452,7 @@ def test_config_muxcable_enable_prbs(self): result = runner.invoke(config.config.commands["muxcable"].commands["prbs"].commands["enable"], ["0", "0", "0", "0"], obj=db) - assert(result.exit_code == 100) + assert result.exit_code == 100 @mock.patch('os.geteuid', mock.MagicMock(return_value=0)) @mock.patch('sonic_y_cable.y_cable.enable_loopback_mode', mock.MagicMock(return_value=1)) @@ -463,7 +463,7 @@ def test_config_muxcable_enable_loopback(self): result = runner.invoke(config.config.commands["muxcable"].commands["loopback"].commands["enable"], ["0", "0", "0"], obj=db) - assert(result.exit_code == 100) + assert result.exit_code == 100 @mock.patch('os.geteuid', mock.MagicMock(return_value=0)) @mock.patch('sonic_y_cable.y_cable.disable_prbs_mode', mock.MagicMock(return_value=1)) @@ -474,7 +474,7 @@ def test_config_muxcable_disble_prbs(self): result = runner.invoke(config.config.commands["muxcable"].commands["prbs"].commands["disable"], ["0", "0"], obj=db) - assert(result.exit_code == 100) + assert result.exit_code == 100 @mock.patch('os.geteuid', mock.MagicMock(return_value=0)) @mock.patch('sonic_y_cable.y_cable.disable_loopback_mode', mock.MagicMock(return_value=1)) @@ -485,7 +485,7 @@ def test_config_muxcable_disable_loopback(self): result = runner.invoke(config.config.commands["muxcable"].commands["loopback"].commands["disable"], ["0", "0"], obj=db) - assert(result.exit_code == 100) + assert result.exit_code == 100 @classmethod def teardown_class(cls): From 424e965cc746350b9acc2eabd52cdd73f5f03595 Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Wed, 3 Feb 2021 23:54:47 +0000 Subject: [PATCH 15/16] fix the doc string Signed-off-by: vaibhav-dahiya --- show/muxcable.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/show/muxcable.py b/show/muxcable.py index f1664a566e..f7431d7f8f 100644 --- a/show/muxcable.py +++ b/show/muxcable.py @@ -345,7 +345,7 @@ def config(port, json_output): @click.argument('port', required=True, default=None, type=click.INT) @click.argument('target', required=True, default=None, type=click.INT) def berinfo(port, target): - """Show muxcable ber (bit error rate) information""" + """Show muxcable BER (bit error rate) information""" if os.geteuid() != 0: click.echo("Root privileges are required for this operation") @@ -366,7 +366,7 @@ def berinfo(port, target): @click.argument('port', required=True, default=None, type=click.INT) @click.argument('target', required=True, default=None, type=click.INT) def eyeinfo(port, target): - """Show muxcable eye information""" + """Show muxcable eye information in mv""" if os.geteuid() != 0: click.echo("Root privileges are required for this operation") From 579b59997832d3fdece59c38f588f0a2d82838d8 Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Thu, 4 Feb 2021 02:35:25 +0000 Subject: [PATCH 16/16] adding lanes to headers Signed-off-by: vaibhav-dahiya --- show/muxcable.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/show/muxcable.py b/show/muxcable.py index f7431d7f8f..f4bc7230fe 100644 --- a/show/muxcable.py +++ b/show/muxcable.py @@ -355,7 +355,7 @@ def berinfo(port, target): if res == False or res == -1: click.echo("Unable to fetch ber info") sys.exit(EXIT_FAIL) - headers = ['Lane1', 'Lane2'] + headers = ['Lane1', 'Lane2', 'Lane3', 'Lane4'] lane_data = [] lane_data.append(res) click.echo(tabulate(lane_data, headers=headers)) @@ -376,7 +376,7 @@ def eyeinfo(port, target): if res == False or res == -1: click.echo("Unable to fetch eye info") sys.exit(EXIT_FAIL) - headers = ['Lane1', 'Lane2'] + headers = ['Lane1', 'Lane2', 'Lane3', 'Lane4'] lane_data = [] lane_data.append(res) click.echo(tabulate(lane_data, headers=headers))