Skip to content

Commit

Permalink
[show][config] fix for show/config muxcable hwmode model value; fix s…
Browse files Browse the repository at this point in the history
…how/config muxcable return codes; (#1494)

his PR fixes the

show mux hwmode muxdirection
config mux hwmode state
cli commands to correctly use the model values for matching the vendor model value present in TRANSCEIVER_INFO table
in state DB.

This PR also supports the fix for return codes for

show mux
config mux 
commands to return 0 if the command executes correctly.

What I did
fix for show/config muxcable hwmode model value; fix show/config muxcable return codes;

Signed-off-by: vaibhav-dahiya <vdahiya@microsoft.com>
  • Loading branch information
vdahiya12 authored and daall committed Mar 12, 2021
1 parent c073d60 commit 02271d4
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 34 deletions.
9 changes: 5 additions & 4 deletions config/muxcable.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import sys

import click
import re
import utilities_common.cli as clicommon
from sonic_py_common import multi_asic
from swsssdk import ConfigDBConnector
Expand All @@ -14,11 +15,11 @@

REDIS_TIMEOUT_MSECS = 0

CONFIG_SUCCESSFUL = 100
CONFIG_SUCCESSFUL = 0
CONFIG_FAIL = 1

VENDOR_NAME = "Credo"
VENDOR_MODEL = "CAC125321P2PA0MS"
VENDOR_MODEL_REGEX = re.compile(r"CAC\w{3}321P2P\w{2}MS")

# Helper functions

Expand Down Expand Up @@ -334,7 +335,7 @@ def state(state, port):
or not. The check gives a way to differentiate between non Y cable ports and Y cable ports.
TODO: this should be removed once their is support for multiple vendors on Y cable"""

if vendor_value != VENDOR_NAME or model_value != VENDOR_MODEL:
if vendor_value != VENDOR_NAME or not re.match(VENDOR_MODEL_REGEX, model_value):
click.echo("ERR: Got invalid vendor value and model for port {}".format(port))
sys.exit(CONFIG_FAIL)

Expand Down Expand Up @@ -420,7 +421,7 @@ def state(state, port):
or not. The check gives a way to differentiate between non Y cable ports and Y cable ports.
TODO: this should be removed once their is support for multiple vendors on Y cable"""

if vendor_value != VENDOR_NAME or model_value != VENDOR_MODEL:
if vendor_value != VENDOR_NAME or not re.match(VENDOR_MODEL_REGEX, model_value):
continue

physical_port = physical_port_list[0]
Expand Down
11 changes: 6 additions & 5 deletions show/muxcable.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import sys

import click
import re
import utilities_common.cli as clicommon
from natsort import natsorted
from sonic_py_common import multi_asic
Expand All @@ -15,15 +16,15 @@

REDIS_TIMEOUT_MSECS = 0

CONFIG_SUCCESSFUL = 101
CONFIG_SUCCESSFUL = 0
CONFIG_FAIL = 1
EXIT_FAIL = 1
EXIT_SUCCESS = 0
STATUS_FAIL = 1
STATUS_SUCCESSFUL = 102
STATUS_SUCCESSFUL = 0

VENDOR_NAME = "Credo"
VENDOR_MODEL = "CAC125321P2PA0MS"
VENDOR_MODEL_REGEX = re.compile(r"CAC\w{3}321P2P\w{2}MS")


#
Expand Down Expand Up @@ -490,7 +491,7 @@ def muxdirection(port):
or not. The check gives a way to differentiate between non Y cable ports and Y cable ports.
TODO: this should be removed once their is support for multiple vendors on Y cable"""

if vendor_value != VENDOR_NAME or model_value != VENDOR_MODEL:
if vendor_value != VENDOR_NAME or not re.match(VENDOR_MODEL_REGEX, model_value):
click.echo("ERR: Got invalid vendor value and model for port {}".format(port))
sys.exit(EXIT_FAIL)

Expand Down Expand Up @@ -586,7 +587,7 @@ def muxdirection(port):
or not. The check gives a way to differentiate between non Y cable ports and Y cable ports.
TODO: this should be removed once their is support for multiple vendors on Y cable"""

if vendor_value != VENDOR_NAME or model_value != VENDOR_MODEL:
if vendor_value != VENDOR_NAME or not re.match(VENDOR_MODEL_REGEX, model_value):
continue

physical_port = physical_port_list[0]
Expand Down
2 changes: 1 addition & 1 deletion tests/mock_tables/state_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"hardware_rev": "AC",
"serial": "MT1706FT02064",
"manufacturer": "Credo",
"model": "CAC125321P2PA0MS",
"model": "CACL1X321P2PA1MS",
"vendor_oui": "00-02-c9",
"vendor_date": "2017-01-13 ",
"connector": "No separable connector",
Expand Down
52 changes: 28 additions & 24 deletions tests/muxcable_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ 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.exit_code == 0
assert result.output == tabular_data_status_output_expected

def test_muxcable_status_json(self):
Expand All @@ -197,7 +197,7 @@ 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.exit_code == 0
assert result.output == json_data_status_output_expected

def test_muxcable_status_config(self):
Expand All @@ -206,7 +206,7 @@ def test_muxcable_status_config(self):

result = runner.invoke(show.cli.commands["muxcable"].commands["config"], obj=db)

assert result.exit_code == 101
assert result.exit_code == 0
assert result.output == tabular_data_config_output_expected

def test_muxcable_status_config_json(self):
Expand All @@ -215,7 +215,7 @@ 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.exit_code == 0
assert result.output == json_data_status_config_output_expected

def test_muxcable_config_json_with_incorrect_port(self):
Expand All @@ -233,7 +233,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 == 0

def test_muxcable_status_json_port_incorrect_index(self):
runner = CliRunner()
Expand Down Expand Up @@ -266,7 +266,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 == 0

def test_muxcable_config_json_with_correct_port(self):
runner = CliRunner()
Expand All @@ -275,7 +275,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 == 0

def test_muxcable_config_json_port_with_incorrect_index(self):
runner = CliRunner()
Expand All @@ -284,7 +284,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 == 0

def test_muxcable_config_json_with_incorrect_port_patch(self):
runner = CliRunner()
Expand All @@ -302,7 +302,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 == 0

def test_config_muxcable_tabular_port_Ethernet8_active(self):
runner = CliRunner()
Expand All @@ -312,7 +312,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 == 0

def test_config_muxcable_tabular_port_Ethernet8_auto(self):
runner = CliRunner()
Expand All @@ -322,15 +322,15 @@ 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 == 0

def test_config_muxcable_mode_auto_json(self):
runner = CliRunner()
db = Db()

result = runner.invoke(config.config.commands["muxcable"].commands["mode"], ["auto", "all", "--json"], obj=db)

assert result.exit_code == 100
assert result.exit_code == 0
assert result.output == json_data_config_output_auto_expected

def test_config_muxcable_mode_active_json(self):
Expand All @@ -341,7 +341,7 @@ def test_config_muxcable_mode_active_json(self):
f = open("newfile1", "w")
f.write(result.output)

assert result.exit_code == 100
assert result.exit_code == 0
assert result.output == json_data_config_output_active_expected

def test_config_muxcable_json_port_auto_Ethernet0(self):
Expand All @@ -353,7 +353,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 == 0

def test_config_muxcable_json_port_active_Ethernet0(self):
runner = CliRunner()
Expand All @@ -364,13 +364,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 == 0

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 == 0

def test_config_muxcable_mode_active_tabular(self):
runner = CliRunner()
Expand All @@ -380,7 +380,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 == 0

def test_config_muxcable_tabular_port(self):
runner = CliRunner()
Expand All @@ -390,7 +390,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 == 0

def test_config_muxcable_tabular_port_Ethernet4_active(self):
runner = CliRunner()
Expand All @@ -400,7 +400,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 == 0

def test_config_muxcable_tabular_port_Ethernet4_auto(self):
runner = CliRunner()
Expand All @@ -410,7 +410,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 == 0

def test_config_muxcable_tabular_port_with_incorrect_index(self):
runner = CliRunner()
Expand Down Expand Up @@ -475,7 +475,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 == 0

@mock.patch('os.geteuid', mock.MagicMock(return_value=0))
@mock.patch('sonic_y_cable.y_cable.enable_loopback_mode', mock.MagicMock(return_value=1))
Expand All @@ -486,7 +486,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 == 0

@mock.patch('os.geteuid', mock.MagicMock(return_value=0))
@mock.patch('sonic_y_cable.y_cable.disable_prbs_mode', mock.MagicMock(return_value=1))
Expand All @@ -497,7 +497,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 == 0

@mock.patch('os.geteuid', mock.MagicMock(return_value=0))
@mock.patch('sonic_y_cable.y_cable.disable_loopback_mode', mock.MagicMock(return_value=1))
Expand All @@ -508,7 +508,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 == 0

@mock.patch('sonic_y_cable.y_cable.get_part_number', mock.MagicMock(return_value=("CACL1X321P2PA1M")))
@mock.patch('sonic_y_cable.y_cable.get_vendor', mock.MagicMock(return_value=("Credo ")))
Expand Down Expand Up @@ -567,6 +567,7 @@ def test_show_muxcable_cableinfo_incorrect_logical_port_return_value(self):
@mock.patch('utilities_common.platform_sfputil_helper.logical_port_name_to_physical_port_list', mock.MagicMock(return_value=[0]))
@mock.patch('sonic_y_cable.y_cable.check_read_side', mock.MagicMock(return_value=(1)))
@mock.patch('sonic_y_cable.y_cable.check_mux_direction', mock.MagicMock(return_value=(1)))
@mock.patch('re.match', mock.MagicMock(return_value=(True)))
def test_show_muxcable_hwmode_muxdirection_port_active(self):
runner = CliRunner()
db = Db()
Expand All @@ -583,6 +584,7 @@ def test_show_muxcable_hwmode_muxdirection_port_active(self):
@mock.patch('utilities_common.platform_sfputil_helper.logical_port_name_to_physical_port_list', mock.MagicMock(return_value=[0]))
@mock.patch('sonic_y_cable.y_cable.check_read_side', mock.MagicMock(return_value=(1)))
@mock.patch('sonic_y_cable.y_cable.check_mux_direction', mock.MagicMock(return_value=(1)))
@mock.patch('re.match', mock.MagicMock(return_value=(True)))
def test_show_muxcable_hwmode_muxdirection_active(self):
runner = CliRunner()
db = Db()
Expand All @@ -597,6 +599,7 @@ def test_show_muxcable_hwmode_muxdirection_active(self):
@mock.patch('utilities_common.platform_sfputil_helper.logical_port_name_to_physical_port_list', mock.MagicMock(return_value=[0]))
@mock.patch('sonic_y_cable.y_cable.check_read_side', mock.MagicMock(return_value=(1)))
@mock.patch('sonic_y_cable.y_cable.check_mux_direction', mock.MagicMock(return_value=(2)))
@mock.patch('re.match', mock.MagicMock(return_value=(True)))
def test_show_muxcable_hwmode_muxdirection_port_standby(self):
runner = CliRunner()
db = Db()
Expand All @@ -613,6 +616,7 @@ def test_show_muxcable_hwmode_muxdirection_port_standby(self):
@mock.patch('utilities_common.platform_sfputil_helper.logical_port_name_to_physical_port_list', mock.MagicMock(return_value=[0]))
@mock.patch('sonic_y_cable.y_cable.check_read_side', mock.MagicMock(return_value=(1)))
@mock.patch('sonic_y_cable.y_cable.check_mux_direction', mock.MagicMock(return_value=(2)))
@mock.patch('re.match', mock.MagicMock(return_value=(True)))
def test_show_muxcable_hwmode_muxdirection_standby(self):
runner = CliRunner()
db = Db()
Expand Down

0 comments on commit 02271d4

Please sign in to comment.