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
28 changes: 28 additions & 0 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 @@ -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)
jleveque marked this conversation as resolved.
Show resolved Hide resolved
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)
jleveque marked this conversation as resolved.
Show resolved Hide resolved

@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)
jleveque marked this conversation as resolved.
Show resolved Hide resolved
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)
37 changes: 37 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,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)
jleveque marked this conversation as resolved.
Show resolved Hide resolved
def berinfo(port, target):

jleveque marked this conversation as resolved.
Show resolved Hide resolved
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)
#res1 = y_cable.get_eye_info(port, target)
jleveque marked this conversation as resolved.
Show resolved Hide resolved
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)
jleveque marked this conversation as resolved.
Show resolved Hide resolved
def eyeinfo(port, target):

jleveque marked this conversation as resolved.
Show resolved Hide resolved
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))