From 24fe1acb0b9111ac79ef8296c23ca14576256a6a Mon Sep 17 00:00:00 2001 From: vdahiya12 <67608553+vdahiya12@users.noreply.github.com> Date: Wed, 30 Jun 2021 07:49:08 -0700 Subject: [PATCH] [show][config] support for interface alias for muxcable commands (#1699) Signed-off-by: vaibhav-dahiya vdahiya@microsoft.com What I did this PR adds support for interface alias support for muxcable commands. Basically for other OS's there could be a different scheme of interface naming which will be now be supported by muxcable commands as well. How I did it Added the changes in muxcable.py in show and config . How to verify it run on a Arista-7050cx3 switch. Previous command output (if the output of a command-line utility has changed) New command output (if the output of a command-line utility has changed) admin@str2-7050cx3-acs-04:/usr$ show mux cableinfo Ethernet15/1 Vendor Model -------- ---------------- Credo CACL2X321P2PA1MS admin@str2-7050cx3-acs-04:/usr$ show mux hwmode muxdirection Ethernet13/1 Port Direction ---------- ----------- Ethernet48 standby Signed-off-by: vaibhav-dahiya --- config/muxcable.py | 31 +++++++++++++---- show/muxcable.py | 38 +++++++++++++++------ utilities_common/platform_sfputil_helper.py | 16 +++++++++ 3 files changed, 68 insertions(+), 17 deletions(-) diff --git a/config/muxcable.py b/config/muxcable.py index 6bd139b992cf..bd6fb7d4b742 100644 --- a/config/muxcable.py +++ b/config/muxcable.py @@ -22,7 +22,6 @@ # Helper functions - def get_value_for_key_in_dict(mdict, port, key, table_name): value = mdict.get(key, None) if value is None: @@ -90,9 +89,12 @@ def lookup_statedb_and_update_configdb(per_npu_statedb, config_db, port, state_c @click.argument('state', metavar='', required=True, type=click.Choice(["active", "auto", "manual"])) @click.argument('port', metavar='', required=True, default=None) @click.option('--json', 'json_output', required=False, is_flag=True, type=click.BOOL) -def mode(state, port, json_output): +@clicommon.pass_db +def mode(db, state, port, json_output): """Config muxcable mode""" + port = platform_sfputil_helper.get_interface_alias(port, db) + port_table_keys = {} y_cable_asic_table_keys = {} per_npu_configdb = {} @@ -258,9 +260,12 @@ def hwmode(): @hwmode.command() @click.argument('state', metavar='', required=True, type=click.Choice(["active", "standby"])) @click.argument('port', metavar='', required=True, default=None) -def state(state, port): +@clicommon.pass_db +def state(db, state, port): """Configure the muxcable mux state {active/standby}""" + port = platform_sfputil_helper.get_interface_alias(port, db) + per_npu_statedb = {} transceiver_table_keys = {} transceiver_dict = {} @@ -457,9 +462,12 @@ def state(state, port): @hwmode.command() @click.argument('state', metavar='', required=True, type=click.Choice(["auto", "manual"])) @click.argument('port', metavar='', required=True, default=None) -def setswitchmode(state, port): +@clicommon.pass_db +def setswitchmode(db, state, port): """Configure the muxcable mux switching mode {auto/manual}""" + port = platform_sfputil_helper.get_interface_alias(port, db) + per_npu_statedb = {} transceiver_dict = {} @@ -701,9 +709,12 @@ def firmware(): @firmware.command() @click.argument('fwfile', metavar='', required=True) @click.argument('port', metavar='', required=True, default=None) -def download(fwfile, port): +@clicommon.pass_db +def download(db, fwfile, port): """Config muxcable firmware download""" + port = platform_sfputil_helper.get_interface_alias(port, db) + per_npu_statedb = {} y_cable_asic_table_keys = {} port_table_keys = {} @@ -751,9 +762,12 @@ def download(fwfile, port): @firmware.command() @click.argument('port', metavar='', required=True, default=None) -def activate(port): +@clicommon.pass_db +def activate(db, port): """Config muxcable firmware activate""" + port = platform_sfputil_helper.get_interface_alias(port, db) + per_npu_statedb = {} y_cable_asic_table_keys = {} port_table_keys = {} @@ -800,9 +814,12 @@ def activate(port): @firmware.command() @click.argument('port', metavar='', required=True, default=None) -def rollback(port): +@clicommon.pass_db +def rollback(db, port): """Config muxcable firmware rollback""" + port = platform_sfputil_helper.get_interface_alias(port, db) + port_table_keys = {} y_cable_asic_table_keys = {} per_npu_statedb = {} diff --git a/show/muxcable.py b/show/muxcable.py index 881f0a894b02..c52dfa6d0e81 100644 --- a/show/muxcable.py +++ b/show/muxcable.py @@ -26,8 +26,6 @@ VENDOR_NAME = "Credo" VENDOR_MODEL_REGEX = re.compile(r"CAC\w{3}321P2P\w{2}MS") - -# # 'muxcable' command ("show muxcable") # @@ -129,9 +127,12 @@ def create_json_dump_per_port_config(port_status_dict, per_npu_configdb, asic_id @muxcable.command() @click.argument('port', required=False, default=None) @click.option('--json', 'json_output', required=False, is_flag=True, type=click.BOOL, help="display the output in json format") -def status(port, json_output): +@clicommon.pass_db +def status(db, port, json_output): """Show muxcable status information""" + port = platform_sfputil_helper.get_interface_alias(port, db) + port_table_keys = {} port_health_table_keys = {} per_npu_statedb = {} @@ -239,9 +240,12 @@ def status(port, json_output): @muxcable.command() @click.argument('port', required=False, default=None) @click.option('--json', 'json_output', required=False, is_flag=True, type=click.BOOL, help="display the output in json format") -def config(port, json_output): +@clicommon.pass_db +def config(db, port, json_output): """Show muxcable config information""" + port = platform_sfputil_helper.get_interface_alias(port, db) + port_mux_tbl_keys = {} asic_start_idx = None per_npu_configdb = {} @@ -407,9 +411,12 @@ def eyeinfo(port, target): @muxcable.command() @click.argument('port', required=True, default=None) -def cableinfo(port): +@clicommon.pass_db +def cableinfo(db, port): """Show muxcable cable information""" + port = platform_sfputil_helper.get_interface_alias(port, db) + if platform_sfputil is not None: physical_port_list = platform_sfputil_helper.logical_port_name_to_physical_port_list(port) @@ -444,9 +451,12 @@ def hwmode(): @hwmode.command() @click.argument('port', metavar='', required=False, default=None) -def muxdirection(port): +@clicommon.pass_db +def muxdirection(db, port): """Shows the current direction of the muxcable {active/standy}""" + port = platform_sfputil_helper.get_interface_alias(port, db) + per_npu_statedb = {} transceiver_table_keys = {} transceiver_dict = {} @@ -649,9 +659,11 @@ def muxdirection(port): @hwmode.command() @click.argument('port', metavar='', required=False, default=None) -def switchmode(port): +def switchmode(db, port): """Shows the current switching mode of the muxcable {auto/manual}""" + port = platform_sfputil_helper.get_interface_alias(port, db) + per_npu_statedb = {} transceiver_dict = {} @@ -848,9 +860,12 @@ def firmware(): @firmware.command() @click.argument('port', metavar='', required=True, default=None) @click.option('--active', 'active', required=False, is_flag=True, type=click.BOOL, help="display the firmware version of only active bank within MCU's") -def version(port, active): +@clicommon.pass_db +def version(db, port, active): """Show muxcable firmware version""" + port = platform_sfputil_helper.get_interface_alias(port, db) + port_table_keys = {} y_cable_asic_table_keys = {} per_npu_statedb = {} @@ -940,12 +955,16 @@ def version(port, active): else: click.echo("there is not a valid asic table for this asic_index".format(asic_index)) + @muxcable.command() @click.argument('port', metavar='', required=True, default=None) @click.option('--json', 'json_output', required=False, is_flag=True, type=click.BOOL, help="display the output in json format") -def metrics(port, json_output): +@clicommon.pass_db +def metrics(db, port, json_output): """Show muxcable metrics """ + port = platform_sfputil_helper.get_interface_alias(port, db) + metrics_table_keys = {} per_npu_statedb = {} metrics_dict = {} @@ -981,7 +1000,6 @@ def metrics(port, json_output): if asic_index is None: click.echo("Got invalid asic index for port {}, cant retreive mux status".format(port)) - metrics_dict[asic_index] = per_npu_statedb[asic_index].get_all( per_npu_statedb[asic_index].STATE_DB, 'MUX_METRICS_TABLE|{}'.format(port)) diff --git a/utilities_common/platform_sfputil_helper.py b/utilities_common/platform_sfputil_helper.py index 27406b8abe9e..37bd6f4d664f 100644 --- a/utilities_common/platform_sfputil_helper.py +++ b/utilities_common/platform_sfputil_helper.py @@ -1,6 +1,8 @@ import sys import click + +from . import cli as clicommon from sonic_py_common import multi_asic, device_info platform_sfputil = None @@ -64,3 +66,17 @@ def get_asic_id_for_logical_port(port): def get_physical_to_logical(): return platform_sfputil.physical_to_logical + + +def get_interface_alias(port, db): + + if port is not "all" and port is not None: + alias = port + iface_alias_converter = clicommon.InterfaceAliasConverter(db) + port = iface_alias_converter.alias_to_name(alias) + if port is None: + click.echo("cannot find port name for alias {}".format(alias)) + sys.exit(1) + + return port +