diff --git a/config/muxcable.py b/config/muxcable.py index 903156bd2216..2e5bc1c80be5 100644 --- a/config/muxcable.py +++ b/config/muxcable.py @@ -3,6 +3,7 @@ import sys import click +import re import utilities_common.cli as clicommon from sonic_py_common import multi_asic from swsscommon.swsscommon import SonicV2Connector, ConfigDBConnector @@ -13,11 +14,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 @@ -333,7 +334,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) @@ -419,7 +420,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] diff --git a/show/muxcable.py b/show/muxcable.py index f688a41403b6..2620247ebef7 100644 --- a/show/muxcable.py +++ b/show/muxcable.py @@ -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 @@ -14,15 +15,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") # @@ -489,7 +490,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) @@ -585,7 +586,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] diff --git a/tests/mock_tables/state_db.json b/tests/mock_tables/state_db.json index bf9383f5e798..45057b5cf474 100644 --- a/tests/mock_tables/state_db.json +++ b/tests/mock_tables/state_db.json @@ -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", diff --git a/tests/muxcable_test.py b/tests/muxcable_test.py index 88c278850f0e..9f91a0336b30 100644 --- a/tests/muxcable_test.py +++ b/tests/muxcable_test.py @@ -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): @@ -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): @@ -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): @@ -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): @@ -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() @@ -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() @@ -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() @@ -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() @@ -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() @@ -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() @@ -322,7 +322,7 @@ 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() @@ -330,7 +330,7 @@ def test_config_muxcable_mode_auto_json(self): 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): @@ -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): @@ -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() @@ -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() @@ -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() @@ -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() @@ -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() @@ -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() @@ -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)) @@ -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)) @@ -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)) @@ -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 "))) @@ -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() @@ -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() @@ -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() @@ -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()