Skip to content

Commit

Permalink
[show][config] support for interface alias for muxcable commands (#1699)
Browse files Browse the repository at this point in the history
Signed-off-by: vaibhav-dahiya [email protected]

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 <[email protected]>
  • Loading branch information
vdahiya12 authored Jun 30, 2021
1 parent 186d851 commit 24fe1ac
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 17 deletions.
31 changes: 24 additions & 7 deletions config/muxcable.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -90,9 +89,12 @@ def lookup_statedb_and_update_configdb(per_npu_statedb, config_db, port, state_c
@click.argument('state', metavar='<operation_status>', required=True, type=click.Choice(["active", "auto", "manual"]))
@click.argument('port', metavar='<port_name>', 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 = {}
Expand Down Expand Up @@ -258,9 +260,12 @@ def hwmode():
@hwmode.command()
@click.argument('state', metavar='<operation_status>', required=True, type=click.Choice(["active", "standby"]))
@click.argument('port', metavar='<port_name>', 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 = {}
Expand Down Expand Up @@ -457,9 +462,12 @@ def state(state, port):
@hwmode.command()
@click.argument('state', metavar='<operation_status>', required=True, type=click.Choice(["auto", "manual"]))
@click.argument('port', metavar='<port_name>', 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 = {}

Expand Down Expand Up @@ -701,9 +709,12 @@ def firmware():
@firmware.command()
@click.argument('fwfile', metavar='<firmware_file>', required=True)
@click.argument('port', metavar='<port_name>', 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 = {}
Expand Down Expand Up @@ -751,9 +762,12 @@ def download(fwfile, port):

@firmware.command()
@click.argument('port', metavar='<port_name>', 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 = {}
Expand Down Expand Up @@ -800,9 +814,12 @@ def activate(port):

@firmware.command()
@click.argument('port', metavar='<port_name>', 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 = {}
Expand Down
38 changes: 28 additions & 10 deletions show/muxcable.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
VENDOR_NAME = "Credo"
VENDOR_MODEL_REGEX = re.compile(r"CAC\w{3}321P2P\w{2}MS")


#
# 'muxcable' command ("show muxcable")
#

Expand Down Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -444,9 +451,12 @@ def hwmode():

@hwmode.command()
@click.argument('port', metavar='<port_name>', 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 = {}
Expand Down Expand Up @@ -649,9 +659,11 @@ def muxdirection(port):

@hwmode.command()
@click.argument('port', metavar='<port_name>', 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 = {}

Expand Down Expand Up @@ -848,9 +860,12 @@ def firmware():
@firmware.command()
@click.argument('port', metavar='<port_name>', 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 = {}
Expand Down Expand Up @@ -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='<port_name>', 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>"""

port = platform_sfputil_helper.get_interface_alias(port, db)

metrics_table_keys = {}
per_npu_statedb = {}
metrics_dict = {}
Expand Down Expand Up @@ -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))

Expand Down
16 changes: 16 additions & 0 deletions utilities_common/platform_sfputil_helper.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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

0 comments on commit 24fe1ac

Please sign in to comment.