Skip to content

Commit

Permalink
fix unit
Browse files Browse the repository at this point in the history
Signed-off-by: vaibhav-dahiya <vdahiya@microsoft.com>
  • Loading branch information
vdahiya12 committed Nov 19, 2021
1 parent 2bc3d3f commit e35d262
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 17 deletions.
12 changes: 8 additions & 4 deletions config/muxcable.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ def enable(db, port, target, mode_value, lane_mask, prbs_direction):
example sudo config mux prbs enable Ethernet48 0 3 3 0
"""

port = platform_sfputil_helper.get_interface_alias(port, db)
port = platform_sfputil_helper.get_interface_name(port, db)

delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_PRBS_CMD")
delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_PRBS_CMD_ARG")
Expand All @@ -386,6 +386,7 @@ def enable(db, port, target, mode_value, lane_mask, prbs_direction):

rc = res_dict[0]

port = platform_sfputil_helper.get_interface_alias(port, db)
delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_PRBS_CMD")
delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_PRBS_CMD_ARG")
delete_all_keys_in_db_table("STATE_DB", "XCVRD_CONFIG_PRBS_RSP")
Expand All @@ -406,7 +407,7 @@ def disable(db, port, target, prbs_direction):
"""Disable PRBS mode on a port
example sudo config mux prbs disable Ethernet48 0
"""
port = platform_sfputil_helper.get_interface_alias(port, db)
port = platform_sfputil_helper.get_interface_name(port, db)

delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_PRBS_CMD")
delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_PRBS_CMD_ARG")
Expand All @@ -432,6 +433,7 @@ def disable(db, port, target, prbs_direction):
delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_PRBS_CMD_ARG")
delete_all_keys_in_db_table("STATE_DB", "XCVRD_CONFIG_PRBS_RSP")

port = platform_sfputil_helper.get_interface_alias(port, db)
if rc == 0:
click.echo("Success in disable PRBS mode port {} on target {}".format(port, target))
else:
Expand All @@ -454,7 +456,7 @@ def loopback():
def enable(db, port, target, lane_mask, mode_value):
"""Enable loopback mode on a port args port target lane_map mode_value"""

port = platform_sfputil_helper.get_interface_alias(port, db)
port = platform_sfputil_helper.get_interface_name(port, db)

delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_LOOP_CMD")
delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_LOOP_CMD_ARG")
Expand All @@ -481,6 +483,7 @@ def enable(db, port, target, lane_mask, mode_value):
delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_LOOP_CMD_ARG")
delete_all_keys_in_db_table("STATE_DB", "XCVRD_CONFIG_LOOP_RSP")

port = platform_sfputil_helper.get_interface_alias(port, db)
if rc == 0:
click.echo("Success in LOOP mode port {} to {}".format(port, mode_value))
else:
Expand All @@ -495,7 +498,7 @@ def enable(db, port, target, lane_mask, mode_value):
def disable(db, port, target):
"""Disable loopback mode on a port"""

port = platform_sfputil_helper.get_interface_alias(port, db)
port = platform_sfputil_helper.get_interface_name(port, db)

delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_LOOP_CMD")
delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_LOOP_CMD_ARG")
Expand All @@ -520,6 +523,7 @@ def disable(db, port, target):
delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_LOOP_CMD_ARG")
delete_all_keys_in_db_table("STATE_DB", "XCVRD_CONFIG_LOOP_RSP")

port = platform_sfputil_helper.get_interface_alias(port, db)
if rc == 0:
click.echo("Success in disable LOOP mode port {} to {}".format(port, target))
else:
Expand Down
1 change: 1 addition & 0 deletions show/muxcable.py
Original file line number Diff line number Diff line change
Expand Up @@ -1146,6 +1146,7 @@ def switchmode(db, port):
res_dict[1] = "unknown"
res_dict = update_and_get_response_for_xcvr_cmd(
"state", "state", "True", "XCVRD_SHOW_HWMODE_SWMODE_CMD", None, "XCVRD_SHOW_HWMODE_SWMODE_RSP", port, 1, None, "probe")
port = platform_sfputil_helper.get_interface_alias(port, db)
temp_list.append(port)
temp_list.append(res_dict[1])
rc = res_dict[1]
Expand Down
54 changes: 41 additions & 13 deletions tests/muxcable_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -778,8 +778,10 @@ def test_config_muxcable_tabular_port_with_incorrect_port(self):

assert result.exit_code == 1

@mock.patch('os.geteuid', mock.MagicMock(return_value=0))
@mock.patch('sonic_y_cable.y_cable.get_eye_info', mock.MagicMock(return_value=[0, 0]))
@mock.patch('show.muxcable.delete_all_keys_in_db_table', mock.MagicMock(return_value=0))
@mock.patch('show.muxcable.update_and_get_response_for_xcvr_cmd', mock.MagicMock(return_value={0: 0,
1: "active"}))
@mock.patch('click.confirm', mock.MagicMock(return_value=("y")))
def test_show_muxcable_eye_info(self):
runner = CliRunner()
db = Db()
Expand All @@ -789,8 +791,10 @@ def test_show_muxcable_eye_info(self):

assert result.exit_code == 0

@mock.patch('os.geteuid', mock.MagicMock(return_value=0))
@mock.patch('sonic_y_cable.y_cable.get_ber_info', mock.MagicMock(return_value=[0, 0]))
@mock.patch('show.muxcable.delete_all_keys_in_db_table', mock.MagicMock(return_value=0))
@mock.patch('show.muxcable.update_and_get_response_for_xcvr_cmd', mock.MagicMock(return_value={0: 0,
1: "active"}))
@mock.patch('click.confirm', mock.MagicMock(return_value=("y")))
def test_show_muxcable_ber_info(self):
runner = CliRunner()
db = Db()
Expand All @@ -800,8 +804,14 @@ def test_show_muxcable_ber_info(self):

assert result.exit_code == 0

@mock.patch('os.geteuid', mock.MagicMock(return_value=0))
@mock.patch('sonic_y_cable.y_cable.enable_prbs_mode', mock.MagicMock(return_value=1))
@mock.patch('config.muxcable.delete_all_keys_in_db_table', mock.MagicMock(return_value=0))
@mock.patch('config.muxcable.update_and_get_response_for_xcvr_cmd', mock.MagicMock(return_value={0: 0,
1: "active"}))
@mock.patch('utilities_common.platform_sfputil_helper.get_logical_list', mock.MagicMock(return_value=["Ethernet0", "Ethernet12"]))
@mock.patch('utilities_common.platform_sfputil_helper.get_asic_id_for_logical_port', mock.MagicMock(return_value=0))
@mock.patch('utilities_common.platform_sfputil_helper.get_physical_to_logical', mock.MagicMock(return_value={0: ["Ethernet12", "Ethernet0"]}))
@mock.patch('utilities_common.platform_sfputil_helper.logical_port_name_to_physical_port_list', mock.MagicMock(return_value=[0]))
@mock.patch('click.confirm', mock.MagicMock(return_value=("y")))
def test_config_muxcable_enable_prbs(self):
runner = CliRunner()
db = Db()
Expand All @@ -811,8 +821,14 @@ def test_config_muxcable_enable_prbs(self):

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))
@mock.patch('config.muxcable.delete_all_keys_in_db_table', mock.MagicMock(return_value=0))
@mock.patch('config.muxcable.update_and_get_response_for_xcvr_cmd', mock.MagicMock(return_value={0: 0,
1: "active"}))
@mock.patch('utilities_common.platform_sfputil_helper.get_logical_list', mock.MagicMock(return_value=["Ethernet0", "Ethernet12"]))
@mock.patch('utilities_common.platform_sfputil_helper.get_asic_id_for_logical_port', mock.MagicMock(return_value=0))
@mock.patch('utilities_common.platform_sfputil_helper.get_physical_to_logical', mock.MagicMock(return_value={0: ["Ethernet12", "Ethernet0"]}))
@mock.patch('utilities_common.platform_sfputil_helper.logical_port_name_to_physical_port_list', mock.MagicMock(return_value=[0]))
@mock.patch('click.confirm', mock.MagicMock(return_value=("y")))
def test_config_muxcable_enable_loopback(self):
runner = CliRunner()
db = Db()
Expand All @@ -822,8 +838,14 @@ def test_config_muxcable_enable_loopback(self):

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))
@mock.patch('config.muxcable.delete_all_keys_in_db_table', mock.MagicMock(return_value=0))
@mock.patch('config.muxcable.update_and_get_response_for_xcvr_cmd', mock.MagicMock(return_value={0: 0,
1: "active"}))
@mock.patch('utilities_common.platform_sfputil_helper.get_logical_list', mock.MagicMock(return_value=["Ethernet0", "Ethernet12"]))
@mock.patch('utilities_common.platform_sfputil_helper.get_asic_id_for_logical_port', mock.MagicMock(return_value=0))
@mock.patch('utilities_common.platform_sfputil_helper.get_physical_to_logical', mock.MagicMock(return_value={0: ["Ethernet12", "Ethernet0"]}))
@mock.patch('utilities_common.platform_sfputil_helper.logical_port_name_to_physical_port_list', mock.MagicMock(return_value=[0]))
@mock.patch('click.confirm', mock.MagicMock(return_value=("y")))
def test_config_muxcable_disble_prbs(self):
runner = CliRunner()
db = Db()
Expand All @@ -833,14 +855,20 @@ def test_config_muxcable_disble_prbs(self):

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))
@mock.patch('config.muxcable.delete_all_keys_in_db_table', mock.MagicMock(return_value=0))
@mock.patch('config.muxcable.update_and_get_response_for_xcvr_cmd', mock.MagicMock(return_value={0: 0,
1: "active"}))
@mock.patch('utilities_common.platform_sfputil_helper.get_logical_list', mock.MagicMock(return_value=["Ethernet0", "Ethernet12"]))
@mock.patch('utilities_common.platform_sfputil_helper.get_asic_id_for_logical_port', mock.MagicMock(return_value=0))
@mock.patch('utilities_common.platform_sfputil_helper.get_physical_to_logical', mock.MagicMock(return_value={0: ["Ethernet12", "Ethernet0"]}))
@mock.patch('utilities_common.platform_sfputil_helper.logical_port_name_to_physical_port_list', mock.MagicMock(return_value=[0]))
@mock.patch('click.confirm', mock.MagicMock(return_value=("y")))
def test_config_muxcable_disable_loopback(self):
runner = CliRunner()
db = Db()

result = runner.invoke(config.config.commands["muxcable"].commands["loopback"].commands["disable"],
["0", "0"], obj=db)
["Ethernet0", "0"], obj=db)

assert result.exit_code == 0

Expand Down

0 comments on commit e35d262

Please sign in to comment.