Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[config][show] cli support for retrieving ber, eye-info and configuring prbs, loopback on Y-cable #1386

Merged
merged 16 commits into from
Feb 4, 2021
34 changes: 32 additions & 2 deletions config/muxcable.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -71,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'
Expand All @@ -90,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",
Expand Down Expand Up @@ -188,3 +189,32 @@ 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(CONFIG_SUCCESSFUL)
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
38 changes: 38 additions & 0 deletions show/muxcable.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -336,3 +338,39 @@ 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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CONFIG_SUCCESSFUL / CONFIG_FAIL names don't really apply to the show command, as nothing is being configured. Can we change them to EXIT_SUCCESS and EXIT_FAILURE, or similar? And what is the difference between the CONFIG_* values and the STATUS_* codes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed. changed these to EXIT_FAILURE . Actually all these error codes require rework now that I read your comment. Originally i wrote STATUS_ and CONFIG_ to differentiate between
show muxcable status and
show muxcable config but they are confusing as we are not configuring everything in config. But hwproxy now already has the error codes handed over. Maybe just rename them and keep the codes(integer value) as is ?

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)
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))