From 2d13098460531d2c7ac34041db42e4276094fd65 Mon Sep 17 00:00:00 2001 From: vdahiya12 <67608553+vdahiya12@users.noreply.github.com> Date: Tue, 9 Aug 2022 13:13:59 -0700 Subject: [PATCH 1/7] [ycabled] add capability to enable/disable telemetry (#279) This PR provides a capability to sonic-utilities CLI to enable/disable telemetry for ycabled. Basically there is a periodic loop for ycabled which posts telemetry data for that configured interval of time(currently 60 sec). This PR diables this data posting, and does not call platform API calls for ycable. This PR is required for the initiative of getting some failover/switchover not get interfered because of sonic-telemetry API calls. The CLI for enabling/disabling telemetry is config muxcable telemetry enable/disable Description Motivation and Context How Has This Been Tested? UT and deploying changes on Arista testbed Signed-off-by: vaibhav-dahiya --- sonic-ycabled/tests/test_y_cable_helper.py | 8525 +++++++++-------- .../ycable/ycable_utilities/y_cable_helper.py | 154 +- 2 files changed, 4410 insertions(+), 4269 deletions(-) diff --git a/sonic-ycabled/tests/test_y_cable_helper.py b/sonic-ycabled/tests/test_y_cable_helper.py index 8048cbcbc..8cb0e3080 100644 --- a/sonic-ycabled/tests/test_y_cable_helper.py +++ b/sonic-ycabled/tests/test_y_cable_helper.py @@ -1,4748 +1,4765 @@ -from .mock_swsscommon import Table -from sonic_platform_base.sfp_base import SfpBase -from swsscommon import swsscommon -from sonic_py_common import daemon_base -from ycable.ycable_utilities.y_cable_helper import * -from ycable.ycable import * -import copy -import os -import sys -import time + from .mock_swsscommon import Table + from sonic_platform_base.sfp_base import SfpBase + from swsscommon import swsscommon + from sonic_py_common import daemon_base + from ycable.ycable_utilities.y_cable_helper import * + from ycable.ycable import * + import copy + import os + import sys + import time -if sys.version_info >= (3, 3): - from unittest.mock import MagicMock, patch -else: - from mock import MagicMock, patch + if sys.version_info >= (3, 3): + from unittest.mock import MagicMock, patch + else: + from mock import MagicMock, patch -daemon_base.db_connect = MagicMock() -swsscommon.Table = MagicMock() + daemon_base.db_connect = MagicMock() + swsscommon.Table = MagicMock() -sys.modules['sonic_y_cable'] = MagicMock() -sys.modules['sonic_y_cable.y_cable'] = MagicMock() + sys.modules['sonic_y_cable'] = MagicMock() + sys.modules['sonic_y_cable.y_cable'] = MagicMock() -os.environ["Y_CABLE_HELPER_UNIT_TESTING"] = "1" + os.environ["Y_CABLE_HELPER_UNIT_TESTING"] = "1" -class helper_logger: - mock_arg = MagicMock() + class helper_logger: + mock_arg = MagicMock() - def log_error(self, mock_arg): - return True + def log_error(self, mock_arg): + return True - def log_warning(self, mock_arg): - return True + def log_warning(self, mock_arg): + return True - def log_debug(self, mock_arg): - return True + def log_debug(self, mock_arg): + return True -class TestYCableScript(object): - def test_xcvrd_helper_class_run(self): - Y_cable_task = YCableTableUpdateTask() + class TestYCableScript(object): + def test_xcvrd_helper_class_run(self): + Y_cable_task = YCableTableUpdateTask() - def test_y_cable_helper_format_mapping_identifier1(self): - rc = format_mapping_identifier("ABC ") - assert(rc == "abc") + def test_y_cable_helper_format_mapping_identifier1(self): + rc = format_mapping_identifier("ABC ") + assert(rc == "abc") - def test_y_cable_helper_format_mapping_identifier_no_instance(self): - rc = format_mapping_identifier(None) - assert(rc == None) - - def test_gather_arg_from_db_and_check_for_type(self): - - arg_tbl = {"Ethernet0": (True, {"abc": "x", "def": "y"})} - dic = {"key": "value"} - rc = gather_arg_from_db_and_check_for_type( - arg_tbl, "Ethernet0", "key", dic, "abc") + def test_y_cable_helper_format_mapping_identifier_no_instance(self): + rc = format_mapping_identifier(None) + assert(rc == None) - assert(rc == ("x", "value", {'abc': 'x', 'def': 'y'})) + def test_gather_arg_from_db_and_check_for_type(self): - def test_gather_arg_from_db_and_check_for_none_type(self): + arg_tbl = {"Ethernet0": (True, {"abc": "x", "def": "y"})} + dic = {"key": "value"} + rc = gather_arg_from_db_and_check_for_type( + arg_tbl, "Ethernet0", "key", dic, "abc") - arg_tbl = {"Ethernet0": (True, {"abcd": "x", "def": "y"})} - dic = {"key": "value"} - rc = gather_arg_from_db_and_check_for_type( - arg_tbl, "Ethernet0", "key", dic, "abc") + assert(rc == ("x", "value", {'abc': 'x', 'def': 'y'})) - assert(rc == (None, "value"), {'abcd': 'x', 'def': 'y'}) + def test_gather_arg_from_db_and_check_for_none_type(self): - def test_y_cable_wrapper_get_transceiver_info(self): - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: - patched_util.get_transceiver_info_dict.return_value = {'manufacturer': 'Microsoft', - 'model': 'model1'} + arg_tbl = {"Ethernet0": (True, {"abcd": "x", "def": "y"})} + dic = {"key": "value"} + rc = gather_arg_from_db_and_check_for_type( + arg_tbl, "Ethernet0", "key", dic, "abc") - transceiver_dict = y_cable_wrapper_get_transceiver_info(1) - vendor = transceiver_dict.get('manufacturer') - model = transceiver_dict.get('model') + assert(rc == (None, "value"), {'abcd': 'x', 'def': 'y'}) - assert(vendor == "Microsoft") - assert(model == "model1") + def test_y_cable_wrapper_get_transceiver_info(self): + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: + patched_util.get_transceiver_info_dict.return_value = {'manufacturer': 'Microsoft', + 'model': 'model1'} + + transceiver_dict = y_cable_wrapper_get_transceiver_info(1) + vendor = transceiver_dict.get('manufacturer') + model = transceiver_dict.get('model') + + assert(vendor == "Microsoft") + assert(model == "model1") + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_chassis') + def test_y_cable_wrapper_get_transceiver_info_with_platform_chassis(self, mock_chassis): + + mock_object = MagicMock() + mock_object.get_transceiver_info.return_value = {'type': '1000_BASE_SX_SFP', + 'hardware_rev': '5', + 'serial': 'PEP3L5D', + 'manufacturer': 'FINISAR', + 'model': 'ABC', + 'connector': 'LC', + 'encoding': '8B10B', + 'ext_identifier': 'SFP', + 'ext_rateselect_compliance': 'DEF', + 'cable_length': '850', + 'nominal_bit_rate': '100', + 'specification_compliance': 'GHI', + 'vendor_date': '2021-01-01', + 'vendor_oui': '00:90:65'} + + mock_chassis.get_sfp = MagicMock(return_value=mock_object) + received_xcvr_info = y_cable_wrapper_get_transceiver_info(1) + + type = received_xcvr_info.get('type') + model = received_xcvr_info.get('model') + vendor_date = received_xcvr_info.get('vendor_date') + + assert(type == "1000_BASE_SX_SFP") + assert(model == "ABC") + assert(vendor_date == "2021-01-01") + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_chassis') + def test_y_cable_wrapper_get_transceiver_info_with_platform_chassis_not_implemented(self, mock_chassis): + + mock_object = MagicMock() + mock_object.get_transceiver_info.side_effect = NotImplementedError + mock_chassis.get_sfp = MagicMock(return_value=mock_object) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_chassis') - def test_y_cable_wrapper_get_transceiver_info_with_platform_chassis(self, mock_chassis): + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: + patched_util.get_transceiver_info_dict.return_value = {'manufacturer': 'microsoft', + 'model': 'simulated'} - mock_object = MagicMock() - mock_object.get_transceiver_info.return_value = {'type': '1000_BASE_SX_SFP', - 'hardware_rev': '5', - 'serial': 'PEP3L5D', - 'manufacturer': 'FINISAR', - 'model': 'ABC', - 'connector': 'LC', - 'encoding': '8B10B', - 'ext_identifier': 'SFP', - 'ext_rateselect_compliance': 'DEF', - 'cable_length': '850', - 'nominal_bit_rate': '100', - 'specification_compliance': 'GHI', - 'vendor_date': '2021-01-01', - 'vendor_oui': '00:90:65'} + transceiver_dict = y_cable_wrapper_get_transceiver_info(1) + vendor = transceiver_dict.get('manufacturer') + model = transceiver_dict.get('model') - mock_chassis.get_sfp = MagicMock(return_value=mock_object) - received_xcvr_info = y_cable_wrapper_get_transceiver_info(1) + assert(vendor == "microsoft") + assert(model == "simulated") - type = received_xcvr_info.get('type') - model = received_xcvr_info.get('model') - vendor_date = received_xcvr_info.get('vendor_date') + def test_y_cable_wrapper_get_presence(self): + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: + patched_util.get_presence.return_value = True - assert(type == "1000_BASE_SX_SFP") - assert(model == "ABC") - assert(vendor_date == "2021-01-01") + presence = y_cable_wrapper_get_presence(1) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_chassis') - def test_y_cable_wrapper_get_transceiver_info_with_platform_chassis_not_implemented(self, mock_chassis): + assert(presence == True) - mock_object = MagicMock() - mock_object.get_transceiver_info.side_effect = NotImplementedError - mock_chassis.get_sfp = MagicMock(return_value=mock_object) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_chassis') + def test_y_cable_wrapper_get_presence_with_platform_chassis(self, mock_chassis): - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: - patched_util.get_transceiver_info_dict.return_value = {'manufacturer': 'microsoft', - 'model': 'simulated'} + mock_object = MagicMock() + mock_object.get_presence = MagicMock(return_value=True) + mock_chassis.get_sfp = MagicMock(return_value=mock_object) + presence = y_cable_wrapper_get_presence(1) - transceiver_dict = y_cable_wrapper_get_transceiver_info(1) - vendor = transceiver_dict.get('manufacturer') - model = transceiver_dict.get('model') + assert(presence == True) - assert(vendor == "microsoft") - assert(model == "simulated") + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_chassis') + def test_y_cable_wrapper_get_presence_with_platform_chassis_raise_exception(self, mock_chassis): - def test_y_cable_wrapper_get_presence(self): - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: - patched_util.get_presence.return_value = True + mock_object = MagicMock(spec=SfpBase) + mock_object.get_presence = MagicMock(side_effect=NotImplementedError) + mock_chassis.get_sfp = MagicMock(return_value=mock_object) - presence = y_cable_wrapper_get_presence(1) + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: + patched_util.get_presence.return_value = True - assert(presence == True) - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_chassis') - def test_y_cable_wrapper_get_presence_with_platform_chassis(self, mock_chassis): - - mock_object = MagicMock() - mock_object.get_presence = MagicMock(return_value=True) - mock_chassis.get_sfp = MagicMock(return_value=mock_object) - presence = y_cable_wrapper_get_presence(1) - - assert(presence == True) - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_chassis') - def test_y_cable_wrapper_get_presence_with_platform_chassis_raise_exception(self, mock_chassis): - - mock_object = MagicMock(spec=SfpBase) - mock_object.get_presence = MagicMock(side_effect=NotImplementedError) - mock_chassis.get_sfp = MagicMock(return_value=mock_object) - - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: - patched_util.get_presence.return_value = True - - assert(y_cable_wrapper_get_presence(1) == True) - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.get_muxcable_info', MagicMock(return_value={'tor_active': 'self', - 'mux_direction': 'self', - 'manual_switch_count': '7', - 'auto_switch_count': '71', - 'link_status_self': 'up', - 'link_status_peer': 'up', - 'link_status_nic': 'up', - 'nic_lane1_active': 'True', - 'nic_lane2_active': 'True', - 'nic_lane3_active': 'True', - 'nic_lane4_active': 'True', - 'self_eye_height_lane1': '500', - 'self_eye_height_lane2': '510', - 'peer_eye_height_lane1': '520', - 'peer_eye_height_lane2': '530', - 'nic_eye_height_lane1': '742', - 'nic_eye_height_lane2': '750', - 'internal_temperature': '28', - 'internal_voltage': '3.3', - 'nic_temperature': '20', - 'nic_voltage': '2.7', - 'version_nic_active': '1.6MS', - 'version_nic_inactive': '1.7MS', - 'version_nic_next': '1.7MS', - 'version_self_active': '1.6MS', - 'version_self_inactive': '1.7MS', - 'version_self_next': '1.7MS', - 'version_peer_active': '1.6MS', - 'version_peer_inactive': '1.7MS', - 'version_peer_next': '1.7MS'})) - def test_post_port_mux_info_to_db(self): - logical_port_name = "Ethernet0" - mux_tbl = Table("STATE_DB", "Y_CABLE_INFO_TABLE") - rc = post_port_mux_info_to_db(logical_port_name, mux_tbl) - assert(rc != -1) - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.get_muxcable_static_info', MagicMock(return_value={'read_side': 'self', - 'nic_lane1_precursor1': '1', - 'nic_lane1_precursor2': '-7', - 'nic_lane1_maincursor': '-1', - 'nic_lane1_postcursor1': '11', - 'nic_lane1_postcursor2': '11', - 'nic_lane2_precursor1': '12', - 'nic_lane2_precursor2': '7', - 'nic_lane2_maincursor': '7', - 'nic_lane2_postcursor1': '7', - 'nic_lane2_postcursor2': '7', - 'tor_self_lane1_precursor1': '17', - 'tor_self_lane1_precursor2': '17', - 'tor_self_lane1_maincursor': '17', - 'tor_self_lane1_postcursor1': '17', - 'tor_self_lane1_postcursor2': '17', - 'tor_self_lane2_precursor1': '7', - 'tor_self_lane2_precursor2': '7', - 'tor_self_lane2_maincursor': '7', - 'tor_self_lane2_postcursor1': '7', - 'tor_self_lane2_postcursor2': '7', - 'tor_peer_lane1_precursor1': '7', - 'tor_peer_lane1_precursor2': '7', - 'tor_peer_lane1_maincursor': '17', - 'tor_peer_lane1_postcursor1': '7', - 'tor_peer_lane1_postcursor2': '17', - 'tor_peer_lane2_precursor1': '7', - 'tor_peer_lane2_precursor2': '7', - 'tor_peer_lane2_maincursor': '17', - 'tor_peer_lane2_postcursor1': '7', - 'tor_peer_lane2_postcursor2': '17'})) - def test_post_port_mux_static_info_to_db(self): - logical_port_name = "Ethernet0" - mux_tbl = Table("STATE_DB", "Y_CABLE_STATIC_INFO_TABLE") - rc = post_port_mux_static_info_to_db(logical_port_name, mux_tbl) - assert(rc != -1) - - def test_y_cable_helper_format_mapping_identifier1(self): - rc = format_mapping_identifier("ABC ") - assert(rc == "abc") - - def test_y_cable_helper_format_mapping_identifier_no_instance(self): - rc = format_mapping_identifier(None) - assert(rc == None) - - def test_y_cable_wrapper_get_transceiver_info(self): - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: - patched_util.get_transceiver_info_dict.return_value = {'manufacturer': 'Microsoft', - 'model': 'model1'} - - transceiver_dict = y_cable_wrapper_get_transceiver_info(1) - vendor = transceiver_dict.get('manufacturer') - model = transceiver_dict.get('model') - - assert(vendor == "Microsoft") - assert(model == "model1") - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_chassis') - def test_y_cable_wrapper_get_transceiver_info_with_platform_chassis(self, mock_chassis): - - mock_object = MagicMock() - mock_object.get_transceiver_info.return_value = {'type': '1000_BASE_SX_SFP', - 'hardware_rev': '5', - 'serial': 'PEP3L5D', - 'manufacturer': 'FINISAR', - 'model': 'ABC', - 'connector': 'LC', - 'encoding': '8B10B', - 'ext_identifier': 'SFP', - 'ext_rateselect_compliance': 'DEF', - 'cable_length': '850', - 'nominal_bit_rate': '100', - 'specification_compliance': 'GHI', - 'vendor_date': '2021-01-01', - 'vendor_oui': '00:90:65'} - - mock_chassis.get_sfp = MagicMock(return_value=mock_object) - received_xcvr_info = y_cable_wrapper_get_transceiver_info(1) - - type = received_xcvr_info.get('type') - model = received_xcvr_info.get('model') - vendor_date = received_xcvr_info.get('vendor_date') - - assert(type == "1000_BASE_SX_SFP") - assert(model == "ABC") - assert(vendor_date == "2021-01-01") - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_chassis') - def test_y_cable_wrapper_get_transceiver_info_with_platform_chassis_not_implemented(self, mock_chassis): - - mock_object = MagicMock() - mock_object.get_transceiver_info.side_effect = NotImplementedError - mock_chassis.get_sfp = MagicMock(return_value=mock_object) - - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: - patched_util.get_transceiver_info_dict.return_value = {'manufacturer': 'microsoft', - 'model': 'simulated'} - - transceiver_dict = y_cable_wrapper_get_transceiver_info(1) - vendor = transceiver_dict.get('manufacturer') - model = transceiver_dict.get('model') - - assert(vendor == "microsoft") - assert(model == "simulated") - - def test_y_cable_wrapper_get_presence(self): - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: - patched_util.get_presence.return_value = True + assert(y_cable_wrapper_get_presence(1) == True) - presence = y_cable_wrapper_get_presence(1) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.get_muxcable_info', MagicMock(return_value={'tor_active': 'self', + 'mux_direction': 'self', + 'manual_switch_count': '7', + 'auto_switch_count': '71', + 'link_status_self': 'up', + 'link_status_peer': 'up', + 'link_status_nic': 'up', + 'nic_lane1_active': 'True', + 'nic_lane2_active': 'True', + 'nic_lane3_active': 'True', + 'nic_lane4_active': 'True', + 'self_eye_height_lane1': '500', + 'self_eye_height_lane2': '510', + 'peer_eye_height_lane1': '520', + 'peer_eye_height_lane2': '530', + 'nic_eye_height_lane1': '742', + 'nic_eye_height_lane2': '750', + 'internal_temperature': '28', + 'internal_voltage': '3.3', + 'nic_temperature': '20', + 'nic_voltage': '2.7', + 'version_nic_active': '1.6MS', + 'version_nic_inactive': '1.7MS', + 'version_nic_next': '1.7MS', + 'version_self_active': '1.6MS', + 'version_self_inactive': '1.7MS', + 'version_self_next': '1.7MS', + 'version_peer_active': '1.6MS', + 'version_peer_inactive': '1.7MS', + 'version_peer_next': '1.7MS'})) + def test_post_port_mux_info_to_db(self): + logical_port_name = "Ethernet0" + mux_tbl = Table("STATE_DB", "Y_CABLE_INFO_TABLE") + rc = post_port_mux_info_to_db(logical_port_name, mux_tbl) + assert(rc != -1) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.get_muxcable_static_info', MagicMock(return_value={'read_side': 'self', + 'nic_lane1_precursor1': '1', + 'nic_lane1_precursor2': '-7', + 'nic_lane1_maincursor': '-1', + 'nic_lane1_postcursor1': '11', + 'nic_lane1_postcursor2': '11', + 'nic_lane2_precursor1': '12', + 'nic_lane2_precursor2': '7', + 'nic_lane2_maincursor': '7', + 'nic_lane2_postcursor1': '7', + 'nic_lane2_postcursor2': '7', + 'tor_self_lane1_precursor1': '17', + 'tor_self_lane1_precursor2': '17', + 'tor_self_lane1_maincursor': '17', + 'tor_self_lane1_postcursor1': '17', + 'tor_self_lane1_postcursor2': '17', + 'tor_self_lane2_precursor1': '7', + 'tor_self_lane2_precursor2': '7', + 'tor_self_lane2_maincursor': '7', + 'tor_self_lane2_postcursor1': '7', + 'tor_self_lane2_postcursor2': '7', + 'tor_peer_lane1_precursor1': '7', + 'tor_peer_lane1_precursor2': '7', + 'tor_peer_lane1_maincursor': '17', + 'tor_peer_lane1_postcursor1': '7', + 'tor_peer_lane1_postcursor2': '17', + 'tor_peer_lane2_precursor1': '7', + 'tor_peer_lane2_precursor2': '7', + 'tor_peer_lane2_maincursor': '17', + 'tor_peer_lane2_postcursor1': '7', + 'tor_peer_lane2_postcursor2': '17'})) + def test_post_port_mux_static_info_to_db(self): + logical_port_name = "Ethernet0" + mux_tbl = Table("STATE_DB", "Y_CABLE_STATIC_INFO_TABLE") + rc = post_port_mux_static_info_to_db(logical_port_name, mux_tbl) + assert(rc != -1) + + def test_y_cable_helper_format_mapping_identifier1(self): + rc = format_mapping_identifier("ABC ") + assert(rc == "abc") + + def test_y_cable_helper_format_mapping_identifier_no_instance(self): + rc = format_mapping_identifier(None) + assert(rc == None) - assert(presence == True) + def test_y_cable_wrapper_get_transceiver_info(self): + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: + patched_util.get_transceiver_info_dict.return_value = {'manufacturer': 'Microsoft', + 'model': 'model1'} + + transceiver_dict = y_cable_wrapper_get_transceiver_info(1) + vendor = transceiver_dict.get('manufacturer') + model = transceiver_dict.get('model') + + assert(vendor == "Microsoft") + assert(model == "model1") + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_chassis') + def test_y_cable_wrapper_get_transceiver_info_with_platform_chassis(self, mock_chassis): + + mock_object = MagicMock() + mock_object.get_transceiver_info.return_value = {'type': '1000_BASE_SX_SFP', + 'hardware_rev': '5', + 'serial': 'PEP3L5D', + 'manufacturer': 'FINISAR', + 'model': 'ABC', + 'connector': 'LC', + 'encoding': '8B10B', + 'ext_identifier': 'SFP', + 'ext_rateselect_compliance': 'DEF', + 'cable_length': '850', + 'nominal_bit_rate': '100', + 'specification_compliance': 'GHI', + 'vendor_date': '2021-01-01', + 'vendor_oui': '00:90:65'} + + mock_chassis.get_sfp = MagicMock(return_value=mock_object) + received_xcvr_info = y_cable_wrapper_get_transceiver_info(1) + + type = received_xcvr_info.get('type') + model = received_xcvr_info.get('model') + vendor_date = received_xcvr_info.get('vendor_date') + + assert(type == "1000_BASE_SX_SFP") + assert(model == "ABC") + assert(vendor_date == "2021-01-01") + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_chassis') + def test_y_cable_wrapper_get_transceiver_info_with_platform_chassis_not_implemented(self, mock_chassis): + + mock_object = MagicMock() + mock_object.get_transceiver_info.side_effect = NotImplementedError + mock_chassis.get_sfp = MagicMock(return_value=mock_object) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_chassis') - def test_y_cable_wrapper_get_presence_with_platform_chassis(self, mock_chassis): + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: + patched_util.get_transceiver_info_dict.return_value = {'manufacturer': 'microsoft', + 'model': 'simulated'} - mock_object = MagicMock() - mock_object.get_presence = MagicMock(return_value=True) - mock_chassis.get_sfp = MagicMock(return_value=mock_object) - presence = y_cable_wrapper_get_presence(1) + transceiver_dict = y_cable_wrapper_get_transceiver_info(1) + vendor = transceiver_dict.get('manufacturer') + model = transceiver_dict.get('model') - assert(presence == True) + assert(vendor == "microsoft") + assert(model == "simulated") - def test_y_cable_toggle_mux_torA_update_status_true(self): + def test_y_cable_wrapper_get_presence(self): + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: + patched_util.get_presence.return_value = True - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + presence = y_cable_wrapper_get_presence(1) - mock_toggle_object = MagicMock() - mock_toggle_object.toggle_mux_to_tor_a.return_value = True - patched_util.get.return_value = mock_toggle_object + assert(presence == True) - rc = y_cable_toggle_mux_torA(1) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_chassis') + def test_y_cable_wrapper_get_presence_with_platform_chassis(self, mock_chassis): - assert(rc == 1) + mock_object = MagicMock() + mock_object.get_presence = MagicMock(return_value=True) + mock_chassis.get_sfp = MagicMock(return_value=mock_object) + presence = y_cable_wrapper_get_presence(1) - def test_y_cable_toggle_mux_torA_no_port_instance(self): + assert(presence == True) - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as port_instance: + def test_y_cable_toggle_mux_torA_update_status_true(self): - port_instance.get.return_value = None - rc = y_cable_toggle_mux_torA(1) + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - assert(rc == -1) + mock_toggle_object = MagicMock() + mock_toggle_object.toggle_mux_to_tor_a.return_value = True + patched_util.get.return_value = mock_toggle_object - def test_y_cable_toggle_mux_torA_update_status_exception(self): + rc = y_cable_toggle_mux_torA(1) - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as port_instance: + assert(rc == 1) - class PortInstanceHelper(): - def __init__(self): - self.EEPROM_ERROR = -1 - self.MUX_TOGGLE_STATUS_NOT_INITIATED_OR_FINISHED = 0 + def test_y_cable_toggle_mux_torA_no_port_instance(self): - # Defining function without self argument creates an exception, - # which is what we want for this test. - def get_mux_direction(): - pass - def toggle_mux_to_tor_a(): - raise NotImplementedError + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as port_instance: - port_instance.get.return_value = PortInstanceHelper() + port_instance.get.return_value = None + rc = y_cable_toggle_mux_torA(1) + assert(rc == -1) - rc = y_cable_toggle_mux_torA(1) + def test_y_cable_toggle_mux_torA_update_status_exception(self): - assert(rc == -1) + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as port_instance: - def test_y_cable_toggle_mux_torA_update_status_true(self): + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 + self.MUX_TOGGLE_STATUS_NOT_INITIATED_OR_FINISHED = 0 - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + # Defining function without self argument creates an exception, + # which is what we want for this test. + def get_mux_direction(): + pass + def toggle_mux_to_tor_a(): + raise NotImplementedError - mock_toggle_object = MagicMock() - mock_toggle_object.toggle_mux_to_tor_a.return_value = True - patched_util.get.return_value = mock_toggle_object + port_instance.get.return_value = PortInstanceHelper() - rc = y_cable_toggle_mux_torA(1) - assert(rc == 1) + rc = y_cable_toggle_mux_torA(1) - def test_y_cable_toggle_mux_torB_no_port_instance(self): + assert(rc == -1) - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as port_instance: + def test_y_cable_toggle_mux_torA_update_status_true(self): - port_instance.get.return_value = None - rc = y_cable_toggle_mux_torB(1) + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - assert(rc == -1) + mock_toggle_object = MagicMock() + mock_toggle_object.toggle_mux_to_tor_a.return_value = True + patched_util.get.return_value = mock_toggle_object - def test_y_cable_toggle_mux_torB_update_status_exception(self): - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as port_instance: + rc = y_cable_toggle_mux_torA(1) - class PortInstanceHelper(): - def __init__(self): - self.EEPROM_ERROR = -1 - self.MUX_TOGGLE_STATUS_NOT_INITIATED_OR_FINISHED = 0 + assert(rc == 1) - # Defining function without self argument creates an exception, - # which is what we want for this test. - def get_mux_direction(): - pass - def toggle_mux_to_tor_a(): - raise NotImplementedError + def test_y_cable_toggle_mux_torB_no_port_instance(self): - port_instance.get.return_value = PortInstanceHelper() + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as port_instance: - rc = y_cable_toggle_mux_torB(1) + port_instance.get.return_value = None + rc = y_cable_toggle_mux_torB(1) - assert(rc == -1) + assert(rc == -1) - def test_y_cable_toggle_mux_torB_update_status_true(self): + def test_y_cable_toggle_mux_torB_update_status_exception(self): + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as port_instance: - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 + self.MUX_TOGGLE_STATUS_NOT_INITIATED_OR_FINISHED = 0 - mock_toggle_object = MagicMock() - mock_toggle_object.toggle_mux_to_tor_b.return_value = True - patched_util.get.return_value = mock_toggle_object + # Defining function without self argument creates an exception, + # which is what we want for this test. + def get_mux_direction(): + pass + def toggle_mux_to_tor_a(): + raise NotImplementedError - rc = y_cable_toggle_mux_torB(1) + port_instance.get.return_value = PortInstanceHelper() - assert(rc == 2) + rc = y_cable_toggle_mux_torB(1) - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - def test_update_tor_active_side_1_active(self): - read_side = 1 - state = "active" - logical_port_name = "Ethernet0" - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + assert(rc == -1) - mock_toggle_object = MagicMock() - mock_toggle_object.toggle_mux_to_tor_a.return_value = True - patched_util.get.return_value = mock_toggle_object + def test_y_cable_toggle_mux_torB_update_status_true(self): - rc = update_tor_active_side(read_side, state, logical_port_name) + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - assert(rc == (1, 1)) + mock_toggle_object = MagicMock() + mock_toggle_object.toggle_mux_to_tor_b.return_value = True + patched_util.get.return_value = mock_toggle_object - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - def test_update_tor_active_side_2_active(self): - read_side = 2 - state = "active" - logical_port_name = "Ethernet0" - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + rc = y_cable_toggle_mux_torB(1) - mock_toggle_object = MagicMock() - mock_toggle_object.toggle_mux_to_tor_b.return_value = True - patched_util.get.return_value = mock_toggle_object + assert(rc == 2) - rc = update_tor_active_side(read_side, state, logical_port_name) + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + def test_update_tor_active_side_1_active(self): + read_side = 1 + state = "active" + logical_port_name = "Ethernet0" + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - assert(rc == (2,2)) + mock_toggle_object = MagicMock() + mock_toggle_object.toggle_mux_to_tor_a.return_value = True + patched_util.get.return_value = mock_toggle_object - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - def test_update_tor_active_side_1_standby(self): - read_side = 1 - state = "standby" - logical_port_name = "Ethernet0" - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + rc = update_tor_active_side(read_side, state, logical_port_name) - mock_toggle_object = MagicMock() - mock_toggle_object.toggle_mux_to_tor_b.return_value = True - patched_util.get.return_value = mock_toggle_object + assert(rc == (1, 1)) - rc = update_tor_active_side(read_side, state, logical_port_name) + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + def test_update_tor_active_side_2_active(self): + read_side = 2 + state = "active" + logical_port_name = "Ethernet0" + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - assert(rc == (2,1)) + mock_toggle_object = MagicMock() + mock_toggle_object.toggle_mux_to_tor_b.return_value = True + patched_util.get.return_value = mock_toggle_object - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - def test_update_tor_active_side_2_standby(self): - read_side = 2 - state = "standby" - logical_port_name = "Ethernet0" - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + rc = update_tor_active_side(read_side, state, logical_port_name) - mock_toggle_object = MagicMock() - mock_toggle_object.toggle_mux_to_tor_a.return_value = True - patched_util.get.return_value = mock_toggle_object + assert(rc == (2,2)) - rc = update_tor_active_side(read_side, state, logical_port_name) + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + def test_update_tor_active_side_1_standby(self): + read_side = 1 + state = "standby" + logical_port_name = "Ethernet0" + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - assert(rc == (1,2)) + mock_toggle_object = MagicMock() + mock_toggle_object.toggle_mux_to_tor_b.return_value = True + patched_util.get.return_value = mock_toggle_object - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=False)) - def test_update_tor_active_side_no_cable_presence(self): - read_side = 1 - state = "active" - logical_port_name = "Ethernet0" - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + rc = update_tor_active_side(read_side, state, logical_port_name) - mock_toggle_object = MagicMock() - mock_toggle_object.toggle_mux_to_tor_a.return_value = True - patched_util.get.return_value = mock_toggle_object + assert(rc == (2,1)) - rc = update_tor_active_side(read_side, state, logical_port_name) + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + def test_update_tor_active_side_2_standby(self): + read_side = 2 + state = "standby" + logical_port_name = "Ethernet0" + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - assert(rc == (-1,-1)) + mock_toggle_object = MagicMock() + mock_toggle_object.toggle_mux_to_tor_a.return_value = True + patched_util.get.return_value = mock_toggle_object - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0, 1, 2])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=False)) - def test_update_tor_active_side_multiple_mappings(self): - read_side = 1 - state = "active" - logical_port_name = "Ethernet0" - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + rc = update_tor_active_side(read_side, state, logical_port_name) - mock_toggle_object = MagicMock() - mock_toggle_object.toggle_mux_to_tor_a.return_value = True - patched_util.get.return_value = mock_toggle_object + assert(rc == (1,2)) - rc = update_tor_active_side(read_side, state, logical_port_name) + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=False)) + def test_update_tor_active_side_no_cable_presence(self): + read_side = 1 + state = "active" + logical_port_name = "Ethernet0" + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - assert(rc == (-1,-1)) + mock_toggle_object = MagicMock() + mock_toggle_object.toggle_mux_to_tor_a.return_value = True + patched_util.get.return_value = mock_toggle_object - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - def test_update_tor_active_side_with_read_update(self): - read_side = -1 - state = "active" - logical_port_name = "Ethernet0" - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + rc = update_tor_active_side(read_side, state, logical_port_name) - mock_toggle_object = MagicMock() - mock_toggle_object.toggle_mux_to_tor_a.return_value = True - mock_toggle_object.get_read_side.return_value = 1 - patched_util.get.return_value = mock_toggle_object + assert(rc == (-1,-1)) - rc = update_tor_active_side(read_side, state, logical_port_name) + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0, 1, 2])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=False)) + def test_update_tor_active_side_multiple_mappings(self): + read_side = 1 + state = "active" + logical_port_name = "Ethernet0" + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - assert(rc == (1, 1)) + mock_toggle_object = MagicMock() + mock_toggle_object.toggle_mux_to_tor_a.return_value = True + patched_util.get.return_value = mock_toggle_object - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - def test_update_tor_active_side_with_read_update(self): - read_side = -1 - state = "active" - logical_port_name = "Ethernet0" - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + rc = update_tor_active_side(read_side, state, logical_port_name) - mock_toggle_object = MagicMock() - mock_toggle_object.toggle_mux_to_tor_b.return_value = True - mock_toggle_object.get_read_side.return_value = 2 - patched_util.get.return_value = mock_toggle_object + assert(rc == (-1,-1)) - rc = update_tor_active_side(read_side, state, logical_port_name) + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + def test_update_tor_active_side_with_read_update(self): + read_side = -1 + state = "active" + logical_port_name = "Ethernet0" + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - assert(rc == (2, 1)) + mock_toggle_object = MagicMock() + mock_toggle_object.toggle_mux_to_tor_a.return_value = True + mock_toggle_object.get_read_side.return_value = 1 + patched_util.get.return_value = mock_toggle_object - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - def test_update_tor_active_side_with_read_update(self): - read_side = -1 - state = "active" - logical_port_name = "Ethernet0" - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + rc = update_tor_active_side(read_side, state, logical_port_name) - mock_toggle_object = MagicMock() - mock_toggle_object.toggle_mux_to_tor_b.return_value = True - mock_toggle_object.get_read_side.return_value = -1 - patched_util.get.return_value = mock_toggle_object + assert(rc == (1, 1)) - rc = update_tor_active_side(read_side, state, logical_port_name) + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + def test_update_tor_active_side_with_read_update(self): + read_side = -1 + state = "active" + logical_port_name = "Ethernet0" + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - assert(rc == (-1, -1)) + mock_toggle_object = MagicMock() + mock_toggle_object.toggle_mux_to_tor_b.return_value = True + mock_toggle_object.get_read_side.return_value = 2 + patched_util.get.return_value = mock_toggle_object - def test_get_mux_cable_info_without_presence(self): + rc = update_tor_active_side(read_side, state, logical_port_name) - rc = get_muxcable_info_without_presence() + assert(rc == (2, 1)) - assert(rc['tor_active'] == 'unknown') - assert(rc['mux_direction'] == 'unknown') - assert(rc['manual_switch_count'] == 'N/A') - assert(rc['auto_switch_count'] == 'N/A') + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + def test_update_tor_active_side_with_read_update(self): + read_side = -1 + state = "active" + logical_port_name = "Ethernet0" + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + mock_toggle_object = MagicMock() + mock_toggle_object.toggle_mux_to_tor_b.return_value = True + mock_toggle_object.get_read_side.return_value = -1 + patched_util.get.return_value = mock_toggle_object - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - def test_get_ycable_physical_port_from_logical_port(self): - instance = get_ycable_physical_port_from_logical_port("Ethernet0") + rc = update_tor_active_side(read_side, state, logical_port_name) - assert(instance == 0) + assert(rc == (-1, -1)) - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=False)) - def test_get_ycable_physical_port_from_logical_port_physical_port_not_present(self): - instance = get_ycable_physical_port_from_logical_port("Ethernet0") + def test_get_mux_cable_info_without_presence(self): - assert(instance == -1) + rc = get_muxcable_info_without_presence() - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value={})) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=False)) - def test_get_ycable_physical_port_from_logical_port_physical_port_list_empty(self): + assert(rc['tor_active'] == 'unknown') + assert(rc['mux_direction'] == 'unknown') + assert(rc['manual_switch_count'] == 'N/A') + assert(rc['auto_switch_count'] == 'N/A') - instance = get_ycable_physical_port_from_logical_port("Ethernet0") - assert(instance == -1) + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + def test_get_ycable_physical_port_from_logical_port(self): + instance = get_ycable_physical_port_from_logical_port("Ethernet0") - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - def test_get_ycable_port_instance_from_logical_port(self): + assert(instance == 0) - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - patched_util.get.return_value = 0 - instance = get_ycable_port_instance_from_logical_port("Ethernet0") + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=False)) + def test_get_ycable_physical_port_from_logical_port_physical_port_not_present(self): + instance = get_ycable_physical_port_from_logical_port("Ethernet0") - assert(instance == 0) + assert(instance == -1) - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=False)) - def test_get_ycable_port_instance_from_logical_port_no_presence(self): - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - patched_util.get.return_value = 0 - instance = get_ycable_port_instance_from_logical_port("Ethernet0") + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value={})) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=False)) + def test_get_ycable_physical_port_from_logical_port_physical_port_list_empty(self): - assert(instance == PORT_INSTANCE_ERROR) + instance = get_ycable_physical_port_from_logical_port("Ethernet0") - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - def test_get_ycable_port_instance_from_logical_port_no_port_instance(self): + assert(instance == -1) - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - def mock_get(): - pass + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + def test_get_ycable_port_instance_from_logical_port(self): - patched_util.get.return_value = mock_get() - instance = get_ycable_port_instance_from_logical_port("E") + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + patched_util.get.return_value = 0 + instance = get_ycable_port_instance_from_logical_port("Ethernet0") - assert(instance == PORT_INSTANCE_ERROR) + assert(instance == 0) - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0, 1, 2])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - def test_get_ycable_port_instance_from_logical_port_multiple_mapping(self): + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=False)) + def test_get_ycable_port_instance_from_logical_port_no_presence(self): + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + patched_util.get.return_value = 0 + instance = get_ycable_port_instance_from_logical_port("Ethernet0") - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - patched_util.get.return_value = 0 - instance = get_ycable_port_instance_from_logical_port("Ethernet0") + assert(instance == PORT_INSTANCE_ERROR) - assert(instance == -1) + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + def test_get_ycable_port_instance_from_logical_port_no_port_instance(self): - def test_update_table_mux_status_for_response_tbl(self): - asic_index = 0 - appl_db = "TEST_DB" - logical_port_name = "Ethernet0" - status = "standby" + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + def mock_get(): + pass - test_table = swsscommon.Table(appl_db[asic_index], "XCVRD_TEST_TABLE") - update_table_mux_status_for_response_tbl( - test_table, status, logical_port_name) + patched_util.get.return_value = mock_get() + instance = get_ycable_port_instance_from_logical_port("E") - rc = test_table.get(logical_port_name) + assert(instance == PORT_INSTANCE_ERROR) - # Since the table class is mocked, the most we can test for is that get doesn't return None - assert(type(rc) != None) + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0, 1, 2])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + def test_get_ycable_port_instance_from_logical_port_multiple_mapping(self): - def test_set_result_and_delete_port(self): + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + patched_util.get.return_value = 0 + instance = get_ycable_port_instance_from_logical_port("Ethernet0") - result = "result" - actual_result = "pass" - appl_db = "TEST_DB" - port = 0 + assert(instance == -1) - command_table = swsscommon.Table(appl_db[0], "XCVRD_COMMAND_TABLE") - response_table = swsscommon.Table(appl_db[1], "XCVRD_RESPONSE_TABLE") + def test_update_table_mux_status_for_response_tbl(self): + asic_index = 0 + appl_db = "TEST_DB" + logical_port_name = "Ethernet0" + status = "standby" - rc = set_result_and_delete_port( - result, actual_result, command_table, response_table, port) - assert(rc == None) + test_table = swsscommon.Table(appl_db[asic_index], "XCVRD_TEST_TABLE") + update_table_mux_status_for_response_tbl( + test_table, status, logical_port_name) - def test_delete_port_from_y_cable_table(self): - logical_port_name = "Ethernet0" - appl_db = "TEST_DB" - y_cable_tbl = swsscommon.Table(appl_db[0], "XCVRD_Y_CBL_TABLE") + rc = test_table.get(logical_port_name) - rc = delete_port_from_y_cable_table(logical_port_name, y_cable_tbl) - assert(rc == None) + # Since the table class is mocked, the most we can test for is that get doesn't return None + assert(type(rc) != None) - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - def test_update_appdb_port_mux_cable_response_table_port_instance_none(self): - asic_index = 0 - appl_db = "TEST_DB" - logical_port_name = "Ethernet0" - read_side = 1 + def test_set_result_and_delete_port(self): - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - def mock_get(): - pass + result = "result" + actual_result = "pass" + appl_db = "TEST_DB" + port = 0 - patched_util.get.return_value = mock_get() + command_table = swsscommon.Table(appl_db[0], "XCVRD_COMMAND_TABLE") + response_table = swsscommon.Table(appl_db[1], "XCVRD_RESPONSE_TABLE") - rc = update_appdb_port_mux_cable_response_table( - logical_port_name, asic_index, appl_db, read_side) + rc = set_result_and_delete_port( + result, actual_result, command_table, response_table, port) assert(rc == None) - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - def test_update_appdb_port_mux_cable_response_table_read_side_none(self): - asic_index = 0 - appl_db = "TEST_DB" - logical_port_name = "Ethernet0" - - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - def mock_read_side(): - pass - - read_side = mock_read_side() - - patched_util.get.return_value = 0 + def test_delete_port_from_y_cable_table(self): + logical_port_name = "Ethernet0" + appl_db = "TEST_DB" + y_cable_tbl = swsscommon.Table(appl_db[0], "XCVRD_Y_CBL_TABLE") - rc = update_appdb_port_mux_cable_response_table( - logical_port_name, asic_index, appl_db, read_side) + rc = delete_port_from_y_cable_table(logical_port_name, y_cable_tbl) assert(rc == None) - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - def test_update_appdb_port_mux_cable_response_table_active_side_none(self): - asic_index = 0 - appl_db = "TEST_DB" - logical_port_name = "Ethernet0" - read_side = 1 + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + def test_update_appdb_port_mux_cable_response_table_port_instance_none(self): + asic_index = 0 + appl_db = "TEST_DB" + logical_port_name = "Ethernet0" + read_side = 1 + + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + def mock_get(): + pass - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + patched_util.get.return_value = mock_get() - class PortInstanceHelper(): - def __init__(self): - self.EEPROM_ERROR = -1 + rc = update_appdb_port_mux_cable_response_table( + logical_port_name, asic_index, appl_db, read_side) + assert(rc == None) - # Defining function without self argument creates an exception, - # which is what we want for this test. - def get_mux_direction(): + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + def test_update_appdb_port_mux_cable_response_table_read_side_none(self): + asic_index = 0 + appl_db = "TEST_DB" + logical_port_name = "Ethernet0" + + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + def mock_read_side(): pass - patched_util.get.return_value = PortInstanceHelper() + read_side = mock_read_side() - rc = update_appdb_port_mux_cable_response_table( - logical_port_name, asic_index, appl_db, read_side) - assert(rc == None) + patched_util.get.return_value = 0 - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - def test_update_appdb_port_mux_cable_response_table_active_side_is_read_side(self): - asic_index = 0 - appl_db = "TEST_DB" - logical_port_name = "Ethernet0" - read_side = 1 + rc = update_appdb_port_mux_cable_response_table( + logical_port_name, asic_index, appl_db, read_side) + assert(rc == None) - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + def test_update_appdb_port_mux_cable_response_table_active_side_none(self): + asic_index = 0 + appl_db = "TEST_DB" + logical_port_name = "Ethernet0" + read_side = 1 - class PortInstanceHelper(): - def __init__(self): - self.EEPROM_ERROR = -1 + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - def get_mux_direction(self): - return 1 + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 - patched_util.get.return_value = PortInstanceHelper() + # Defining function without self argument creates an exception, + # which is what we want for this test. + def get_mux_direction(): + pass - rc = update_appdb_port_mux_cable_response_table( - logical_port_name, asic_index, appl_db, read_side) - assert(rc == None) + patched_util.get.return_value = PortInstanceHelper() - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - def test_update_appdb_port_mux_cable_response_table_active_side_not_read_side(self): - asic_index = 0 - appl_db = "TEST_DB" - logical_port_name = "Ethernet0" - read_side = 2 + rc = update_appdb_port_mux_cable_response_table( + logical_port_name, asic_index, appl_db, read_side) + assert(rc == None) + + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + def test_update_appdb_port_mux_cable_response_table_active_side_is_read_side(self): + asic_index = 0 + appl_db = "TEST_DB" + logical_port_name = "Ethernet0" + read_side = 1 - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - class PortInstanceHelper(): - def __init__(self): - self.EEPROM_ERROR = -1 + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 - def get_mux_direction(self): - return 1 + def get_mux_direction(self): + return 1 - patched_util.get.return_value = PortInstanceHelper() + patched_util.get.return_value = PortInstanceHelper() - rc = update_appdb_port_mux_cable_response_table( - logical_port_name, asic_index, appl_db, read_side) - assert(rc == None) + rc = update_appdb_port_mux_cable_response_table( + logical_port_name, asic_index, appl_db, read_side) + assert(rc == None) - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - def test_update_appdb_port_mux_cable_response_table_active_side_status_unknown(self): - asic_index = 0 - appl_db = "TEST_DB" - logical_port_name = "Ethernet0" - read_side = 1 + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + def test_update_appdb_port_mux_cable_response_table_active_side_not_read_side(self): + asic_index = 0 + appl_db = "TEST_DB" + logical_port_name = "Ethernet0" + read_side = 2 - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - class PortInstanceHelper(): - def __init__(self): - self.EEPROM_ERROR = -1 + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 - def get_mux_direction(self): - return 4 + def get_mux_direction(self): + return 1 - patched_util.get.return_value = PortInstanceHelper() + patched_util.get.return_value = PortInstanceHelper() - rc = update_appdb_port_mux_cable_response_table( - logical_port_name, asic_index, appl_db, read_side) - assert(rc == None) + rc = update_appdb_port_mux_cable_response_table( + logical_port_name, asic_index, appl_db, read_side) + assert(rc == None) - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=False)) - def test_update_appdb_port_mux_cable_response_table_no_presence_status_unknown(self): - asic_index = 0 - appl_db = "TEST_DB" - logical_port_name = "Ethernet0" - read_side = 1 + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + def test_update_appdb_port_mux_cable_response_table_active_side_status_unknown(self): + asic_index = 0 + appl_db = "TEST_DB" + logical_port_name = "Ethernet0" + read_side = 1 - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - class PortInstanceHelper(): - def __init__(self): - self.EEPROM_ERROR = -1 + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 - def get_mux_direction(self): - return 4 + def get_mux_direction(self): + return 4 - patched_util.get.return_value = PortInstanceHelper() + patched_util.get.return_value = PortInstanceHelper() - rc = update_appdb_port_mux_cable_response_table( - logical_port_name, asic_index, appl_db, read_side) - assert(rc == None) + rc = update_appdb_port_mux_cable_response_table( + logical_port_name, asic_index, appl_db, read_side) + assert(rc == None) + + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=False)) + def test_update_appdb_port_mux_cable_response_table_no_presence_status_unknown(self): + asic_index = 0 + appl_db = "TEST_DB" + logical_port_name = "Ethernet0" + read_side = 1 - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0, 1, 2])) - def test_update_appdb_port_mux_cable_response_table_invalid_ycable_mapping(self): - asic_index = 0 - appl_db = "TEST_DB" - logical_port_name = "Ethernet0" - read_side = 1 + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 - class PortInstanceHelper(): - def __init__(self): - self.EEPROM_ERROR = -1 + def get_mux_direction(self): + return 4 - def get_mux_direction(self): - return 4 + patched_util.get.return_value = PortInstanceHelper() - patched_util.get.return_value = PortInstanceHelper() + rc = update_appdb_port_mux_cable_response_table( + logical_port_name, asic_index, appl_db, read_side) + assert(rc == None) - rc = update_appdb_port_mux_cable_response_table( - logical_port_name, asic_index, appl_db, read_side) - assert(rc == None) + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0, 1, 2])) + def test_update_appdb_port_mux_cable_response_table_invalid_ycable_mapping(self): + asic_index = 0 + appl_db = "TEST_DB" + logical_port_name = "Ethernet0" + read_side = 1 - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0, 1, 2])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - def test_read_y_cable_and_update_statedb_port_tbl_invalid_ycable_mapping(self): + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - logical_port_name = "Ethernet0" - statedb_port_tbl = {} - asic_index = 0 - appl_db = "TEST_DB" + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 - statedb_port_tbl[asic_index] = swsscommon.Table( - appl_db[asic_index], "STATEDB_PORT_TABLE") + def get_mux_direction(self): + return 4 - rc = read_y_cable_and_update_statedb_port_tbl( - logical_port_name, statedb_port_tbl[asic_index]) - assert(rc == None) + patched_util.get.return_value = PortInstanceHelper() - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_read_y_cable_and_update_statedb_port_tbl_port_instance_none(self): + rc = update_appdb_port_mux_cable_response_table( + logical_port_name, asic_index, appl_db, read_side) + assert(rc == None) - logical_port_name = "Ethernet0" - statedb_port_tbl = {} - asic_index = 0 - appl_db = "TEST_DB" + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0, 1, 2])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + def test_read_y_cable_and_update_statedb_port_tbl_invalid_ycable_mapping(self): - statedb_port_tbl[asic_index] = swsscommon.Table( - appl_db[asic_index], "STATEDB_PORT_TABLE") + logical_port_name = "Ethernet0" + statedb_port_tbl = {} + asic_index = 0 + appl_db = "TEST_DB" - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - def mock_get(): - pass + statedb_port_tbl[asic_index] = swsscommon.Table( + appl_db[asic_index], "STATEDB_PORT_TABLE") - patched_util.get.return_value = mock_get() rc = read_y_cable_and_update_statedb_port_tbl( logical_port_name, statedb_port_tbl[asic_index]) assert(rc == None) - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=False)) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_read_y_cable_and_update_statedb_port_tbl_get_presence_false(self): - - logical_port_name = "Ethernet0" - statedb_port_tbl = {} - asic_index = 0 - appl_db = "TEST_DB" + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_read_y_cable_and_update_statedb_port_tbl_port_instance_none(self): - statedb_port_tbl[asic_index] = swsscommon.Table( - appl_db[asic_index], "STATEDB_PORT_TABLE") + logical_port_name = "Ethernet0" + statedb_port_tbl = {} + asic_index = 0 + appl_db = "TEST_DB" - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - def mock_get(): - pass + statedb_port_tbl[asic_index] = swsscommon.Table( + appl_db[asic_index], "STATEDB_PORT_TABLE") - patched_util.get.return_value = mock_get() - rc = read_y_cable_and_update_statedb_port_tbl( - logical_port_name, statedb_port_tbl[asic_index]) - assert(rc == None) + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + def mock_get(): + pass - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_read_y_cable_and_update_statedb_port_tbl_port_instance_get_read_side_exception(self): + patched_util.get.return_value = mock_get() + rc = read_y_cable_and_update_statedb_port_tbl( + logical_port_name, statedb_port_tbl[asic_index]) + assert(rc == None) - logical_port_name = "Ethernet0" - statedb_port_tbl = {} - asic_index = 0 - appl_db = "TEST_DB" + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=False)) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_read_y_cable_and_update_statedb_port_tbl_get_presence_false(self): - statedb_port_tbl[asic_index] = swsscommon.Table( - appl_db[asic_index], "STATEDB_PORT_TABLE") + logical_port_name = "Ethernet0" + statedb_port_tbl = {} + asic_index = 0 + appl_db = "TEST_DB" - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - class PortInstanceHelper(): - def __init__(self): - self.EEPROM_ERROR = -1 + statedb_port_tbl[asic_index] = swsscommon.Table( + appl_db[asic_index], "STATEDB_PORT_TABLE") - # Defining function without self argument creates an exception, - # which is what we want for this test. - def get_read_side(): + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + def mock_get(): pass - patched_util.get.return_value = PortInstanceHelper() - rc = read_y_cable_and_update_statedb_port_tbl( - logical_port_name, statedb_port_tbl[asic_index]) - assert(rc == None) + patched_util.get.return_value = mock_get() + rc = read_y_cable_and_update_statedb_port_tbl( + logical_port_name, statedb_port_tbl[asic_index]) + assert(rc == None) - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_read_y_cable_and_update_statedb_port_tbl_port_instance_get_mux_dir_exception(self): + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_read_y_cable_and_update_statedb_port_tbl_port_instance_get_read_side_exception(self): - logical_port_name = "Ethernet0" - statedb_port_tbl = {} - asic_index = 0 - appl_db = "TEST_DB" + logical_port_name = "Ethernet0" + statedb_port_tbl = {} + asic_index = 0 + appl_db = "TEST_DB" - statedb_port_tbl[asic_index] = swsscommon.Table( - appl_db[asic_index], "STATEDB_PORT_TABLE") + statedb_port_tbl[asic_index] = swsscommon.Table( + appl_db[asic_index], "STATEDB_PORT_TABLE") - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - class PortInstanceHelper(): - def __init__(self): - self.EEPROM_ERROR = -1 + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 - def get_read_side(self): - return 1 + # Defining function without self argument creates an exception, + # which is what we want for this test. + def get_read_side(): + pass - # Defining function without self argument creates an exception, - # which is what we want for this test. - def get_mux_direction(): - pass + patched_util.get.return_value = PortInstanceHelper() + rc = read_y_cable_and_update_statedb_port_tbl( + logical_port_name, statedb_port_tbl[asic_index]) + assert(rc == None) - patched_util.get.return_value = PortInstanceHelper() - rc = read_y_cable_and_update_statedb_port_tbl( - logical_port_name, statedb_port_tbl[asic_index]) - assert(rc == None) + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_read_y_cable_and_update_statedb_port_tbl_port_instance_get_mux_dir_exception(self): - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_read_y_cable_and_update_statedb_port_tbl_port_instance_status_active(self): + logical_port_name = "Ethernet0" + statedb_port_tbl = {} + asic_index = 0 + appl_db = "TEST_DB" - logical_port_name = "Ethernet0" - statedb_port_tbl = {} - asic_index = 0 - appl_db = "TEST_DB" + statedb_port_tbl[asic_index] = swsscommon.Table( + appl_db[asic_index], "STATEDB_PORT_TABLE") - statedb_port_tbl[asic_index] = swsscommon.Table( - appl_db[asic_index], "STATEDB_PORT_TABLE") + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - class PortInstanceHelper(): - def __init__(self): - self.EEPROM_ERROR = -1 + def get_read_side(self): + return 1 - def get_read_side(self): - return 1 + # Defining function without self argument creates an exception, + # which is what we want for this test. + def get_mux_direction(): + pass - def get_mux_direction(self): - return 1 + patched_util.get.return_value = PortInstanceHelper() + rc = read_y_cable_and_update_statedb_port_tbl( + logical_port_name, statedb_port_tbl[asic_index]) + assert(rc == None) - patched_util.get.return_value = PortInstanceHelper() - rc = read_y_cable_and_update_statedb_port_tbl( - logical_port_name, statedb_port_tbl[asic_index]) - assert(rc == None) + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_read_y_cable_and_update_statedb_port_tbl_port_instance_status_active(self): - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_read_y_cable_and_update_statedb_port_tbl_port_instance_status_standby(self): + logical_port_name = "Ethernet0" + statedb_port_tbl = {} + asic_index = 0 + appl_db = "TEST_DB" - logical_port_name = "Ethernet0" - statedb_port_tbl = {} - asic_index = 0 - appl_db = "TEST_DB" + statedb_port_tbl[asic_index] = swsscommon.Table( + appl_db[asic_index], "STATEDB_PORT_TABLE") - statedb_port_tbl[asic_index] = swsscommon.Table( - appl_db[asic_index], "STATEDB_PORT_TABLE") + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - class PortInstanceHelper(): - def __init__(self): - self.EEPROM_ERROR = -1 + def get_read_side(self): + return 1 - def get_read_side(self): - return 1 + def get_mux_direction(self): + return 1 - def get_mux_direction(self): - return 2 + patched_util.get.return_value = PortInstanceHelper() + rc = read_y_cable_and_update_statedb_port_tbl( + logical_port_name, statedb_port_tbl[asic_index]) + assert(rc == None) - patched_util.get.return_value = PortInstanceHelper() - rc = read_y_cable_and_update_statedb_port_tbl( - logical_port_name, statedb_port_tbl[asic_index]) - assert(rc == None) + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_read_y_cable_and_update_statedb_port_tbl_port_instance_status_standby(self): - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_read_y_cable_and_update_statedb_port_tbl_port_instance_status_unknown(self): + logical_port_name = "Ethernet0" + statedb_port_tbl = {} + asic_index = 0 + appl_db = "TEST_DB" - logical_port_name = "Ethernet0" - statedb_port_tbl = {} - asic_index = 0 - appl_db = "TEST_DB" + statedb_port_tbl[asic_index] = swsscommon.Table( + appl_db[asic_index], "STATEDB_PORT_TABLE") - statedb_port_tbl[asic_index] = swsscommon.Table( - appl_db[asic_index], "STATEDB_PORT_TABLE") + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - class PortInstanceHelper(): - def __init__(self): - self.EEPROM_ERROR = -1 + def get_read_side(self): + return 1 - def get_read_side(self): - return 1 + def get_mux_direction(self): + return 2 - def get_mux_direction(self): - return 0 + patched_util.get.return_value = PortInstanceHelper() + rc = read_y_cable_and_update_statedb_port_tbl( + logical_port_name, statedb_port_tbl[asic_index]) + assert(rc == None) - patched_util.get.return_value = PortInstanceHelper() - rc = read_y_cable_and_update_statedb_port_tbl( - logical_port_name, statedb_port_tbl[asic_index]) - assert(rc == None) + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_read_y_cable_and_update_statedb_port_tbl_port_instance_status_unknown(self): - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_create_tables_and_insert_mux_unknown_entries(self): - - state_db = {} - asic_index = 0 - logical_port_name = "Ethernet0" - - y_cable_tbl = {} - static_tbl = {} - mux_tbl = {} - - rc = create_tables_and_insert_mux_unknown_entries( - state_db, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name) - assert(rc == None) - - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_check_identifier_presence_and_update_mux_table_entry_status_false(self): - - asic_index = 0 - logical_port_name = "Ethernet0" - status = False - fvs = [('state', "manual")] - state_db = {} - test_db = "TEST_DB" - y_cable_tbl = {} - static_tbl = {} - mux_tbl = {} - port_tbl = {} - y_cable_presence = True - - y_cable_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], swsscommon.STATE_HW_MUX_CABLE_TABLE_NAME) - static_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], MUX_CABLE_STATIC_INFO_TABLE) - mux_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], MUX_CABLE_INFO_TABLE) - port_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], "PORT_INFO_TABLE") - port_tbl[asic_index].get.return_value = (status, fvs) - - rc = check_identifier_presence_and_update_mux_table_entry( - state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) - assert(rc == None) - - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_check_identifier_presence_and_update_mux_table_entry_state_absent(self): - - asic_index = 0 - logical_port_name = "Ethernet0" - status = True - fvs = [('badstate', "auto")] - state_db = {} - test_db = "TEST_DB" - y_cable_tbl = {} - static_tbl = {} - mux_tbl = {} - port_tbl = {} - y_cable_presence = True - - y_cable_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], swsscommon.STATE_HW_MUX_CABLE_TABLE_NAME) - static_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], MUX_CABLE_STATIC_INFO_TABLE) - mux_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], MUX_CABLE_INFO_TABLE) - port_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], "PORT_INFO_TABLE") - port_tbl[asic_index].get.return_value = (status, fvs) - - rc = check_identifier_presence_and_update_mux_table_entry( - state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) - assert(rc == None) - - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_check_identifier_presence_and_update_mux_table_entry_bad_state_value(self): - - asic_index = 0 - logical_port_name = "Ethernet0" - status = True - fvs = [('state', "badvalue")] - state_db = {} - test_db = "TEST_DB" - y_cable_tbl = {} - static_tbl = {} - mux_tbl = {} - port_tbl = {} - y_cable_presence = True - - y_cable_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], swsscommon.STATE_HW_MUX_CABLE_TABLE_NAME) - static_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], MUX_CABLE_STATIC_INFO_TABLE) - mux_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], MUX_CABLE_INFO_TABLE) - port_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], "PORT_INFO_TABLE") - port_tbl[asic_index].get.return_value = (status, fvs) - - rc = check_identifier_presence_and_update_mux_table_entry( - state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) - assert(rc == None) - - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=False)) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_check_identifier_presence_and_update_mux_table_entry_no_presence(self): - - asic_index = 0 - logical_port_name = "Ethernet0" - status = True - fvs = [('state', "auto"), ('read_side', 1)] - state_db = {} - test_db = "TEST_DB" - y_cable_tbl = {} - static_tbl = {} - mux_tbl = {} - port_tbl = {} - y_cable_presence = True - - y_cable_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], swsscommon.STATE_HW_MUX_CABLE_TABLE_NAME) - static_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], MUX_CABLE_STATIC_INFO_TABLE) - mux_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], MUX_CABLE_INFO_TABLE) - port_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], "PORT_INFO_TABLE") - port_tbl[asic_index].get.return_value = (status, fvs) - - rc = check_identifier_presence_and_update_mux_table_entry( - state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) - assert(rc == None) - - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_check_identifier_presence_and_update_mux_table_entry_no_port_info(self): - - asic_index = 0 - logical_port_name = "Ethernet0" - status = True - fvs = [('state', "auto"), ('read_side', 1)] - state_db = {} - test_db = "TEST_DB" - y_cable_tbl = {} - static_tbl = {} - mux_tbl = {} - port_tbl = {} - y_cable_presence = True - - y_cable_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], swsscommon.STATE_HW_MUX_CABLE_TABLE_NAME) - static_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], MUX_CABLE_STATIC_INFO_TABLE) - mux_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], MUX_CABLE_INFO_TABLE) - port_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], "PORT_INFO_TABLE") - port_tbl[asic_index].get.return_value = (status, fvs) - - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: - patched_util.get_transceiver_info_dict.return_value = None + logical_port_name = "Ethernet0" + statedb_port_tbl = {} + asic_index = 0 + appl_db = "TEST_DB" - rc = check_identifier_presence_and_update_mux_table_entry( - state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) - assert(rc == None) + statedb_port_tbl[asic_index] = swsscommon.Table( + appl_db[asic_index], "STATEDB_PORT_TABLE") - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0, 1, 2])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_check_identifier_presence_and_update_mux_table_entry_multiple_port_instances(self): - - asic_index = 0 - logical_port_name = "Ethernet0" - status = True - fvs = [('state', "auto"), ('read_side', 1)] - state_db = {} - test_db = "TEST_DB" - y_cable_tbl = {} - static_tbl = {} - mux_tbl = {} - port_tbl = {} - y_cable_presence = True - - y_cable_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], swsscommon.STATE_HW_MUX_CABLE_TABLE_NAME) - static_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], MUX_CABLE_STATIC_INFO_TABLE) - mux_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], MUX_CABLE_INFO_TABLE) - port_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], "PORT_INFO_TABLE") - port_tbl[asic_index].get.return_value = (status, fvs) - - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: - patched_util.get_transceiver_info_dict.return_value = { - 'manufacturer': 'Microsoft', 'model': 'simulated'} + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 - rc = check_identifier_presence_and_update_mux_table_entry( - state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) - assert(rc == None) + def get_read_side(self): + return 1 - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_check_identifier_presence_and_update_mux_table_entry_no_vendor_port_info(self): - - asic_index = 0 - logical_port_name = "Ethernet0" - status = True - fvs = [('state', "auto"), ('read_side', 1)] - state_db = {} - test_db = "TEST_DB" - y_cable_tbl = {} - static_tbl = {} - mux_tbl = {} - port_tbl = {} - y_cable_presence = True - - y_cable_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], swsscommon.STATE_HW_MUX_CABLE_TABLE_NAME) - static_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], MUX_CABLE_STATIC_INFO_TABLE) - mux_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], MUX_CABLE_INFO_TABLE) - port_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], "PORT_INFO_TABLE") - port_tbl[asic_index].get.return_value = (status, fvs) - - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: - patched_util.get_transceiver_info_dict.return_value = { - 'bad_manufacturer': 'Microsoft', 'model': 'simulated'} + def get_mux_direction(self): + return 0 - rc = check_identifier_presence_and_update_mux_table_entry( - state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) - assert(rc == None) + patched_util.get.return_value = PortInstanceHelper() + rc = read_y_cable_and_update_statedb_port_tbl( + logical_port_name, statedb_port_tbl[asic_index]) + assert(rc == None) - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_check_identifier_presence_and_update_mux_table_entry_no_model_port_info(self): - - asic_index = 0 - logical_port_name = "Ethernet0" - status = True - fvs = [('state', "auto"), ('read_side', 1)] - state_db = {} - test_db = "TEST_DB" - y_cable_tbl = {} - static_tbl = {} - mux_tbl = {} - port_tbl = {} - y_cable_presence = True - - y_cable_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], swsscommon.STATE_HW_MUX_CABLE_TABLE_NAME) - static_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], MUX_CABLE_STATIC_INFO_TABLE) - mux_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], MUX_CABLE_INFO_TABLE) - port_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], "PORT_INFO_TABLE") - port_tbl[asic_index].get.return_value = (status, fvs) - - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: - patched_util.get_transceiver_info_dict.return_value = { - 'manufacturer': 'Microsoft', 'bad_model': 'simulated'} + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_create_tables_and_insert_mux_unknown_entries(self): - rc = check_identifier_presence_and_update_mux_table_entry( - state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) - assert(rc == None) + state_db = {} + asic_index = 0 + logical_port_name = "Ethernet0" - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_check_identifier_presence_and_update_mux_table_entry_invalid_vendor_port_info(self): - - asic_index = 0 - logical_port_name = "Ethernet0" - status = True - fvs = [('state', "auto"), ('read_side', 1)] - state_db = {} - test_db = "TEST_DB" - y_cable_tbl = {} - static_tbl = {} - mux_tbl = {} - port_tbl = {} - y_cable_presence = True - - y_cable_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], swsscommon.STATE_HW_MUX_CABLE_TABLE_NAME) - static_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], MUX_CABLE_STATIC_INFO_TABLE) - mux_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], MUX_CABLE_INFO_TABLE) - port_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], "PORT_INFO_TABLE") - port_tbl[asic_index].get.return_value = (status, fvs) - - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: - patched_util.get_transceiver_info_dict.return_value = { - 'manufacturer': 'not_Microsoft', 'model': 'simulated'} + y_cable_tbl = {} + static_tbl = {} + mux_tbl = {} - rc = check_identifier_presence_and_update_mux_table_entry( - state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) + rc = create_tables_and_insert_mux_unknown_entries( + state_db, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name) assert(rc == None) - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_check_identifier_presence_and_update_mux_table_entry_invalid_model_port_info(self): - - asic_index = 0 - logical_port_name = "Ethernet0" - status = True - fvs = [('state', "auto"), ('read_side', 1)] - - state_db = {} - test_db = "TEST_DB" - y_cable_tbl = {} - static_tbl = {} - mux_tbl = {} - port_tbl = {} - y_cable_presence = True - - y_cable_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], swsscommon.STATE_HW_MUX_CABLE_TABLE_NAME) - static_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], MUX_CABLE_STATIC_INFO_TABLE) - mux_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], MUX_CABLE_INFO_TABLE) - port_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], "PORT_INFO_TABLE") - port_tbl[asic_index].get.return_value = (status, fvs) - - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: - patched_util.get_transceiver_info_dict.return_value = { - 'manufacturer': 'Microsoft', 'model': 'bad_model1'} + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_check_identifier_presence_and_update_mux_table_entry_status_false(self): + + asic_index = 0 + logical_port_name = "Ethernet0" + status = False + fvs = [('state', "manual")] + state_db = {} + test_db = "TEST_DB" + y_cable_tbl = {} + static_tbl = {} + mux_tbl = {} + port_tbl = {} + y_cable_presence = True + + y_cable_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], swsscommon.STATE_HW_MUX_CABLE_TABLE_NAME) + static_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], MUX_CABLE_STATIC_INFO_TABLE) + mux_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], MUX_CABLE_INFO_TABLE) + port_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], "PORT_INFO_TABLE") + port_tbl[asic_index].get.return_value = (status, fvs) rc = check_identifier_presence_and_update_mux_table_entry( - state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) + state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) assert(rc == None) - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_check_identifier_presence_and_update_mux_table_entry_module_dir_none(self): - - asic_index = 0 - logical_port_name = "Ethernet0" - status = True - fvs = [('state', "auto"), ('read_side', 1)] - - state_db = {} - test_db = "TEST_DB" - y_cable_tbl = {} - static_tbl = {} - mux_tbl = {} - port_tbl = {} - y_cable_presence = True - - y_cable_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], swsscommon.STATE_HW_MUX_CABLE_TABLE_NAME) - static_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], MUX_CABLE_STATIC_INFO_TABLE) - mux_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], MUX_CABLE_INFO_TABLE) - port_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], "PORT_INFO_TABLE") - port_tbl[asic_index].get.return_value = (status, fvs) - - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: - patched_util.get_transceiver_info_dict.return_value = { - 'manufacturer': 'not_Microsoft', 'model': 'simulated'} - - with patch('sonic_y_cable.y_cable_vendor_mapping.mapping') as mock_mapping: - mock_mapping.get.return_value = None - - rc = check_identifier_presence_and_update_mux_table_entry( - state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) - assert(rc == None) + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_check_identifier_presence_and_update_mux_table_entry_state_absent(self): - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('sonic_y_cable.y_cable_vendor_mapping.mapping.get', MagicMock(return_value={"Microsoft": {"module": "test_module"}})) - def test_check_identifier_presence_and_update_mux_table_entry_module_none(self): - - asic_index = 0 - logical_port_name = "Ethernet0" - status = True - fvs = [('state', "auto"), ('read_side', 1)] - - state_db = {} - test_db = "TEST_DB" - y_cable_tbl = {} - static_tbl = {} - mux_tbl = {} - port_tbl = {} - y_cable_presence = True - - y_cable_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], swsscommon.STATE_HW_MUX_CABLE_TABLE_NAME) - static_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], MUX_CABLE_STATIC_INFO_TABLE) - mux_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], MUX_CABLE_INFO_TABLE) - port_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], "PORT_INFO_TABLE") - port_tbl[asic_index].get.return_value = (status, fvs) - - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: - patched_util.get_transceiver_info_dict.return_value = { - 'manufacturer': 'not_Microsoft', 'model': 'model1'} + asic_index = 0 + logical_port_name = "Ethernet0" + status = True + fvs = [('badstate', "auto")] + state_db = {} + test_db = "TEST_DB" + y_cable_tbl = {} + static_tbl = {} + mux_tbl = {} + port_tbl = {} + y_cable_presence = True + + y_cable_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], swsscommon.STATE_HW_MUX_CABLE_TABLE_NAME) + static_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], MUX_CABLE_STATIC_INFO_TABLE) + mux_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], MUX_CABLE_INFO_TABLE) + port_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], "PORT_INFO_TABLE") + port_tbl[asic_index].get.return_value = (status, fvs) rc = check_identifier_presence_and_update_mux_table_entry( - state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) + state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) assert(rc == None) - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('sonic_y_cable.y_cable_vendor_mapping.mapping.get', MagicMock(return_value={"simulated": "microsoft.y_cable_simulated"})) - def test_check_identifier_presence_and_update_mux_table_entry_module_microsoft(self): - - asic_index = 0 - logical_port_name = "Ethernet0" - status = True - fvs = [('state', "auto"), ('read_side', 1)] - - state_db = {} - test_db = "TEST_DB" - y_cable_tbl = {} - static_tbl = {} - mux_tbl = {} - port_tbl = {} - y_cable_presence = [True] - - y_cable_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], swsscommon.STATE_HW_MUX_CABLE_TABLE_NAME) - static_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], MUX_CABLE_STATIC_INFO_TABLE) - mux_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], MUX_CABLE_INFO_TABLE) - port_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], "PORT_INFO_TABLE") - port_tbl[asic_index].get.return_value = (status, fvs) - - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: - patched_util.get_transceiver_info_dict.return_value = { - 'manufacturer': 'microsoft', 'model': 'simulated'} - - sys.modules['builtins.getattr'] = MagicMock() - rc = check_identifier_presence_and_update_mux_table_entry( - state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) - assert(rc == None) + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_check_identifier_presence_and_update_mux_table_entry_bad_state_value(self): - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('sonic_y_cable.y_cable_vendor_mapping.mapping.get', MagicMock(return_value={"simulated": "microsoft.y_cable_simulated"})) - def test_check_identifier_presence_and_update_mux_table_entry_module_microsoft_y_cable_presence_false(self): - - asic_index = 0 - logical_port_name = "Ethernet0" - status = True - fvs = [('state', "auto"), ('read_side', 1)] - - state_db = {} - test_db = "TEST_DB" - y_cable_tbl = {} - static_tbl = {} - mux_tbl = {} - port_tbl = {} - y_cable_presence = [False] - - port_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], "PORT_INFO_TABLE") - port_tbl[asic_index].get.return_value = (status, fvs) - - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: - patched_util.get_transceiver_info_dict.return_value = { - 'manufacturer': 'microsoft', 'model': 'simulated'} - - sys.modules['builtins.getattr'] = MagicMock() - rc = check_identifier_presence_and_update_mux_table_entry( - state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) - assert(rc == None) + asic_index = 0 + logical_port_name = "Ethernet0" + status = True + fvs = [('state', "badvalue")] + state_db = {} + test_db = "TEST_DB" + y_cable_tbl = {} + static_tbl = {} + mux_tbl = {} + port_tbl = {} + y_cable_presence = True + + y_cable_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], swsscommon.STATE_HW_MUX_CABLE_TABLE_NAME) + static_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], MUX_CABLE_STATIC_INFO_TABLE) + mux_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], MUX_CABLE_INFO_TABLE) + port_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], "PORT_INFO_TABLE") + port_tbl[asic_index].get.return_value = (status, fvs) - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_check_identifier_presence_and_delete_mux_table_entry(self): - - asic_index = 0 - logical_port_name = "Ethernet0" - status = True - fvs = [('state', "auto"), ('read_side', 1)] - - state_db = {} - test_db = "TEST_DB" - y_cable_tbl = {} - static_tbl = {} - mux_tbl = {} - port_tbl = {} - y_cable_presence = [True] - delete_change_event = [True] - - port_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], "PORT_INFO_TABLE") - port_tbl[asic_index].get.return_value = (status, fvs) - - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as port_instance: - rc = check_identifier_presence_and_delete_mux_table_entry( - state_db, port_tbl, asic_index, logical_port_name, y_cable_presence, delete_change_event) + rc = check_identifier_presence_and_update_mux_table_entry( + state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) assert(rc == None) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_chassis') - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') - @patch('swsscommon.swsscommon.Table') - def test_init_ports_status_for_y_cable(self, platform_chassis, platform_sfp, mock_swsscommon_table): - - platform_sfp = MagicMock() - platform_chassis = MagicMock() - - mock_logical_port_name = [""] - - def mock_get_asic_id(mock_logical_port_name): - return 0 - - y_cable_presence = [True] - - mock_table = MagicMock() - mock_table.getKeys = MagicMock(return_value=['Ethernet0', 'Ethernet4']) - mock_swsscommon_table.return_value = mock_table - - rc = init_ports_status_for_y_cable(platform_sfp, platform_chassis, - y_cable_presence, stop_event=threading.Event()) + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=False)) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_check_identifier_presence_and_update_mux_table_entry_no_presence(self): - assert(rc == None) + asic_index = 0 + logical_port_name = "Ethernet0" + status = True + fvs = [('state', "auto"), ('read_side', 1)] + state_db = {} + test_db = "TEST_DB" + y_cable_tbl = {} + static_tbl = {} + mux_tbl = {} + port_tbl = {} + y_cable_presence = True + + y_cable_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], swsscommon.STATE_HW_MUX_CABLE_TABLE_NAME) + static_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], MUX_CABLE_STATIC_INFO_TABLE) + mux_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], MUX_CABLE_INFO_TABLE) + port_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], "PORT_INFO_TABLE") + port_tbl[asic_index].get.return_value = (status, fvs) - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('swsscommon.swsscommon.Table') - def test_change_ports_status_for_y_cable_change_event(self, mock_swsscommon_table): + rc = check_identifier_presence_and_update_mux_table_entry( + state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) + assert(rc == None) - mock_logical_port_name = [""] + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_check_identifier_presence_and_update_mux_table_entry_no_port_info(self): - def mock_get_asic_id(mock_logical_port_name): - return 0 + asic_index = 0 + logical_port_name = "Ethernet0" + status = True + fvs = [('state', "auto"), ('read_side', 1)] + state_db = {} + test_db = "TEST_DB" + y_cable_tbl = {} + static_tbl = {} + mux_tbl = {} + port_tbl = {} + y_cable_presence = True + + y_cable_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], swsscommon.STATE_HW_MUX_CABLE_TABLE_NAME) + static_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], MUX_CABLE_STATIC_INFO_TABLE) + mux_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], MUX_CABLE_INFO_TABLE) + port_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], "PORT_INFO_TABLE") + port_tbl[asic_index].get.return_value = (status, fvs) - y_cable_presence = [True] - logical_port_dict = {'Ethernet0': '1'} + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: + patched_util.get_transceiver_info_dict.return_value = None - mock_table = MagicMock() - mock_table.getKeys = MagicMock(return_value=['Ethernet0', 'Ethernet4']) - mock_table.get = MagicMock( - side_effect=[(True, (('index', 1), )), (True, (('index', 2), ))]) - mock_swsscommon_table.return_value = mock_table + rc = check_identifier_presence_and_update_mux_table_entry( + state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) + assert(rc == None) - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0, 1, 2])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_check_identifier_presence_and_update_mux_table_entry_multiple_port_instances(self): - patched_util.get_asic_id_for_logical_port.return_value = 0 + asic_index = 0 + logical_port_name = "Ethernet0" + status = True + fvs = [('state', "auto"), ('read_side', 1)] + state_db = {} + test_db = "TEST_DB" + y_cable_tbl = {} + static_tbl = {} + mux_tbl = {} + port_tbl = {} + y_cable_presence = True + + y_cable_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], swsscommon.STATE_HW_MUX_CABLE_TABLE_NAME) + static_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], MUX_CABLE_STATIC_INFO_TABLE) + mux_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], MUX_CABLE_INFO_TABLE) + port_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], "PORT_INFO_TABLE") + port_tbl[asic_index].get.return_value = (status, fvs) - change_ports_status_for_y_cable_change_event( - logical_port_dict, y_cable_presence, stop_event=threading.Event()) + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: + patched_util.get_transceiver_info_dict.return_value = { + 'manufacturer': 'Microsoft', 'model': 'simulated'} - mock_swsscommon_table.assert_called() + rc = check_identifier_presence_and_update_mux_table_entry( + state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) + assert(rc == None) @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('swsscommon.swsscommon.Table') - def test_change_ports_status_for_y_cable_change_event_sfp_removed(self, mock_swsscommon_table): + def test_check_identifier_presence_and_update_mux_table_entry_no_vendor_port_info(self): - mock_logical_port_name = [""] + asic_index = 0 + logical_port_name = "Ethernet0" + status = True + fvs = [('state', "auto"), ('read_side', 1)] + state_db = {} + test_db = "TEST_DB" + y_cable_tbl = {} + static_tbl = {} + mux_tbl = {} + port_tbl = {} + y_cable_presence = True + + y_cable_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], swsscommon.STATE_HW_MUX_CABLE_TABLE_NAME) + static_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], MUX_CABLE_STATIC_INFO_TABLE) + mux_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], MUX_CABLE_INFO_TABLE) + port_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], "PORT_INFO_TABLE") + port_tbl[asic_index].get.return_value = (status, fvs) - def mock_get_asic_id(mock_logical_port_name): - return 0 + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: + patched_util.get_transceiver_info_dict.return_value = { + 'bad_manufacturer': 'Microsoft', 'model': 'simulated'} - y_cable_presence = [True] - logical_port_dict = {'Ethernet0': '1'} + rc = check_identifier_presence_and_update_mux_table_entry( + state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) + assert(rc == None) - mock_table = MagicMock() - mock_table.getKeys = MagicMock(return_value=['Ethernet0', 'Ethernet4']) - mock_table.get = MagicMock( - side_effect=[(True, (('index', 1), )), (True, (('index', 2), ))]) - mock_swsscommon_table.return_value = mock_table + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_check_identifier_presence_and_update_mux_table_entry_no_model_port_info(self): - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: + asic_index = 0 + logical_port_name = "Ethernet0" + status = True + fvs = [('state', "auto"), ('read_side', 1)] + state_db = {} + test_db = "TEST_DB" + y_cable_tbl = {} + static_tbl = {} + mux_tbl = {} + port_tbl = {} + y_cable_presence = True + + y_cable_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], swsscommon.STATE_HW_MUX_CABLE_TABLE_NAME) + static_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], MUX_CABLE_STATIC_INFO_TABLE) + mux_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], MUX_CABLE_INFO_TABLE) + port_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], "PORT_INFO_TABLE") + port_tbl[asic_index].get.return_value = (status, fvs) - patched_util.get_asic_id_for_logical_port.return_value = 0 - change_ports_status_for_y_cable_change_event( - logical_port_dict, y_cable_presence, stop_event=threading.Event()) + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: + patched_util.get_transceiver_info_dict.return_value = { + 'manufacturer': 'Microsoft', 'bad_model': 'simulated'} - mock_swsscommon_table.assert_called() + rc = check_identifier_presence_and_update_mux_table_entry( + state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) + assert(rc == None) - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('swsscommon.swsscommon.Table') - def test_change_ports_status_for_y_cable_change_event_sfp_unknown(self, mock_swsscommon_table): + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_check_identifier_presence_and_update_mux_table_entry_invalid_vendor_port_info(self): - mock_logical_port_name = [""] + asic_index = 0 + logical_port_name = "Ethernet0" + status = True + fvs = [('state', "auto"), ('read_side', 1)] + state_db = {} + test_db = "TEST_DB" + y_cable_tbl = {} + static_tbl = {} + mux_tbl = {} + port_tbl = {} + y_cable_presence = True + + y_cable_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], swsscommon.STATE_HW_MUX_CABLE_TABLE_NAME) + static_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], MUX_CABLE_STATIC_INFO_TABLE) + mux_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], MUX_CABLE_INFO_TABLE) + port_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], "PORT_INFO_TABLE") + port_tbl[asic_index].get.return_value = (status, fvs) - def mock_get_asic_id(mock_logical_port_name): - return 0 + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: + patched_util.get_transceiver_info_dict.return_value = { + 'manufacturer': 'not_Microsoft', 'model': 'simulated'} - y_cable_presence = [True] - logical_port_dict = {'Ethernet0': '2'} + rc = check_identifier_presence_and_update_mux_table_entry( + state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) + assert(rc == None) - mock_table = MagicMock() - mock_table.getKeys = MagicMock(return_value=['Ethernet0', 'Ethernet4']) - mock_table.get = MagicMock( - side_effect=[(True, (('index', 1), )), (True, (('index', 2), ))]) - mock_swsscommon_table.return_value = mock_table + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_check_identifier_presence_and_update_mux_table_entry_invalid_model_port_info(self): - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: + asic_index = 0 + logical_port_name = "Ethernet0" + status = True + fvs = [('state', "auto"), ('read_side', 1)] - patched_util.get_asic_id_for_logical_port.return_value = 0 - change_ports_status_for_y_cable_change_event( - logical_port_dict, y_cable_presence, stop_event=threading.Event()) + state_db = {} + test_db = "TEST_DB" + y_cable_tbl = {} + static_tbl = {} + mux_tbl = {} + port_tbl = {} + y_cable_presence = True + + y_cable_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], swsscommon.STATE_HW_MUX_CABLE_TABLE_NAME) + static_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], MUX_CABLE_STATIC_INFO_TABLE) + mux_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], MUX_CABLE_INFO_TABLE) + port_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], "PORT_INFO_TABLE") + port_tbl[asic_index].get.return_value = (status, fvs) - mock_swsscommon_table.assert_called() + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: + patched_util.get_transceiver_info_dict.return_value = { + 'manufacturer': 'Microsoft', 'model': 'bad_model1'} - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - def test_delete_ports_status_for_y_cable(self, mock_swsscommon_table): + rc = check_identifier_presence_and_update_mux_table_entry( + state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) + assert(rc == None) - mock_table = MagicMock() - mock_table.getKeys = MagicMock(return_value=['Ethernet0', 'Ethernet4']) - mock_table.get = MagicMock( - side_effect=[(True, (('index', 1), )), (True, (('index', 2), ))]) - mock_swsscommon_table.return_value = mock_table + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_check_identifier_presence_and_update_mux_table_entry_module_dir_none(self): - mock_logical_port_name = [""] + asic_index = 0 + logical_port_name = "Ethernet0" + status = True + fvs = [('state', "auto"), ('read_side', 1)] - def mock_get_asic_id(mock_logical_port_name): - return 0 + state_db = {} + test_db = "TEST_DB" + y_cable_tbl = {} + static_tbl = {} + mux_tbl = {} + port_tbl = {} + y_cable_presence = True + + y_cable_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], swsscommon.STATE_HW_MUX_CABLE_TABLE_NAME) + static_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], MUX_CABLE_STATIC_INFO_TABLE) + mux_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], MUX_CABLE_INFO_TABLE) + port_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], "PORT_INFO_TABLE") + port_tbl[asic_index].get.return_value = (status, fvs) - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: + patched_util.get_transceiver_info_dict.return_value = { + 'manufacturer': 'not_Microsoft', 'model': 'simulated'} - patched_util.logical.return_value = ['Ethernet0', 'Ethernet4'] - patched_util.get_asic_id_for_logical_port.return_value = 0 + with patch('sonic_y_cable.y_cable_vendor_mapping.mapping') as mock_mapping: + mock_mapping.get.return_value = None - rc = delete_ports_status_for_y_cable() + rc = check_identifier_presence_and_update_mux_table_entry( + state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) + assert(rc == None) - mock_swsscommon_table.assert_called() + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('sonic_y_cable.y_cable_vendor_mapping.mapping.get', MagicMock(return_value={"Microsoft": {"module": "test_module"}})) + def test_check_identifier_presence_and_update_mux_table_entry_module_none(self): - def test_check_identifier_presence_and_update_mux_info_entry(self): - asic_index = 0 - logical_port_name = "Ethernet0" + asic_index = 0 + logical_port_name = "Ethernet0" + status = True + fvs = [('state', "auto"), ('read_side', 1)] - state_db = {} - test_db = "TEST_DB" - mux_tbl = {} + state_db = {} + test_db = "TEST_DB" + y_cable_tbl = {} + static_tbl = {} + mux_tbl = {} + port_tbl = {} + y_cable_presence = True + + y_cable_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], swsscommon.STATE_HW_MUX_CABLE_TABLE_NAME) + static_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], MUX_CABLE_STATIC_INFO_TABLE) + mux_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], MUX_CABLE_INFO_TABLE) + port_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], "PORT_INFO_TABLE") + port_tbl[asic_index].get.return_value = (status, fvs) - mux_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], MUX_CABLE_INFO_TABLE) + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: + patched_util.get_transceiver_info_dict.return_value = { + 'manufacturer': 'not_Microsoft', 'model': 'model1'} - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: + rc = check_identifier_presence_and_update_mux_table_entry( + state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) + assert(rc == None) - patched_util.logical.return_value = ['Ethernet0', 'Ethernet4'] - rc = check_identifier_presence_and_update_mux_info_entry( - state_db, mux_tbl, asic_index, logical_port_name) - assert(rc == None) + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('sonic_y_cable.y_cable_vendor_mapping.mapping.get', MagicMock(return_value={"simulated": "microsoft.y_cable_simulated"})) + def test_check_identifier_presence_and_update_mux_table_entry_module_microsoft(self): - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - def test_get_firmware_dict(self, port_instance): + asic_index = 0 + logical_port_name = "Ethernet0" + status = True + fvs = [('state', "auto"), ('read_side', 1)] - port_instance = MagicMock() - port_instance.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - port_instance.download_firmware_status = 1 + state_db = {} + test_db = "TEST_DB" + y_cable_tbl = {} + static_tbl = {} + mux_tbl = {} + port_tbl = {} + y_cable_presence = [True] + + y_cable_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], swsscommon.STATE_HW_MUX_CABLE_TABLE_NAME) + static_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], MUX_CABLE_STATIC_INFO_TABLE) + mux_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], MUX_CABLE_INFO_TABLE) + port_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], "PORT_INFO_TABLE") + port_tbl[asic_index].get.return_value = (status, fvs) - physical_port = 1 - target = "simulated_target" - side = "a" - mux_info_dict = {} - logical_port_name = "Ethernet0" + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: + patched_util.get_transceiver_info_dict.return_value = { + 'manufacturer': 'microsoft', 'model': 'simulated'} - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: + sys.modules['builtins.getattr'] = MagicMock() + rc = check_identifier_presence_and_update_mux_table_entry( + state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) + assert(rc == None) - patched_util.get_asic_id_for_logical_port.return_value = 0 + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('sonic_y_cable.y_cable_vendor_mapping.mapping.get', MagicMock(return_value={"simulated": "microsoft.y_cable_simulated"})) + def test_check_identifier_presence_and_update_mux_table_entry_module_microsoft_y_cable_presence_false(self): + asic_index = 0 + logical_port_name = "Ethernet0" status = True fvs = [('state', "auto"), ('read_side', 1)] - Table = MagicMock() - Table.get.return_value = (status, fvs) - rc = get_firmware_dict( - physical_port, port_instance, target, side, mux_info_dict, logical_port_name) + state_db = {} + test_db = "TEST_DB" + y_cable_tbl = {} + static_tbl = {} + mux_tbl = {} + port_tbl = {} + y_cable_presence = [False] - assert(mux_info_dict['version_a_active'] == None) - assert(mux_info_dict['version_a_inactive'] == None) - assert(mux_info_dict['version_a_next'] == None) + port_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], "PORT_INFO_TABLE") + port_tbl[asic_index].get.return_value = (status, fvs) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - def test_get_firmware_dict_asic_error(self, port_instance): - - port_instance = MagicMock() - port_instance.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - port_instance.download_firmware_status = 1 - - physical_port = 1 - target = "simulated_target" - side = "a" - mux_info_dict = {} - logical_port_name = "Ethernet0" + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: + patched_util.get_transceiver_info_dict.return_value = { + 'manufacturer': 'microsoft', 'model': 'simulated'} - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: + sys.modules['builtins.getattr'] = MagicMock() + rc = check_identifier_presence_and_update_mux_table_entry( + state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) + assert(rc == None) - patched_util.get_asic_id_for_logical_port.return_value = 0 + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_check_identifier_presence_and_delete_mux_table_entry(self): + asic_index = 0 + logical_port_name = "Ethernet0" status = True fvs = [('state', "auto"), ('read_side', 1)] - Table = MagicMock() - Table.get.return_value = (status, fvs) - swsscommon.Table.return_value.get.return_value = ( - False, {"read_side": "2"}) - rc = get_firmware_dict( - physical_port, port_instance, target, side, mux_info_dict, logical_port_name) + state_db = {} + test_db = "TEST_DB" + y_cable_tbl = {} + static_tbl = {} + mux_tbl = {} + port_tbl = {} + y_cable_presence = [True] + delete_change_event = [True] + + port_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], "PORT_INFO_TABLE") + port_tbl[asic_index].get.return_value = (status, fvs) + + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as port_instance: + rc = check_identifier_presence_and_delete_mux_table_entry( + state_db, port_tbl, asic_index, logical_port_name, y_cable_presence, delete_change_event) + assert(rc == None) - assert(mux_info_dict['version_a_active'] == "N/A") - assert(mux_info_dict['version_a_inactive'] == "N/A") - assert(mux_info_dict['version_a_next'] == "N/A") + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_chassis') + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') + @patch('swsscommon.swsscommon.Table') + def test_init_ports_status_for_y_cable(self, platform_chassis, platform_sfp, mock_swsscommon_table): - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - def test_get_firmware_dict_download_status_failed_exception(self, port_instance): + platform_sfp = MagicMock() + platform_chassis = MagicMock() - port_instance = MagicMock() - port_instance.FIRMWARE_DOWNLOAD_STATUS_FAILED = -1 - port_instance.download_firmware_status = -1 - port_instance.get_firmware_version = MagicMock( - side_effect=NotImplementedError) + mock_logical_port_name = [""] - physical_port = 1 - target = "simulated_target" - side = "a" - mux_info_dict = {} - logical_port_name = "Ethernet0" + def mock_get_asic_id(mock_logical_port_name): + return 0 - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: + y_cable_presence = [True] - patched_util.get_asic_id_for_logical_port.return_value = 0 + mock_table = MagicMock() + mock_table.getKeys = MagicMock(return_value=['Ethernet0', 'Ethernet4']) + mock_swsscommon_table.return_value = mock_table - status = True - fvs = [('state', "auto"), ('read_side', 1)] - Table = MagicMock() - Table.get.return_value = (status, fvs) + rc = init_ports_status_for_y_cable(platform_sfp, platform_chassis, + y_cable_presence, stop_event=threading.Event()) - rc = get_firmware_dict( - physical_port, port_instance, target, side, mux_info_dict, logical_port_name) + assert(rc == None) - assert(mux_info_dict['version_a_active'] == "N/A") - assert(mux_info_dict['version_a_inactive'] == "N/A") - assert(mux_info_dict['version_a_next'] == "N/A") + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('swsscommon.swsscommon.Table') + def test_change_ports_status_for_y_cable_change_event(self, mock_swsscommon_table): - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - def test_get_firmware_dict_download_status_failed(self, port_instance): + mock_logical_port_name = [""] - port_instance = MagicMock() - port_instance.FIRMWARE_DOWNLOAD_STATUS_FAILED = -1 - port_instance.download_firmware_status = -1 - port_instance.get_firmware_version = MagicMock( - return_value={"version_active": "2021", "version_inactive": "2020", "version_next": "2022"}) + def mock_get_asic_id(mock_logical_port_name): + return 0 - physical_port = 1 - target = "simulated_target" - side = "a" - mux_info_dict = {} - logical_port_name = "Ethernet0" + y_cable_presence = [True] + logical_port_dict = {'Ethernet0': '1'} - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: + mock_table = MagicMock() + mock_table.getKeys = MagicMock(return_value=['Ethernet0', 'Ethernet4']) + mock_table.get = MagicMock( + side_effect=[(True, (('index', 1), )), (True, (('index', 2), ))]) + mock_swsscommon_table.return_value = mock_table - patched_util.get_asic_id_for_logical_port.return_value = 0 + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: - status = True - fvs = [('state', "auto"), ('read_side', 1)] - Table = MagicMock() - Table.get.return_value = (status, fvs) + patched_util.get_asic_id_for_logical_port.return_value = 0 - rc = get_firmware_dict( - physical_port, port_instance, target, side, mux_info_dict, logical_port_name) + change_ports_status_for_y_cable_change_event( + logical_port_dict, y_cable_presence, stop_event=threading.Event()) - assert(mux_info_dict['version_a_active'] == "2021") - assert(mux_info_dict['version_a_inactive'] == "2020") - assert(mux_info_dict['version_a_next'] == "2022") + mock_swsscommon_table.assert_called() - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') - def test_get_muxcable_info(self, platform_sfputil): - physical_port = 20 + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('swsscommon.swsscommon.Table') + def test_change_ports_status_for_y_cable_change_event_sfp_removed(self, mock_swsscommon_table): - logical_port_name = "Ethernet20" - swsscommon.Table.return_value.get.return_value = ( - True, {"read_side": "1"}) - platform_sfputil.get_asic_id_for_logical_port = 0 + mock_logical_port_name = [""] - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + def mock_get_asic_id(mock_logical_port_name): + return 0 - class PortInstanceHelper(): - def __init__(self): - self.EEPROM_ERROR = -1 - self.TARGET_NIC = 1 - self.TARGET_TOR_A = 1 - self.TARGET_TOR_B = 1 - self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - self.FIRMWARE_DOWNLOAD_STATUS_FAILED = 2 - self.download_firmware_status = 0 - self.MUX_TOGGLE_STATUS_INPROGRESS = 1 - self.MUX_TOGGLE_STATUS_FAILED = 2 - self.MUX_TOGGLE_STATUS_NOT_INITIATED_OR_FINISHED = 2 - self.mux_toggle_status = 0 - self.SWITCH_COUNT_MANUAL = "manual" - self.SWITCH_COUNT_AUTO = "auto" + y_cable_presence = [True] + logical_port_dict = {'Ethernet0': '1'} - def get_active_linked_tor_side(self): - return 1 + mock_table = MagicMock() + mock_table.getKeys = MagicMock(return_value=['Ethernet0', 'Ethernet4']) + mock_table.get = MagicMock( + side_effect=[(True, (('index', 1), )), (True, (('index', 2), ))]) + mock_swsscommon_table.return_value = mock_table - def get_mux_direction(self): - return 1 + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: - def get_switch_count_total(self, switch_count): - return 1 + patched_util.get_asic_id_for_logical_port.return_value = 0 + change_ports_status_for_y_cable_change_event( + logical_port_dict, y_cable_presence, stop_event=threading.Event()) - def get_eye_heights(self, tgt_tor): - return 500 + mock_swsscommon_table.assert_called() - def is_link_active(self, tgt_nic): - return True + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('swsscommon.swsscommon.Table') + def test_change_ports_status_for_y_cable_change_event_sfp_unknown(self, mock_swsscommon_table): - def get_local_temperature(self): - return 22.75 + mock_logical_port_name = [""] - def get_local_voltage(self): - return 0.5 + def mock_get_asic_id(mock_logical_port_name): + return 0 - def get_nic_voltage(self): - return 2.7 + y_cable_presence = [True] + logical_port_dict = {'Ethernet0': '2'} - def get_nic_temperature(self): - return 20 - - patched_util.get.return_value = PortInstanceHelper() + mock_table = MagicMock() + mock_table.getKeys = MagicMock(return_value=['Ethernet0', 'Ethernet4']) + mock_table.get = MagicMock( + side_effect=[(True, (('index', 1), )), (True, (('index', 2), ))]) + mock_swsscommon_table.return_value = mock_table with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: + patched_util.get_asic_id_for_logical_port.return_value = 0 + change_ports_status_for_y_cable_change_event( + logical_port_dict, y_cable_presence, stop_event=threading.Event()) - rc = get_muxcable_info(physical_port, logical_port_name) + mock_swsscommon_table.assert_called() + + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + def test_delete_ports_status_for_y_cable(self, mock_swsscommon_table): - assert(rc['tor_active'] == 'active') - assert(rc['mux_direction'] == 'self') - assert(rc['internal_voltage'] == 0.5) + mock_table = MagicMock() + mock_table.getKeys = MagicMock(return_value=['Ethernet0', 'Ethernet4']) + mock_table.get = MagicMock( + side_effect=[(True, (('index', 1), )), (True, (('index', 2), ))]) + mock_swsscommon_table.return_value = mock_table - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') - def test_get_muxcable_info_peer_side(self, platform_sfputil): - physical_port = 20 + mock_logical_port_name = [""] - logical_port_name = "Ethernet20" - platform_sfputil.get_asic_id_for_logical_port = 0 - swsscommon.Table.return_value.get.return_value = ( - True, {"read_side": "2"}) + def mock_get_asic_id(mock_logical_port_name): + return 0 - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: - class PortInstanceHelper(): - def __init__(self): - self.EEPROM_ERROR = -1 - self.TARGET_NIC = 1 - self.TARGET_TOR_A = 1 - self.TARGET_TOR_B = 1 - self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - self.FIRMWARE_DOWNLOAD_STATUS_FAILED = 2 - self.download_firmware_status = 0 - self.MUX_TOGGLE_STATUS_INPROGRESS = 1 - self.MUX_TOGGLE_STATUS_FAILED = 2 - self.MUX_TOGGLE_STATUS_NOT_INITIATED_OR_FINISHED = 2 - self.mux_toggle_status = 0 - self.SWITCH_COUNT_MANUAL = "manual" - self.SWITCH_COUNT_AUTO = "auto" + patched_util.logical.return_value = ['Ethernet0', 'Ethernet4'] + patched_util.get_asic_id_for_logical_port.return_value = 0 - def get_active_linked_tor_side(self): - return 1 + rc = delete_ports_status_for_y_cable() - def get_mux_direction(self): - return 1 + mock_swsscommon_table.assert_called() - def get_switch_count_total(self, switch_count): - return 1 + def test_check_identifier_presence_and_update_mux_info_entry(self): + asic_index = 0 + logical_port_name = "Ethernet0" - def get_eye_heights(self, tgt_tor): - return 500 + state_db = {} + test_db = "TEST_DB" + mux_tbl = {} - def is_link_active(self, tgt_nic): - return True + mux_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], MUX_CABLE_INFO_TABLE) - def get_local_temperature(self): - return 22.75 + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: - def get_local_voltage(self): - return 0.5 + patched_util.logical.return_value = ['Ethernet0', 'Ethernet4'] + rc = check_identifier_presence_and_update_mux_info_entry( + state_db, mux_tbl, asic_index, logical_port_name) + assert(rc == None) - def get_nic_voltage(self): - return 2.7 + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + def test_get_firmware_dict(self, port_instance): - def get_nic_temperature(self): - return 20 + port_instance = MagicMock() + port_instance.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + port_instance.download_firmware_status = 1 - patched_util.get.return_value = PortInstanceHelper() + physical_port = 1 + target = "simulated_target" + side = "a" + mux_info_dict = {} + logical_port_name = "Ethernet0" with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: + patched_util.get_asic_id_for_logical_port.return_value = 0 - rc = get_muxcable_info(physical_port, logical_port_name) + status = True + fvs = [('state', "auto"), ('read_side', 1)] + Table = MagicMock() + Table.get.return_value = (status, fvs) + + rc = get_firmware_dict( + physical_port, port_instance, target, side, mux_info_dict, logical_port_name) + + assert(mux_info_dict['version_a_active'] == None) + assert(mux_info_dict['version_a_inactive'] == None) + assert(mux_info_dict['version_a_next'] == None) - assert(rc['tor_active'] == 'standby') - assert(rc['mux_direction'] == 'peer') - assert(rc['internal_voltage'] == 0.5) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + def test_get_firmware_dict_asic_error(self, port_instance): - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_get_muxcable_info_exceptions(self, platform_sfputil): - physical_port = 20 + port_instance = MagicMock() + port_instance.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + port_instance.download_firmware_status = 1 - logical_port_name = "Ethernet20" - platform_sfputil.get_asic_id_for_logical_port = 0 + physical_port = 1 + target = "simulated_target" + side = "a" + mux_info_dict = {} + logical_port_name = "Ethernet0" - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: + + patched_util.get_asic_id_for_logical_port.return_value = 0 + + status = True + fvs = [('state', "auto"), ('read_side', 1)] + Table = MagicMock() + Table.get.return_value = (status, fvs) + swsscommon.Table.return_value.get.return_value = ( + False, {"read_side": "2"}) - class PortInstanceHelper(): - def __init__(self): - self.EEPROM_ERROR = -1 - self.TARGET_NIC = 1 - self.TARGET_TOR_A = 1 - self.TARGET_TOR_B = 1 - self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - self.FIRMWARE_DOWNLOAD_STATUS_FAILED = 2 - self.download_firmware_status = 0 - self.MUX_TOGGLE_STATUS_INPROGRESS = 1 - self.MUX_TOGGLE_STATUS_FAILED = 2 - self.MUX_TOGGLE_STATUS_NOT_INITIATED_OR_FINISHED = 2 - self.mux_toggle_status = 0 - self.SWITCH_COUNT_MANUAL = "manual" - self.SWITCH_COUNT_AUTO = "auto" + rc = get_firmware_dict( + physical_port, port_instance, target, side, mux_info_dict, logical_port_name) - def get_active_linked_tor_side(): - return 1 + assert(mux_info_dict['version_a_active'] == "N/A") + assert(mux_info_dict['version_a_inactive'] == "N/A") + assert(mux_info_dict['version_a_next'] == "N/A") - def get_mux_direction(): - return 1 + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + def test_get_firmware_dict_download_status_failed_exception(self, port_instance): + + port_instance = MagicMock() + port_instance.FIRMWARE_DOWNLOAD_STATUS_FAILED = -1 + port_instance.download_firmware_status = -1 + port_instance.get_firmware_version = MagicMock( + side_effect=NotImplementedError) - def get_switch_count_total(self, switch_count): - return 1 + physical_port = 1 + target = "simulated_target" + side = "a" + mux_info_dict = {} + logical_port_name = "Ethernet0" + + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: - def get_eye_heights(tgt_tor): - return 500 + patched_util.get_asic_id_for_logical_port.return_value = 0 - def is_link_active(self, tgt_nic): - return True + status = True + fvs = [('state', "auto"), ('read_side', 1)] + Table = MagicMock() + Table.get.return_value = (status, fvs) - def get_local_temperature(): - return 22.75 + rc = get_firmware_dict( + physical_port, port_instance, target, side, mux_info_dict, logical_port_name) - def get_local_voltage(): - return 0.5 + assert(mux_info_dict['version_a_active'] == "N/A") + assert(mux_info_dict['version_a_inactive'] == "N/A") + assert(mux_info_dict['version_a_next'] == "N/A") - def get_nic_voltage(): - return 2.7 + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + def test_get_firmware_dict_download_status_failed(self, port_instance): - def get_nic_temperature(): - return 20 + port_instance = MagicMock() + port_instance.FIRMWARE_DOWNLOAD_STATUS_FAILED = -1 + port_instance.download_firmware_status = -1 + port_instance.get_firmware_version = MagicMock( + return_value={"version_active": "2021", "version_inactive": "2020", "version_next": "2022"}) - patched_util.get.return_value = PortInstanceHelper() + physical_port = 1 + target = "simulated_target" + side = "a" + mux_info_dict = {} + logical_port_name = "Ethernet0" with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: + patched_util.get_asic_id_for_logical_port.return_value = 0 - rc = get_muxcable_info(physical_port, logical_port_name) + status = True + fvs = [('state', "auto"), ('read_side', 1)] + Table = MagicMock() + Table.get.return_value = (status, fvs) - assert(rc['tor_active'] == 'unknown') - assert(rc['mux_direction'] == 'unknown') - assert(rc['self_eye_height_lane1'] == 'N/A') + rc = get_firmware_dict( + physical_port, port_instance, target, side, mux_info_dict, logical_port_name) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_get_muxcable_info_true_exceptions_peer_side(self, platform_sfputil): - physical_port = 20 + assert(mux_info_dict['version_a_active'] == "2021") + assert(mux_info_dict['version_a_inactive'] == "2020") + assert(mux_info_dict['version_a_next'] == "2022") - logical_port_name = "Ethernet20" - platform_sfputil.get_asic_id_for_logical_port = 0 - swsscommon.Table.return_value.get.return_value = ( - True, {"read_side": "2"}) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') + def test_get_muxcable_info(self, platform_sfputil): + physical_port = 20 - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + logical_port_name = "Ethernet20" + swsscommon.Table.return_value.get.return_value = ( + True, {"read_side": "1"}) + platform_sfputil.get_asic_id_for_logical_port = 0 - class PortInstanceHelper(): - def __init__(self): - self.EEPROM_ERROR = -1 - self.TARGET_NIC = 1 - self.TARGET_TOR_A = 1 - self.TARGET_TOR_B = 1 - self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - self.FIRMWARE_DOWNLOAD_STATUS_FAILED = 2 - self.download_firmware_status = 0 - self.MUX_TOGGLE_STATUS_INPROGRESS = 1 - self.MUX_TOGGLE_STATUS_NOT_INITIATED_OR_FINISHED = 2 - self.MUX_TOGGLE_STATUS_FAILED = 2 - self.mux_toggle_status = 0 - self.SWITCH_COUNT_MANUAL = "manual" - self.SWITCH_COUNT_AUTO = "auto" + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - def get_active_linked_tor_side(self): - raise NotImplementedError + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 + self.TARGET_NIC = 1 + self.TARGET_TOR_A = 1 + self.TARGET_TOR_B = 1 + self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + self.FIRMWARE_DOWNLOAD_STATUS_FAILED = 2 + self.download_firmware_status = 0 + self.MUX_TOGGLE_STATUS_INPROGRESS = 1 + self.MUX_TOGGLE_STATUS_FAILED = 2 + self.MUX_TOGGLE_STATUS_NOT_INITIATED_OR_FINISHED = 2 + self.mux_toggle_status = 0 + self.SWITCH_COUNT_MANUAL = "manual" + self.SWITCH_COUNT_AUTO = "auto" - def get_mux_direction(self): - raise NotImplementedError + def get_active_linked_tor_side(self): + return 1 - def get_switch_count_total(self, switch_count): - raise NotImplementedError + def get_mux_direction(self): + return 1 - def get_eye_heights(self, tgt_tor): - raise NotImplementedError + def get_switch_count_total(self, switch_count): + return 1 - def is_link_active(self, tgt_nic): - return False + def get_eye_heights(self, tgt_tor): + return 500 - def get_local_temperature(self): - raise NotImplementedError + def is_link_active(self, tgt_nic): + return True - def get_local_voltage(self): - raise NotImplementedError + def get_local_temperature(self): + return 22.75 - def get_nic_voltage(self): - raise NotImplementedError + def get_local_voltage(self): + return 0.5 - def get_nic_temperature(self): - raise NotImplementedError + def get_nic_voltage(self): + return 2.7 - patched_util.get.return_value = PortInstanceHelper() + def get_nic_temperature(self): + return 20 - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: - patched_util.get_asic_id_for_logical_port.return_value = 0 + patched_util.get.return_value = PortInstanceHelper() - rc = get_muxcable_info(physical_port, logical_port_name) + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: + patched_util.get_asic_id_for_logical_port.return_value = 0 - assert(rc['tor_active'] == 'unknown') - assert(rc['mux_direction'] == 'unknown') - assert(rc['self_eye_height_lane1'] == 'N/A') + rc = get_muxcable_info(physical_port, logical_port_name) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_get_muxcable_info_true_exceptions(self, platform_sfputil): - physical_port = 20 + assert(rc['tor_active'] == 'active') + assert(rc['mux_direction'] == 'self') + assert(rc['internal_voltage'] == 0.5) - logical_port_name = "Ethernet20" - platform_sfputil.get_asic_id_for_logical_port = 0 + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') + def test_get_muxcable_info_peer_side(self, platform_sfputil): + physical_port = 20 - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + logical_port_name = "Ethernet20" + platform_sfputil.get_asic_id_for_logical_port = 0 + swsscommon.Table.return_value.get.return_value = ( + True, {"read_side": "2"}) - class PortInstanceHelper(): - def __init__(self): - self.EEPROM_ERROR = -1 - self.TARGET_NIC = 1 - self.TARGET_TOR_A = 1 - self.TARGET_TOR_B = 1 - self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - self.FIRMWARE_DOWNLOAD_STATUS_FAILED = 2 - self.download_firmware_status = 0 - self.MUX_TOGGLE_STATUS_INPROGRESS = 1 - self.MUX_TOGGLE_STATUS_FAILED = 2 - self.MUX_TOGGLE_STATUS_NOT_INITIATED_OR_FINISHED = 2 - self.mux_toggle_status = 0 - self.SWITCH_COUNT_MANUAL = "manual" - self.SWITCH_COUNT_AUTO = "auto" + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - def get_active_linked_tor_side(self): - raise NotImplementedError + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 + self.TARGET_NIC = 1 + self.TARGET_TOR_A = 1 + self.TARGET_TOR_B = 1 + self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + self.FIRMWARE_DOWNLOAD_STATUS_FAILED = 2 + self.download_firmware_status = 0 + self.MUX_TOGGLE_STATUS_INPROGRESS = 1 + self.MUX_TOGGLE_STATUS_FAILED = 2 + self.MUX_TOGGLE_STATUS_NOT_INITIATED_OR_FINISHED = 2 + self.mux_toggle_status = 0 + self.SWITCH_COUNT_MANUAL = "manual" + self.SWITCH_COUNT_AUTO = "auto" - def get_mux_direction(self): - raise NotImplementedError + def get_active_linked_tor_side(self): + return 1 - def get_switch_count_total(self, switch_count): - raise NotImplementedError + def get_mux_direction(self): + return 1 - def get_eye_heights(self, tgt_tor): - raise NotImplementedError + def get_switch_count_total(self, switch_count): + return 1 - def is_link_active(self, tgt_nic): - return False + def get_eye_heights(self, tgt_tor): + return 500 - def get_local_temperature(self): - raise NotImplementedError + def is_link_active(self, tgt_nic): + return True - def get_local_voltage(self): - raise NotImplementedError + def get_local_temperature(self): + return 22.75 - def get_nic_voltage(self): - raise NotImplementedError + def get_local_voltage(self): + return 0.5 - def get_nic_temperature(self): - raise NotImplementedError + def get_nic_voltage(self): + return 2.7 - patched_util.get.return_value = PortInstanceHelper() + def get_nic_temperature(self): + return 20 - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: - patched_util.get_asic_id_for_logical_port.return_value = 0 + patched_util.get.return_value = PortInstanceHelper() - rc = get_muxcable_info(physical_port, logical_port_name) + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: + patched_util.get_asic_id_for_logical_port.return_value = 0 - assert(rc['tor_active'] == 'unknown') - assert(rc['mux_direction'] == 'unknown') - assert(rc['self_eye_height_lane1'] == 'N/A') + rc = get_muxcable_info(physical_port, logical_port_name) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_get_muxcable_info_exceptions_peer_side(self, platform_sfputil): - physical_port = 20 + assert(rc['tor_active'] == 'standby') + assert(rc['mux_direction'] == 'peer') + assert(rc['internal_voltage'] == 0.5) - logical_port_name = "Ethernet20" - platform_sfputil.get_asic_id_for_logical_port = 0 - swsscommon.Table.return_value.get.return_value = ( - True, {"read_side": "2"}) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_get_muxcable_info_exceptions(self, platform_sfputil): + physical_port = 20 - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + logical_port_name = "Ethernet20" + platform_sfputil.get_asic_id_for_logical_port = 0 - class PortInstanceHelper(): - def __init__(self): - self.EEPROM_ERROR = -1 - self.TARGET_NIC = 1 - self.TARGET_TOR_A = 1 - self.TARGET_TOR_B = 1 - self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - self.FIRMWARE_DOWNLOAD_STATUS_FAILED = 2 - self.download_firmware_status = 0 - self.MUX_TOGGLE_STATUS_INPROGRESS = 1 - self.MUX_TOGGLE_STATUS_NOT_INITIATED_OR_FINISHED = 2 - self.mux_toggle_status = 0 - self.SWITCH_COUNT_MANUAL = "manual" - self.SWITCH_COUNT_AUTO = "auto" + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - def get_active_linked_tor_side(): - return 1 + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 + self.TARGET_NIC = 1 + self.TARGET_TOR_A = 1 + self.TARGET_TOR_B = 1 + self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + self.FIRMWARE_DOWNLOAD_STATUS_FAILED = 2 + self.download_firmware_status = 0 + self.MUX_TOGGLE_STATUS_INPROGRESS = 1 + self.MUX_TOGGLE_STATUS_FAILED = 2 + self.MUX_TOGGLE_STATUS_NOT_INITIATED_OR_FINISHED = 2 + self.mux_toggle_status = 0 + self.SWITCH_COUNT_MANUAL = "manual" + self.SWITCH_COUNT_AUTO = "auto" - def get_mux_direction(): - return 1 + def get_active_linked_tor_side(): + return 1 - def get_switch_count_total(self, switch_count): - return 1 + def get_mux_direction(): + return 1 - def get_eye_heights(tgt_tor): - return 500 + def get_switch_count_total(self, switch_count): + return 1 - def is_link_active(self, tgt_nic): - return True + def get_eye_heights(tgt_tor): + return 500 - def get_local_temperature(): - return 22.75 + def is_link_active(self, tgt_nic): + return True - def get_local_voltage(): - return 0.5 + def get_local_temperature(): + return 22.75 - def get_nic_voltage(): - return 2.7 + def get_local_voltage(): + return 0.5 - def get_nic_temperature(): - return 20 + def get_nic_voltage(): + return 2.7 - patched_util.get.return_value = PortInstanceHelper() + def get_nic_temperature(): + return 20 - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: - patched_util.get_asic_id_for_logical_port.return_value = 0 + patched_util.get.return_value = PortInstanceHelper() - rc = get_muxcable_info(physical_port, logical_port_name) - - assert(rc['tor_active'] == 'unknown') - assert(rc['mux_direction'] == 'unknown') - assert(rc['self_eye_height_lane1'] == 'N/A') - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_get_muxcable_static_info(self, platform_sfputil): - physical_port = 0 - - logical_port_name = "Ethernet0" - - platform_sfputil.get_asic_id_for_logical_port = 0 - swsscommon.Table.return_value.get.return_value = ( - True, {"read_side": "1"}) - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - class PortInstanceHelper(): - def __init__(self): - self.EEPROM_ERROR = -1 - self.TARGET_NIC = 0 - self.TARGET_TOR_A = 1 - self.TARGET_TOR_B = 2 - self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - self.download_firmware_status = 1 - self.MUX_TOGGLE_STATUS_INPROGRESS = 1 - self.MUX_TOGGLE_STATUS_FAILED = 2 - self.MUX_TOGGLE_STATUS_NOT_INITIATED_OR_FINISHED = 2 - self.mux_toggle_status = 0 - self.SWITCH_COUNT_MANUAL = "manual" - self.SWITCH_COUNT_AUTO = "auto" - - def get_target_cursor_values(self, i, tgt): - if (tgt == self.TARGET_NIC): - return ([1, 7, 7, 1, 0]) - elif (tgt == self.TARGET_TOR_A): - return ([17, 17, 17, 17, 17]) - elif (tgt == self.TARGET_TOR_B): - return ([-17, -17, -17, -17, -17]) - - patched_util.get.return_value = PortInstanceHelper() + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: + patched_util.get_asic_id_for_logical_port.return_value = 0 - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: - patched_util.get_asic_id_for_logical_port.return_value = 0 - rc = get_muxcable_static_info(physical_port, logical_port_name) - - assert (rc['read_side'] == 'tor1') - assert (rc['nic_lane1_precursor1'] == 1) - assert (rc['nic_lane1_precursor2'] == 7) - assert (rc['nic_lane1_maincursor'] == 7) - assert (rc['nic_lane1_postcursor1'] == 1) - assert (rc['nic_lane1_postcursor2'] == 0) - - assert (rc['nic_lane2_precursor1'] == 1) - assert (rc['nic_lane2_precursor2'] == 7) - assert (rc['nic_lane2_maincursor'] == 7) - assert (rc['nic_lane2_postcursor1'] == 1) - assert (rc['nic_lane2_postcursor2'] == 0) - - assert (rc['tor_self_lane1_precursor1'] == 17) - assert (rc['tor_self_lane1_precursor2'] == 17) - assert (rc['tor_self_lane1_maincursor'] == 17) - assert (rc['tor_self_lane1_postcursor1'] == 17) - assert (rc['tor_self_lane1_postcursor2'] == 17) - - assert (rc['tor_self_lane2_precursor1'] == 17) - assert (rc['tor_self_lane2_precursor2'] == 17) - assert (rc['tor_self_lane2_maincursor'] == 17) - assert (rc['tor_self_lane2_postcursor1'] == 17) - assert (rc['tor_self_lane2_postcursor2'] == 17) - - assert (rc['tor_peer_lane1_precursor1'] == -17) - assert (rc['tor_peer_lane1_precursor2'] == -17) - assert (rc['tor_peer_lane1_maincursor'] == -17) - assert (rc['tor_peer_lane1_postcursor1'] == -17) - assert (rc['tor_peer_lane1_postcursor2'] == -17) - - assert (rc['tor_peer_lane2_precursor1'] == -17) - assert (rc['tor_peer_lane2_precursor2'] == -17) - assert (rc['tor_peer_lane2_maincursor'] == -17) - assert (rc['tor_peer_lane2_postcursor1'] == -17) - assert (rc['tor_peer_lane2_postcursor2'] == -17) - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_get_muxcable_static_info_read_side_peer(self, platform_sfputil): - physical_port = 0 - - logical_port_name = "Ethernet0" - - #swsscommon.Table = MagicMock() - # this patch is already done as global instance - platform_sfputil.get_asic_id_for_logical_port = 0 - swsscommon.Table.return_value.get.return_value = ( - True, {"read_side": "2"}) - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - class PortInstanceHelper(): - def __init__(self): - self.EEPROM_ERROR = -1 - self.TARGET_NIC = 0 - self.TARGET_TOR_A = 1 - self.TARGET_TOR_B = 2 - self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - self.download_firmware_status = 1 - self.MUX_TOGGLE_STATUS_INPROGRESS = 1 - self.MUX_TOGGLE_STATUS_FAILED = 2 - self.MUX_TOGGLE_STATUS_NOT_INITIATED_OR_FINISHED = 2 - self.mux_toggle_status = 0 - self.SWITCH_COUNT_MANUAL = "manual" - self.SWITCH_COUNT_AUTO = "auto" - - def get_target_cursor_values(self, i, tgt): - if (tgt == self.TARGET_NIC): - return ([1, 7, 7, 1, 0]) - elif (tgt == self.TARGET_TOR_A): - return ([-17, -17, -17, -17, -17]) - elif (tgt == self.TARGET_TOR_B): - return ([-17, -17, -17, -17, -17]) - - patched_util.get.return_value = PortInstanceHelper() + rc = get_muxcable_info(physical_port, logical_port_name) - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: - patched_util.get_asic_id_for_logical_port.return_value = 0 - rc = get_muxcable_static_info(physical_port, logical_port_name) - - assert (rc['read_side'] == 'tor2') - assert (rc['nic_lane1_precursor1'] == 1) - assert (rc['nic_lane1_precursor2'] == 7) - assert (rc['nic_lane1_maincursor'] == 7) - assert (rc['nic_lane1_postcursor1'] == 1) - assert (rc['nic_lane1_postcursor2'] == 0) - - assert (rc['nic_lane2_precursor1'] == 1) - assert (rc['nic_lane2_precursor2'] == 7) - assert (rc['nic_lane2_maincursor'] == 7) - assert (rc['nic_lane2_postcursor1'] == 1) - assert (rc['nic_lane2_postcursor2'] == 0) - - assert (rc['tor_self_lane1_precursor1'] == -17) - assert (rc['tor_self_lane1_precursor2'] == -17) - assert (rc['tor_self_lane1_maincursor'] == -17) - assert (rc['tor_self_lane1_postcursor1'] == -17) - assert (rc['tor_self_lane1_postcursor2'] == -17) - - assert (rc['tor_self_lane2_precursor1'] == -17) - assert (rc['tor_self_lane2_precursor2'] == -17) - assert (rc['tor_self_lane2_maincursor'] == -17) - assert (rc['tor_self_lane2_postcursor1'] == -17) - assert (rc['tor_self_lane2_postcursor2'] == -17) - - assert (rc['tor_peer_lane1_precursor1'] == -17) - assert (rc['tor_peer_lane1_precursor2'] == -17) - assert (rc['tor_peer_lane1_maincursor'] == -17) - assert (rc['tor_peer_lane1_postcursor1'] == -17) - assert (rc['tor_peer_lane1_postcursor2'] == -17) - - assert (rc['tor_peer_lane2_precursor1'] == -17) - assert (rc['tor_peer_lane2_precursor2'] == -17) - assert (rc['tor_peer_lane2_maincursor'] == -17) - assert (rc['tor_peer_lane2_postcursor1'] == -17) - assert (rc['tor_peer_lane2_postcursor2'] == -17) - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_get_muxcable_static_info_read_side_peer_exceptions(self, platform_sfputil): - physical_port = 0 - - logical_port_name = "Ethernet0" - - #swsscommon.Table = MagicMock() - # this patch is already done as global instance - platform_sfputil.get_asic_id_for_logical_port = 0 - swsscommon.Table.return_value.get.return_value = ( - True, {"read_side": "2"}) - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - class PortInstanceHelper(): - def __init__(self): - self.EEPROM_ERROR = -1 - self.TARGET_NIC = 0 - self.TARGET_TOR_A = 1 - self.TARGET_TOR_B = 2 - self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - self.download_firmware_status = 1 - self.MUX_TOGGLE_STATUS_INPROGRESS = 1 - self.MUX_TOGGLE_STATUS_FAILED = 2 - self.MUX_TOGGLE_STATUS_NOT_INITIATED_OR_FINISHED = 2 - self.mux_toggle_status = 0 - self.SWITCH_COUNT_MANUAL = "manual" - self.SWITCH_COUNT_AUTO = "auto" - - def get_target_cursor_values(self, i, tgt): - raise NotImplementedError - - patched_util.get.return_value = PortInstanceHelper() + assert(rc['tor_active'] == 'unknown') + assert(rc['mux_direction'] == 'unknown') + assert(rc['self_eye_height_lane1'] == 'N/A') - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: - patched_util.get_asic_id_for_logical_port.return_value = 0 - rc = get_muxcable_static_info(physical_port, logical_port_name) - - assert (rc['read_side'] == 'tor2') - assert (rc['nic_lane1_precursor1'] == "N/A") - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - def test_task_download_firmware_worker(self, port_instance, mock_swsscommon_table): - port = "Ethernet0" - physical_port = 0 - file_full_path = "/path/to/file" - - def mock_download_fw(filepath): - return 0 - - port_instance.download_firmware = mock_download_fw - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_down_fw_rsp_tbl = mock_swsscommon_table - xcvrd_down_fw_cmd_sts_tbl = mock_swsscommon_table - - rc = {} - - task_download_firmware_worker(port, physical_port, port_instance, file_full_path, - xcvrd_down_fw_rsp_tbl, xcvrd_down_fw_cmd_sts_tbl, rc) - - assert(rc[0] == 0) - - def test_set_show_firmware_fields(self): - - mux_info_dict = {} - xcvrd_show_fw_res_tbl = Table("STATE_DB", "XCVRD_SHOW_FW_RES") - mux_info_dict['version_self_active'] = '0.8' - mux_info_dict['version_self_inactive'] = '0.7' - mux_info_dict['version_self_next'] = '0.7' - mux_info_dict['version_peer_active'] = '0.8' - mux_info_dict['version_peer_inactive'] = '0.7' - mux_info_dict['version_peer_next'] = '0.7' - mux_info_dict['version_nic_active'] = '0.8' - mux_info_dict['version_nic_inactive'] = '0.7' - mux_info_dict['version_nic_next'] = '0.7' - rc = set_show_firmware_fields( - "Ethernet0", mux_info_dict, xcvrd_show_fw_res_tbl) - - assert(rc == 0) - - @patch('sonic_py_common.device_info.get_paths_to_platform_and_hwsku_dirs', MagicMock(return_value=('/tmp', None))) - @patch('swsscommon.swsscommon.WarmStart', MagicMock()) - @patch('ycable.ycable.platform_sfputil', MagicMock()) - @patch('ycable.ycable.DaemonYcable.load_platform_util', MagicMock()) - def test_DaemonYcable_init_deinit(self): - ycable = DaemonYcable(SYSLOG_IDENTIFIER) - ycable.init() - ycable.deinit() - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "enable", {"mode_value": "0", - "lane_mask": "0", - "direction": "0"}))) - def test_handle_config_prbs_cmd_arg_tbl_notification_no_port(self, port_instance, mock_swsscommon_table): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_config_prbs_cmd_arg_tbl = mock_swsscommon_table - xcvrd_config_prbs_cmd_sts_tbl = mock_swsscommon_table - xcvrd_config_prbs_rsp_tbl = mock_swsscommon_table - asic_index = 0 - port = "Ethernet0" - fvp = {"config_prbs": True} - - rc = handle_config_prbs_cmd_arg_tbl_notification( - fvp, xcvrd_config_prbs_cmd_arg_tbl, xcvrd_config_prbs_cmd_sts_tbl, xcvrd_config_prbs_rsp_tbl, asic_index, port) - assert(rc == -1) - - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "enable", {"mode_value": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - def test_handle_config_prbs_cmd_arg_tbl_notification_no_instance(self, mock_swsscommon_table): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_config_prbs_cmd_arg_tbl = mock_swsscommon_table - xcvrd_config_prbs_cmd_sts_tbl = mock_swsscommon_table - xcvrd_config_prbs_rsp_tbl = mock_swsscommon_table - asic_index = 0 - port = "Ethernet0" - fvp = {"config_prbs": True} - - rc = handle_config_prbs_cmd_arg_tbl_notification( - fvp, xcvrd_config_prbs_cmd_arg_tbl, xcvrd_config_prbs_cmd_sts_tbl, xcvrd_config_prbs_rsp_tbl, asic_index, port) - assert(rc == -1) - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "enable", {"mode_value": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_config_prbs_cmd_arg_tbl_notification_with_instance_enable(self, port_instance, mock_swsscommon_table, port_instance_helper): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_config_prbs_cmd_arg_tbl = mock_swsscommon_table - xcvrd_config_prbs_cmd_sts_tbl = mock_swsscommon_table - xcvrd_config_prbs_rsp_tbl = mock_swsscommon_table - port_instance = MagicMock() - port_instance.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - port_instance.PRBS_DIRECTION_BOTH = 2 - port_instance.enable_prbs_mode.return_value = True - port_instance.disable_prbs_mode.return_value = True - port_instance_helper = port_instance - - asic_index = 0 - port = "Ethernet0" - fvp = {"config_prbs": True} - - rc = handle_config_prbs_cmd_arg_tbl_notification( - fvp, xcvrd_config_prbs_cmd_arg_tbl, xcvrd_config_prbs_cmd_sts_tbl, xcvrd_config_prbs_rsp_tbl, asic_index, port) - assert(rc == None) - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "disable", {"mode_value": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_config_prbs_cmd_arg_tbl_notification_with_instance_disable(self, port_instance, mock_swsscommon_table, port_instance_helper): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_config_prbs_cmd_arg_tbl = mock_swsscommon_table - xcvrd_config_prbs_cmd_sts_tbl = mock_swsscommon_table - xcvrd_config_prbs_rsp_tbl = mock_swsscommon_table - port_instance = MagicMock() - port_instance.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - port_instance.PRBS_DIRECTION_BOTH = 2 - port_instance.enable_prbs_mode.return_value = True - port_instance.disable_prbs_mode.return_value = True - port_instance_helper = port_instance - - asic_index = 0 - port = "Ethernet0" - fvp = {"config_prbs": True} - - rc = handle_config_prbs_cmd_arg_tbl_notification( - fvp, xcvrd_config_prbs_cmd_arg_tbl, xcvrd_config_prbs_cmd_sts_tbl, xcvrd_config_prbs_rsp_tbl, asic_index, port) - assert(rc == None) - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "reset", {"mode_value": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_config_prbs_cmd_arg_tbl_notification_with_instance_reset(self, port_instance, mock_swsscommon_table, port_instance_helper): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_config_prbs_cmd_arg_tbl = mock_swsscommon_table - xcvrd_config_prbs_cmd_sts_tbl = mock_swsscommon_table - xcvrd_config_prbs_rsp_tbl = mock_swsscommon_table - port_instance = MagicMock() - port_instance.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - port_instance.PRBS_DIRECTION_BOTH = 2 - port_instance.enable_prbs_mode.return_value = True - port_instance.disable_prbs_mode.return_value = True - port_instance.reset.return_value = True - port_instance_helper = port_instance - - asic_index = 0 - port = "Ethernet0" - fvp = {"config_prbs": True} - - rc = handle_config_prbs_cmd_arg_tbl_notification( - fvp, xcvrd_config_prbs_cmd_arg_tbl, xcvrd_config_prbs_cmd_sts_tbl, xcvrd_config_prbs_rsp_tbl, asic_index, port) - assert(rc == None) - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "anlt", {"mode": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_config_prbs_cmd_arg_tbl_notification_with_instance_anlt_enable(self, port_instance, mock_swsscommon_table, port_instance_helper): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_config_prbs_cmd_arg_tbl = mock_swsscommon_table - xcvrd_config_prbs_cmd_sts_tbl = mock_swsscommon_table - xcvrd_config_prbs_rsp_tbl = mock_swsscommon_table - port_instance = MagicMock() - port_instance.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - port_instance.PRBS_DIRECTION_BOTH = 2 - port_instance.enable_prbs_mode.return_value = True - port_instance.disable_prbs_mode.return_value = True - port_instance.reset.return_value = True - port_instance.set_anlt.return_value = True - port_instance_helper = port_instance - - asic_index = 0 - port = "Ethernet0" - fvp = {"config_prbs": True} - - rc = handle_config_prbs_cmd_arg_tbl_notification( - fvp, xcvrd_config_prbs_cmd_arg_tbl, xcvrd_config_prbs_cmd_sts_tbl, xcvrd_config_prbs_rsp_tbl, asic_index, port) - assert(rc == None) - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "anlt", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_config_prbs_cmd_arg_tbl_notification_with_instance_anlt_disable(self, port_instance, mock_swsscommon_table, port_instance_helper): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_config_prbs_cmd_arg_tbl = mock_swsscommon_table - xcvrd_config_prbs_cmd_sts_tbl = mock_swsscommon_table - xcvrd_config_prbs_rsp_tbl = mock_swsscommon_table - port_instance = MagicMock() - port_instance.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - port_instance.PRBS_DIRECTION_BOTH = 2 - port_instance.enable_prbs_mode.return_value = True - port_instance.disable_prbs_mode.return_value = True - port_instance.reset.return_value = True - port_instance.set_anlt.return_value = True - port_instance_helper = port_instance - - asic_index = 0 - port = "Ethernet0" - fvp = {"config_prbs": True} - - rc = handle_config_prbs_cmd_arg_tbl_notification( - fvp, xcvrd_config_prbs_cmd_arg_tbl, xcvrd_config_prbs_cmd_sts_tbl, xcvrd_config_prbs_rsp_tbl, asic_index, port) - assert(rc == -1) - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"mode": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_config_prbs_cmd_arg_tbl_notification_with_instance_fec_enable(self, port_instance, mock_swsscommon_table, port_instance_helper): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_config_prbs_cmd_arg_tbl = mock_swsscommon_table - xcvrd_config_prbs_cmd_sts_tbl = mock_swsscommon_table - xcvrd_config_prbs_rsp_tbl = mock_swsscommon_table - port_instance = MagicMock() - port_instance.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - port_instance.PRBS_DIRECTION_BOTH = 2 - port_instance.enable_prbs_mode.return_value = True - port_instance.disable_prbs_mode.return_value = True - port_instance.reset.return_value = True - port_instance.set_fec_mode.return_value = True - port_instance_helper = port_instance - - asic_index = 0 - port = "Ethernet0" - fvp = {"config_prbs": True} - - rc = handle_config_prbs_cmd_arg_tbl_notification( - fvp, xcvrd_config_prbs_cmd_arg_tbl, xcvrd_config_prbs_cmd_sts_tbl, xcvrd_config_prbs_rsp_tbl, asic_index, port) - assert(rc == None) - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_config_prbs_cmd_arg_tbl_notification_with_instance_fec_disable(self, port_instance, mock_swsscommon_table, port_instance_helper): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_config_prbs_cmd_arg_tbl = mock_swsscommon_table - xcvrd_config_prbs_cmd_sts_tbl = mock_swsscommon_table - xcvrd_config_prbs_rsp_tbl = mock_swsscommon_table - port_instance = MagicMock() - port_instance.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - port_instance.PRBS_DIRECTION_BOTH = 2 - port_instance.enable_prbs_mode.return_value = True - port_instance.disable_prbs_mode.return_value = True - port_instance.reset.return_value = True - port_instance.set_fec_mode.return_value = True - port_instance_helper = port_instance - - asic_index = 0 - port = "Ethernet0" - fvp = {"config_prbs": True} - - rc = handle_config_prbs_cmd_arg_tbl_notification( - fvp, xcvrd_config_prbs_cmd_arg_tbl, xcvrd_config_prbs_cmd_sts_tbl, xcvrd_config_prbs_rsp_tbl, asic_index, port) - assert(rc == -1) - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_config_prbs_cmd_arg_tbl_notification_else_value(self, port_instance, mock_swsscommon_table, port_instance_helper): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_config_prbs_cmd_arg_tbl = mock_swsscommon_table - xcvrd_config_prbs_cmd_sts_tbl = mock_swsscommon_table - xcvrd_config_prbs_rsp_tbl = mock_swsscommon_table - port_instance = MagicMock() - port_instance.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - port_instance.PRBS_DIRECTION_BOTH = 2 - port_instance.enable_prbs_mode.return_value = True - port_instance.disable_prbs_mode.return_value = True - port_instance.reset.return_value = True - port_instance.set_fec_mode.return_value = True - port_instance_helper = port_instance - - asic_index = 0 - port = "Ethernet0" - fvp = {"config_abc": True} - - rc = handle_config_prbs_cmd_arg_tbl_notification( - fvp, xcvrd_config_prbs_cmd_arg_tbl, xcvrd_config_prbs_cmd_sts_tbl, xcvrd_config_prbs_rsp_tbl, asic_index, port) - assert(rc == None) - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_config_loop_cmd_arg_tbl_notification_else_value(self, port_instance, mock_swsscommon_table, port_instance_helper): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_config_loop_cmd_arg_tbl = mock_swsscommon_table - xcvrd_config_loop_cmd_sts_tbl = mock_swsscommon_table - xcvrd_config_loop_rsp_tbl = mock_swsscommon_table - port_instance = MagicMock() - port_instance.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - port_instance.PRBS_DIRECTION_BOTH = 2 - port_instance.enable_prbs_mode.return_value = True - port_instance.disable_prbs_mode.return_value = True - port_instance.reset.return_value = True - port_instance.set_fec_mode.return_value = True - port_instance_helper = port_instance - - asic_index = 0 - port = "Ethernet0" - fvp = {"config_abc": True} - - rc = handle_config_loop_cmd_arg_tbl_notification( - fvp, xcvrd_config_loop_cmd_arg_tbl, xcvrd_config_loop_cmd_sts_tbl, xcvrd_config_loop_rsp_tbl, asic_index, port) - assert(rc == None) - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_config_loop_cmd_arg_tbl_notification_else_value(self, port_instance, mock_swsscommon_table, port_instance_helper): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_config_loop_cmd_arg_tbl = mock_swsscommon_table - xcvrd_config_loop_cmd_sts_tbl = mock_swsscommon_table - xcvrd_config_loop_rsp_tbl = mock_swsscommon_table - port_instance = MagicMock() - port_instance.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - port_instance.PRBS_DIRECTION_BOTH = 2 - port_instance.enable_prbs_mode.return_value = True - port_instance.disable_prbs_mode.return_value = True - port_instance.reset.return_value = True - port_instance.set_fec_mode.return_value = True - port_instance_helper = port_instance - - asic_index = 0 - port = "Ethernet0" - fvp = {"config_loop": True} - - rc = handle_config_loop_cmd_arg_tbl_notification( - fvp, xcvrd_config_loop_cmd_arg_tbl, xcvrd_config_loop_cmd_sts_tbl, xcvrd_config_loop_rsp_tbl, asic_index, port) - assert(rc == None) - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - def test_handle_config_loop_cmd_arg_tbl_notification_no_port(self, port_instance, mock_swsscommon_table, port_instance_helper): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_config_loop_cmd_arg_tbl = mock_swsscommon_table - xcvrd_config_loop_cmd_sts_tbl = mock_swsscommon_table - xcvrd_config_loop_rsp_tbl = mock_swsscommon_table - port_instance = MagicMock() - port_instance.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - port_instance.PRBS_DIRECTION_BOTH = 2 - port_instance.enable_prbs_mode.return_value = True - port_instance.disable_prbs_mode.return_value = True - port_instance.reset.return_value = True - port_instance.set_fec_mode.return_value = True - port_instance_helper = port_instance - - asic_index = 0 - port = "Ethernet0" - fvp = {"config_loop": True} - - rc = handle_config_loop_cmd_arg_tbl_notification( - fvp, xcvrd_config_loop_cmd_arg_tbl, xcvrd_config_loop_cmd_sts_tbl, xcvrd_config_loop_rsp_tbl, asic_index, port) - assert(rc == -1) - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_config_loop_cmd_arg_tbl_notification_no_instance(self, port_instance, mock_swsscommon_table): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_config_loop_cmd_arg_tbl = mock_swsscommon_table - xcvrd_config_loop_cmd_sts_tbl = mock_swsscommon_table - xcvrd_config_loop_rsp_tbl = mock_swsscommon_table - port_instance = MagicMock() - port_instance.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - port_instance.PRBS_DIRECTION_BOTH = 2 - port_instance.enable_prbs_mode.return_value = True - port_instance.disable_prbs_mode.return_value = True - port_instance.reset.return_value = True - port_instance.set_fec_mode.return_value = True - port_instance_helper = port_instance - - asic_index = 0 - port = "Ethernet0" - fvp = {"config_loop": True} - - rc = handle_config_loop_cmd_arg_tbl_notification( - fvp, xcvrd_config_loop_cmd_arg_tbl, xcvrd_config_loop_cmd_sts_tbl, xcvrd_config_loop_rsp_tbl, asic_index, port) - assert(rc == -1) - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "enable", {"enable": "0", - "lane_mask": "0", - "mode_value": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_config_loop_cmd_arg_tbl_notification_enable(self, port_instance, mock_swsscommon_table, port_instance_helper): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_config_loop_cmd_arg_tbl = mock_swsscommon_table - xcvrd_config_loop_cmd_sts_tbl = mock_swsscommon_table - xcvrd_config_loop_rsp_tbl = mock_swsscommon_table - port_instance = MagicMock() - port_instance.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - port_instance.PRBS_DIRECTION_BOTH = 2 - port_instance.enable_loopback_mode.return_value = True - port_instance.disable_loopback_mode.return_value = True - port_instance.reset.return_value = True - port_instance.set_fec_mode.return_value = True - port_instance_helper = port_instance - - asic_index = 0 - port = "Ethernet0" - fvp = {"config_loop": True} - - rc = handle_config_loop_cmd_arg_tbl_notification( - fvp, xcvrd_config_loop_cmd_arg_tbl, xcvrd_config_loop_cmd_sts_tbl, xcvrd_config_loop_rsp_tbl, asic_index, port) - assert(rc == None) - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "disable", {"disable": "0", - "lane_mask": "0", - "mode_value": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_config_loop_cmd_arg_tbl_notification_disable(self, port_instance, mock_swsscommon_table, port_instance_helper): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_config_loop_cmd_arg_tbl = mock_swsscommon_table - xcvrd_config_loop_cmd_sts_tbl = mock_swsscommon_table - xcvrd_config_loop_rsp_tbl = mock_swsscommon_table - port_instance = MagicMock() - port_instance.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - port_instance.PRBS_DIRECTION_BOTH = 2 - port_instance.enable_loopback_mode.return_value = True - port_instance.disable_loopback_mode.return_value = True - port_instance.reset.return_value = True - port_instance.set_fec_mode.return_value = True - port_instance_helper = port_instance - - asic_index = 0 - port = "Ethernet0" - fvp = {"config_loop": True} - - rc = handle_config_loop_cmd_arg_tbl_notification( - fvp, xcvrd_config_loop_cmd_arg_tbl, xcvrd_config_loop_cmd_sts_tbl, xcvrd_config_loop_rsp_tbl, asic_index, port) - assert(rc == None) - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_show_event_cmd_arg_tbl_notification_else_value(self, port_instance, mock_swsscommon_table, port_instance_helper): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_show_event_cmd_sts_tbl = mock_swsscommon_table - xcvrd_show_event_rsp_tbl = mock_swsscommon_table - xcvrd_show_event_res_tbl = mock_swsscommon_table - port_instance = MagicMock() - port_instance.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - port_instance.PRBS_DIRECTION_BOTH = 2 - port_instance.enable_prbs_mode.return_value = True - port_instance.disable_prbs_mode.return_value = True - port_instance.reset.return_value = True - port_instance.set_fec_mode.return_value = True - port_instance_helper = port_instance - - asic_index = 0 - port = "Ethernet0" - fvp = {"config_loop": True} - - rc = handle_show_event_cmd_arg_tbl_notification( - fvp, xcvrd_show_event_cmd_sts_tbl, xcvrd_show_event_rsp_tbl, xcvrd_show_event_res_tbl, asic_index, port) - assert(rc == None) - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_show_event_cmd_arg_tbl_notification_get_log(self, port_instance, mock_swsscommon_table, port_instance_helper): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_show_event_cmd_sts_tbl = mock_swsscommon_table - xcvrd_show_event_rsp_tbl = mock_swsscommon_table - xcvrd_show_event_res_tbl = mock_swsscommon_table - port_instance = MagicMock() - port_instance.get_event_log.return_value = ["log 1", "log 2"] - - asic_index = 0 - port = "Ethernet0" - fvp = {"show_event": True} - - rc = handle_show_event_cmd_arg_tbl_notification( - fvp, xcvrd_show_event_cmd_sts_tbl, xcvrd_show_event_rsp_tbl, xcvrd_show_event_res_tbl, asic_index, port) - assert(rc == None) - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_show_event_cmd_arg_tbl_notification_get_actual_log(self, port_instance, mock_swsscommon_table, port_instance_helper): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_show_event_cmd_sts_tbl = mock_swsscommon_table - xcvrd_show_event_rsp_tbl = mock_swsscommon_table - xcvrd_show_event_res_tbl = mock_swsscommon_table - port_instance = MagicMock() - port_instance.get_event_log.return_value = ["log 1", "log 2"] - port_instance_helper.return_value = port_instance - asic_index = 0 - port = "Ethernet0" - fvp = {"show_event": True} - - rc = handle_show_event_cmd_arg_tbl_notification( - fvp, xcvrd_show_event_cmd_sts_tbl, xcvrd_show_event_rsp_tbl, xcvrd_show_event_res_tbl, asic_index, port) - assert(rc == None) - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_show_event_cmd_arg_tbl_notification_get_no_log(self, port_instance, mock_swsscommon_table, port_instance_helper): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_show_event_cmd_sts_tbl = mock_swsscommon_table - xcvrd_show_event_rsp_tbl = mock_swsscommon_table - xcvrd_show_event_res_tbl = mock_swsscommon_table - port_instance = MagicMock() - port_instance.get_event_log.return_value = Exception( - NotImplementedError) - - asic_index = 0 - port = "Ethernet0" - fvp = {"show_event": True} - - rc = handle_show_event_cmd_arg_tbl_notification( - fvp, xcvrd_show_event_cmd_sts_tbl, xcvrd_show_event_rsp_tbl, xcvrd_show_event_res_tbl, asic_index, port) - assert(rc == None) - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_show_event_cmd_arg_tbl_notification_no_port(self, port_instance, mock_swsscommon_table, port_instance_helper): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_show_event_cmd_sts_tbl = mock_swsscommon_table - xcvrd_show_event_rsp_tbl = mock_swsscommon_table - xcvrd_show_event_res_tbl = mock_swsscommon_table - port_instance = MagicMock() - port_instance.get_event_log.return_value = ["log 1", "log 2"] - port_instance_helper = port_instance - - asic_index = 0 - port = "Ethernet0" - fvp = {"show_event": True} - - rc = handle_show_event_cmd_arg_tbl_notification( - fvp, xcvrd_show_event_cmd_sts_tbl, xcvrd_show_event_rsp_tbl, xcvrd_show_event_res_tbl, asic_index, port) - assert(rc == -1) - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - def test_handle_show_event_cmd_arg_tbl_notification_no_instance(self, port_instance, mock_swsscommon_table): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_show_event_cmd_sts_tbl = mock_swsscommon_table - xcvrd_show_event_rsp_tbl = mock_swsscommon_table - xcvrd_show_event_res_tbl = mock_swsscommon_table - port_instance = MagicMock() - port_instance.get_event_log.return_value = ["log 1", "log 2"] - - asic_index = 0 - port = "Ethernet0" - fvp = {"show_event": True} - - rc = handle_show_event_cmd_arg_tbl_notification( - fvp, xcvrd_show_event_cmd_sts_tbl, xcvrd_show_event_rsp_tbl, xcvrd_show_event_res_tbl, asic_index, port) - assert(rc == -1) - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_get_fec_cmd_arg_tbl_notification_no_status(self, port_instance, mock_swsscommon_table, port_instance_helper): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_show_fec_rsp_tbl = mock_swsscommon_table - xcvrd_show_fec_cmd_sts_tbl = mock_swsscommon_table - xcvrd_show_fec_res_tbl = mock_swsscommon_table - port_instance = MagicMock() - - asic_index = 0 - port = "Ethernet0" - fvp = {"show_event": True} - - rc = handle_get_fec_cmd_arg_tbl_notification( - fvp, xcvrd_show_fec_rsp_tbl, xcvrd_show_fec_cmd_sts_tbl, xcvrd_show_fec_res_tbl, asic_index, port) - assert(rc == None) - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_get_fec_cmd_arg_tbl_notification_no_port(self, port_instance, mock_swsscommon_table, port_instance_helper): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_show_fec_rsp_tbl = mock_swsscommon_table - xcvrd_show_fec_cmd_sts_tbl = mock_swsscommon_table - xcvrd_show_fec_res_tbl = mock_swsscommon_table - port_instance = MagicMock() - - asic_index = 0 - port = "Ethernet0" - fvp = {"get_fec": True} - - rc = handle_get_fec_cmd_arg_tbl_notification( - fvp, xcvrd_show_fec_rsp_tbl, xcvrd_show_fec_cmd_sts_tbl, xcvrd_show_fec_res_tbl, asic_index, port) - assert(rc == -1) - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_get_fec_cmd_arg_tbl_notification_no_instance(self, port_instance, mock_swsscommon_table): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_show_fec_rsp_tbl = mock_swsscommon_table - xcvrd_show_fec_cmd_sts_tbl = mock_swsscommon_table - xcvrd_show_fec_res_tbl = mock_swsscommon_table - port_instance = MagicMock() - port_instance_helper = port_instance - - asic_index = 0 - port = "Ethernet0" - fvp = {"get_fec": True} - - rc = handle_get_fec_cmd_arg_tbl_notification( - fvp, xcvrd_show_fec_rsp_tbl, xcvrd_show_fec_cmd_sts_tbl, xcvrd_show_fec_res_tbl, asic_index, port) - assert(rc == -1) - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_get_fec_cmd_arg_tbl_notification_get_result(self, port_instance, mock_swsscommon_table, port_instance_helper): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_show_fec_rsp_tbl = mock_swsscommon_table - xcvrd_show_fec_cmd_sts_tbl = mock_swsscommon_table - xcvrd_show_fec_res_tbl = mock_swsscommon_table - port_instance = MagicMock() - port_instance.get_fec_mode.return_value = 0 - port_instance.get_anlt.return_value = 0 - port_instance.get_speed.return_value = 0 - - asic_index = 0 - port = "Ethernet0" - fvp = {"get_fec": True} - - rc = handle_get_fec_cmd_arg_tbl_notification( - fvp, xcvrd_show_fec_rsp_tbl, xcvrd_show_fec_cmd_sts_tbl, xcvrd_show_fec_res_tbl, asic_index, port) - assert(rc == None) - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_get_fec_cmd_arg_tbl_notification_no_status(self, port_instance, mock_swsscommon_table, port_instance_helper): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_show_ber_cmd_arg_tbl = mock_swsscommon_table - xcvrd_show_ber_rsp_tbl = mock_swsscommon_table - xcvrd_show_ber_cmd_sts_tbl = mock_swsscommon_table - xcvrd_show_ber_res_tbl = mock_swsscommon_table - port_instance = MagicMock() - - asic_index = 0 - port = "Ethernet0" - fvp = {"show_event": True} - - rc = handle_show_ber_cmd_arg_tbl_notification( - fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port) - assert(rc == None) - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_get_fec_cmd_arg_tbl_notification_no_port(self, port_instance, mock_swsscommon_table, port_instance_helper): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_show_ber_cmd_arg_tbl = mock_swsscommon_table - xcvrd_show_ber_rsp_tbl = mock_swsscommon_table - xcvrd_show_ber_cmd_sts_tbl = mock_swsscommon_table - xcvrd_show_ber_res_tbl = mock_swsscommon_table - port_instance = MagicMock() - - asic_index = 0 - port = "Ethernet0" - fvp = {"get_ber": True} - - rc = handle_show_ber_cmd_arg_tbl_notification( - fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port) - assert(rc == -1) - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_get_fec_cmd_arg_tbl_notification_no_instance(self, port_instance, mock_swsscommon_table): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_show_ber_cmd_arg_tbl = mock_swsscommon_table - xcvrd_show_ber_rsp_tbl = mock_swsscommon_table - xcvrd_show_ber_cmd_sts_tbl = mock_swsscommon_table - xcvrd_show_ber_res_tbl = mock_swsscommon_table - port_instance = MagicMock() - - asic_index = 0 - port = "Ethernet0" - fvp = {"get_ber": True} - - rc = handle_show_ber_cmd_arg_tbl_notification( - fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port) - assert(rc == -1) - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "ber", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_get_fec_cmd_arg_tbl_notification_get_ber(self, port_instance, mock_swsscommon_table, port_instance_helper): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_show_ber_cmd_arg_tbl = mock_swsscommon_table - xcvrd_show_ber_rsp_tbl = mock_swsscommon_table - xcvrd_show_ber_cmd_sts_tbl = mock_swsscommon_table - xcvrd_show_ber_res_tbl = mock_swsscommon_table - port_instance = MagicMock() - port_instance.get_ber_info.return_value = ["100", "200"] - - asic_index = 0 - port = "Ethernet0" - fvp = {"get_ber": True} - - rc = handle_show_ber_cmd_arg_tbl_notification( - fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port) - assert(rc == None) - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "eye", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_get_fec_cmd_arg_tbl_notification_get_eye(self, port_instance, mock_swsscommon_table, port_instance_helper): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_show_ber_cmd_arg_tbl = mock_swsscommon_table - xcvrd_show_ber_rsp_tbl = mock_swsscommon_table - xcvrd_show_ber_cmd_sts_tbl = mock_swsscommon_table - xcvrd_show_ber_res_tbl = mock_swsscommon_table - port_instance = MagicMock() - port_instance.get_eye_info.return_value = ["100", "200"] - - asic_index = 0 - port = "Ethernet0" - fvp = {"get_ber": True} - - rc = handle_show_ber_cmd_arg_tbl_notification( - fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port) - assert(rc == None) - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec_stats", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_get_fec_cmd_arg_tbl_notification_get_fec_stats(self, port_instance, mock_swsscommon_table, port_instance_helper): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_show_ber_cmd_arg_tbl = mock_swsscommon_table - xcvrd_show_ber_rsp_tbl = mock_swsscommon_table - xcvrd_show_ber_cmd_sts_tbl = mock_swsscommon_table - xcvrd_show_ber_res_tbl = mock_swsscommon_table - port_instance = MagicMock() - port_instance.get_fec_stats.return_value = {"100": "200"} - - asic_index = 0 - port = "Ethernet0" - fvp = {"get_ber": True} - - rc = handle_show_ber_cmd_arg_tbl_notification( - fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port) - assert(rc == None) - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "pcs_stats", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_get_fec_cmd_arg_tbl_notification_get_pcs_stats(self, port_instance, mock_swsscommon_table, port_instance_helper): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_show_ber_cmd_arg_tbl = mock_swsscommon_table - xcvrd_show_ber_rsp_tbl = mock_swsscommon_table - xcvrd_show_ber_cmd_sts_tbl = mock_swsscommon_table - xcvrd_show_ber_res_tbl = mock_swsscommon_table - port_instance = MagicMock() - port_instance.get_pcs_stats.return_value = {"100": "200"} - - asic_index = 0 - port = "Ethernet0" - fvp = {"get_ber": True} - - rc = handle_show_ber_cmd_arg_tbl_notification( - fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port) - assert(rc == None) - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "cable_alive", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_get_fec_cmd_arg_tbl_notification_get_alive_status(self, port_instance, mock_swsscommon_table, port_instance_helper): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_show_ber_cmd_arg_tbl = mock_swsscommon_table - xcvrd_show_ber_rsp_tbl = mock_swsscommon_table - xcvrd_show_ber_cmd_sts_tbl = mock_swsscommon_table - xcvrd_show_ber_res_tbl = mock_swsscommon_table - port_instance = MagicMock() - port_instance.get_alive_status.return_value = True - - asic_index = 0 - port = "Ethernet0" - fvp = {"get_ber": True} - - rc = handle_show_ber_cmd_arg_tbl_notification( - fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port) - assert(rc == None) - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "debug_dump", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_get_fec_cmd_arg_tbl_notification_get_debug_dump_registers(self, port_instance, mock_swsscommon_table, port_instance_helper): + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_get_muxcable_info_true_exceptions_peer_side(self, platform_sfputil): + physical_port = 20 - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table + logical_port_name = "Ethernet20" + platform_sfputil.get_asic_id_for_logical_port = 0 + swsscommon.Table.return_value.get.return_value = ( + True, {"read_side": "2"}) - xcvrd_show_ber_cmd_arg_tbl = mock_swsscommon_table - xcvrd_show_ber_rsp_tbl = mock_swsscommon_table - xcvrd_show_ber_cmd_sts_tbl = mock_swsscommon_table - xcvrd_show_ber_res_tbl = mock_swsscommon_table - port_instance = MagicMock() - port_instance.debug_dump_registers.return_value = {"register1": "100"} + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - asic_index = 0 - port = "Ethernet0" - fvp = {"get_ber": True} + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 + self.TARGET_NIC = 1 + self.TARGET_TOR_A = 1 + self.TARGET_TOR_B = 1 + self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + self.FIRMWARE_DOWNLOAD_STATUS_FAILED = 2 + self.download_firmware_status = 0 + self.MUX_TOGGLE_STATUS_INPROGRESS = 1 + self.MUX_TOGGLE_STATUS_NOT_INITIATED_OR_FINISHED = 2 + self.MUX_TOGGLE_STATUS_FAILED = 2 + self.mux_toggle_status = 0 + self.SWITCH_COUNT_MANUAL = "manual" + self.SWITCH_COUNT_AUTO = "auto" - rc = handle_show_ber_cmd_arg_tbl_notification( - fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port) - assert(rc == None) - """ + def get_active_linked_tor_side(self): + raise NotImplementedError - def handle_config_firmware_roll_cmd_arg_tbl_notification(fvp, xcvrd_roll_fw_cmd_sts_tbl, xcvrd_roll_fw_rsp_tbl, asic_index, port): + def get_mux_direction(self): + raise NotImplementedError - fvp_dict = dict(fvp) + def get_switch_count_total(self, switch_count): + raise NotImplementedError + def get_eye_heights(self, tgt_tor): + raise NotImplementedError - if "rollback_firmware" in fvp_dict: - file_name = fvp_dict["rollback_firmware"] - status = 'False' + def is_link_active(self, tgt_nic): + return False - if file_name == 'null': - file_full_path = None - else: - file_full_path = '/usr/share/sonic/firmware/{}'.format(file_name) - if not os.path.isfile(file_full_path): - helper_logger.log_error("Error: cli cmd mux rollback firmware file does not exist port {} file {}".format(port, file_name)) - set_result_and_delete_port('status', status, xcvrd_roll_fw_cmd_sts_tbl[asic_index], xcvrd_roll_fw_rsp_tbl[asic_index], port) - break + def get_local_temperature(self): + raise NotImplementedError + def get_local_voltage(self): + raise NotImplementedError + def get_nic_voltage(self): + raise NotImplementedError - physical_port = get_ycable_physical_port_from_logical_port(port) - if physical_port is None or physical_port == PHYSICAL_PORT_MAPPING_ERROR: - # error scenario update table accordingly - helper_logger.log_warning("Error: Could not get physical port for cli cmd mux rollback firmware port {}".format(port)) - set_result_and_delete_port('status', status, xcvrd_roll_fw_cmd_sts_tbl[asic_index], xcvrd_roll_fw_rsp_tbl[asic_index], port) - break + def get_nic_temperature(self): + raise NotImplementedError - port_instance = get_ycable_port_instance_from_logical_port(port) - if port_instance is None or port_instance in port_mapping_error_values: - # error scenario update table accordingly - helper_logger.log_warning("Error: Could not get port instance for cli cmd mux rollback firmware port {}".format(port)) - set_result_and_delete_port('status', status, xcvrd_roll_fw_cmd_sts_tbl[asic_index], xcvrd_roll_fw_rsp_tbl[asic_index], port) + patched_util.get.return_value = PortInstanceHelper() - with y_cable_port_locks[physical_port]: - try: - status = port_instance.rollback_firmware(file_full_path) - except Exception as e: - status = -1 - helper_logger.log_warning("Failed to execute the rollback_firmware API for port {} due to {}".format(physical_port,repr(e))) - set_result_and_delete_port('status', status, xcvrd_roll_fw_cmd_sts_tbl[asic_index], xcvrd_roll_fw_rsp_tbl[asic_index], port) - else: - helper_logger.log_error("Wrong param for cli cmd mux rollback firmware port {}".format(port)) - set_result_and_delete_port('status', 'False', xcvrd_roll_fw_cmd_sts_tbl[asic_index], xcvrd_roll_fw_rsp_tbl[asic_index], port) - """ - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_config_firmware_roll_cmd_arg_tbl_notification_no_port(self, port_instance, mock_swsscommon_table, port_instance_helper): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_down_fw_cmd_sts_tbl = mock_swsscommon_table - xcvrd_down_fw_rsp_tbl = mock_swsscommon_table - port_instance = MagicMock() - - asic_index = 0 - port = "Ethernet0" - fvp = {"rollback_firmware": "null"} - - rc = handle_config_firmware_roll_cmd_arg_tbl_notification( - fvp, xcvrd_down_fw_cmd_sts_tbl, xcvrd_down_fw_rsp_tbl, asic_index, port) - assert(rc == -1) - - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_config_firmware_roll_cmd_arg_tbl_notification_no_instance(self, mock_swsscommon_table): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_down_fw_cmd_sts_tbl = mock_swsscommon_table - xcvrd_down_fw_rsp_tbl = mock_swsscommon_table - - asic_index = 0 - port = "Ethernet0" - fvp = {"rollback_firmware": "null"} - - rc = handle_config_firmware_roll_cmd_arg_tbl_notification( - fvp, xcvrd_down_fw_cmd_sts_tbl, xcvrd_down_fw_rsp_tbl, asic_index, port) - assert(rc == -1) - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_config_firmware_roll_cmd_arg_tbl_notification_with_instance(self, port_instance, mock_swsscommon_table): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_down_fw_cmd_sts_tbl = mock_swsscommon_table - xcvrd_down_fw_rsp_tbl = mock_swsscommon_table - port_instance = MagicMock() - - asic_index = 0 - port = "Ethernet0" - fvp = {"rollback_firmware": "null"} - - rc = handle_config_firmware_roll_cmd_arg_tbl_notification( - fvp, xcvrd_down_fw_cmd_sts_tbl, xcvrd_down_fw_rsp_tbl, asic_index, port) - assert(rc == None) - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_config_firmware_roll_cmd_arg_tbl_notification_no_port_and_instance(self, port_instance, mock_swsscommon_table, port_instance_helper): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_down_fw_cmd_sts_tbl = mock_swsscommon_table - xcvrd_down_fw_rsp_tbl = mock_swsscommon_table - port_instance = MagicMock() - - asic_index = 0 - port = "Ethernet0" - fvp = {"rollback_firmware": "null"} - - rc = handle_config_firmware_roll_cmd_arg_tbl_notification( - fvp, xcvrd_down_fw_cmd_sts_tbl, xcvrd_down_fw_rsp_tbl, asic_index, port) - assert(rc == -1) - - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('os.path.isfile', MagicMock(return_value=True)) - def test_handle_config_firmware_down_cmd_arg_tbl_notification_no_port(self, mock_swsscommon_table): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_down_fw_cmd_sts_tbl = mock_swsscommon_table - xcvrd_down_fw_rsp_tbl = mock_swsscommon_table - - asic_index = 0 - task_download_firmware_thread = {} - port = "Ethernet0" - fvp = {"download_firmware": "null"} - - rc = handle_config_firmware_down_cmd_arg_tbl_notification( - fvp, xcvrd_down_fw_cmd_sts_tbl, xcvrd_down_fw_rsp_tbl, asic_index, port, task_download_firmware_thread) - assert(rc == -1) - - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('os.path.isfile', MagicMock(return_value=True)) - def test_handle_config_firmware_down_cmd_arg_tbl_notification_else_condition(self, mock_swsscommon_table): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_down_fw_cmd_sts_tbl = mock_swsscommon_table - xcvrd_down_fw_rsp_tbl = mock_swsscommon_table - - asic_index = 0 - task_download_firmware_thread = {} - port = "Ethernet0" - fvp = {"downoad_firmware": "null"} - - rc = handle_config_firmware_down_cmd_arg_tbl_notification( - fvp, xcvrd_down_fw_cmd_sts_tbl, xcvrd_down_fw_rsp_tbl, asic_index, port, task_download_firmware_thread) - assert(rc == None) - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') - @patch('threading.Thread') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('os.path.isfile', MagicMock(return_value=True)) - def test_handle_config_firmware_down_cmd_arg_tbl_notification_with_instance(self, port_instance, mock_swsscommon_table, port_instance_helper, thread_obj): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_down_fw_cmd_sts_tbl = mock_swsscommon_table - xcvrd_down_fw_rsp_tbl = mock_swsscommon_table - port_instance = MagicMock() - thread_instance = MagicMock() - thread_instance.start = MagicMock() - thread_obj = thread_instance - port_instance_helper = port_instance - - asic_index = 0 - task_download_firmware_thread = {} - port = "Ethernet0" - fvp = {"download_firmware": "null"} - - rc = handle_config_firmware_down_cmd_arg_tbl_notification( - fvp, xcvrd_down_fw_cmd_sts_tbl, xcvrd_down_fw_rsp_tbl, asic_index, port, task_download_firmware_thread) - assert(rc == None) - - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('os.path.isfile', MagicMock(return_value=True)) - def test_handle_config_firmware_down_cmd_arg_tbl_notification_no_instance(self, mock_swsscommon_table): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_down_fw_cmd_sts_tbl = mock_swsscommon_table - xcvrd_down_fw_rsp_tbl = mock_swsscommon_table - - asic_index = 0 - task_download_firmware_thread = {} - port = "Ethernet0" - fvp = {"download_firmware": "null"} - - rc = handle_config_firmware_down_cmd_arg_tbl_notification( - fvp, xcvrd_down_fw_cmd_sts_tbl, xcvrd_down_fw_rsp_tbl, asic_index, port, task_download_firmware_thread) - assert(rc == -1) - - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('os.path.isfile', MagicMock(return_value=True)) - def test_handle_config_firmware_acti_cmd_arg_tbl_notification_no_port(self, mock_swsscommon_table): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_down_fw_cmd_sts_tbl = mock_swsscommon_table - xcvrd_down_fw_rsp_tbl = mock_swsscommon_table - xcvrd_acti_fw_cmd_arg_tbl = mock_swsscommon_table - - asic_index = 0 - task_download_firmware_thread = {} - port = "Ethernet0" - fvp = {"activate_firmware": "null"} - - rc = handle_config_firmware_acti_cmd_arg_tbl_notification( - fvp, xcvrd_down_fw_cmd_sts_tbl, xcvrd_down_fw_rsp_tbl, xcvrd_acti_fw_cmd_arg_tbl, asic_index, port) - assert(rc == -1) - - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('os.path.isfile', MagicMock(return_value=True)) - def test_handle_config_firmware_acti_cmd_arg_tbl_notification_else_condition(self, mock_swsscommon_table): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_down_fw_cmd_sts_tbl = mock_swsscommon_table - xcvrd_down_fw_rsp_tbl = mock_swsscommon_table - xcvrd_acti_fw_cmd_arg_tbl = mock_swsscommon_table - - asic_index = 0 - task_download_firmware_thread = {} - port = "Ethernet0" - fvp = {"down_firmware": "null"} - - rc = handle_config_firmware_acti_cmd_arg_tbl_notification( - fvp, xcvrd_down_fw_cmd_sts_tbl, xcvrd_down_fw_rsp_tbl, xcvrd_acti_fw_cmd_arg_tbl, asic_index, port) - assert(rc == None) - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "activate_firmware", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('os.path.isfile', MagicMock(return_value=True)) - @patch('time.sleep', MagicMock(return_value=True)) - def test_handle_config_firmware_acti_cmd_arg_tbl_notification_with_instance(self, port_instance, mock_swsscommon_table, port_instance_helper): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_down_fw_cmd_sts_tbl = mock_swsscommon_table - xcvrd_down_fw_rsp_tbl = mock_swsscommon_table - xcvrd_acti_fw_cmd_arg_tbl = mock_swsscommon_table - port_instance = MagicMock() - port_instance.activate_firmware = MagicMock(return_value=True) - thread_instance = MagicMock() - thread_instance.start = MagicMock() - thread_obj = thread_instance - port_instance_helper = port_instance - - asic_index = 0 - task_download_firmware_thread = {} - port = "Ethernet0" - fvp = {"activate_firmware": "null"} - - rc = handle_config_firmware_acti_cmd_arg_tbl_notification( - fvp, xcvrd_down_fw_cmd_sts_tbl, xcvrd_down_fw_rsp_tbl, xcvrd_acti_fw_cmd_arg_tbl, asic_index, port) - assert(rc == None) - - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('os.path.isfile', MagicMock(return_value=True)) - def test_handle_config_firmware_acti_cmd_arg_tbl_notification_no_instance(self, mock_swsscommon_table): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_down_fw_cmd_sts_tbl = mock_swsscommon_table - xcvrd_down_fw_rsp_tbl = mock_swsscommon_table - xcvrd_acti_fw_cmd_arg_tbl = mock_swsscommon_table - - asic_index = 0 - task_download_firmware_thread = {} - port = "Ethernet0" - fvp = {"activate_firmware": "null"} - - rc = handle_config_firmware_acti_cmd_arg_tbl_notification( - fvp, xcvrd_down_fw_cmd_sts_tbl, xcvrd_down_fw_rsp_tbl, xcvrd_acti_fw_cmd_arg_tbl, asic_index, port) - assert(rc == -1) - - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('os.path.isfile', MagicMock(return_value=True)) - def test_handle_show_firmware_show_cmd_arg_tbl_notification_no_port(self, mock_swsscommon_table): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_down_fw_cmd_sts_tbl = mock_swsscommon_table - xcvrd_down_fw_rsp_tbl = mock_swsscommon_table - xcvrd_acti_fw_cmd_arg_tbl = mock_swsscommon_table - xcvrd_show_fw_res_tbl = mock_swsscommon_table - - asic_index = 0 - task_download_firmware_thread = {} - port = "Ethernet0" - fvp = {"firmware_version": "null"} - - rc = handle_show_firmware_show_cmd_arg_tbl_notification( - fvp, xcvrd_down_fw_cmd_sts_tbl, xcvrd_down_fw_rsp_tbl, xcvrd_show_fw_res_tbl, asic_index, port) - assert(rc == -1) - - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('os.path.isfile', MagicMock(return_value=True)) - def test_handle_show_firmware_show_cmd_arg_tbl_notification_else_condition(self, mock_swsscommon_table): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_down_fw_cmd_sts_tbl = mock_swsscommon_table - xcvrd_down_fw_rsp_tbl = mock_swsscommon_table - xcvrd_acti_fw_cmd_arg_tbl = mock_swsscommon_table - xcvrd_show_fw_res_tbl = mock_swsscommon_table - - asic_index = 0 - task_download_firmware_thread = {} - port = "Ethernet0" - fvp = {"down_firmware": "null"} - - rc = handle_show_firmware_show_cmd_arg_tbl_notification( - fvp, xcvrd_down_fw_cmd_sts_tbl, xcvrd_down_fw_rsp_tbl, xcvrd_show_fw_res_tbl, asic_index, port) - assert(rc == None) - - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "activate_firmware", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('os.path.isfile', MagicMock(return_value=True)) - @patch('time.sleep', MagicMock(return_value=True)) - def test_handle_show_firmware_show_cmd_arg_tbl_notification_with_instance(self, mock_swsscommon_table, platform_sfputil): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_down_fw_cmd_sts_tbl = mock_swsscommon_table - xcvrd_down_fw_rsp_tbl = mock_swsscommon_table - xcvrd_acti_fw_cmd_arg_tbl = mock_swsscommon_table - xcvrd_show_fw_res_tbl = mock_swsscommon_table - asic_index = 0 - task_download_firmware_thread = {} - port = "Ethernet0" - platform_sfputil.get_asic_id_for_logical_port = 0 - fvp = {"firmware_version": "null"} - - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - class PortInstanceHelper(): - def __init__(self): - self.EEPROM_ERROR = -1 - self.TARGET_NIC = 1 - self.TARGET_TOR_A = 1 - self.TARGET_TOR_B = 1 - self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - self.FIRMWARE_DOWNLOAD_STATUS_FAILED = 2 - self.download_firmware_status = 0 - self.MUX_TOGGLE_STATUS_INPROGRESS = 1 - self.MUX_TOGGLE_STATUS_FAILED = 2 - self.MUX_TOGGLE_STATUS_NOT_INITIATED_OR_FINISHED = 2 - self.mux_toggle_status = 0 - self.SWITCH_COUNT_MANUAL = "manual" - self.SWITCH_COUNT_AUTO = "auto" - - def get_read_side(self): - return 1 - - # Defining function without self argument creates an exception, - # which is what we want for this test. - def get_mux_direction(): - pass + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: + patched_util.get_asic_id_for_logical_port.return_value = 0 - patched_util.get.return_value = PortInstanceHelper() - rc = handle_show_firmware_show_cmd_arg_tbl_notification( - fvp, xcvrd_down_fw_cmd_sts_tbl, xcvrd_down_fw_rsp_tbl, xcvrd_show_fw_res_tbl, asic_index, port) - assert(rc == None) + rc = get_muxcable_info(physical_port, logical_port_name) - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('os.path.isfile', MagicMock(return_value=True)) - def test_handle_show_firmware_show_cmd_arg_tbl_notification_no_instance(self, mock_swsscommon_table): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_down_fw_cmd_sts_tbl = mock_swsscommon_table - xcvrd_down_fw_rsp_tbl = mock_swsscommon_table - xcvrd_acti_fw_cmd_arg_tbl = mock_swsscommon_table - xcvrd_show_fw_res_tbl = mock_swsscommon_table - - asic_index = 0 - task_download_firmware_thread = {} - port = "Ethernet0" - fvp = {"firmware_version": "null"} - - rc = handle_show_firmware_show_cmd_arg_tbl_notification( - fvp, xcvrd_down_fw_cmd_sts_tbl, xcvrd_down_fw_rsp_tbl, xcvrd_show_fw_res_tbl, asic_index, port) - assert(rc == -1) - - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('os.path.isfile', MagicMock(return_value=True)) - def test_handle_config_mux_switchmode_cmd_arg_tbl_notification_no_port(self, mock_swsscommon_table): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_config_hwmode_swmode_cmd_sts_tbl = mock_swsscommon_table - xcvrd_config_hwmode_swmode_rsp_tbl = mock_swsscommon_table - xcvrd_acti_fw_cmd_arg_tbl = mock_swsscommon_table - xcvrd_show_fw_res_tbl = mock_swsscommon_table - - asic_index = 0 - task_download_firmware_thread = {} - port = "Ethernet0" - fvp = {"config": "null"} - - rc = handle_config_mux_switchmode_arg_tbl_notification( - fvp, xcvrd_config_hwmode_swmode_cmd_sts_tbl, xcvrd_config_hwmode_swmode_rsp_tbl, asic_index, port) - assert(rc == -1) - - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('os.path.isfile', MagicMock(return_value=True)) - def test_handle_config_mux_switchmode_cmd_arg_tbl_notification_else_condition(self, mock_swsscommon_table): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_config_hwmode_swmode_cmd_sts_tbl = mock_swsscommon_table - xcvrd_config_hwmode_swmode_rsp_tbl = mock_swsscommon_table - - asic_index = 0 - task_download_firmware_thread = {} - port = "Ethernet0" - fvp = {"down_firmware": "null"} - - rc = handle_config_mux_switchmode_arg_tbl_notification( - fvp, xcvrd_config_hwmode_swmode_cmd_sts_tbl, xcvrd_config_hwmode_swmode_rsp_tbl, asic_index, port) - assert(rc == None) - - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "activate_firmware", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('os.path.isfile', MagicMock(return_value=True)) - @patch('time.sleep', MagicMock(return_value=True)) - def test_handle_config_mux_switchmode_cmd_arg_tbl_notification_with_instance_manual(self, mock_swsscommon_table, platform_sfputil): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_config_hwmode_swmode_cmd_sts_tbl = mock_swsscommon_table - xcvrd_config_hwmode_swmode_rsp_tbl = mock_swsscommon_table - asic_index = 0 - task_download_firmware_thread = {} - port = "Ethernet0" - platform_sfputil.get_asic_id_for_logical_port = 0 - fvp = {"config": "manual"} - - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - class PortInstanceHelper(): - def __init__(self): - self.EEPROM_ERROR = -1 - self.TARGET_NIC = 1 - self.TARGET_TOR_A = 1 - self.TARGET_TOR_B = 1 - self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - self.FIRMWARE_DOWNLOAD_STATUS_FAILED = 2 - self.download_firmware_status = 0 - self.SWITCH_COUNT_MANUAL = "manual" - self.SWITCH_COUNT_AUTO = "auto" - self.SWITCHING_MODE_MANUAL = "manual" - - def get_read_side(self): - return 1 - - def set_switching_mode(self, mode): - return True - - # Defining function without self argument creates an exception, - # which is what we want for this test. - def get_mux_direction(): - pass + assert(rc['tor_active'] == 'unknown') + assert(rc['mux_direction'] == 'unknown') + assert(rc['self_eye_height_lane1'] == 'N/A') - patched_util.get.return_value = PortInstanceHelper() - rc = handle_config_mux_switchmode_arg_tbl_notification( - fvp, xcvrd_config_hwmode_swmode_cmd_sts_tbl, xcvrd_config_hwmode_swmode_rsp_tbl, asic_index, port) - assert(rc == None) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_get_muxcable_info_true_exceptions(self, platform_sfputil): + physical_port = 20 - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('os.path.isfile', MagicMock(return_value=True)) - def test_handle_config_mux_switchmode_cmd_arg_tbl_notification_no_instance(self, mock_swsscommon_table): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_config_hwmode_swmode_cmd_sts_tbl = mock_swsscommon_table - xcvrd_config_hwmode_swmode_rsp_tbl = mock_swsscommon_table - xcvrd_show_hwmode_swmode_cmd_sts_tbl = mock_swsscommon_table - xcvrd_show_hwmode_swmode_rsp_tbl = mock_swsscommon_table - - asic_index = 0 - task_download_firmware_thread = {} - port = "Ethernet0" - fvp = {"config": "manual"} - - rc = handle_config_mux_switchmode_arg_tbl_notification( - fvp, xcvrd_config_hwmode_swmode_cmd_sts_tbl, xcvrd_config_hwmode_swmode_rsp_tbl, asic_index, port) - assert(rc == -1) - - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "activate_firmware", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('os.path.isfile', MagicMock(return_value=True)) - @patch('time.sleep', MagicMock(return_value=True)) - def test_handle_config_mux_switchmode_cmd_arg_tbl_notification_with_instance_auto(self, mock_swsscommon_table, platform_sfputil): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_config_hwmode_swmode_cmd_sts_tbl = mock_swsscommon_table - xcvrd_config_hwmode_swmode_rsp_tbl = mock_swsscommon_table - xcvrd_show_hwmode_swmode_cmd_sts_tbl = mock_swsscommon_table - xcvrd_show_hwmode_swmode_rsp_tbl = mock_swsscommon_table - asic_index = 0 - task_download_firmware_thread = {} - port = "Ethernet0" - platform_sfputil.get_asic_id_for_logical_port = 0 - fvp = {"config": "auto"} - - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - class PortInstanceHelper(): - def __init__(self): - self.EEPROM_ERROR = -1 - self.TARGET_NIC = 1 - self.TARGET_TOR_A = 1 - self.TARGET_TOR_B = 1 - self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - self.FIRMWARE_DOWNLOAD_STATUS_FAILED = 2 - self.download_firmware_status = 0 - self.SWITCH_COUNT_MANUAL = "manual" - self.SWITCH_COUNT_AUTO = "auto" - self.SWITCHING_MODE_MANUAL = "manual" - self.SWITCHING_MODE_AUTO = "auto" - - def get_read_side(self): - return 1 - - def set_switching_mode(self, mode): - return True - - # Defining function without self argument creates an exception, - # which is what we want for this test. - def get_mux_direction(): - pass + logical_port_name = "Ethernet20" + platform_sfputil.get_asic_id_for_logical_port = 0 - patched_util.get.return_value = PortInstanceHelper() - rc = handle_config_mux_switchmode_arg_tbl_notification( - fvp, xcvrd_config_hwmode_swmode_cmd_sts_tbl, xcvrd_config_hwmode_swmode_rsp_tbl, asic_index, port) + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 + self.TARGET_NIC = 1 + self.TARGET_TOR_A = 1 + self.TARGET_TOR_B = 1 + self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + self.FIRMWARE_DOWNLOAD_STATUS_FAILED = 2 + self.download_firmware_status = 0 + self.MUX_TOGGLE_STATUS_INPROGRESS = 1 + self.MUX_TOGGLE_STATUS_FAILED = 2 + self.MUX_TOGGLE_STATUS_NOT_INITIATED_OR_FINISHED = 2 + self.mux_toggle_status = 0 + self.SWITCH_COUNT_MANUAL = "manual" + self.SWITCH_COUNT_AUTO = "auto" + + def get_active_linked_tor_side(self): + raise NotImplementedError + + def get_mux_direction(self): + raise NotImplementedError + + def get_switch_count_total(self, switch_count): + raise NotImplementedError + + def get_eye_heights(self, tgt_tor): + raise NotImplementedError + + def is_link_active(self, tgt_nic): + return False + + def get_local_temperature(self): + raise NotImplementedError + + def get_local_voltage(self): + raise NotImplementedError + + def get_nic_voltage(self): + raise NotImplementedError + + def get_nic_temperature(self): + raise NotImplementedError + + patched_util.get.return_value = PortInstanceHelper() + + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: + patched_util.get_asic_id_for_logical_port.return_value = 0 + + rc = get_muxcable_info(physical_port, logical_port_name) + + assert(rc['tor_active'] == 'unknown') + assert(rc['mux_direction'] == 'unknown') + assert(rc['self_eye_height_lane1'] == 'N/A') + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_get_muxcable_info_exceptions_peer_side(self, platform_sfputil): + physical_port = 20 + + logical_port_name = "Ethernet20" + platform_sfputil.get_asic_id_for_logical_port = 0 + swsscommon.Table.return_value.get.return_value = ( + True, {"read_side": "2"}) + + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 + self.TARGET_NIC = 1 + self.TARGET_TOR_A = 1 + self.TARGET_TOR_B = 1 + self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + self.FIRMWARE_DOWNLOAD_STATUS_FAILED = 2 + self.download_firmware_status = 0 + self.MUX_TOGGLE_STATUS_INPROGRESS = 1 + self.MUX_TOGGLE_STATUS_NOT_INITIATED_OR_FINISHED = 2 + self.mux_toggle_status = 0 + self.SWITCH_COUNT_MANUAL = "manual" + self.SWITCH_COUNT_AUTO = "auto" + + def get_active_linked_tor_side(): + return 1 + + def get_mux_direction(): + return 1 + + def get_switch_count_total(self, switch_count): + return 1 + + def get_eye_heights(tgt_tor): + return 500 + + def is_link_active(self, tgt_nic): + return True + + def get_local_temperature(): + return 22.75 + + def get_local_voltage(): + return 0.5 + + def get_nic_voltage(): + return 2.7 + + def get_nic_temperature(): + return 20 + + patched_util.get.return_value = PortInstanceHelper() + + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: + patched_util.get_asic_id_for_logical_port.return_value = 0 + + rc = get_muxcable_info(physical_port, logical_port_name) + + assert(rc['tor_active'] == 'unknown') + assert(rc['mux_direction'] == 'unknown') + assert(rc['self_eye_height_lane1'] == 'N/A') + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_get_muxcable_static_info(self, platform_sfputil): + physical_port = 0 + + logical_port_name = "Ethernet0" + + platform_sfputil.get_asic_id_for_logical_port = 0 + swsscommon.Table.return_value.get.return_value = ( + True, {"read_side": "1"}) + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 + self.TARGET_NIC = 0 + self.TARGET_TOR_A = 1 + self.TARGET_TOR_B = 2 + self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + self.download_firmware_status = 1 + self.MUX_TOGGLE_STATUS_INPROGRESS = 1 + self.MUX_TOGGLE_STATUS_FAILED = 2 + self.MUX_TOGGLE_STATUS_NOT_INITIATED_OR_FINISHED = 2 + self.mux_toggle_status = 0 + self.SWITCH_COUNT_MANUAL = "manual" + self.SWITCH_COUNT_AUTO = "auto" + + def get_target_cursor_values(self, i, tgt): + if (tgt == self.TARGET_NIC): + return ([1, 7, 7, 1, 0]) + elif (tgt == self.TARGET_TOR_A): + return ([17, 17, 17, 17, 17]) + elif (tgt == self.TARGET_TOR_B): + return ([-17, -17, -17, -17, -17]) + + patched_util.get.return_value = PortInstanceHelper() + + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: + patched_util.get_asic_id_for_logical_port.return_value = 0 + rc = get_muxcable_static_info(physical_port, logical_port_name) + + assert (rc['read_side'] == 'tor1') + assert (rc['nic_lane1_precursor1'] == 1) + assert (rc['nic_lane1_precursor2'] == 7) + assert (rc['nic_lane1_maincursor'] == 7) + assert (rc['nic_lane1_postcursor1'] == 1) + assert (rc['nic_lane1_postcursor2'] == 0) + + assert (rc['nic_lane2_precursor1'] == 1) + assert (rc['nic_lane2_precursor2'] == 7) + assert (rc['nic_lane2_maincursor'] == 7) + assert (rc['nic_lane2_postcursor1'] == 1) + assert (rc['nic_lane2_postcursor2'] == 0) + + assert (rc['tor_self_lane1_precursor1'] == 17) + assert (rc['tor_self_lane1_precursor2'] == 17) + assert (rc['tor_self_lane1_maincursor'] == 17) + assert (rc['tor_self_lane1_postcursor1'] == 17) + assert (rc['tor_self_lane1_postcursor2'] == 17) + + assert (rc['tor_self_lane2_precursor1'] == 17) + assert (rc['tor_self_lane2_precursor2'] == 17) + assert (rc['tor_self_lane2_maincursor'] == 17) + assert (rc['tor_self_lane2_postcursor1'] == 17) + assert (rc['tor_self_lane2_postcursor2'] == 17) + + assert (rc['tor_peer_lane1_precursor1'] == -17) + assert (rc['tor_peer_lane1_precursor2'] == -17) + assert (rc['tor_peer_lane1_maincursor'] == -17) + assert (rc['tor_peer_lane1_postcursor1'] == -17) + assert (rc['tor_peer_lane1_postcursor2'] == -17) + + assert (rc['tor_peer_lane2_precursor1'] == -17) + assert (rc['tor_peer_lane2_precursor2'] == -17) + assert (rc['tor_peer_lane2_maincursor'] == -17) + assert (rc['tor_peer_lane2_postcursor1'] == -17) + assert (rc['tor_peer_lane2_postcursor2'] == -17) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_get_muxcable_static_info_read_side_peer(self, platform_sfputil): + physical_port = 0 + + logical_port_name = "Ethernet0" + + #swsscommon.Table = MagicMock() + # this patch is already done as global instance + platform_sfputil.get_asic_id_for_logical_port = 0 + swsscommon.Table.return_value.get.return_value = ( + True, {"read_side": "2"}) + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 + self.TARGET_NIC = 0 + self.TARGET_TOR_A = 1 + self.TARGET_TOR_B = 2 + self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + self.download_firmware_status = 1 + self.MUX_TOGGLE_STATUS_INPROGRESS = 1 + self.MUX_TOGGLE_STATUS_FAILED = 2 + self.MUX_TOGGLE_STATUS_NOT_INITIATED_OR_FINISHED = 2 + self.mux_toggle_status = 0 + self.SWITCH_COUNT_MANUAL = "manual" + self.SWITCH_COUNT_AUTO = "auto" + + def get_target_cursor_values(self, i, tgt): + if (tgt == self.TARGET_NIC): + return ([1, 7, 7, 1, 0]) + elif (tgt == self.TARGET_TOR_A): + return ([-17, -17, -17, -17, -17]) + elif (tgt == self.TARGET_TOR_B): + return ([-17, -17, -17, -17, -17]) + + patched_util.get.return_value = PortInstanceHelper() + + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: + patched_util.get_asic_id_for_logical_port.return_value = 0 + rc = get_muxcable_static_info(physical_port, logical_port_name) + + assert (rc['read_side'] == 'tor2') + assert (rc['nic_lane1_precursor1'] == 1) + assert (rc['nic_lane1_precursor2'] == 7) + assert (rc['nic_lane1_maincursor'] == 7) + assert (rc['nic_lane1_postcursor1'] == 1) + assert (rc['nic_lane1_postcursor2'] == 0) + + assert (rc['nic_lane2_precursor1'] == 1) + assert (rc['nic_lane2_precursor2'] == 7) + assert (rc['nic_lane2_maincursor'] == 7) + assert (rc['nic_lane2_postcursor1'] == 1) + assert (rc['nic_lane2_postcursor2'] == 0) + + assert (rc['tor_self_lane1_precursor1'] == -17) + assert (rc['tor_self_lane1_precursor2'] == -17) + assert (rc['tor_self_lane1_maincursor'] == -17) + assert (rc['tor_self_lane1_postcursor1'] == -17) + assert (rc['tor_self_lane1_postcursor2'] == -17) + + assert (rc['tor_self_lane2_precursor1'] == -17) + assert (rc['tor_self_lane2_precursor2'] == -17) + assert (rc['tor_self_lane2_maincursor'] == -17) + assert (rc['tor_self_lane2_postcursor1'] == -17) + assert (rc['tor_self_lane2_postcursor2'] == -17) + + assert (rc['tor_peer_lane1_precursor1'] == -17) + assert (rc['tor_peer_lane1_precursor2'] == -17) + assert (rc['tor_peer_lane1_maincursor'] == -17) + assert (rc['tor_peer_lane1_postcursor1'] == -17) + assert (rc['tor_peer_lane1_postcursor2'] == -17) + + assert (rc['tor_peer_lane2_precursor1'] == -17) + assert (rc['tor_peer_lane2_precursor2'] == -17) + assert (rc['tor_peer_lane2_maincursor'] == -17) + assert (rc['tor_peer_lane2_postcursor1'] == -17) + assert (rc['tor_peer_lane2_postcursor2'] == -17) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_get_muxcable_static_info_read_side_peer_exceptions(self, platform_sfputil): + physical_port = 0 + + logical_port_name = "Ethernet0" + + #swsscommon.Table = MagicMock() + # this patch is already done as global instance + platform_sfputil.get_asic_id_for_logical_port = 0 + swsscommon.Table.return_value.get.return_value = ( + True, {"read_side": "2"}) + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 + self.TARGET_NIC = 0 + self.TARGET_TOR_A = 1 + self.TARGET_TOR_B = 2 + self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + self.download_firmware_status = 1 + self.MUX_TOGGLE_STATUS_INPROGRESS = 1 + self.MUX_TOGGLE_STATUS_FAILED = 2 + self.MUX_TOGGLE_STATUS_NOT_INITIATED_OR_FINISHED = 2 + self.mux_toggle_status = 0 + self.SWITCH_COUNT_MANUAL = "manual" + self.SWITCH_COUNT_AUTO = "auto" + + def get_target_cursor_values(self, i, tgt): + raise NotImplementedError + + patched_util.get.return_value = PortInstanceHelper() + + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: + patched_util.get_asic_id_for_logical_port.return_value = 0 + rc = get_muxcable_static_info(physical_port, logical_port_name) + + assert (rc['read_side'] == 'tor2') + assert (rc['nic_lane1_precursor1'] == "N/A") + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + def test_task_download_firmware_worker(self, port_instance, mock_swsscommon_table): + port = "Ethernet0" + physical_port = 0 + file_full_path = "/path/to/file" + + def mock_download_fw(filepath): + return 0 + + port_instance.download_firmware = mock_download_fw + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_down_fw_rsp_tbl = mock_swsscommon_table + xcvrd_down_fw_cmd_sts_tbl = mock_swsscommon_table + + rc = {} + + task_download_firmware_worker(port, physical_port, port_instance, file_full_path, + xcvrd_down_fw_rsp_tbl, xcvrd_down_fw_cmd_sts_tbl, rc) + + assert(rc[0] == 0) + + def test_set_show_firmware_fields(self): + + mux_info_dict = {} + xcvrd_show_fw_res_tbl = Table("STATE_DB", "XCVRD_SHOW_FW_RES") + mux_info_dict['version_self_active'] = '0.8' + mux_info_dict['version_self_inactive'] = '0.7' + mux_info_dict['version_self_next'] = '0.7' + mux_info_dict['version_peer_active'] = '0.8' + mux_info_dict['version_peer_inactive'] = '0.7' + mux_info_dict['version_peer_next'] = '0.7' + mux_info_dict['version_nic_active'] = '0.8' + mux_info_dict['version_nic_inactive'] = '0.7' + mux_info_dict['version_nic_next'] = '0.7' + rc = set_show_firmware_fields( + "Ethernet0", mux_info_dict, xcvrd_show_fw_res_tbl) + + assert(rc == 0) + + @patch('sonic_py_common.device_info.get_paths_to_platform_and_hwsku_dirs', MagicMock(return_value=('/tmp', None))) + @patch('swsscommon.swsscommon.WarmStart', MagicMock()) + @patch('ycable.ycable.platform_sfputil', MagicMock()) + @patch('ycable.ycable.DaemonYcable.load_platform_util', MagicMock()) + def test_DaemonYcable_init_deinit(self): + ycable = DaemonYcable(SYSLOG_IDENTIFIER) + ycable.init() + ycable.deinit() + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "enable", {"mode_value": "0", + "lane_mask": "0", + "direction": "0"}))) + def test_handle_config_prbs_cmd_arg_tbl_notification_no_port(self, port_instance, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_config_prbs_cmd_arg_tbl = mock_swsscommon_table + xcvrd_config_prbs_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_prbs_rsp_tbl = mock_swsscommon_table + asic_index = 0 + port = "Ethernet0" + fvp = {"config_prbs": True} + + rc = handle_config_prbs_cmd_arg_tbl_notification( + fvp, xcvrd_config_prbs_cmd_arg_tbl, xcvrd_config_prbs_cmd_sts_tbl, xcvrd_config_prbs_rsp_tbl, asic_index, port) + assert(rc == -1) + + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "enable", {"mode_value": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + def test_handle_config_prbs_cmd_arg_tbl_notification_no_instance(self, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_config_prbs_cmd_arg_tbl = mock_swsscommon_table + xcvrd_config_prbs_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_prbs_rsp_tbl = mock_swsscommon_table + asic_index = 0 + port = "Ethernet0" + fvp = {"config_prbs": True} + + rc = handle_config_prbs_cmd_arg_tbl_notification( + fvp, xcvrd_config_prbs_cmd_arg_tbl, xcvrd_config_prbs_cmd_sts_tbl, xcvrd_config_prbs_rsp_tbl, asic_index, port) + assert(rc == -1) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "enable", {"mode_value": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_config_prbs_cmd_arg_tbl_notification_with_instance_enable(self, port_instance, mock_swsscommon_table, port_instance_helper): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_config_prbs_cmd_arg_tbl = mock_swsscommon_table + xcvrd_config_prbs_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_prbs_rsp_tbl = mock_swsscommon_table + port_instance = MagicMock() + port_instance.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + port_instance.PRBS_DIRECTION_BOTH = 2 + port_instance.enable_prbs_mode.return_value = True + port_instance.disable_prbs_mode.return_value = True + port_instance_helper = port_instance + + asic_index = 0 + port = "Ethernet0" + fvp = {"config_prbs": True} + + rc = handle_config_prbs_cmd_arg_tbl_notification( + fvp, xcvrd_config_prbs_cmd_arg_tbl, xcvrd_config_prbs_cmd_sts_tbl, xcvrd_config_prbs_rsp_tbl, asic_index, port) assert(rc == None) - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('os.path.isfile', MagicMock(return_value=True)) - def test_handle_show_mux_switchmode_cmd_arg_tbl_notification_no_port(self, mock_swsscommon_table): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_config_hwmode_swmode_cmd_sts_tbl = mock_swsscommon_table - xcvrd_config_hwmode_swmode_rsp_tbl = mock_swsscommon_table - xcvrd_show_hwmode_swmode_cmd_sts_tbl = mock_swsscommon_table - xcvrd_show_hwmode_swmode_rsp_tbl = mock_swsscommon_table - - asic_index = 0 - task_download_firmware_thread = {} - port = "Ethernet0" - fvp = {"state": "null"} - - rc = handle_show_hwmode_swmode_cmd_arg_tbl_notification( - fvp, xcvrd_show_hwmode_swmode_cmd_sts_tbl, xcvrd_show_hwmode_swmode_rsp_tbl, asic_index, port) - assert(rc == -1) - - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('os.path.isfile', MagicMock(return_value=True)) - def test_handle_show_mux_switchmode_cmd_arg_tbl_notification_else_condition(self, mock_swsscommon_table): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_config_hwmode_swmode_cmd_sts_tbl = mock_swsscommon_table - xcvrd_config_hwmode_swmode_rsp_tbl = mock_swsscommon_table - xcvrd_show_hwmode_swmode_cmd_sts_tbl = mock_swsscommon_table - xcvrd_show_hwmode_swmode_rsp_tbl = mock_swsscommon_table - - asic_index = 0 - task_download_firmware_thread = {} - port = "Ethernet0" - fvp = {"down_firmware": "null"} - - rc = handle_show_hwmode_swmode_cmd_arg_tbl_notification( - fvp, xcvrd_show_hwmode_swmode_cmd_sts_tbl, xcvrd_show_hwmode_swmode_rsp_tbl, asic_index, port) - assert(rc == None) - - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "activate_firmware", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('os.path.isfile', MagicMock(return_value=True)) - @patch('time.sleep', MagicMock(return_value=True)) - def test_handle_show_mux_switchmode_cmd_arg_tbl_notification_with_instance_manual(self, mock_swsscommon_table, platform_sfputil): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_config_hwmode_swmode_cmd_sts_tbl = mock_swsscommon_table - xcvrd_config_hwmode_swmode_rsp_tbl = mock_swsscommon_table - xcvrd_show_hwmode_swmode_cmd_sts_tbl = mock_swsscommon_table - xcvrd_show_hwmode_swmode_rsp_tbl = mock_swsscommon_table - asic_index = 0 - task_download_firmware_thread = {} - port = "Ethernet0" - platform_sfputil.get_asic_id_for_logical_port = 0 - fvp = {"state": "manual"} - - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - class PortInstanceHelper(): - def __init__(self): - self.EEPROM_ERROR = -1 - self.TARGET_NIC = 1 - self.TARGET_TOR_A = 1 - self.TARGET_TOR_B = 1 - self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - self.FIRMWARE_DOWNLOAD_STATUS_FAILED = 2 - self.download_firmware_status = 0 - self.SWITCH_COUNT_MANUAL = "manual" - self.SWITCH_COUNT_AUTO = 0 - self.SWITCHING_MODE_MANUAL = 0 - self.SWITCHING_MODE_AUTO = 1 - - def get_read_side(self): - return 1 - - def get_switching_mode(self): - return 0 + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "disable", {"mode_value": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_config_prbs_cmd_arg_tbl_notification_with_instance_disable(self, port_instance, mock_swsscommon_table, port_instance_helper): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_config_prbs_cmd_arg_tbl = mock_swsscommon_table + xcvrd_config_prbs_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_prbs_rsp_tbl = mock_swsscommon_table + port_instance = MagicMock() + port_instance.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + port_instance.PRBS_DIRECTION_BOTH = 2 + port_instance.enable_prbs_mode.return_value = True + port_instance.disable_prbs_mode.return_value = True + port_instance_helper = port_instance + + asic_index = 0 + port = "Ethernet0" + fvp = {"config_prbs": True} + + rc = handle_config_prbs_cmd_arg_tbl_notification( + fvp, xcvrd_config_prbs_cmd_arg_tbl, xcvrd_config_prbs_cmd_sts_tbl, xcvrd_config_prbs_rsp_tbl, asic_index, port) + assert(rc == None) - # Defining function without self argument creates an exception, - # which is what we want for this test. - def get_mux_direction(): - pass + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "reset", {"mode_value": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_config_prbs_cmd_arg_tbl_notification_with_instance_reset(self, port_instance, mock_swsscommon_table, port_instance_helper): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_config_prbs_cmd_arg_tbl = mock_swsscommon_table + xcvrd_config_prbs_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_prbs_rsp_tbl = mock_swsscommon_table + port_instance = MagicMock() + port_instance.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + port_instance.PRBS_DIRECTION_BOTH = 2 + port_instance.enable_prbs_mode.return_value = True + port_instance.disable_prbs_mode.return_value = True + port_instance.reset.return_value = True + port_instance_helper = port_instance + + asic_index = 0 + port = "Ethernet0" + fvp = {"config_prbs": True} + + rc = handle_config_prbs_cmd_arg_tbl_notification( + fvp, xcvrd_config_prbs_cmd_arg_tbl, xcvrd_config_prbs_cmd_sts_tbl, xcvrd_config_prbs_rsp_tbl, asic_index, port) + assert(rc == None) - patched_util.get.return_value = PortInstanceHelper() - rc = handle_show_hwmode_swmode_cmd_arg_tbl_notification( - fvp, xcvrd_show_hwmode_swmode_cmd_sts_tbl, xcvrd_show_hwmode_swmode_rsp_tbl, asic_index, port) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "anlt", {"mode": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_config_prbs_cmd_arg_tbl_notification_with_instance_anlt_enable(self, port_instance, mock_swsscommon_table, port_instance_helper): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_config_prbs_cmd_arg_tbl = mock_swsscommon_table + xcvrd_config_prbs_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_prbs_rsp_tbl = mock_swsscommon_table + port_instance = MagicMock() + port_instance.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + port_instance.PRBS_DIRECTION_BOTH = 2 + port_instance.enable_prbs_mode.return_value = True + port_instance.disable_prbs_mode.return_value = True + port_instance.reset.return_value = True + port_instance.set_anlt.return_value = True + port_instance_helper = port_instance + + asic_index = 0 + port = "Ethernet0" + fvp = {"config_prbs": True} + + rc = handle_config_prbs_cmd_arg_tbl_notification( + fvp, xcvrd_config_prbs_cmd_arg_tbl, xcvrd_config_prbs_cmd_sts_tbl, xcvrd_config_prbs_rsp_tbl, asic_index, port) assert(rc == None) - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('os.path.isfile', MagicMock(return_value=True)) - def test_handle_show_mux_switchmode_cmd_arg_tbl_notification_no_instance(self, mock_swsscommon_table): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_config_hwmode_swmode_cmd_sts_tbl = mock_swsscommon_table - xcvrd_config_hwmode_swmode_rsp_tbl = mock_swsscommon_table - xcvrd_show_hwmode_swmode_cmd_sts_tbl = mock_swsscommon_table - xcvrd_show_hwmode_swmode_rsp_tbl = mock_swsscommon_table - - asic_index = 0 - task_download_firmware_thread = {} - port = "Ethernet0" - fvp = {"state": "manual"} - - rc = handle_show_hwmode_swmode_cmd_arg_tbl_notification( - fvp, xcvrd_show_hwmode_swmode_cmd_sts_tbl, xcvrd_show_hwmode_swmode_rsp_tbl, asic_index, port) - assert(rc == -1) - - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "activate_firmware", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('os.path.isfile', MagicMock(return_value=True)) - @patch('time.sleep', MagicMock(return_value=True)) - def test_handle_show_mux_switchmode_cmd_arg_tbl_notification_with_instance_auto(self, mock_swsscommon_table, platform_sfputil): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_config_hwmode_swmode_cmd_sts_tbl = mock_swsscommon_table - xcvrd_config_hwmode_swmode_rsp_tbl = mock_swsscommon_table - xcvrd_show_hwmode_swmode_cmd_sts_tbl = mock_swsscommon_table - xcvrd_show_hwmode_swmode_rsp_tbl = mock_swsscommon_table - asic_index = 0 - task_download_firmware_thread = {} - port = "Ethernet0" - platform_sfputil.get_asic_id_for_logical_port = 0 - fvp = {"state": "auto"} - - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - class PortInstanceHelper(): - def __init__(self): - self.EEPROM_ERROR = -1 - self.TARGET_NIC = 1 - self.TARGET_TOR_A = 1 - self.TARGET_TOR_B = 1 - self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - self.FIRMWARE_DOWNLOAD_STATUS_FAILED = 2 - self.download_firmware_status = 0 - self.SWITCH_COUNT_MANUAL = "manual" - self.SWITCH_COUNT_AUTO = "auto" - self.SWITCHING_MODE_MANUAL = 0 - self.SWITCHING_MODE_AUTO = 1 - - def get_read_side(self): - return 1 - - def get_switching_mode(self): - return 1 - - # Defining function without self argument creates an exception, - # which is what we want for this test. - def get_mux_direction(): - pass + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "anlt", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_config_prbs_cmd_arg_tbl_notification_with_instance_anlt_disable(self, port_instance, mock_swsscommon_table, port_instance_helper): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_config_prbs_cmd_arg_tbl = mock_swsscommon_table + xcvrd_config_prbs_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_prbs_rsp_tbl = mock_swsscommon_table + port_instance = MagicMock() + port_instance.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + port_instance.PRBS_DIRECTION_BOTH = 2 + port_instance.enable_prbs_mode.return_value = True + port_instance.disable_prbs_mode.return_value = True + port_instance.reset.return_value = True + port_instance.set_anlt.return_value = True + port_instance_helper = port_instance + + asic_index = 0 + port = "Ethernet0" + fvp = {"config_prbs": True} + + rc = handle_config_prbs_cmd_arg_tbl_notification( + fvp, xcvrd_config_prbs_cmd_arg_tbl, xcvrd_config_prbs_cmd_sts_tbl, xcvrd_config_prbs_rsp_tbl, asic_index, port) + assert(rc == -1) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"mode": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_config_prbs_cmd_arg_tbl_notification_with_instance_fec_enable(self, port_instance, mock_swsscommon_table, port_instance_helper): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_config_prbs_cmd_arg_tbl = mock_swsscommon_table + xcvrd_config_prbs_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_prbs_rsp_tbl = mock_swsscommon_table + port_instance = MagicMock() + port_instance.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + port_instance.PRBS_DIRECTION_BOTH = 2 + port_instance.enable_prbs_mode.return_value = True + port_instance.disable_prbs_mode.return_value = True + port_instance.reset.return_value = True + port_instance.set_fec_mode.return_value = True + port_instance_helper = port_instance + + asic_index = 0 + port = "Ethernet0" + fvp = {"config_prbs": True} + + rc = handle_config_prbs_cmd_arg_tbl_notification( + fvp, xcvrd_config_prbs_cmd_arg_tbl, xcvrd_config_prbs_cmd_sts_tbl, xcvrd_config_prbs_rsp_tbl, asic_index, port) + assert(rc == None) - patched_util.get.return_value = PortInstanceHelper() - rc = handle_show_hwmode_swmode_cmd_arg_tbl_notification( - fvp, xcvrd_show_hwmode_swmode_cmd_sts_tbl, xcvrd_show_hwmode_swmode_rsp_tbl, asic_index, port) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_config_prbs_cmd_arg_tbl_notification_with_instance_fec_disable(self, port_instance, mock_swsscommon_table, port_instance_helper): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_config_prbs_cmd_arg_tbl = mock_swsscommon_table + xcvrd_config_prbs_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_prbs_rsp_tbl = mock_swsscommon_table + port_instance = MagicMock() + port_instance.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + port_instance.PRBS_DIRECTION_BOTH = 2 + port_instance.enable_prbs_mode.return_value = True + port_instance.disable_prbs_mode.return_value = True + port_instance.reset.return_value = True + port_instance.set_fec_mode.return_value = True + port_instance_helper = port_instance + + asic_index = 0 + port = "Ethernet0" + fvp = {"config_prbs": True} + + rc = handle_config_prbs_cmd_arg_tbl_notification( + fvp, xcvrd_config_prbs_cmd_arg_tbl, xcvrd_config_prbs_cmd_sts_tbl, xcvrd_config_prbs_rsp_tbl, asic_index, port) + assert(rc == -1) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_config_prbs_cmd_arg_tbl_notification_else_value(self, port_instance, mock_swsscommon_table, port_instance_helper): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_config_prbs_cmd_arg_tbl = mock_swsscommon_table + xcvrd_config_prbs_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_prbs_rsp_tbl = mock_swsscommon_table + port_instance = MagicMock() + port_instance.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + port_instance.PRBS_DIRECTION_BOTH = 2 + port_instance.enable_prbs_mode.return_value = True + port_instance.disable_prbs_mode.return_value = True + port_instance.reset.return_value = True + port_instance.set_fec_mode.return_value = True + port_instance_helper = port_instance + + asic_index = 0 + port = "Ethernet0" + fvp = {"config_abc": True} + + rc = handle_config_prbs_cmd_arg_tbl_notification( + fvp, xcvrd_config_prbs_cmd_arg_tbl, xcvrd_config_prbs_cmd_sts_tbl, xcvrd_config_prbs_rsp_tbl, asic_index, port) assert(rc == None) - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('os.path.isfile', MagicMock(return_value=True)) - def test_handle_config_mux_state_cmd_arg_tbl_notification_no_port(self, mock_swsscommon_table): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_config_hwmode_state_cmd_sts_tbl = mock_swsscommon_table - xcvrd_config_hwmode_state_rsp_tbl = mock_swsscommon_table - - asic_index = 0 - task_download_firmware_thread = {} - port = "Ethernet0" - fvp = {"config": "active"} - - rc = handle_config_hwmode_state_cmd_arg_tbl_notification( - fvp, xcvrd_config_hwmode_state_cmd_sts_tbl, xcvrd_config_hwmode_state_rsp_tbl, asic_index, port) - assert(rc == -1) - - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('os.path.isfile', MagicMock(return_value=True)) - def test_handle_show_mux_switchmode_cmd_arg_tbl_notification_else_condition(self, mock_swsscommon_table): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_config_hwmode_state_cmd_sts_tbl = mock_swsscommon_table - xcvrd_config_hwmode_state_rsp_tbl = mock_swsscommon_table - - asic_index = 0 - task_download_firmware_thread = {} - port = "Ethernet0" - fvp = {"down_firmware": "null"} - - rc = handle_config_hwmode_state_cmd_arg_tbl_notification( - fvp, xcvrd_config_hwmode_state_cmd_sts_tbl, xcvrd_config_hwmode_state_rsp_tbl, asic_index, port) - assert(rc == None) - - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "activate_firmware", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('os.path.isfile', MagicMock(return_value=True)) - @patch('time.sleep', MagicMock(return_value=True)) - def test_handle_config_mux_state_cmd_arg_tbl_notification_with_instance_manual(self, mock_swsscommon_table, platform_sfputil): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_config_hwmode_state_cmd_sts_tbl = mock_swsscommon_table - xcvrd_config_hwmode_state_rsp_tbl = mock_swsscommon_table - asic_index = 0 - task_download_firmware_thread = {} - port = "Ethernet0" - platform_sfputil.get_asic_id_for_logical_port = 0 - fvp = {"config": "active"} - - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - class PortInstanceHelper(): - def __init__(self): - self.EEPROM_ERROR = -1 - self.TARGET_NIC = 1 - self.TARGET_TOR_A = 1 - self.TARGET_TOR_B = 1 - self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - self.FIRMWARE_DOWNLOAD_STATUS_FAILED = 2 - self.download_firmware_status = 0 - self.SWITCH_COUNT_MANUAL = "manual" - self.SWITCH_COUNT_AUTO = 0 - self.SWITCHING_MODE_MANUAL = 0 - self.SWITCHING_MODE_AUTO = 1 - - def get_read_side(self): - return 1 - - def get_switching_mode(self): - return 0 + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_config_loop_cmd_arg_tbl_notification_else_value(self, port_instance, mock_swsscommon_table, port_instance_helper): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_config_loop_cmd_arg_tbl = mock_swsscommon_table + xcvrd_config_loop_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_loop_rsp_tbl = mock_swsscommon_table + port_instance = MagicMock() + port_instance.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + port_instance.PRBS_DIRECTION_BOTH = 2 + port_instance.enable_prbs_mode.return_value = True + port_instance.disable_prbs_mode.return_value = True + port_instance.reset.return_value = True + port_instance.set_fec_mode.return_value = True + port_instance_helper = port_instance + + asic_index = 0 + port = "Ethernet0" + fvp = {"config_abc": True} + + rc = handle_config_loop_cmd_arg_tbl_notification( + fvp, xcvrd_config_loop_cmd_arg_tbl, xcvrd_config_loop_cmd_sts_tbl, xcvrd_config_loop_rsp_tbl, asic_index, port) + assert(rc == None) - # Defining function without self argument creates an exception, - # which is what we want for this test. - def get_mux_direction(): - pass + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_config_loop_cmd_arg_tbl_notification_else_value(self, port_instance, mock_swsscommon_table, port_instance_helper): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_config_loop_cmd_arg_tbl = mock_swsscommon_table + xcvrd_config_loop_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_loop_rsp_tbl = mock_swsscommon_table + port_instance = MagicMock() + port_instance.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + port_instance.PRBS_DIRECTION_BOTH = 2 + port_instance.enable_prbs_mode.return_value = True + port_instance.disable_prbs_mode.return_value = True + port_instance.reset.return_value = True + port_instance.set_fec_mode.return_value = True + port_instance_helper = port_instance + + asic_index = 0 + port = "Ethernet0" + fvp = {"config_loop": True} + + rc = handle_config_loop_cmd_arg_tbl_notification( + fvp, xcvrd_config_loop_cmd_arg_tbl, xcvrd_config_loop_cmd_sts_tbl, xcvrd_config_loop_rsp_tbl, asic_index, port) + assert(rc == None) - patched_util.get.return_value = PortInstanceHelper() - rc = handle_config_hwmode_state_cmd_arg_tbl_notification( - fvp, xcvrd_config_hwmode_state_cmd_sts_tbl, xcvrd_config_hwmode_state_rsp_tbl, asic_index, port) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + def test_handle_config_loop_cmd_arg_tbl_notification_no_port(self, port_instance, mock_swsscommon_table, port_instance_helper): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_config_loop_cmd_arg_tbl = mock_swsscommon_table + xcvrd_config_loop_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_loop_rsp_tbl = mock_swsscommon_table + port_instance = MagicMock() + port_instance.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + port_instance.PRBS_DIRECTION_BOTH = 2 + port_instance.enable_prbs_mode.return_value = True + port_instance.disable_prbs_mode.return_value = True + port_instance.reset.return_value = True + port_instance.set_fec_mode.return_value = True + port_instance_helper = port_instance + + asic_index = 0 + port = "Ethernet0" + fvp = {"config_loop": True} + + rc = handle_config_loop_cmd_arg_tbl_notification( + fvp, xcvrd_config_loop_cmd_arg_tbl, xcvrd_config_loop_cmd_sts_tbl, xcvrd_config_loop_rsp_tbl, asic_index, port) + assert(rc == -1) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_config_loop_cmd_arg_tbl_notification_no_instance(self, port_instance, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_config_loop_cmd_arg_tbl = mock_swsscommon_table + xcvrd_config_loop_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_loop_rsp_tbl = mock_swsscommon_table + port_instance = MagicMock() + port_instance.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + port_instance.PRBS_DIRECTION_BOTH = 2 + port_instance.enable_prbs_mode.return_value = True + port_instance.disable_prbs_mode.return_value = True + port_instance.reset.return_value = True + port_instance.set_fec_mode.return_value = True + port_instance_helper = port_instance + + asic_index = 0 + port = "Ethernet0" + fvp = {"config_loop": True} + + rc = handle_config_loop_cmd_arg_tbl_notification( + fvp, xcvrd_config_loop_cmd_arg_tbl, xcvrd_config_loop_cmd_sts_tbl, xcvrd_config_loop_rsp_tbl, asic_index, port) + assert(rc == -1) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "enable", {"enable": "0", + "lane_mask": "0", + "mode_value": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_config_loop_cmd_arg_tbl_notification_enable(self, port_instance, mock_swsscommon_table, port_instance_helper): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_config_loop_cmd_arg_tbl = mock_swsscommon_table + xcvrd_config_loop_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_loop_rsp_tbl = mock_swsscommon_table + port_instance = MagicMock() + port_instance.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + port_instance.PRBS_DIRECTION_BOTH = 2 + port_instance.enable_loopback_mode.return_value = True + port_instance.disable_loopback_mode.return_value = True + port_instance.reset.return_value = True + port_instance.set_fec_mode.return_value = True + port_instance_helper = port_instance + + asic_index = 0 + port = "Ethernet0" + fvp = {"config_loop": True} + + rc = handle_config_loop_cmd_arg_tbl_notification( + fvp, xcvrd_config_loop_cmd_arg_tbl, xcvrd_config_loop_cmd_sts_tbl, xcvrd_config_loop_rsp_tbl, asic_index, port) assert(rc == None) - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('os.path.isfile', MagicMock(return_value=True)) - def test_handle_config_mux_state_cmd_arg_tbl_notification_no_instance(self, mock_swsscommon_table): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_config_hwmode_state_cmd_sts_tbl = mock_swsscommon_table - xcvrd_config_hwmode_state_rsp_tbl = mock_swsscommon_table - - asic_index = 0 - task_download_firmware_thread = {} - port = "Ethernet0" - fvp = {"config": "active"} - - rc = handle_config_hwmode_state_cmd_arg_tbl_notification( - fvp, xcvrd_config_hwmode_state_cmd_sts_tbl, xcvrd_config_hwmode_state_rsp_tbl, asic_index, port) - assert(rc == -1) - - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "activate_firmware", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('os.path.isfile', MagicMock(return_value=True)) - @patch('time.sleep', MagicMock(return_value=True)) - def test_handle_config_mux_state_cmd_arg_tbl_notification_with_instance_auto(self, mock_swsscommon_table, platform_sfputil): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_config_hwmode_state_cmd_sts_tbl = mock_swsscommon_table - xcvrd_config_hwmode_state_rsp_tbl = mock_swsscommon_table - asic_index = 0 - task_download_firmware_thread = {} - port = "Ethernet0" - platform_sfputil.get_asic_id_for_logical_port = 0 - fvp = {"config": "active"} - - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - class PortInstanceHelper(): - def __init__(self): - self.EEPROM_ERROR = -1 - self.TARGET_NIC = 1 - self.TARGET_TOR_A = 1 - self.TARGET_TOR_B = 1 - self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - self.FIRMWARE_DOWNLOAD_STATUS_FAILED = 2 - self.download_firmware_status = 0 - self.SWITCH_COUNT_MANUAL = "manual" - self.SWITCH_COUNT_AUTO = "auto" - self.SWITCHING_MODE_MANUAL = 0 - self.SWITCHING_MODE_AUTO = 1 - - def get_read_side(self): - return 1 - - def get_switching_mode(self): - return 1 - - # Defining function without self argument creates an exception, - # which is what we want for this test. - def get_mux_direction(): - pass + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "disable", {"disable": "0", + "lane_mask": "0", + "mode_value": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_config_loop_cmd_arg_tbl_notification_disable(self, port_instance, mock_swsscommon_table, port_instance_helper): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_config_loop_cmd_arg_tbl = mock_swsscommon_table + xcvrd_config_loop_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_loop_rsp_tbl = mock_swsscommon_table + port_instance = MagicMock() + port_instance.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + port_instance.PRBS_DIRECTION_BOTH = 2 + port_instance.enable_loopback_mode.return_value = True + port_instance.disable_loopback_mode.return_value = True + port_instance.reset.return_value = True + port_instance.set_fec_mode.return_value = True + port_instance_helper = port_instance + + asic_index = 0 + port = "Ethernet0" + fvp = {"config_loop": True} + + rc = handle_config_loop_cmd_arg_tbl_notification( + fvp, xcvrd_config_loop_cmd_arg_tbl, xcvrd_config_loop_cmd_sts_tbl, xcvrd_config_loop_rsp_tbl, asic_index, port) + assert(rc == None) - patched_util.get.return_value = PortInstanceHelper() - rc = handle_config_hwmode_state_cmd_arg_tbl_notification( - fvp, xcvrd_config_hwmode_state_cmd_sts_tbl, xcvrd_config_hwmode_state_rsp_tbl, asic_index, port) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_show_event_cmd_arg_tbl_notification_else_value(self, port_instance, mock_swsscommon_table, port_instance_helper): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_show_event_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_event_rsp_tbl = mock_swsscommon_table + xcvrd_show_event_res_tbl = mock_swsscommon_table + port_instance = MagicMock() + port_instance.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + port_instance.PRBS_DIRECTION_BOTH = 2 + port_instance.enable_prbs_mode.return_value = True + port_instance.disable_prbs_mode.return_value = True + port_instance.reset.return_value = True + port_instance.set_fec_mode.return_value = True + port_instance_helper = port_instance + + asic_index = 0 + port = "Ethernet0" + fvp = {"config_loop": True} + + rc = handle_show_event_cmd_arg_tbl_notification( + fvp, xcvrd_show_event_cmd_sts_tbl, xcvrd_show_event_rsp_tbl, xcvrd_show_event_res_tbl, asic_index, port) assert(rc == None) - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('os.path.isfile', MagicMock(return_value=True)) - def test_handle_show_mux_state_cmd_arg_tbl_notification_no_port(self, mock_swsscommon_table): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_show_hwmode_dir_cmd_sts_tbl = mock_swsscommon_table - xcvrd_show_hwmode_dir_rsp_tbl = mock_swsscommon_table - xcvrd_show_hwmode_dir_res_tbl = mock_swsscommon_table - - asic_index = 0 - task_download_firmware_thread = {} - port = "Ethernet0" - fvp = {"state": "active"} - - rc = handle_show_hwmode_state_cmd_arg_tbl_notification( - fvp, xcvrd_show_hwmode_dir_cmd_sts_tbl, xcvrd_show_hwmode_dir_rsp_tbl, xcvrd_show_hwmode_dir_res_tbl, asic_index, port) - assert(rc == -1) - - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('os.path.isfile', MagicMock(return_value=True)) - def test_handle_show_mux_state_cmd_arg_tbl_notification_else_condition(self, mock_swsscommon_table): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_show_hwmode_dir_cmd_sts_tbl = mock_swsscommon_table - xcvrd_show_hwmode_dir_rsp_tbl = mock_swsscommon_table - xcvrd_show_hwmode_dir_res_tbl = mock_swsscommon_table - xcvrd_config_hwmode_state_cmd_sts_tbl = mock_swsscommon_table - xcvrd_config_hwmode_state_rsp_tbl = mock_swsscommon_table - - asic_index = 0 - task_download_firmware_thread = {} - port = "Ethernet0" - fvp = {"down_firmware": "null"} - - rc = handle_show_hwmode_state_cmd_arg_tbl_notification( - fvp, xcvrd_show_hwmode_dir_cmd_sts_tbl, xcvrd_show_hwmode_dir_rsp_tbl, xcvrd_show_hwmode_dir_res_tbl, asic_index, port) - assert(rc == None) - - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "activate_firmware", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('os.path.isfile', MagicMock(return_value=True)) - @patch('time.sleep', MagicMock(return_value=True)) - def test_handle_show_mux_state_cmd_arg_tbl_notification_with_instance_manual(self, mock_swsscommon_table, platform_sfputil): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_show_hwmode_dir_cmd_sts_tbl = mock_swsscommon_table - xcvrd_show_hwmode_dir_rsp_tbl = mock_swsscommon_table - xcvrd_show_hwmode_dir_res_tbl = mock_swsscommon_table - xcvrd_config_hwmode_state_cmd_sts_tbl = mock_swsscommon_table - xcvrd_config_hwmode_state_rsp_tbl = mock_swsscommon_table - asic_index = 0 - task_download_firmware_thread = {} - port = "Ethernet0" - platform_sfputil.get_asic_id_for_logical_port = 0 - fvp = {"state": "active"} - - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - class PortInstanceHelper(): - def __init__(self): - self.EEPROM_ERROR = -1 - self.TARGET_NIC = 1 - self.TARGET_TOR_A = 1 - self.TARGET_TOR_B = 1 - self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - self.FIRMWARE_DOWNLOAD_STATUS_FAILED = 2 - self.download_firmware_status = 0 - self.SWITCH_COUNT_MANUAL = "manual" - self.SWITCH_COUNT_AUTO = 0 - self.SWITCHING_MODE_MANUAL = 0 - self.SWITCHING_MODE_AUTO = 1 - - def get_read_side(self): - return 1 - - def get_mux_direction(self): - return 1 - - def get_switching_mode(self): - return 0 + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_show_event_cmd_arg_tbl_notification_get_log(self, port_instance, mock_swsscommon_table, port_instance_helper): - patched_util.get.return_value = PortInstanceHelper() - rc = handle_show_hwmode_state_cmd_arg_tbl_notification( - fvp, xcvrd_show_hwmode_dir_cmd_sts_tbl, xcvrd_show_hwmode_dir_rsp_tbl, xcvrd_show_hwmode_dir_res_tbl, asic_index, port) + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_show_event_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_event_rsp_tbl = mock_swsscommon_table + xcvrd_show_event_res_tbl = mock_swsscommon_table + port_instance = MagicMock() + port_instance.get_event_log.return_value = ["log 1", "log 2"] + + asic_index = 0 + port = "Ethernet0" + fvp = {"show_event": True} + + rc = handle_show_event_cmd_arg_tbl_notification( + fvp, xcvrd_show_event_cmd_sts_tbl, xcvrd_show_event_rsp_tbl, xcvrd_show_event_res_tbl, asic_index, port) assert(rc == None) - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('os.path.isfile', MagicMock(return_value=True)) - def test_handle_show_mux_state_cmd_arg_tbl_notification_no_instance(self, mock_swsscommon_table): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_show_hwmode_dir_cmd_sts_tbl = mock_swsscommon_table - xcvrd_show_hwmode_dir_rsp_tbl = mock_swsscommon_table - xcvrd_show_hwmode_dir_res_tbl = mock_swsscommon_table - - asic_index = 0 - task_download_firmware_thread = {} - port = "Ethernet0" - fvp = {"state": "active"} - - rc = handle_show_hwmode_state_cmd_arg_tbl_notification( - fvp, xcvrd_show_hwmode_dir_cmd_sts_tbl, xcvrd_show_hwmode_dir_rsp_tbl, xcvrd_show_hwmode_dir_res_tbl, asic_index, port) - assert(rc == -1) - - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "activate_firmware", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('os.path.isfile', MagicMock(return_value=True)) - @patch('time.sleep', MagicMock(return_value=True)) - def test_handle_show_mux_state_cmd_arg_tbl_notification_with_instance_auto(self, mock_swsscommon_table, platform_sfputil): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_config_hwmode_state_cmd_sts_tbl = mock_swsscommon_table - xcvrd_config_hwmode_state_rsp_tbl = mock_swsscommon_table - xcvrd_show_hwmode_dir_cmd_sts_tbl = mock_swsscommon_table - xcvrd_show_hwmode_dir_rsp_tbl = mock_swsscommon_table - xcvrd_show_hwmode_dir_res_tbl = mock_swsscommon_table - asic_index = 0 - task_download_firmware_thread = {} - port = "Ethernet0" - platform_sfputil.get_asic_id_for_logical_port = 0 - fvp = {"state": "active"} - - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - class PortInstanceHelper(): - def __init__(self): - self.EEPROM_ERROR = -1 - self.TARGET_NIC = 1 - self.TARGET_TOR_A = 1 - self.TARGET_TOR_B = 1 - self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - self.FIRMWARE_DOWNLOAD_STATUS_FAILED = 2 - self.download_firmware_status = 0 - self.SWITCH_COUNT_MANUAL = "manual" - self.SWITCH_COUNT_AUTO = "auto" - self.SWITCHING_MODE_MANUAL = 0 - self.SWITCHING_MODE_AUTO = 1 - - def get_read_side(self): - return 1 - - def get_switching_mode(self): - return 1 - - def get_mux_direction(self): - return 2 - - patched_util.get.return_value = PortInstanceHelper() - rc = handle_show_hwmode_state_cmd_arg_tbl_notification( - fvp, xcvrd_show_hwmode_dir_cmd_sts_tbl, xcvrd_show_hwmode_dir_rsp_tbl, xcvrd_show_hwmode_dir_res_tbl, asic_index, port) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_show_event_cmd_arg_tbl_notification_get_actual_log(self, port_instance, mock_swsscommon_table, port_instance_helper): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_show_event_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_event_rsp_tbl = mock_swsscommon_table + xcvrd_show_event_res_tbl = mock_swsscommon_table + port_instance = MagicMock() + port_instance.get_event_log.return_value = ["log 1", "log 2"] + port_instance_helper.return_value = port_instance + asic_index = 0 + port = "Ethernet0" + fvp = {"show_event": True} + + rc = handle_show_event_cmd_arg_tbl_notification( + fvp, xcvrd_show_event_cmd_sts_tbl, xcvrd_show_event_rsp_tbl, xcvrd_show_event_res_tbl, asic_index, port) assert(rc == None) - def test_get_mux_cable_static_info_without_presence(self): + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_show_event_cmd_arg_tbl_notification_get_no_log(self, port_instance, mock_swsscommon_table, port_instance_helper): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_show_event_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_event_rsp_tbl = mock_swsscommon_table + xcvrd_show_event_res_tbl = mock_swsscommon_table + port_instance = MagicMock() + port_instance.get_event_log.return_value = Exception( + NotImplementedError) + + asic_index = 0 + port = "Ethernet0" + fvp = {"show_event": True} + + rc = handle_show_event_cmd_arg_tbl_notification( + fvp, xcvrd_show_event_cmd_sts_tbl, xcvrd_show_event_rsp_tbl, xcvrd_show_event_res_tbl, asic_index, port) + assert(rc == None) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_show_event_cmd_arg_tbl_notification_no_port(self, port_instance, mock_swsscommon_table, port_instance_helper): - rc = get_muxcable_static_info_without_presence() + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table - assert(rc['read_side'] == '-1') - assert(rc['nic_lane1_precursor1'] == 'N/A') - assert(rc['nic_lane1_precursor1'] == 'N/A') - assert(rc['nic_lane1_postcursor1'] == 'N/A') - assert(rc['nic_lane1_postcursor2'] == 'N/A') + xcvrd_show_event_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_event_rsp_tbl = mock_swsscommon_table + xcvrd_show_event_res_tbl = mock_swsscommon_table + port_instance = MagicMock() + port_instance.get_event_log.return_value = ["log 1", "log 2"] + port_instance_helper = port_instance + asic_index = 0 + port = "Ethernet0" + fvp = {"show_event": True} + rc = handle_show_event_cmd_arg_tbl_notification( + fvp, xcvrd_show_event_cmd_sts_tbl, xcvrd_show_event_rsp_tbl, xcvrd_show_event_res_tbl, asic_index, port) + assert(rc == -1) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + def test_handle_show_event_cmd_arg_tbl_notification_no_instance(self, port_instance, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_show_event_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_event_rsp_tbl = mock_swsscommon_table + xcvrd_show_event_res_tbl = mock_swsscommon_table + port_instance = MagicMock() + port_instance.get_event_log.return_value = ["log 1", "log 2"] + + asic_index = 0 + port = "Ethernet0" + fvp = {"show_event": True} + + rc = handle_show_event_cmd_arg_tbl_notification( + fvp, xcvrd_show_event_cmd_sts_tbl, xcvrd_show_event_rsp_tbl, xcvrd_show_event_res_tbl, asic_index, port) + assert(rc == -1) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_get_fec_cmd_arg_tbl_notification_no_status(self, port_instance, mock_swsscommon_table, port_instance_helper): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_show_fec_rsp_tbl = mock_swsscommon_table + xcvrd_show_fec_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_fec_res_tbl = mock_swsscommon_table + port_instance = MagicMock() + + asic_index = 0 + port = "Ethernet0" + fvp = {"show_event": True} + + rc = handle_get_fec_cmd_arg_tbl_notification( + fvp, xcvrd_show_fec_rsp_tbl, xcvrd_show_fec_cmd_sts_tbl, xcvrd_show_fec_res_tbl, asic_index, port) + assert(rc == None) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_get_fec_cmd_arg_tbl_notification_no_port(self, port_instance, mock_swsscommon_table, port_instance_helper): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_show_fec_rsp_tbl = mock_swsscommon_table + xcvrd_show_fec_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_fec_res_tbl = mock_swsscommon_table + port_instance = MagicMock() + + asic_index = 0 + port = "Ethernet0" + fvp = {"get_fec": True} + + rc = handle_get_fec_cmd_arg_tbl_notification( + fvp, xcvrd_show_fec_rsp_tbl, xcvrd_show_fec_cmd_sts_tbl, xcvrd_show_fec_res_tbl, asic_index, port) + assert(rc == -1) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_get_fec_cmd_arg_tbl_notification_no_instance(self, port_instance, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_show_fec_rsp_tbl = mock_swsscommon_table + xcvrd_show_fec_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_fec_res_tbl = mock_swsscommon_table + port_instance = MagicMock() + port_instance_helper = port_instance + + asic_index = 0 + port = "Ethernet0" + fvp = {"get_fec": True} + + rc = handle_get_fec_cmd_arg_tbl_notification( + fvp, xcvrd_show_fec_rsp_tbl, xcvrd_show_fec_cmd_sts_tbl, xcvrd_show_fec_res_tbl, asic_index, port) + assert(rc == -1) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_get_fec_cmd_arg_tbl_notification_get_result(self, port_instance, mock_swsscommon_table, port_instance_helper): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_show_fec_rsp_tbl = mock_swsscommon_table + xcvrd_show_fec_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_fec_res_tbl = mock_swsscommon_table + port_instance = MagicMock() + port_instance.get_fec_mode.return_value = 0 + port_instance.get_anlt.return_value = 0 + port_instance.get_speed.return_value = 0 + + asic_index = 0 + port = "Ethernet0" + fvp = {"get_fec": True} + + rc = handle_get_fec_cmd_arg_tbl_notification( + fvp, xcvrd_show_fec_rsp_tbl, xcvrd_show_fec_cmd_sts_tbl, xcvrd_show_fec_res_tbl, asic_index, port) + assert(rc == None) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_get_fec_cmd_arg_tbl_notification_no_status(self, port_instance, mock_swsscommon_table, port_instance_helper): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_show_ber_cmd_arg_tbl = mock_swsscommon_table + xcvrd_show_ber_rsp_tbl = mock_swsscommon_table + xcvrd_show_ber_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_ber_res_tbl = mock_swsscommon_table + port_instance = MagicMock() + + asic_index = 0 + port = "Ethernet0" + fvp = {"show_event": True} + + rc = handle_show_ber_cmd_arg_tbl_notification( + fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port) + assert(rc == None) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_get_fec_cmd_arg_tbl_notification_no_port(self, port_instance, mock_swsscommon_table, port_instance_helper): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_show_ber_cmd_arg_tbl = mock_swsscommon_table + xcvrd_show_ber_rsp_tbl = mock_swsscommon_table + xcvrd_show_ber_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_ber_res_tbl = mock_swsscommon_table + port_instance = MagicMock() + + asic_index = 0 + port = "Ethernet0" + fvp = {"get_ber": True} + + rc = handle_show_ber_cmd_arg_tbl_notification( + fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port) + assert(rc == -1) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_get_fec_cmd_arg_tbl_notification_no_instance(self, port_instance, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_show_ber_cmd_arg_tbl = mock_swsscommon_table + xcvrd_show_ber_rsp_tbl = mock_swsscommon_table + xcvrd_show_ber_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_ber_res_tbl = mock_swsscommon_table + port_instance = MagicMock() + + asic_index = 0 + port = "Ethernet0" + fvp = {"get_ber": True} + + rc = handle_show_ber_cmd_arg_tbl_notification( + fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port) + assert(rc == -1) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "ber", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_get_fec_cmd_arg_tbl_notification_get_ber(self, port_instance, mock_swsscommon_table, port_instance_helper): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_show_ber_cmd_arg_tbl = mock_swsscommon_table + xcvrd_show_ber_rsp_tbl = mock_swsscommon_table + xcvrd_show_ber_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_ber_res_tbl = mock_swsscommon_table + port_instance = MagicMock() + port_instance.get_ber_info.return_value = ["100", "200"] + + asic_index = 0 + port = "Ethernet0" + fvp = {"get_ber": True} + + rc = handle_show_ber_cmd_arg_tbl_notification( + fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port) + assert(rc == None) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "eye", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_get_fec_cmd_arg_tbl_notification_get_eye(self, port_instance, mock_swsscommon_table, port_instance_helper): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_show_ber_cmd_arg_tbl = mock_swsscommon_table + xcvrd_show_ber_rsp_tbl = mock_swsscommon_table + xcvrd_show_ber_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_ber_res_tbl = mock_swsscommon_table + port_instance = MagicMock() + port_instance.get_eye_info.return_value = ["100", "200"] + + asic_index = 0 + port = "Ethernet0" + fvp = {"get_ber": True} + + rc = handle_show_ber_cmd_arg_tbl_notification( + fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port) + assert(rc == None) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec_stats", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_get_fec_cmd_arg_tbl_notification_get_fec_stats(self, port_instance, mock_swsscommon_table, port_instance_helper): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_show_ber_cmd_arg_tbl = mock_swsscommon_table + xcvrd_show_ber_rsp_tbl = mock_swsscommon_table + xcvrd_show_ber_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_ber_res_tbl = mock_swsscommon_table + port_instance = MagicMock() + port_instance.get_fec_stats.return_value = {"100": "200"} + + asic_index = 0 + port = "Ethernet0" + fvp = {"get_ber": True} + + rc = handle_show_ber_cmd_arg_tbl_notification( + fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port) + assert(rc == None) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "pcs_stats", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_get_fec_cmd_arg_tbl_notification_get_pcs_stats(self, port_instance, mock_swsscommon_table, port_instance_helper): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_show_ber_cmd_arg_tbl = mock_swsscommon_table + xcvrd_show_ber_rsp_tbl = mock_swsscommon_table + xcvrd_show_ber_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_ber_res_tbl = mock_swsscommon_table + port_instance = MagicMock() + port_instance.get_pcs_stats.return_value = {"100": "200"} + + asic_index = 0 + port = "Ethernet0" + fvp = {"get_ber": True} + + rc = handle_show_ber_cmd_arg_tbl_notification( + fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port) + assert(rc == None) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "cable_alive", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_get_fec_cmd_arg_tbl_notification_get_alive_status(self, port_instance, mock_swsscommon_table, port_instance_helper): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_show_ber_cmd_arg_tbl = mock_swsscommon_table + xcvrd_show_ber_rsp_tbl = mock_swsscommon_table + xcvrd_show_ber_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_ber_res_tbl = mock_swsscommon_table + port_instance = MagicMock() + port_instance.get_alive_status.return_value = True + + asic_index = 0 + port = "Ethernet0" + fvp = {"get_ber": True} + + rc = handle_show_ber_cmd_arg_tbl_notification( + fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port) + assert(rc == None) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "debug_dump", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_get_fec_cmd_arg_tbl_notification_get_debug_dump_registers(self, port_instance, mock_swsscommon_table, port_instance_helper): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_show_ber_cmd_arg_tbl = mock_swsscommon_table + xcvrd_show_ber_rsp_tbl = mock_swsscommon_table + xcvrd_show_ber_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_ber_res_tbl = mock_swsscommon_table + port_instance = MagicMock() + port_instance.debug_dump_registers.return_value = {"register1": "100"} + + asic_index = 0 + port = "Ethernet0" + fvp = {"get_ber": True} + + rc = handle_show_ber_cmd_arg_tbl_notification( + fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port) + assert(rc == None) + """ + + def handle_config_firmware_roll_cmd_arg_tbl_notification(fvp, xcvrd_roll_fw_cmd_sts_tbl, xcvrd_roll_fw_rsp_tbl, asic_index, port): + + fvp_dict = dict(fvp) + + + if "rollback_firmware" in fvp_dict: + file_name = fvp_dict["rollback_firmware"] + status = 'False' + + if file_name == 'null': + file_full_path = None + else: + file_full_path = '/usr/share/sonic/firmware/{}'.format(file_name) + if not os.path.isfile(file_full_path): + helper_logger.log_error("Error: cli cmd mux rollback firmware file does not exist port {} file {}".format(port, file_name)) + set_result_and_delete_port('status', status, xcvrd_roll_fw_cmd_sts_tbl[asic_index], xcvrd_roll_fw_rsp_tbl[asic_index], port) + break + + + + physical_port = get_ycable_physical_port_from_logical_port(port) + if physical_port is None or physical_port == PHYSICAL_PORT_MAPPING_ERROR: + # error scenario update table accordingly + helper_logger.log_warning("Error: Could not get physical port for cli cmd mux rollback firmware port {}".format(port)) + set_result_and_delete_port('status', status, xcvrd_roll_fw_cmd_sts_tbl[asic_index], xcvrd_roll_fw_rsp_tbl[asic_index], port) + break + + port_instance = get_ycable_port_instance_from_logical_port(port) + if port_instance is None or port_instance in port_mapping_error_values: + # error scenario update table accordingly + helper_logger.log_warning("Error: Could not get port instance for cli cmd mux rollback firmware port {}".format(port)) + set_result_and_delete_port('status', status, xcvrd_roll_fw_cmd_sts_tbl[asic_index], xcvrd_roll_fw_rsp_tbl[asic_index], port) + + with y_cable_port_locks[physical_port]: + try: + status = port_instance.rollback_firmware(file_full_path) + except Exception as e: + status = -1 + helper_logger.log_warning("Failed to execute the rollback_firmware API for port {} due to {}".format(physical_port,repr(e))) + set_result_and_delete_port('status', status, xcvrd_roll_fw_cmd_sts_tbl[asic_index], xcvrd_roll_fw_rsp_tbl[asic_index], port) + else: + helper_logger.log_error("Wrong param for cli cmd mux rollback firmware port {}".format(port)) + set_result_and_delete_port('status', 'False', xcvrd_roll_fw_cmd_sts_tbl[asic_index], xcvrd_roll_fw_rsp_tbl[asic_index], port) + """ + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_config_firmware_roll_cmd_arg_tbl_notification_no_port(self, port_instance, mock_swsscommon_table, port_instance_helper): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_down_fw_cmd_sts_tbl = mock_swsscommon_table + xcvrd_down_fw_rsp_tbl = mock_swsscommon_table + port_instance = MagicMock() + + asic_index = 0 + port = "Ethernet0" + fvp = {"rollback_firmware": "null"} + + rc = handle_config_firmware_roll_cmd_arg_tbl_notification( + fvp, xcvrd_down_fw_cmd_sts_tbl, xcvrd_down_fw_rsp_tbl, asic_index, port) + assert(rc == -1) + + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_config_firmware_roll_cmd_arg_tbl_notification_no_instance(self, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_down_fw_cmd_sts_tbl = mock_swsscommon_table + xcvrd_down_fw_rsp_tbl = mock_swsscommon_table + + asic_index = 0 + port = "Ethernet0" + fvp = {"rollback_firmware": "null"} + + rc = handle_config_firmware_roll_cmd_arg_tbl_notification( + fvp, xcvrd_down_fw_cmd_sts_tbl, xcvrd_down_fw_rsp_tbl, asic_index, port) + assert(rc == -1) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_config_firmware_roll_cmd_arg_tbl_notification_with_instance(self, port_instance, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_down_fw_cmd_sts_tbl = mock_swsscommon_table + xcvrd_down_fw_rsp_tbl = mock_swsscommon_table + port_instance = MagicMock() + + asic_index = 0 + port = "Ethernet0" + fvp = {"rollback_firmware": "null"} + + rc = handle_config_firmware_roll_cmd_arg_tbl_notification( + fvp, xcvrd_down_fw_cmd_sts_tbl, xcvrd_down_fw_rsp_tbl, asic_index, port) + assert(rc == None) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_config_firmware_roll_cmd_arg_tbl_notification_no_port_and_instance(self, port_instance, mock_swsscommon_table, port_instance_helper): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_down_fw_cmd_sts_tbl = mock_swsscommon_table + xcvrd_down_fw_rsp_tbl = mock_swsscommon_table + port_instance = MagicMock() + + asic_index = 0 + port = "Ethernet0" + fvp = {"rollback_firmware": "null"} + + rc = handle_config_firmware_roll_cmd_arg_tbl_notification( + fvp, xcvrd_down_fw_cmd_sts_tbl, xcvrd_down_fw_rsp_tbl, asic_index, port) + assert(rc == -1) + + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('os.path.isfile', MagicMock(return_value=True)) + def test_handle_config_firmware_down_cmd_arg_tbl_notification_no_port(self, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_down_fw_cmd_sts_tbl = mock_swsscommon_table + xcvrd_down_fw_rsp_tbl = mock_swsscommon_table + + asic_index = 0 + task_download_firmware_thread = {} + port = "Ethernet0" + fvp = {"download_firmware": "null"} + + rc = handle_config_firmware_down_cmd_arg_tbl_notification( + fvp, xcvrd_down_fw_cmd_sts_tbl, xcvrd_down_fw_rsp_tbl, asic_index, port, task_download_firmware_thread) + assert(rc == -1) + + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('os.path.isfile', MagicMock(return_value=True)) + def test_handle_config_firmware_down_cmd_arg_tbl_notification_else_condition(self, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_down_fw_cmd_sts_tbl = mock_swsscommon_table + xcvrd_down_fw_rsp_tbl = mock_swsscommon_table + + asic_index = 0 + task_download_firmware_thread = {} + port = "Ethernet0" + fvp = {"downoad_firmware": "null"} + + rc = handle_config_firmware_down_cmd_arg_tbl_notification( + fvp, xcvrd_down_fw_cmd_sts_tbl, xcvrd_down_fw_rsp_tbl, asic_index, port, task_download_firmware_thread) + assert(rc == None) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('threading.Thread') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('os.path.isfile', MagicMock(return_value=True)) + def test_handle_config_firmware_down_cmd_arg_tbl_notification_with_instance(self, port_instance, mock_swsscommon_table, port_instance_helper, thread_obj): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_down_fw_cmd_sts_tbl = mock_swsscommon_table + xcvrd_down_fw_rsp_tbl = mock_swsscommon_table + port_instance = MagicMock() + thread_instance = MagicMock() + thread_instance.start = MagicMock() + thread_obj = thread_instance + port_instance_helper = port_instance + + asic_index = 0 + task_download_firmware_thread = {} + port = "Ethernet0" + fvp = {"download_firmware": "null"} + + rc = handle_config_firmware_down_cmd_arg_tbl_notification( + fvp, xcvrd_down_fw_cmd_sts_tbl, xcvrd_down_fw_rsp_tbl, asic_index, port, task_download_firmware_thread) + assert(rc == None) + + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('os.path.isfile', MagicMock(return_value=True)) + def test_handle_config_firmware_down_cmd_arg_tbl_notification_no_instance(self, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_down_fw_cmd_sts_tbl = mock_swsscommon_table + xcvrd_down_fw_rsp_tbl = mock_swsscommon_table + + asic_index = 0 + task_download_firmware_thread = {} + port = "Ethernet0" + fvp = {"download_firmware": "null"} + + rc = handle_config_firmware_down_cmd_arg_tbl_notification( + fvp, xcvrd_down_fw_cmd_sts_tbl, xcvrd_down_fw_rsp_tbl, asic_index, port, task_download_firmware_thread) + assert(rc == -1) + + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('os.path.isfile', MagicMock(return_value=True)) + def test_handle_config_firmware_acti_cmd_arg_tbl_notification_no_port(self, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_down_fw_cmd_sts_tbl = mock_swsscommon_table + xcvrd_down_fw_rsp_tbl = mock_swsscommon_table + xcvrd_acti_fw_cmd_arg_tbl = mock_swsscommon_table + + asic_index = 0 + task_download_firmware_thread = {} + port = "Ethernet0" + fvp = {"activate_firmware": "null"} + + rc = handle_config_firmware_acti_cmd_arg_tbl_notification( + fvp, xcvrd_down_fw_cmd_sts_tbl, xcvrd_down_fw_rsp_tbl, xcvrd_acti_fw_cmd_arg_tbl, asic_index, port) + assert(rc == -1) + + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('os.path.isfile', MagicMock(return_value=True)) + def test_handle_config_firmware_acti_cmd_arg_tbl_notification_else_condition(self, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_down_fw_cmd_sts_tbl = mock_swsscommon_table + xcvrd_down_fw_rsp_tbl = mock_swsscommon_table + xcvrd_acti_fw_cmd_arg_tbl = mock_swsscommon_table + + asic_index = 0 + task_download_firmware_thread = {} + port = "Ethernet0" + fvp = {"down_firmware": "null"} + + rc = handle_config_firmware_acti_cmd_arg_tbl_notification( + fvp, xcvrd_down_fw_cmd_sts_tbl, xcvrd_down_fw_rsp_tbl, xcvrd_acti_fw_cmd_arg_tbl, asic_index, port) + assert(rc == None) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "activate_firmware", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('os.path.isfile', MagicMock(return_value=True)) + @patch('time.sleep', MagicMock(return_value=True)) + def test_handle_config_firmware_acti_cmd_arg_tbl_notification_with_instance(self, port_instance, mock_swsscommon_table, port_instance_helper): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_down_fw_cmd_sts_tbl = mock_swsscommon_table + xcvrd_down_fw_rsp_tbl = mock_swsscommon_table + xcvrd_acti_fw_cmd_arg_tbl = mock_swsscommon_table + port_instance = MagicMock() + port_instance.activate_firmware = MagicMock(return_value=True) + thread_instance = MagicMock() + thread_instance.start = MagicMock() + thread_obj = thread_instance + port_instance_helper = port_instance + + asic_index = 0 + task_download_firmware_thread = {} + port = "Ethernet0" + fvp = {"activate_firmware": "null"} + + rc = handle_config_firmware_acti_cmd_arg_tbl_notification( + fvp, xcvrd_down_fw_cmd_sts_tbl, xcvrd_down_fw_rsp_tbl, xcvrd_acti_fw_cmd_arg_tbl, asic_index, port) + assert(rc == None) + + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('os.path.isfile', MagicMock(return_value=True)) + def test_handle_config_firmware_acti_cmd_arg_tbl_notification_no_instance(self, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_down_fw_cmd_sts_tbl = mock_swsscommon_table + xcvrd_down_fw_rsp_tbl = mock_swsscommon_table + xcvrd_acti_fw_cmd_arg_tbl = mock_swsscommon_table + + asic_index = 0 + task_download_firmware_thread = {} + port = "Ethernet0" + fvp = {"activate_firmware": "null"} + + rc = handle_config_firmware_acti_cmd_arg_tbl_notification( + fvp, xcvrd_down_fw_cmd_sts_tbl, xcvrd_down_fw_rsp_tbl, xcvrd_acti_fw_cmd_arg_tbl, asic_index, port) + assert(rc == -1) + + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('os.path.isfile', MagicMock(return_value=True)) + def test_handle_show_firmware_show_cmd_arg_tbl_notification_no_port(self, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_down_fw_cmd_sts_tbl = mock_swsscommon_table + xcvrd_down_fw_rsp_tbl = mock_swsscommon_table + xcvrd_acti_fw_cmd_arg_tbl = mock_swsscommon_table + xcvrd_show_fw_res_tbl = mock_swsscommon_table + + asic_index = 0 + task_download_firmware_thread = {} + port = "Ethernet0" + fvp = {"firmware_version": "null"} + + rc = handle_show_firmware_show_cmd_arg_tbl_notification( + fvp, xcvrd_down_fw_cmd_sts_tbl, xcvrd_down_fw_rsp_tbl, xcvrd_show_fw_res_tbl, asic_index, port) + assert(rc == -1) + + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('os.path.isfile', MagicMock(return_value=True)) + def test_handle_show_firmware_show_cmd_arg_tbl_notification_else_condition(self, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_down_fw_cmd_sts_tbl = mock_swsscommon_table + xcvrd_down_fw_rsp_tbl = mock_swsscommon_table + xcvrd_acti_fw_cmd_arg_tbl = mock_swsscommon_table + xcvrd_show_fw_res_tbl = mock_swsscommon_table + + asic_index = 0 + task_download_firmware_thread = {} + port = "Ethernet0" + fvp = {"down_firmware": "null"} + + rc = handle_show_firmware_show_cmd_arg_tbl_notification( + fvp, xcvrd_down_fw_cmd_sts_tbl, xcvrd_down_fw_rsp_tbl, xcvrd_show_fw_res_tbl, asic_index, port) + assert(rc == None) + + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "activate_firmware", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('os.path.isfile', MagicMock(return_value=True)) + @patch('time.sleep', MagicMock(return_value=True)) + def test_handle_show_firmware_show_cmd_arg_tbl_notification_with_instance(self, mock_swsscommon_table, platform_sfputil): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_down_fw_cmd_sts_tbl = mock_swsscommon_table + xcvrd_down_fw_rsp_tbl = mock_swsscommon_table + xcvrd_acti_fw_cmd_arg_tbl = mock_swsscommon_table + xcvrd_show_fw_res_tbl = mock_swsscommon_table + asic_index = 0 + task_download_firmware_thread = {} + port = "Ethernet0" + platform_sfputil.get_asic_id_for_logical_port = 0 + fvp = {"firmware_version": "null"} + + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 + self.TARGET_NIC = 1 + self.TARGET_TOR_A = 1 + self.TARGET_TOR_B = 1 + self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + self.FIRMWARE_DOWNLOAD_STATUS_FAILED = 2 + self.download_firmware_status = 0 + self.MUX_TOGGLE_STATUS_INPROGRESS = 1 + self.MUX_TOGGLE_STATUS_FAILED = 2 + self.MUX_TOGGLE_STATUS_NOT_INITIATED_OR_FINISHED = 2 + self.mux_toggle_status = 0 + self.SWITCH_COUNT_MANUAL = "manual" + self.SWITCH_COUNT_AUTO = "auto" + + def get_read_side(self): + return 1 + + # Defining function without self argument creates an exception, + # which is what we want for this test. + def get_mux_direction(): + pass + + patched_util.get.return_value = PortInstanceHelper() + rc = handle_show_firmware_show_cmd_arg_tbl_notification( + fvp, xcvrd_down_fw_cmd_sts_tbl, xcvrd_down_fw_rsp_tbl, xcvrd_show_fw_res_tbl, asic_index, port) + assert(rc == None) + + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('os.path.isfile', MagicMock(return_value=True)) + def test_handle_show_firmware_show_cmd_arg_tbl_notification_no_instance(self, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_down_fw_cmd_sts_tbl = mock_swsscommon_table + xcvrd_down_fw_rsp_tbl = mock_swsscommon_table + xcvrd_acti_fw_cmd_arg_tbl = mock_swsscommon_table + xcvrd_show_fw_res_tbl = mock_swsscommon_table + + asic_index = 0 + task_download_firmware_thread = {} + port = "Ethernet0" + fvp = {"firmware_version": "null"} + + rc = handle_show_firmware_show_cmd_arg_tbl_notification( + fvp, xcvrd_down_fw_cmd_sts_tbl, xcvrd_down_fw_rsp_tbl, xcvrd_show_fw_res_tbl, asic_index, port) + assert(rc == -1) + + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('os.path.isfile', MagicMock(return_value=True)) + def test_handle_config_mux_switchmode_cmd_arg_tbl_notification_no_port(self, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_config_hwmode_swmode_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_hwmode_swmode_rsp_tbl = mock_swsscommon_table + xcvrd_acti_fw_cmd_arg_tbl = mock_swsscommon_table + xcvrd_show_fw_res_tbl = mock_swsscommon_table + + asic_index = 0 + task_download_firmware_thread = {} + port = "Ethernet0" + fvp = {"config": "null"} + + rc = handle_config_mux_switchmode_arg_tbl_notification( + fvp, xcvrd_config_hwmode_swmode_cmd_sts_tbl, xcvrd_config_hwmode_swmode_rsp_tbl, asic_index, port) + assert(rc == -1) + + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('os.path.isfile', MagicMock(return_value=True)) + def test_handle_config_mux_switchmode_cmd_arg_tbl_notification_else_condition(self, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_config_hwmode_swmode_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_hwmode_swmode_rsp_tbl = mock_swsscommon_table + + asic_index = 0 + task_download_firmware_thread = {} + port = "Ethernet0" + fvp = {"down_firmware": "null"} + + rc = handle_config_mux_switchmode_arg_tbl_notification( + fvp, xcvrd_config_hwmode_swmode_cmd_sts_tbl, xcvrd_config_hwmode_swmode_rsp_tbl, asic_index, port) + assert(rc == None) + + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "activate_firmware", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('os.path.isfile', MagicMock(return_value=True)) + @patch('time.sleep', MagicMock(return_value=True)) + def test_handle_config_mux_switchmode_cmd_arg_tbl_notification_with_instance_manual(self, mock_swsscommon_table, platform_sfputil): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_config_hwmode_swmode_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_hwmode_swmode_rsp_tbl = mock_swsscommon_table + asic_index = 0 + task_download_firmware_thread = {} + port = "Ethernet0" + platform_sfputil.get_asic_id_for_logical_port = 0 + fvp = {"config": "manual"} + + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 + self.TARGET_NIC = 1 + self.TARGET_TOR_A = 1 + self.TARGET_TOR_B = 1 + self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + self.FIRMWARE_DOWNLOAD_STATUS_FAILED = 2 + self.download_firmware_status = 0 + self.SWITCH_COUNT_MANUAL = "manual" + self.SWITCH_COUNT_AUTO = "auto" + self.SWITCHING_MODE_MANUAL = "manual" + + def get_read_side(self): + return 1 + + def set_switching_mode(self, mode): + return True + + # Defining function without self argument creates an exception, + # which is what we want for this test. + def get_mux_direction(): + pass + + patched_util.get.return_value = PortInstanceHelper() + rc = handle_config_mux_switchmode_arg_tbl_notification( + fvp, xcvrd_config_hwmode_swmode_cmd_sts_tbl, xcvrd_config_hwmode_swmode_rsp_tbl, asic_index, port) + assert(rc == None) + + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('os.path.isfile', MagicMock(return_value=True)) + def test_handle_config_mux_switchmode_cmd_arg_tbl_notification_no_instance(self, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_config_hwmode_swmode_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_hwmode_swmode_rsp_tbl = mock_swsscommon_table + xcvrd_show_hwmode_swmode_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_hwmode_swmode_rsp_tbl = mock_swsscommon_table + + asic_index = 0 + task_download_firmware_thread = {} + port = "Ethernet0" + fvp = {"config": "manual"} + + rc = handle_config_mux_switchmode_arg_tbl_notification( + fvp, xcvrd_config_hwmode_swmode_cmd_sts_tbl, xcvrd_config_hwmode_swmode_rsp_tbl, asic_index, port) + assert(rc == -1) + + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "activate_firmware", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('os.path.isfile', MagicMock(return_value=True)) + @patch('time.sleep', MagicMock(return_value=True)) + def test_handle_config_mux_switchmode_cmd_arg_tbl_notification_with_instance_auto(self, mock_swsscommon_table, platform_sfputil): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_config_hwmode_swmode_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_hwmode_swmode_rsp_tbl = mock_swsscommon_table + xcvrd_show_hwmode_swmode_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_hwmode_swmode_rsp_tbl = mock_swsscommon_table + asic_index = 0 + task_download_firmware_thread = {} + port = "Ethernet0" + platform_sfputil.get_asic_id_for_logical_port = 0 + fvp = {"config": "auto"} + + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 + self.TARGET_NIC = 1 + self.TARGET_TOR_A = 1 + self.TARGET_TOR_B = 1 + self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + self.FIRMWARE_DOWNLOAD_STATUS_FAILED = 2 + self.download_firmware_status = 0 + self.SWITCH_COUNT_MANUAL = "manual" + self.SWITCH_COUNT_AUTO = "auto" + self.SWITCHING_MODE_MANUAL = "manual" + self.SWITCHING_MODE_AUTO = "auto" + + def get_read_side(self): + return 1 + + def set_switching_mode(self, mode): + return True + + # Defining function without self argument creates an exception, + # which is what we want for this test. + def get_mux_direction(): + pass + + patched_util.get.return_value = PortInstanceHelper() + rc = handle_config_mux_switchmode_arg_tbl_notification( + fvp, xcvrd_config_hwmode_swmode_cmd_sts_tbl, xcvrd_config_hwmode_swmode_rsp_tbl, asic_index, port) + assert(rc == None) + + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('os.path.isfile', MagicMock(return_value=True)) + def test_handle_show_mux_switchmode_cmd_arg_tbl_notification_no_port(self, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_config_hwmode_swmode_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_hwmode_swmode_rsp_tbl = mock_swsscommon_table + xcvrd_show_hwmode_swmode_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_hwmode_swmode_rsp_tbl = mock_swsscommon_table + + asic_index = 0 + task_download_firmware_thread = {} + port = "Ethernet0" + fvp = {"state": "null"} + + rc = handle_show_hwmode_swmode_cmd_arg_tbl_notification( + fvp, xcvrd_show_hwmode_swmode_cmd_sts_tbl, xcvrd_show_hwmode_swmode_rsp_tbl, asic_index, port) + assert(rc == -1) + + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('os.path.isfile', MagicMock(return_value=True)) + def test_handle_show_mux_switchmode_cmd_arg_tbl_notification_else_condition(self, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_config_hwmode_swmode_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_hwmode_swmode_rsp_tbl = mock_swsscommon_table + xcvrd_show_hwmode_swmode_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_hwmode_swmode_rsp_tbl = mock_swsscommon_table + + asic_index = 0 + task_download_firmware_thread = {} + port = "Ethernet0" + fvp = {"down_firmware": "null"} + + rc = handle_show_hwmode_swmode_cmd_arg_tbl_notification( + fvp, xcvrd_show_hwmode_swmode_cmd_sts_tbl, xcvrd_show_hwmode_swmode_rsp_tbl, asic_index, port) + assert(rc == None) + + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "activate_firmware", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('os.path.isfile', MagicMock(return_value=True)) + @patch('time.sleep', MagicMock(return_value=True)) + def test_handle_show_mux_switchmode_cmd_arg_tbl_notification_with_instance_manual(self, mock_swsscommon_table, platform_sfputil): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_config_hwmode_swmode_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_hwmode_swmode_rsp_tbl = mock_swsscommon_table + xcvrd_show_hwmode_swmode_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_hwmode_swmode_rsp_tbl = mock_swsscommon_table + asic_index = 0 + task_download_firmware_thread = {} + port = "Ethernet0" + platform_sfputil.get_asic_id_for_logical_port = 0 + fvp = {"state": "manual"} + + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 + self.TARGET_NIC = 1 + self.TARGET_TOR_A = 1 + self.TARGET_TOR_B = 1 + self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + self.FIRMWARE_DOWNLOAD_STATUS_FAILED = 2 + self.download_firmware_status = 0 + self.SWITCH_COUNT_MANUAL = "manual" + self.SWITCH_COUNT_AUTO = 0 + self.SWITCHING_MODE_MANUAL = 0 + self.SWITCHING_MODE_AUTO = 1 + + def get_read_side(self): + return 1 + + def get_switching_mode(self): + return 0 + + # Defining function without self argument creates an exception, + # which is what we want for this test. + def get_mux_direction(): + pass + + patched_util.get.return_value = PortInstanceHelper() + rc = handle_show_hwmode_swmode_cmd_arg_tbl_notification( + fvp, xcvrd_show_hwmode_swmode_cmd_sts_tbl, xcvrd_show_hwmode_swmode_rsp_tbl, asic_index, port) + assert(rc == None) + + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('os.path.isfile', MagicMock(return_value=True)) + def test_handle_show_mux_switchmode_cmd_arg_tbl_notification_no_instance(self, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_config_hwmode_swmode_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_hwmode_swmode_rsp_tbl = mock_swsscommon_table + xcvrd_show_hwmode_swmode_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_hwmode_swmode_rsp_tbl = mock_swsscommon_table + + asic_index = 0 + task_download_firmware_thread = {} + port = "Ethernet0" + fvp = {"state": "manual"} + + rc = handle_show_hwmode_swmode_cmd_arg_tbl_notification( + fvp, xcvrd_show_hwmode_swmode_cmd_sts_tbl, xcvrd_show_hwmode_swmode_rsp_tbl, asic_index, port) + assert(rc == -1) + + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "activate_firmware", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('os.path.isfile', MagicMock(return_value=True)) + @patch('time.sleep', MagicMock(return_value=True)) + def test_handle_show_mux_switchmode_cmd_arg_tbl_notification_with_instance_auto(self, mock_swsscommon_table, platform_sfputil): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_config_hwmode_swmode_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_hwmode_swmode_rsp_tbl = mock_swsscommon_table + xcvrd_show_hwmode_swmode_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_hwmode_swmode_rsp_tbl = mock_swsscommon_table + asic_index = 0 + task_download_firmware_thread = {} + port = "Ethernet0" + platform_sfputil.get_asic_id_for_logical_port = 0 + fvp = {"state": "auto"} + + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 + self.TARGET_NIC = 1 + self.TARGET_TOR_A = 1 + self.TARGET_TOR_B = 1 + self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + self.FIRMWARE_DOWNLOAD_STATUS_FAILED = 2 + self.download_firmware_status = 0 + self.SWITCH_COUNT_MANUAL = "manual" + self.SWITCH_COUNT_AUTO = "auto" + self.SWITCHING_MODE_MANUAL = 0 + self.SWITCHING_MODE_AUTO = 1 + + def get_read_side(self): + return 1 + + def get_switching_mode(self): + return 1 + + # Defining function without self argument creates an exception, + # which is what we want for this test. + def get_mux_direction(): + pass + + patched_util.get.return_value = PortInstanceHelper() + rc = handle_show_hwmode_swmode_cmd_arg_tbl_notification( + fvp, xcvrd_show_hwmode_swmode_cmd_sts_tbl, xcvrd_show_hwmode_swmode_rsp_tbl, asic_index, port) + assert(rc == None) + + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('os.path.isfile', MagicMock(return_value=True)) + def test_handle_config_mux_state_cmd_arg_tbl_notification_no_port(self, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_config_hwmode_state_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_hwmode_state_rsp_tbl = mock_swsscommon_table + + asic_index = 0 + task_download_firmware_thread = {} + port = "Ethernet0" + fvp = {"config": "active"} + + rc = handle_config_hwmode_state_cmd_arg_tbl_notification( + fvp, xcvrd_config_hwmode_state_cmd_sts_tbl, xcvrd_config_hwmode_state_rsp_tbl, asic_index, port) + assert(rc == -1) + + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('os.path.isfile', MagicMock(return_value=True)) + def test_handle_show_mux_switchmode_cmd_arg_tbl_notification_else_condition(self, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_config_hwmode_state_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_hwmode_state_rsp_tbl = mock_swsscommon_table + + asic_index = 0 + task_download_firmware_thread = {} + port = "Ethernet0" + fvp = {"down_firmware": "null"} + + rc = handle_config_hwmode_state_cmd_arg_tbl_notification( + fvp, xcvrd_config_hwmode_state_cmd_sts_tbl, xcvrd_config_hwmode_state_rsp_tbl, asic_index, port) + assert(rc == None) + + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "activate_firmware", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('os.path.isfile', MagicMock(return_value=True)) + @patch('time.sleep', MagicMock(return_value=True)) + def test_handle_config_mux_state_cmd_arg_tbl_notification_with_instance_manual(self, mock_swsscommon_table, platform_sfputil): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_config_hwmode_state_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_hwmode_state_rsp_tbl = mock_swsscommon_table + asic_index = 0 + task_download_firmware_thread = {} + port = "Ethernet0" + platform_sfputil.get_asic_id_for_logical_port = 0 + fvp = {"config": "active"} + + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 + self.TARGET_NIC = 1 + self.TARGET_TOR_A = 1 + self.TARGET_TOR_B = 1 + self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + self.FIRMWARE_DOWNLOAD_STATUS_FAILED = 2 + self.download_firmware_status = 0 + self.SWITCH_COUNT_MANUAL = "manual" + self.SWITCH_COUNT_AUTO = 0 + self.SWITCHING_MODE_MANUAL = 0 + self.SWITCHING_MODE_AUTO = 1 + + def get_read_side(self): + return 1 + + def get_switching_mode(self): + return 0 + + # Defining function without self argument creates an exception, + # which is what we want for this test. + def get_mux_direction(): + pass + + patched_util.get.return_value = PortInstanceHelper() + rc = handle_config_hwmode_state_cmd_arg_tbl_notification( + fvp, xcvrd_config_hwmode_state_cmd_sts_tbl, xcvrd_config_hwmode_state_rsp_tbl, asic_index, port) + assert(rc == None) + + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('os.path.isfile', MagicMock(return_value=True)) + def test_handle_config_mux_state_cmd_arg_tbl_notification_no_instance(self, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_config_hwmode_state_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_hwmode_state_rsp_tbl = mock_swsscommon_table + + asic_index = 0 + task_download_firmware_thread = {} + port = "Ethernet0" + fvp = {"config": "active"} + + rc = handle_config_hwmode_state_cmd_arg_tbl_notification( + fvp, xcvrd_config_hwmode_state_cmd_sts_tbl, xcvrd_config_hwmode_state_rsp_tbl, asic_index, port) + assert(rc == -1) + + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "activate_firmware", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('os.path.isfile', MagicMock(return_value=True)) + @patch('time.sleep', MagicMock(return_value=True)) + def test_handle_config_mux_state_cmd_arg_tbl_notification_with_instance_auto(self, mock_swsscommon_table, platform_sfputil): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_config_hwmode_state_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_hwmode_state_rsp_tbl = mock_swsscommon_table + asic_index = 0 + task_download_firmware_thread = {} + port = "Ethernet0" + platform_sfputil.get_asic_id_for_logical_port = 0 + fvp = {"config": "active"} + + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 + self.TARGET_NIC = 1 + self.TARGET_TOR_A = 1 + self.TARGET_TOR_B = 1 + self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + self.FIRMWARE_DOWNLOAD_STATUS_FAILED = 2 + self.download_firmware_status = 0 + self.SWITCH_COUNT_MANUAL = "manual" + self.SWITCH_COUNT_AUTO = "auto" + self.SWITCHING_MODE_MANUAL = 0 + self.SWITCHING_MODE_AUTO = 1 + + def get_read_side(self): + return 1 + + def get_switching_mode(self): + return 1 + + # Defining function without self argument creates an exception, + # which is what we want for this test. + def get_mux_direction(): + pass + + patched_util.get.return_value = PortInstanceHelper() + rc = handle_config_hwmode_state_cmd_arg_tbl_notification( + fvp, xcvrd_config_hwmode_state_cmd_sts_tbl, xcvrd_config_hwmode_state_rsp_tbl, asic_index, port) + assert(rc == None) + + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('os.path.isfile', MagicMock(return_value=True)) + def test_handle_show_mux_state_cmd_arg_tbl_notification_no_port(self, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_show_hwmode_dir_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_hwmode_dir_rsp_tbl = mock_swsscommon_table + xcvrd_show_hwmode_dir_res_tbl = mock_swsscommon_table + + asic_index = 0 + task_download_firmware_thread = {} + port = "Ethernet0" + fvp = {"state": "active"} + + rc = handle_show_hwmode_state_cmd_arg_tbl_notification( + fvp, xcvrd_show_hwmode_dir_cmd_sts_tbl, xcvrd_show_hwmode_dir_rsp_tbl, xcvrd_show_hwmode_dir_res_tbl, asic_index, port) + assert(rc == -1) + + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('os.path.isfile', MagicMock(return_value=True)) + def test_handle_show_mux_state_cmd_arg_tbl_notification_else_condition(self, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_show_hwmode_dir_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_hwmode_dir_rsp_tbl = mock_swsscommon_table + xcvrd_show_hwmode_dir_res_tbl = mock_swsscommon_table + xcvrd_config_hwmode_state_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_hwmode_state_rsp_tbl = mock_swsscommon_table + + asic_index = 0 + task_download_firmware_thread = {} + port = "Ethernet0" + fvp = {"down_firmware": "null"} + + rc = handle_show_hwmode_state_cmd_arg_tbl_notification( + fvp, xcvrd_show_hwmode_dir_cmd_sts_tbl, xcvrd_show_hwmode_dir_rsp_tbl, xcvrd_show_hwmode_dir_res_tbl, asic_index, port) + assert(rc == None) + + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "activate_firmware", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('os.path.isfile', MagicMock(return_value=True)) + @patch('time.sleep', MagicMock(return_value=True)) + def test_handle_show_mux_state_cmd_arg_tbl_notification_with_instance_manual(self, mock_swsscommon_table, platform_sfputil): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_show_hwmode_dir_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_hwmode_dir_rsp_tbl = mock_swsscommon_table + xcvrd_show_hwmode_dir_res_tbl = mock_swsscommon_table + xcvrd_config_hwmode_state_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_hwmode_state_rsp_tbl = mock_swsscommon_table + asic_index = 0 + task_download_firmware_thread = {} + port = "Ethernet0" + platform_sfputil.get_asic_id_for_logical_port = 0 + fvp = {"state": "active"} + + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 + self.TARGET_NIC = 1 + self.TARGET_TOR_A = 1 + self.TARGET_TOR_B = 1 + self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + self.FIRMWARE_DOWNLOAD_STATUS_FAILED = 2 + self.download_firmware_status = 0 + self.SWITCH_COUNT_MANUAL = "manual" + self.SWITCH_COUNT_AUTO = 0 + self.SWITCHING_MODE_MANUAL = 0 + self.SWITCHING_MODE_AUTO = 1 + + def get_read_side(self): + return 1 + + def get_mux_direction(self): + return 1 + + def get_switching_mode(self): + return 0 + + patched_util.get.return_value = PortInstanceHelper() + rc = handle_show_hwmode_state_cmd_arg_tbl_notification( + fvp, xcvrd_show_hwmode_dir_cmd_sts_tbl, xcvrd_show_hwmode_dir_rsp_tbl, xcvrd_show_hwmode_dir_res_tbl, asic_index, port) + assert(rc == None) + + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('os.path.isfile', MagicMock(return_value=True)) + def test_handle_show_mux_state_cmd_arg_tbl_notification_no_instance(self, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_show_hwmode_dir_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_hwmode_dir_rsp_tbl = mock_swsscommon_table + xcvrd_show_hwmode_dir_res_tbl = mock_swsscommon_table + + asic_index = 0 + task_download_firmware_thread = {} + port = "Ethernet0" + fvp = {"state": "active"} + + rc = handle_show_hwmode_state_cmd_arg_tbl_notification( + fvp, xcvrd_show_hwmode_dir_cmd_sts_tbl, xcvrd_show_hwmode_dir_rsp_tbl, xcvrd_show_hwmode_dir_res_tbl, asic_index, port) + assert(rc == -1) + + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "activate_firmware", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('os.path.isfile', MagicMock(return_value=True)) + @patch('time.sleep', MagicMock(return_value=True)) + def test_handle_show_mux_state_cmd_arg_tbl_notification_with_instance_auto(self, mock_swsscommon_table, platform_sfputil): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_config_hwmode_state_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_hwmode_state_rsp_tbl = mock_swsscommon_table + xcvrd_show_hwmode_dir_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_hwmode_dir_rsp_tbl = mock_swsscommon_table + xcvrd_show_hwmode_dir_res_tbl = mock_swsscommon_table + asic_index = 0 + task_download_firmware_thread = {} + port = "Ethernet0" + platform_sfputil.get_asic_id_for_logical_port = 0 + fvp = {"state": "active"} + + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 + self.TARGET_NIC = 1 + self.TARGET_TOR_A = 1 + self.TARGET_TOR_B = 1 + self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + self.FIRMWARE_DOWNLOAD_STATUS_FAILED = 2 + self.download_firmware_status = 0 + self.SWITCH_COUNT_MANUAL = "manual" + self.SWITCH_COUNT_AUTO = "auto" + self.SWITCHING_MODE_MANUAL = 0 + self.SWITCHING_MODE_AUTO = 1 + + def get_read_side(self): + return 1 + + def get_switching_mode(self): + return 1 + + def get_mux_direction(self): + return 2 + + patched_util.get.return_value = PortInstanceHelper() + rc = handle_show_hwmode_state_cmd_arg_tbl_notification( + fvp, xcvrd_show_hwmode_dir_cmd_sts_tbl, xcvrd_show_hwmode_dir_rsp_tbl, xcvrd_show_hwmode_dir_res_tbl, asic_index, port) + assert(rc == None) + + def test_get_mux_cable_static_info_without_presence(self): + + rc = get_muxcable_static_info_without_presence() + + assert(rc['read_side'] == '-1') + assert(rc['nic_lane1_precursor1'] == 'N/A') + assert(rc['nic_lane1_precursor1'] == 'N/A') + assert(rc['nic_lane1_postcursor1'] == 'N/A') + assert(rc['nic_lane1_postcursor2'] == 'N/A') + assert(rc != None) + + + @patch('ycable.ycable_utilities.y_cable_helper.disable_telemetry') + def test_handle_ycable_enable_disable_tel_notification(self, patch): + + fvp_m = {"disable_telemetry": "True"} + rc = handle_ycable_enable_disable_tel_notification(fvp_m, "Y_CABLE") + assert(rc == None) + + def test_handle_ycable_enable_disable_tel_notification_probe(self): + + fvp_m = {"log_verbosity": "notice"} + rc = handle_ycable_enable_disable_tel_notification(fvp_m, "Y_CABLE") + assert(rc == None) + + fvp_m = {"log_verbosity": "debug"} + rc = handle_ycable_enable_disable_tel_notification(fvp_m, "Y_CABLE") + assert(rc == None) diff --git a/sonic-ycabled/ycable/ycable_utilities/y_cable_helper.py b/sonic-ycabled/ycable/ycable_utilities/y_cable_helper.py index 3504e1119..2933a7769 100644 --- a/sonic-ycabled/ycable/ycable_utilities/y_cable_helper.py +++ b/sonic-ycabled/ycable/ycable_utilities/y_cable_helper.py @@ -50,6 +50,7 @@ y_cable_port_instances = {} y_cable_port_locks = {} +disable_telemetry = False Y_CABLE_STATUS_NO_TOR_ACTIVE = 0 Y_CABLE_STATUS_TORA_ACTIVE = 1 @@ -981,6 +982,11 @@ def delete_ports_status_for_y_cable(): def check_identifier_presence_and_update_mux_info_entry(state_db, mux_tbl, asic_index, logical_port_name): + global disable_telemetry + + if disable_telemetry == True: + return + # Get the namespaces in the platform config_db, port_tbl = {}, {} namespaces = multi_asic.get_front_end_namespaces() @@ -2520,6 +2526,136 @@ def handle_show_hwmode_state_cmd_arg_tbl_notification(fvp, xcvrd_show_hwmode_dir else: helper_logger.log_warning("Error: Wrong input param for cli command show mux hwmode muxdirection logical port {}".format(port)) set_result_and_delete_port('state', 'unknown', xcvrd_show_hwmode_dir_cmd_sts_tbl[asic_index], xcvrd_show_hwmode_dir_rsp_tbl[asic_index], port) + helper_logger.log_warning("command key not present in the notification fwd state handling port {}".format(port)) + + +def handle_hw_mux_cable_table_grpc_notification(fvp, hw_mux_cable_tbl, asic_index, grpc_metrics_tbl, peer, port): + + # entering this section signifies a gRPC start for state + # change request from swss so initiate recording in mux_metrics table + time_start = datetime.datetime.utcnow().strftime("%Y-%b-%d %H:%M:%S.%f") + # This check might be redundant, to check, the presence of this Port in keys + # in logical_port_list but keep for now for coherency + # also skip checking in logical_port_list inside sfp_util + + helper_logger.log_debug("Y_CABLE_DEBUG:recevied the notification mux hw state") + fvp_dict = dict(fvp) + toggle_side = "self" + + if "state" in fvp_dict: + # got a state change + new_state = fvp_dict["state"] + requested_status = new_state + if requested_status in ["active", "standby"]: + + (status, fvs) = hw_mux_cable_tbl[asic_index].get(port) + if status is False: + helper_logger.log_warning("Could not retreive fieldvalue pairs for {}, inside state_db table {}".format( + port, hw_mux_cable_tbl[asic_index].getTableName())) + return + helper_logger.log_debug("Y_CABLE_DEBUG processing the notification mux hw state port {}".format(port)) + mux_port_dict = dict(fvs) + old_state = mux_port_dict.get("state", None) + read_side = mux_port_dict.get("read_side", None) + curr_read_side = int(read_side) + # Now whatever is the state requested, call gRPC to update the soc state appropriately + if peer == True: + curr_read_side = 1-int(read_side) + toggle_side = "peer" + + if new_state == "active": + state_req = 1 + elif new_state == "standby": + state_req = 0 + + helper_logger.log_notice( + "calling RPC for hw mux_cable set state ispeer = {} port {} portid {} read_side {} state requested {}".format(peer, port, curr_read_side, read_side, new_state)) + + request = linkmgr_grpc_driver_pb2.AdminRequest(portid=[curr_read_side], state=[state_req]) + + stub = grpc_port_stubs.get(port, None) + if stub is None: + helper_logger.log_debug("Y_CABLE_DEBUG:stub is None for performing hw mux RPC port {}".format(port)) + retry_setup_grpc_channel_for_port(port, asic_index) + stub = grpc_port_stubs.get(port, None) + if stub is None: + helper_logger.log_warning( + "gRPC channel was initially not setup for performing hw mux set state RPC port {}, trying to set gRPC channel again also did not work, posting unknown state for stateDB:HW_MUX_CABLE_TABLE".format(port)) + active_side = new_state = 'unknown' + time_end = datetime.datetime.utcnow().strftime("%Y-%b-%d %H:%M:%S.%f") + fvs_metrics = swsscommon.FieldValuePairs([('xcvrd_switch_{}_{}_start'.format(toggle_side, new_state), str(time_start)), + ('xcvrd_switch_{}_{}_end'.format(toggle_side, new_state), str(time_end))]) + grpc_metrics_tbl[asic_index].set(port, fvs_metrics) + + fvs_updated = swsscommon.FieldValuePairs([('state', new_state), + ('read_side', read_side), + ('active_side', str(active_side))]) + hw_mux_cable_tbl[asic_index].set(port, fvs_updated) + return + + ret, response = try_grpc(stub.SetAdminForwardingPortState, SET_ADMIN_FORWARDING_TIMEOUT, request) + + if response is not None: + # Debug only, remove this section once Server side is Finalized + hw_response_port_ids = response.portid + hw_response_port_ids_state = response.state + helper_logger.log_notice( + "Set admin state RPC received response port {} port ids = {} curr_read_side {} read_side {}".format(port, hw_response_port_ids, curr_read_side, read_side)) + helper_logger.log_notice( + "Set admin state RPC received response port {} state values = {} curr_read_side {} read_side {}".format(port, hw_response_port_ids_state, curr_read_side, read_side)) + else: + helper_logger.log_notice("response was none hw_mux_cable_table_grpc_notification {} ".format(port)) + + active_side = parse_grpc_response_hw_mux_cable_change_state(ret, response, curr_read_side, port) + + if active_side == "unknown": + helper_logger.log_warning( + "ERR: Got a change event for updating gRPC but could not toggle the mux-direction for port {} state from {} to {}, writing unknown".format(port, old_state, new_state)) + new_state = 'unknown' + + time_end = datetime.datetime.utcnow().strftime("%Y-%b-%d %H:%M:%S.%f") + fvs_metrics = swsscommon.FieldValuePairs([('xcvrd_switch_{}_{}_start'.format(toggle_side, new_state), str(time_start)), + ('xcvrd_switch_{}_{}_end'.format(toggle_side, new_state), str(time_end))]) + grpc_metrics_tbl[asic_index].set(port, fvs_metrics) + + fvs_updated = swsscommon.FieldValuePairs([('state', new_state), + ('read_side', read_side), + ('active_side', str(active_side))]) + hw_mux_cable_tbl[asic_index].set(port, fvs_updated) + helper_logger.log_debug("Y_CABLE_DEBUG: processed the notification hw mux state cleanly {}".format(port)) + else: + helper_logger.log_info("Got a change event on port {} of table {} that does not contain state".format( + port, swsscommon.APP_HW_MUX_CABLE_TABLE_NAME)) + +def handle_ycable_enable_disable_tel_notification(fvp_m, key): + + global disable_telemetry + + if fvp_m: + + if key != "Y_CABLE": + return + + fvp_dict = dict(fvp_m) + if "log_verbosity" in fvp_dict: + # check if xcvrd got a probe command + probe_identifier = fvp_dict["log_verbosity"] + + if probe_identifier == "debug": + helper_logger.set_min_log_priority_debug() + + elif probe_identifier == "notice": + helper_logger.set_min_log_priority_notice() + if "disable_telemetry" in fvp_dict: + # check if xcvrd got a probe command + enable = fvp_dict["disable_telemetry"] + + helper_logger.log_notice("Y_CABLE_DEBUG: trying to enable/disable telemetry flag to {}".format(enable)) + if enable == "True": + disable_telemetry = True + + elif enable == "False": + disable_telemetry = False # Thread wrapper class to update y_cable status periodically class YCableTableUpdateTask(object): @@ -2863,22 +2999,10 @@ def task_cli_worker(self): if not key: break - helper_logger.log_notice("Y_CABLE_DEBUG: trying to enable/disable debug logs") if fvp_m: - - if key == "Y_CABLE": - continue - - fvp_dict = dict(fvp_m) - if "log_verbosity" in fvp_dict: - # check if xcvrd got a probe command - probe_identifier = fvp_dict["log_verbosity"] - - if probe_identifier == "debug": - helper_logger.set_min_log_priority_debug() - - elif probe_identifier == "notice": - helper_logger.set_min_log_priority_notice() + helper_logger.log_notice("Y_CABLE_DEBUG: trying to enable/disable debug logs") + handle_ycable_enable_disable_tel_notification(fvp_m, 'Y_CABLE') + break while True: # show muxcable hwmode state From fa7bebcab4a216adabaa2dc51f15703ad79d1612 Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Tue, 9 Aug 2022 22:37:18 +0000 Subject: [PATCH 2/7] fix branch changes Signed-off-by: vaibhav-dahiya --- sonic-ycabled/tests/test_y_cable_helper.py | 8526 ++++++++--------- .../ycable/ycable_utilities/y_cable_helper.py | 100 - 2 files changed, 4263 insertions(+), 4363 deletions(-) diff --git a/sonic-ycabled/tests/test_y_cable_helper.py b/sonic-ycabled/tests/test_y_cable_helper.py index 8cb0e3080..bab9a95ad 100644 --- a/sonic-ycabled/tests/test_y_cable_helper.py +++ b/sonic-ycabled/tests/test_y_cable_helper.py @@ -1,4765 +1,4765 @@ - from .mock_swsscommon import Table - from sonic_platform_base.sfp_base import SfpBase - from swsscommon import swsscommon - from sonic_py_common import daemon_base - from ycable.ycable_utilities.y_cable_helper import * - from ycable.ycable import * - import copy - import os - import sys - import time +from .mock_swsscommon import Table +from sonic_platform_base.sfp_base import SfpBase +from swsscommon import swsscommon +from sonic_py_common import daemon_base +from ycable.ycable_utilities.y_cable_helper import * +from ycable.ycable import * +import copy +import os +import sys +import time - if sys.version_info >= (3, 3): - from unittest.mock import MagicMock, patch - else: - from mock import MagicMock, patch +if sys.version_info >= (3, 3): + from unittest.mock import MagicMock, patch +else: + from mock import MagicMock, patch - daemon_base.db_connect = MagicMock() - swsscommon.Table = MagicMock() +daemon_base.db_connect = MagicMock() +swsscommon.Table = MagicMock() - sys.modules['sonic_y_cable'] = MagicMock() - sys.modules['sonic_y_cable.y_cable'] = MagicMock() +sys.modules['sonic_y_cable'] = MagicMock() +sys.modules['sonic_y_cable.y_cable'] = MagicMock() - os.environ["Y_CABLE_HELPER_UNIT_TESTING"] = "1" +os.environ["Y_CABLE_HELPER_UNIT_TESTING"] = "1" - class helper_logger: - mock_arg = MagicMock() +class helper_logger: + mock_arg = MagicMock() - def log_error(self, mock_arg): - return True + def log_error(self, mock_arg): + return True - def log_warning(self, mock_arg): - return True + def log_warning(self, mock_arg): + return True - def log_debug(self, mock_arg): - return True + def log_debug(self, mock_arg): + return True - class TestYCableScript(object): - def test_xcvrd_helper_class_run(self): - Y_cable_task = YCableTableUpdateTask() +class TestYCableScript(object): + def test_xcvrd_helper_class_run(self): + Y_cable_task = YCableTableUpdateTask() - def test_y_cable_helper_format_mapping_identifier1(self): - rc = format_mapping_identifier("ABC ") - assert(rc == "abc") + def test_y_cable_helper_format_mapping_identifier1(self): + rc = format_mapping_identifier("ABC ") + assert(rc == "abc") - def test_y_cable_helper_format_mapping_identifier_no_instance(self): - rc = format_mapping_identifier(None) - assert(rc == None) + def test_y_cable_helper_format_mapping_identifier_no_instance(self): + rc = format_mapping_identifier(None) + assert(rc == None) - def test_gather_arg_from_db_and_check_for_type(self): + def test_gather_arg_from_db_and_check_for_type(self): - arg_tbl = {"Ethernet0": (True, {"abc": "x", "def": "y"})} - dic = {"key": "value"} - rc = gather_arg_from_db_and_check_for_type( - arg_tbl, "Ethernet0", "key", dic, "abc") + arg_tbl = {"Ethernet0": (True, {"abc": "x", "def": "y"})} + dic = {"key": "value"} + rc = gather_arg_from_db_and_check_for_type( + arg_tbl, "Ethernet0", "key", dic, "abc") - assert(rc == ("x", "value", {'abc': 'x', 'def': 'y'})) + assert(rc == ("x", "value", {'abc': 'x', 'def': 'y'})) - def test_gather_arg_from_db_and_check_for_none_type(self): + def test_gather_arg_from_db_and_check_for_none_type(self): - arg_tbl = {"Ethernet0": (True, {"abcd": "x", "def": "y"})} - dic = {"key": "value"} - rc = gather_arg_from_db_and_check_for_type( - arg_tbl, "Ethernet0", "key", dic, "abc") + arg_tbl = {"Ethernet0": (True, {"abcd": "x", "def": "y"})} + dic = {"key": "value"} + rc = gather_arg_from_db_and_check_for_type( + arg_tbl, "Ethernet0", "key", dic, "abc") - assert(rc == (None, "value"), {'abcd': 'x', 'def': 'y'}) + assert(rc == (None, "value"), {'abcd': 'x', 'def': 'y'}) - def test_y_cable_wrapper_get_transceiver_info(self): - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: - patched_util.get_transceiver_info_dict.return_value = {'manufacturer': 'Microsoft', - 'model': 'model1'} - - transceiver_dict = y_cable_wrapper_get_transceiver_info(1) - vendor = transceiver_dict.get('manufacturer') - model = transceiver_dict.get('model') - - assert(vendor == "Microsoft") - assert(model == "model1") - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_chassis') - def test_y_cable_wrapper_get_transceiver_info_with_platform_chassis(self, mock_chassis): - - mock_object = MagicMock() - mock_object.get_transceiver_info.return_value = {'type': '1000_BASE_SX_SFP', - 'hardware_rev': '5', - 'serial': 'PEP3L5D', - 'manufacturer': 'FINISAR', - 'model': 'ABC', - 'connector': 'LC', - 'encoding': '8B10B', - 'ext_identifier': 'SFP', - 'ext_rateselect_compliance': 'DEF', - 'cable_length': '850', - 'nominal_bit_rate': '100', - 'specification_compliance': 'GHI', - 'vendor_date': '2021-01-01', - 'vendor_oui': '00:90:65'} - - mock_chassis.get_sfp = MagicMock(return_value=mock_object) - received_xcvr_info = y_cable_wrapper_get_transceiver_info(1) - - type = received_xcvr_info.get('type') - model = received_xcvr_info.get('model') - vendor_date = received_xcvr_info.get('vendor_date') - - assert(type == "1000_BASE_SX_SFP") - assert(model == "ABC") - assert(vendor_date == "2021-01-01") - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_chassis') - def test_y_cable_wrapper_get_transceiver_info_with_platform_chassis_not_implemented(self, mock_chassis): - - mock_object = MagicMock() - mock_object.get_transceiver_info.side_effect = NotImplementedError - mock_chassis.get_sfp = MagicMock(return_value=mock_object) + def test_y_cable_wrapper_get_transceiver_info(self): + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: + patched_util.get_transceiver_info_dict.return_value = {'manufacturer': 'Microsoft', + 'model': 'model1'} - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: - patched_util.get_transceiver_info_dict.return_value = {'manufacturer': 'microsoft', - 'model': 'simulated'} + transceiver_dict = y_cable_wrapper_get_transceiver_info(1) + vendor = transceiver_dict.get('manufacturer') + model = transceiver_dict.get('model') - transceiver_dict = y_cable_wrapper_get_transceiver_info(1) - vendor = transceiver_dict.get('manufacturer') - model = transceiver_dict.get('model') + assert(vendor == "Microsoft") + assert(model == "model1") - assert(vendor == "microsoft") - assert(model == "simulated") + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_chassis') + def test_y_cable_wrapper_get_transceiver_info_with_platform_chassis(self, mock_chassis): - def test_y_cable_wrapper_get_presence(self): - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: - patched_util.get_presence.return_value = True + mock_object = MagicMock() + mock_object.get_transceiver_info.return_value = {'type': '1000_BASE_SX_SFP', + 'hardware_rev': '5', + 'serial': 'PEP3L5D', + 'manufacturer': 'FINISAR', + 'model': 'ABC', + 'connector': 'LC', + 'encoding': '8B10B', + 'ext_identifier': 'SFP', + 'ext_rateselect_compliance': 'DEF', + 'cable_length': '850', + 'nominal_bit_rate': '100', + 'specification_compliance': 'GHI', + 'vendor_date': '2021-01-01', + 'vendor_oui': '00:90:65'} - presence = y_cable_wrapper_get_presence(1) + mock_chassis.get_sfp = MagicMock(return_value=mock_object) + received_xcvr_info = y_cable_wrapper_get_transceiver_info(1) - assert(presence == True) + type = received_xcvr_info.get('type') + model = received_xcvr_info.get('model') + vendor_date = received_xcvr_info.get('vendor_date') - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_chassis') - def test_y_cable_wrapper_get_presence_with_platform_chassis(self, mock_chassis): + assert(type == "1000_BASE_SX_SFP") + assert(model == "ABC") + assert(vendor_date == "2021-01-01") - mock_object = MagicMock() - mock_object.get_presence = MagicMock(return_value=True) - mock_chassis.get_sfp = MagicMock(return_value=mock_object) - presence = y_cable_wrapper_get_presence(1) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_chassis') + def test_y_cable_wrapper_get_transceiver_info_with_platform_chassis_not_implemented(self, mock_chassis): - assert(presence == True) + mock_object = MagicMock() + mock_object.get_transceiver_info.side_effect = NotImplementedError + mock_chassis.get_sfp = MagicMock(return_value=mock_object) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_chassis') - def test_y_cable_wrapper_get_presence_with_platform_chassis_raise_exception(self, mock_chassis): + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: + patched_util.get_transceiver_info_dict.return_value = {'manufacturer': 'microsoft', + 'model': 'simulated'} - mock_object = MagicMock(spec=SfpBase) - mock_object.get_presence = MagicMock(side_effect=NotImplementedError) - mock_chassis.get_sfp = MagicMock(return_value=mock_object) + transceiver_dict = y_cable_wrapper_get_transceiver_info(1) + vendor = transceiver_dict.get('manufacturer') + model = transceiver_dict.get('model') - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: - patched_util.get_presence.return_value = True + assert(vendor == "microsoft") + assert(model == "simulated") - assert(y_cable_wrapper_get_presence(1) == True) + def test_y_cable_wrapper_get_presence(self): + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: + patched_util.get_presence.return_value = True - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.get_muxcable_info', MagicMock(return_value={'tor_active': 'self', - 'mux_direction': 'self', - 'manual_switch_count': '7', - 'auto_switch_count': '71', - 'link_status_self': 'up', - 'link_status_peer': 'up', - 'link_status_nic': 'up', - 'nic_lane1_active': 'True', - 'nic_lane2_active': 'True', - 'nic_lane3_active': 'True', - 'nic_lane4_active': 'True', - 'self_eye_height_lane1': '500', - 'self_eye_height_lane2': '510', - 'peer_eye_height_lane1': '520', - 'peer_eye_height_lane2': '530', - 'nic_eye_height_lane1': '742', - 'nic_eye_height_lane2': '750', - 'internal_temperature': '28', - 'internal_voltage': '3.3', - 'nic_temperature': '20', - 'nic_voltage': '2.7', - 'version_nic_active': '1.6MS', - 'version_nic_inactive': '1.7MS', - 'version_nic_next': '1.7MS', - 'version_self_active': '1.6MS', - 'version_self_inactive': '1.7MS', - 'version_self_next': '1.7MS', - 'version_peer_active': '1.6MS', - 'version_peer_inactive': '1.7MS', - 'version_peer_next': '1.7MS'})) - def test_post_port_mux_info_to_db(self): - logical_port_name = "Ethernet0" - mux_tbl = Table("STATE_DB", "Y_CABLE_INFO_TABLE") - rc = post_port_mux_info_to_db(logical_port_name, mux_tbl) - assert(rc != -1) - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.get_muxcable_static_info', MagicMock(return_value={'read_side': 'self', - 'nic_lane1_precursor1': '1', - 'nic_lane1_precursor2': '-7', - 'nic_lane1_maincursor': '-1', - 'nic_lane1_postcursor1': '11', - 'nic_lane1_postcursor2': '11', - 'nic_lane2_precursor1': '12', - 'nic_lane2_precursor2': '7', - 'nic_lane2_maincursor': '7', - 'nic_lane2_postcursor1': '7', - 'nic_lane2_postcursor2': '7', - 'tor_self_lane1_precursor1': '17', - 'tor_self_lane1_precursor2': '17', - 'tor_self_lane1_maincursor': '17', - 'tor_self_lane1_postcursor1': '17', - 'tor_self_lane1_postcursor2': '17', - 'tor_self_lane2_precursor1': '7', - 'tor_self_lane2_precursor2': '7', - 'tor_self_lane2_maincursor': '7', - 'tor_self_lane2_postcursor1': '7', - 'tor_self_lane2_postcursor2': '7', - 'tor_peer_lane1_precursor1': '7', - 'tor_peer_lane1_precursor2': '7', - 'tor_peer_lane1_maincursor': '17', - 'tor_peer_lane1_postcursor1': '7', - 'tor_peer_lane1_postcursor2': '17', - 'tor_peer_lane2_precursor1': '7', - 'tor_peer_lane2_precursor2': '7', - 'tor_peer_lane2_maincursor': '17', - 'tor_peer_lane2_postcursor1': '7', - 'tor_peer_lane2_postcursor2': '17'})) - def test_post_port_mux_static_info_to_db(self): - logical_port_name = "Ethernet0" - mux_tbl = Table("STATE_DB", "Y_CABLE_STATIC_INFO_TABLE") - rc = post_port_mux_static_info_to_db(logical_port_name, mux_tbl) - assert(rc != -1) - - def test_y_cable_helper_format_mapping_identifier1(self): - rc = format_mapping_identifier("ABC ") - assert(rc == "abc") - - def test_y_cable_helper_format_mapping_identifier_no_instance(self): - rc = format_mapping_identifier(None) - assert(rc == None) + presence = y_cable_wrapper_get_presence(1) - def test_y_cable_wrapper_get_transceiver_info(self): - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: - patched_util.get_transceiver_info_dict.return_value = {'manufacturer': 'Microsoft', - 'model': 'model1'} - - transceiver_dict = y_cable_wrapper_get_transceiver_info(1) - vendor = transceiver_dict.get('manufacturer') - model = transceiver_dict.get('model') - - assert(vendor == "Microsoft") - assert(model == "model1") - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_chassis') - def test_y_cable_wrapper_get_transceiver_info_with_platform_chassis(self, mock_chassis): - - mock_object = MagicMock() - mock_object.get_transceiver_info.return_value = {'type': '1000_BASE_SX_SFP', - 'hardware_rev': '5', - 'serial': 'PEP3L5D', - 'manufacturer': 'FINISAR', - 'model': 'ABC', - 'connector': 'LC', - 'encoding': '8B10B', - 'ext_identifier': 'SFP', - 'ext_rateselect_compliance': 'DEF', - 'cable_length': '850', - 'nominal_bit_rate': '100', - 'specification_compliance': 'GHI', - 'vendor_date': '2021-01-01', - 'vendor_oui': '00:90:65'} - - mock_chassis.get_sfp = MagicMock(return_value=mock_object) - received_xcvr_info = y_cable_wrapper_get_transceiver_info(1) - - type = received_xcvr_info.get('type') - model = received_xcvr_info.get('model') - vendor_date = received_xcvr_info.get('vendor_date') - - assert(type == "1000_BASE_SX_SFP") - assert(model == "ABC") - assert(vendor_date == "2021-01-01") - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_chassis') - def test_y_cable_wrapper_get_transceiver_info_with_platform_chassis_not_implemented(self, mock_chassis): - - mock_object = MagicMock() - mock_object.get_transceiver_info.side_effect = NotImplementedError - mock_chassis.get_sfp = MagicMock(return_value=mock_object) + assert(presence == True) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_chassis') + def test_y_cable_wrapper_get_presence_with_platform_chassis(self, mock_chassis): + + mock_object = MagicMock() + mock_object.get_presence = MagicMock(return_value=True) + mock_chassis.get_sfp = MagicMock(return_value=mock_object) + presence = y_cable_wrapper_get_presence(1) + + assert(presence == True) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_chassis') + def test_y_cable_wrapper_get_presence_with_platform_chassis_raise_exception(self, mock_chassis): + + mock_object = MagicMock(spec=SfpBase) + mock_object.get_presence = MagicMock(side_effect=NotImplementedError) + mock_chassis.get_sfp = MagicMock(return_value=mock_object) + + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: + patched_util.get_presence.return_value = True + + assert(y_cable_wrapper_get_presence(1) == True) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.get_muxcable_info', MagicMock(return_value={'tor_active': 'self', + 'mux_direction': 'self', + 'manual_switch_count': '7', + 'auto_switch_count': '71', + 'link_status_self': 'up', + 'link_status_peer': 'up', + 'link_status_nic': 'up', + 'nic_lane1_active': 'True', + 'nic_lane2_active': 'True', + 'nic_lane3_active': 'True', + 'nic_lane4_active': 'True', + 'self_eye_height_lane1': '500', + 'self_eye_height_lane2': '510', + 'peer_eye_height_lane1': '520', + 'peer_eye_height_lane2': '530', + 'nic_eye_height_lane1': '742', + 'nic_eye_height_lane2': '750', + 'internal_temperature': '28', + 'internal_voltage': '3.3', + 'nic_temperature': '20', + 'nic_voltage': '2.7', + 'version_nic_active': '1.6MS', + 'version_nic_inactive': '1.7MS', + 'version_nic_next': '1.7MS', + 'version_self_active': '1.6MS', + 'version_self_inactive': '1.7MS', + 'version_self_next': '1.7MS', + 'version_peer_active': '1.6MS', + 'version_peer_inactive': '1.7MS', + 'version_peer_next': '1.7MS'})) + def test_post_port_mux_info_to_db(self): + logical_port_name = "Ethernet0" + mux_tbl = Table("STATE_DB", "Y_CABLE_INFO_TABLE") + rc = post_port_mux_info_to_db(logical_port_name, mux_tbl) + assert(rc != -1) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.get_muxcable_static_info', MagicMock(return_value={'read_side': 'self', + 'nic_lane1_precursor1': '1', + 'nic_lane1_precursor2': '-7', + 'nic_lane1_maincursor': '-1', + 'nic_lane1_postcursor1': '11', + 'nic_lane1_postcursor2': '11', + 'nic_lane2_precursor1': '12', + 'nic_lane2_precursor2': '7', + 'nic_lane2_maincursor': '7', + 'nic_lane2_postcursor1': '7', + 'nic_lane2_postcursor2': '7', + 'tor_self_lane1_precursor1': '17', + 'tor_self_lane1_precursor2': '17', + 'tor_self_lane1_maincursor': '17', + 'tor_self_lane1_postcursor1': '17', + 'tor_self_lane1_postcursor2': '17', + 'tor_self_lane2_precursor1': '7', + 'tor_self_lane2_precursor2': '7', + 'tor_self_lane2_maincursor': '7', + 'tor_self_lane2_postcursor1': '7', + 'tor_self_lane2_postcursor2': '7', + 'tor_peer_lane1_precursor1': '7', + 'tor_peer_lane1_precursor2': '7', + 'tor_peer_lane1_maincursor': '17', + 'tor_peer_lane1_postcursor1': '7', + 'tor_peer_lane1_postcursor2': '17', + 'tor_peer_lane2_precursor1': '7', + 'tor_peer_lane2_precursor2': '7', + 'tor_peer_lane2_maincursor': '17', + 'tor_peer_lane2_postcursor1': '7', + 'tor_peer_lane2_postcursor2': '17'})) + def test_post_port_mux_static_info_to_db(self): + logical_port_name = "Ethernet0" + mux_tbl = Table("STATE_DB", "Y_CABLE_STATIC_INFO_TABLE") + rc = post_port_mux_static_info_to_db(logical_port_name, mux_tbl) + assert(rc != -1) + + def test_y_cable_helper_format_mapping_identifier1(self): + rc = format_mapping_identifier("ABC ") + assert(rc == "abc") + + def test_y_cable_helper_format_mapping_identifier_no_instance(self): + rc = format_mapping_identifier(None) + assert(rc == None) + + def test_y_cable_wrapper_get_transceiver_info(self): + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: + patched_util.get_transceiver_info_dict.return_value = {'manufacturer': 'Microsoft', + 'model': 'model1'} + + transceiver_dict = y_cable_wrapper_get_transceiver_info(1) + vendor = transceiver_dict.get('manufacturer') + model = transceiver_dict.get('model') + + assert(vendor == "Microsoft") + assert(model == "model1") + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_chassis') + def test_y_cable_wrapper_get_transceiver_info_with_platform_chassis(self, mock_chassis): + + mock_object = MagicMock() + mock_object.get_transceiver_info.return_value = {'type': '1000_BASE_SX_SFP', + 'hardware_rev': '5', + 'serial': 'PEP3L5D', + 'manufacturer': 'FINISAR', + 'model': 'ABC', + 'connector': 'LC', + 'encoding': '8B10B', + 'ext_identifier': 'SFP', + 'ext_rateselect_compliance': 'DEF', + 'cable_length': '850', + 'nominal_bit_rate': '100', + 'specification_compliance': 'GHI', + 'vendor_date': '2021-01-01', + 'vendor_oui': '00:90:65'} + + mock_chassis.get_sfp = MagicMock(return_value=mock_object) + received_xcvr_info = y_cable_wrapper_get_transceiver_info(1) + + type = received_xcvr_info.get('type') + model = received_xcvr_info.get('model') + vendor_date = received_xcvr_info.get('vendor_date') + + assert(type == "1000_BASE_SX_SFP") + assert(model == "ABC") + assert(vendor_date == "2021-01-01") + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_chassis') + def test_y_cable_wrapper_get_transceiver_info_with_platform_chassis_not_implemented(self, mock_chassis): + + mock_object = MagicMock() + mock_object.get_transceiver_info.side_effect = NotImplementedError + mock_chassis.get_sfp = MagicMock(return_value=mock_object) + + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: + patched_util.get_transceiver_info_dict.return_value = {'manufacturer': 'microsoft', + 'model': 'simulated'} + + transceiver_dict = y_cable_wrapper_get_transceiver_info(1) + vendor = transceiver_dict.get('manufacturer') + model = transceiver_dict.get('model') + + assert(vendor == "microsoft") + assert(model == "simulated") + + def test_y_cable_wrapper_get_presence(self): + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: + patched_util.get_presence.return_value = True - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: - patched_util.get_transceiver_info_dict.return_value = {'manufacturer': 'microsoft', - 'model': 'simulated'} + presence = y_cable_wrapper_get_presence(1) - transceiver_dict = y_cable_wrapper_get_transceiver_info(1) - vendor = transceiver_dict.get('manufacturer') - model = transceiver_dict.get('model') + assert(presence == True) - assert(vendor == "microsoft") - assert(model == "simulated") + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_chassis') + def test_y_cable_wrapper_get_presence_with_platform_chassis(self, mock_chassis): - def test_y_cable_wrapper_get_presence(self): - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: - patched_util.get_presence.return_value = True + mock_object = MagicMock() + mock_object.get_presence = MagicMock(return_value=True) + mock_chassis.get_sfp = MagicMock(return_value=mock_object) + presence = y_cable_wrapper_get_presence(1) - presence = y_cable_wrapper_get_presence(1) + assert(presence == True) - assert(presence == True) + def test_y_cable_toggle_mux_torA_update_status_true(self): - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_chassis') - def test_y_cable_wrapper_get_presence_with_platform_chassis(self, mock_chassis): + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - mock_object = MagicMock() - mock_object.get_presence = MagicMock(return_value=True) - mock_chassis.get_sfp = MagicMock(return_value=mock_object) - presence = y_cable_wrapper_get_presence(1) + mock_toggle_object = MagicMock() + mock_toggle_object.toggle_mux_to_tor_a.return_value = True + patched_util.get.return_value = mock_toggle_object - assert(presence == True) + rc = y_cable_toggle_mux_torA(1) - def test_y_cable_toggle_mux_torA_update_status_true(self): + assert(rc == 1) - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + def test_y_cable_toggle_mux_torA_no_port_instance(self): - mock_toggle_object = MagicMock() - mock_toggle_object.toggle_mux_to_tor_a.return_value = True - patched_util.get.return_value = mock_toggle_object + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as port_instance: - rc = y_cable_toggle_mux_torA(1) + port_instance.get.return_value = None + rc = y_cable_toggle_mux_torA(1) - assert(rc == 1) + assert(rc == -1) - def test_y_cable_toggle_mux_torA_no_port_instance(self): + def test_y_cable_toggle_mux_torA_update_status_exception(self): - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as port_instance: + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as port_instance: - port_instance.get.return_value = None - rc = y_cable_toggle_mux_torA(1) + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 + self.MUX_TOGGLE_STATUS_NOT_INITIATED_OR_FINISHED = 0 - assert(rc == -1) + # Defining function without self argument creates an exception, + # which is what we want for this test. + def get_mux_direction(): + pass + def toggle_mux_to_tor_a(): + raise NotImplementedError - def test_y_cable_toggle_mux_torA_update_status_exception(self): + port_instance.get.return_value = PortInstanceHelper() - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as port_instance: - class PortInstanceHelper(): - def __init__(self): - self.EEPROM_ERROR = -1 - self.MUX_TOGGLE_STATUS_NOT_INITIATED_OR_FINISHED = 0 + rc = y_cable_toggle_mux_torA(1) - # Defining function without self argument creates an exception, - # which is what we want for this test. - def get_mux_direction(): - pass - def toggle_mux_to_tor_a(): - raise NotImplementedError + assert(rc == -1) - port_instance.get.return_value = PortInstanceHelper() + def test_y_cable_toggle_mux_torA_update_status_true(self): + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - rc = y_cable_toggle_mux_torA(1) + mock_toggle_object = MagicMock() + mock_toggle_object.toggle_mux_to_tor_a.return_value = True + patched_util.get.return_value = mock_toggle_object - assert(rc == -1) + rc = y_cable_toggle_mux_torA(1) - def test_y_cable_toggle_mux_torA_update_status_true(self): + assert(rc == 1) - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + def test_y_cable_toggle_mux_torB_no_port_instance(self): - mock_toggle_object = MagicMock() - mock_toggle_object.toggle_mux_to_tor_a.return_value = True - patched_util.get.return_value = mock_toggle_object + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as port_instance: - rc = y_cable_toggle_mux_torA(1) + port_instance.get.return_value = None + rc = y_cable_toggle_mux_torB(1) - assert(rc == 1) + assert(rc == -1) - def test_y_cable_toggle_mux_torB_no_port_instance(self): + def test_y_cable_toggle_mux_torB_update_status_exception(self): + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as port_instance: - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as port_instance: + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 + self.MUX_TOGGLE_STATUS_NOT_INITIATED_OR_FINISHED = 0 - port_instance.get.return_value = None - rc = y_cable_toggle_mux_torB(1) + # Defining function without self argument creates an exception, + # which is what we want for this test. + def get_mux_direction(): + pass + def toggle_mux_to_tor_a(): + raise NotImplementedError - assert(rc == -1) + port_instance.get.return_value = PortInstanceHelper() - def test_y_cable_toggle_mux_torB_update_status_exception(self): - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as port_instance: + rc = y_cable_toggle_mux_torB(1) - class PortInstanceHelper(): - def __init__(self): - self.EEPROM_ERROR = -1 - self.MUX_TOGGLE_STATUS_NOT_INITIATED_OR_FINISHED = 0 + assert(rc == -1) - # Defining function without self argument creates an exception, - # which is what we want for this test. - def get_mux_direction(): - pass - def toggle_mux_to_tor_a(): - raise NotImplementedError + def test_y_cable_toggle_mux_torB_update_status_true(self): - port_instance.get.return_value = PortInstanceHelper() + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - rc = y_cable_toggle_mux_torB(1) + mock_toggle_object = MagicMock() + mock_toggle_object.toggle_mux_to_tor_b.return_value = True + patched_util.get.return_value = mock_toggle_object - assert(rc == -1) + rc = y_cable_toggle_mux_torB(1) - def test_y_cable_toggle_mux_torB_update_status_true(self): + assert(rc == 2) - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + def test_update_tor_active_side_1_active(self): + read_side = 1 + state = "active" + logical_port_name = "Ethernet0" + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - mock_toggle_object = MagicMock() - mock_toggle_object.toggle_mux_to_tor_b.return_value = True - patched_util.get.return_value = mock_toggle_object + mock_toggle_object = MagicMock() + mock_toggle_object.toggle_mux_to_tor_a.return_value = True + patched_util.get.return_value = mock_toggle_object - rc = y_cable_toggle_mux_torB(1) + rc = update_tor_active_side(read_side, state, logical_port_name) - assert(rc == 2) + assert(rc == (1, 1)) - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - def test_update_tor_active_side_1_active(self): - read_side = 1 - state = "active" - logical_port_name = "Ethernet0" - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + def test_update_tor_active_side_2_active(self): + read_side = 2 + state = "active" + logical_port_name = "Ethernet0" + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - mock_toggle_object = MagicMock() - mock_toggle_object.toggle_mux_to_tor_a.return_value = True - patched_util.get.return_value = mock_toggle_object + mock_toggle_object = MagicMock() + mock_toggle_object.toggle_mux_to_tor_b.return_value = True + patched_util.get.return_value = mock_toggle_object - rc = update_tor_active_side(read_side, state, logical_port_name) + rc = update_tor_active_side(read_side, state, logical_port_name) - assert(rc == (1, 1)) + assert(rc == (2,2)) - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - def test_update_tor_active_side_2_active(self): - read_side = 2 - state = "active" - logical_port_name = "Ethernet0" - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + def test_update_tor_active_side_1_standby(self): + read_side = 1 + state = "standby" + logical_port_name = "Ethernet0" + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - mock_toggle_object = MagicMock() - mock_toggle_object.toggle_mux_to_tor_b.return_value = True - patched_util.get.return_value = mock_toggle_object + mock_toggle_object = MagicMock() + mock_toggle_object.toggle_mux_to_tor_b.return_value = True + patched_util.get.return_value = mock_toggle_object - rc = update_tor_active_side(read_side, state, logical_port_name) + rc = update_tor_active_side(read_side, state, logical_port_name) - assert(rc == (2,2)) + assert(rc == (2,1)) - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - def test_update_tor_active_side_1_standby(self): - read_side = 1 - state = "standby" - logical_port_name = "Ethernet0" - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + def test_update_tor_active_side_2_standby(self): + read_side = 2 + state = "standby" + logical_port_name = "Ethernet0" + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - mock_toggle_object = MagicMock() - mock_toggle_object.toggle_mux_to_tor_b.return_value = True - patched_util.get.return_value = mock_toggle_object + mock_toggle_object = MagicMock() + mock_toggle_object.toggle_mux_to_tor_a.return_value = True + patched_util.get.return_value = mock_toggle_object - rc = update_tor_active_side(read_side, state, logical_port_name) + rc = update_tor_active_side(read_side, state, logical_port_name) - assert(rc == (2,1)) + assert(rc == (1,2)) - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - def test_update_tor_active_side_2_standby(self): - read_side = 2 - state = "standby" - logical_port_name = "Ethernet0" - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=False)) + def test_update_tor_active_side_no_cable_presence(self): + read_side = 1 + state = "active" + logical_port_name = "Ethernet0" + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - mock_toggle_object = MagicMock() - mock_toggle_object.toggle_mux_to_tor_a.return_value = True - patched_util.get.return_value = mock_toggle_object + mock_toggle_object = MagicMock() + mock_toggle_object.toggle_mux_to_tor_a.return_value = True + patched_util.get.return_value = mock_toggle_object - rc = update_tor_active_side(read_side, state, logical_port_name) + rc = update_tor_active_side(read_side, state, logical_port_name) - assert(rc == (1,2)) + assert(rc == (-1,-1)) - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=False)) - def test_update_tor_active_side_no_cable_presence(self): - read_side = 1 - state = "active" - logical_port_name = "Ethernet0" - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0, 1, 2])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=False)) + def test_update_tor_active_side_multiple_mappings(self): + read_side = 1 + state = "active" + logical_port_name = "Ethernet0" + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - mock_toggle_object = MagicMock() - mock_toggle_object.toggle_mux_to_tor_a.return_value = True - patched_util.get.return_value = mock_toggle_object + mock_toggle_object = MagicMock() + mock_toggle_object.toggle_mux_to_tor_a.return_value = True + patched_util.get.return_value = mock_toggle_object - rc = update_tor_active_side(read_side, state, logical_port_name) + rc = update_tor_active_side(read_side, state, logical_port_name) - assert(rc == (-1,-1)) + assert(rc == (-1,-1)) - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0, 1, 2])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=False)) - def test_update_tor_active_side_multiple_mappings(self): - read_side = 1 - state = "active" - logical_port_name = "Ethernet0" - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + def test_update_tor_active_side_with_read_update(self): + read_side = -1 + state = "active" + logical_port_name = "Ethernet0" + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - mock_toggle_object = MagicMock() - mock_toggle_object.toggle_mux_to_tor_a.return_value = True - patched_util.get.return_value = mock_toggle_object + mock_toggle_object = MagicMock() + mock_toggle_object.toggle_mux_to_tor_a.return_value = True + mock_toggle_object.get_read_side.return_value = 1 + patched_util.get.return_value = mock_toggle_object - rc = update_tor_active_side(read_side, state, logical_port_name) + rc = update_tor_active_side(read_side, state, logical_port_name) - assert(rc == (-1,-1)) + assert(rc == (1, 1)) - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - def test_update_tor_active_side_with_read_update(self): - read_side = -1 - state = "active" - logical_port_name = "Ethernet0" - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + def test_update_tor_active_side_with_read_update(self): + read_side = -1 + state = "active" + logical_port_name = "Ethernet0" + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - mock_toggle_object = MagicMock() - mock_toggle_object.toggle_mux_to_tor_a.return_value = True - mock_toggle_object.get_read_side.return_value = 1 - patched_util.get.return_value = mock_toggle_object + mock_toggle_object = MagicMock() + mock_toggle_object.toggle_mux_to_tor_b.return_value = True + mock_toggle_object.get_read_side.return_value = 2 + patched_util.get.return_value = mock_toggle_object - rc = update_tor_active_side(read_side, state, logical_port_name) + rc = update_tor_active_side(read_side, state, logical_port_name) - assert(rc == (1, 1)) + assert(rc == (2, 1)) - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - def test_update_tor_active_side_with_read_update(self): - read_side = -1 - state = "active" - logical_port_name = "Ethernet0" - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + def test_update_tor_active_side_with_read_update(self): + read_side = -1 + state = "active" + logical_port_name = "Ethernet0" + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - mock_toggle_object = MagicMock() - mock_toggle_object.toggle_mux_to_tor_b.return_value = True - mock_toggle_object.get_read_side.return_value = 2 - patched_util.get.return_value = mock_toggle_object + mock_toggle_object = MagicMock() + mock_toggle_object.toggle_mux_to_tor_b.return_value = True + mock_toggle_object.get_read_side.return_value = -1 + patched_util.get.return_value = mock_toggle_object - rc = update_tor_active_side(read_side, state, logical_port_name) + rc = update_tor_active_side(read_side, state, logical_port_name) - assert(rc == (2, 1)) + assert(rc == (-1, -1)) - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - def test_update_tor_active_side_with_read_update(self): - read_side = -1 - state = "active" - logical_port_name = "Ethernet0" - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + def test_get_mux_cable_info_without_presence(self): - mock_toggle_object = MagicMock() - mock_toggle_object.toggle_mux_to_tor_b.return_value = True - mock_toggle_object.get_read_side.return_value = -1 - patched_util.get.return_value = mock_toggle_object + rc = get_muxcable_info_without_presence() - rc = update_tor_active_side(read_side, state, logical_port_name) + assert(rc['tor_active'] == 'unknown') + assert(rc['mux_direction'] == 'unknown') + assert(rc['manual_switch_count'] == 'N/A') + assert(rc['auto_switch_count'] == 'N/A') - assert(rc == (-1, -1)) - def test_get_mux_cable_info_without_presence(self): + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + def test_get_ycable_physical_port_from_logical_port(self): + instance = get_ycable_physical_port_from_logical_port("Ethernet0") - rc = get_muxcable_info_without_presence() + assert(instance == 0) - assert(rc['tor_active'] == 'unknown') - assert(rc['mux_direction'] == 'unknown') - assert(rc['manual_switch_count'] == 'N/A') - assert(rc['auto_switch_count'] == 'N/A') + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=False)) + def test_get_ycable_physical_port_from_logical_port_physical_port_not_present(self): + instance = get_ycable_physical_port_from_logical_port("Ethernet0") + assert(instance == -1) - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - def test_get_ycable_physical_port_from_logical_port(self): - instance = get_ycable_physical_port_from_logical_port("Ethernet0") + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value={})) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=False)) + def test_get_ycable_physical_port_from_logical_port_physical_port_list_empty(self): - assert(instance == 0) + instance = get_ycable_physical_port_from_logical_port("Ethernet0") - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=False)) - def test_get_ycable_physical_port_from_logical_port_physical_port_not_present(self): - instance = get_ycable_physical_port_from_logical_port("Ethernet0") + assert(instance == -1) - assert(instance == -1) + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + def test_get_ycable_port_instance_from_logical_port(self): - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value={})) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=False)) - def test_get_ycable_physical_port_from_logical_port_physical_port_list_empty(self): + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + patched_util.get.return_value = 0 + instance = get_ycable_port_instance_from_logical_port("Ethernet0") - instance = get_ycable_physical_port_from_logical_port("Ethernet0") + assert(instance == 0) - assert(instance == -1) + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=False)) + def test_get_ycable_port_instance_from_logical_port_no_presence(self): + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + patched_util.get.return_value = 0 + instance = get_ycable_port_instance_from_logical_port("Ethernet0") - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - def test_get_ycable_port_instance_from_logical_port(self): + assert(instance == PORT_INSTANCE_ERROR) - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - patched_util.get.return_value = 0 - instance = get_ycable_port_instance_from_logical_port("Ethernet0") + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + def test_get_ycable_port_instance_from_logical_port_no_port_instance(self): - assert(instance == 0) + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + def mock_get(): + pass - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=False)) - def test_get_ycable_port_instance_from_logical_port_no_presence(self): - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - patched_util.get.return_value = 0 - instance = get_ycable_port_instance_from_logical_port("Ethernet0") + patched_util.get.return_value = mock_get() + instance = get_ycable_port_instance_from_logical_port("E") - assert(instance == PORT_INSTANCE_ERROR) + assert(instance == PORT_INSTANCE_ERROR) - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - def test_get_ycable_port_instance_from_logical_port_no_port_instance(self): + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0, 1, 2])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + def test_get_ycable_port_instance_from_logical_port_multiple_mapping(self): - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - def mock_get(): - pass + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + patched_util.get.return_value = 0 + instance = get_ycable_port_instance_from_logical_port("Ethernet0") - patched_util.get.return_value = mock_get() - instance = get_ycable_port_instance_from_logical_port("E") + assert(instance == -1) - assert(instance == PORT_INSTANCE_ERROR) + def test_update_table_mux_status_for_response_tbl(self): + asic_index = 0 + appl_db = "TEST_DB" + logical_port_name = "Ethernet0" + status = "standby" - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0, 1, 2])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - def test_get_ycable_port_instance_from_logical_port_multiple_mapping(self): + test_table = swsscommon.Table(appl_db[asic_index], "XCVRD_TEST_TABLE") + update_table_mux_status_for_response_tbl( + test_table, status, logical_port_name) - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - patched_util.get.return_value = 0 - instance = get_ycable_port_instance_from_logical_port("Ethernet0") + rc = test_table.get(logical_port_name) - assert(instance == -1) + # Since the table class is mocked, the most we can test for is that get doesn't return None + assert(type(rc) != None) - def test_update_table_mux_status_for_response_tbl(self): - asic_index = 0 - appl_db = "TEST_DB" - logical_port_name = "Ethernet0" - status = "standby" + def test_set_result_and_delete_port(self): - test_table = swsscommon.Table(appl_db[asic_index], "XCVRD_TEST_TABLE") - update_table_mux_status_for_response_tbl( - test_table, status, logical_port_name) + result = "result" + actual_result = "pass" + appl_db = "TEST_DB" + port = 0 - rc = test_table.get(logical_port_name) + command_table = swsscommon.Table(appl_db[0], "XCVRD_COMMAND_TABLE") + response_table = swsscommon.Table(appl_db[1], "XCVRD_RESPONSE_TABLE") - # Since the table class is mocked, the most we can test for is that get doesn't return None - assert(type(rc) != None) + rc = set_result_and_delete_port( + result, actual_result, command_table, response_table, port) + assert(rc == None) - def test_set_result_and_delete_port(self): + def test_delete_port_from_y_cable_table(self): + logical_port_name = "Ethernet0" + appl_db = "TEST_DB" + y_cable_tbl = swsscommon.Table(appl_db[0], "XCVRD_Y_CBL_TABLE") - result = "result" - actual_result = "pass" - appl_db = "TEST_DB" - port = 0 + rc = delete_port_from_y_cable_table(logical_port_name, y_cable_tbl) + assert(rc == None) - command_table = swsscommon.Table(appl_db[0], "XCVRD_COMMAND_TABLE") - response_table = swsscommon.Table(appl_db[1], "XCVRD_RESPONSE_TABLE") + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + def test_update_appdb_port_mux_cable_response_table_port_instance_none(self): + asic_index = 0 + appl_db = "TEST_DB" + logical_port_name = "Ethernet0" + read_side = 1 - rc = set_result_and_delete_port( - result, actual_result, command_table, response_table, port) - assert(rc == None) + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + def mock_get(): + pass - def test_delete_port_from_y_cable_table(self): - logical_port_name = "Ethernet0" - appl_db = "TEST_DB" - y_cable_tbl = swsscommon.Table(appl_db[0], "XCVRD_Y_CBL_TABLE") + patched_util.get.return_value = mock_get() - rc = delete_port_from_y_cable_table(logical_port_name, y_cable_tbl) + rc = update_appdb_port_mux_cable_response_table( + logical_port_name, asic_index, appl_db, read_side) assert(rc == None) - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - def test_update_appdb_port_mux_cable_response_table_port_instance_none(self): - asic_index = 0 - appl_db = "TEST_DB" - logical_port_name = "Ethernet0" - read_side = 1 - - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - def mock_get(): - pass + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + def test_update_appdb_port_mux_cable_response_table_read_side_none(self): + asic_index = 0 + appl_db = "TEST_DB" + logical_port_name = "Ethernet0" - patched_util.get.return_value = mock_get() + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + def mock_read_side(): + pass - rc = update_appdb_port_mux_cable_response_table( - logical_port_name, asic_index, appl_db, read_side) - assert(rc == None) + read_side = mock_read_side() - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - def test_update_appdb_port_mux_cable_response_table_read_side_none(self): - asic_index = 0 - appl_db = "TEST_DB" - logical_port_name = "Ethernet0" - - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - def mock_read_side(): - pass + patched_util.get.return_value = 0 - read_side = mock_read_side() + rc = update_appdb_port_mux_cable_response_table( + logical_port_name, asic_index, appl_db, read_side) + assert(rc == None) - patched_util.get.return_value = 0 + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + def test_update_appdb_port_mux_cable_response_table_active_side_none(self): + asic_index = 0 + appl_db = "TEST_DB" + logical_port_name = "Ethernet0" + read_side = 1 - rc = update_appdb_port_mux_cable_response_table( - logical_port_name, asic_index, appl_db, read_side) - assert(rc == None) + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - def test_update_appdb_port_mux_cable_response_table_active_side_none(self): - asic_index = 0 - appl_db = "TEST_DB" - logical_port_name = "Ethernet0" - read_side = 1 + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + # Defining function without self argument creates an exception, + # which is what we want for this test. + def get_mux_direction(): + pass - class PortInstanceHelper(): - def __init__(self): - self.EEPROM_ERROR = -1 + patched_util.get.return_value = PortInstanceHelper() - # Defining function without self argument creates an exception, - # which is what we want for this test. - def get_mux_direction(): - pass + rc = update_appdb_port_mux_cable_response_table( + logical_port_name, asic_index, appl_db, read_side) + assert(rc == None) - patched_util.get.return_value = PortInstanceHelper() + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + def test_update_appdb_port_mux_cable_response_table_active_side_is_read_side(self): + asic_index = 0 + appl_db = "TEST_DB" + logical_port_name = "Ethernet0" + read_side = 1 - rc = update_appdb_port_mux_cable_response_table( - logical_port_name, asic_index, appl_db, read_side) - assert(rc == None) + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - def test_update_appdb_port_mux_cable_response_table_active_side_is_read_side(self): - asic_index = 0 - appl_db = "TEST_DB" - logical_port_name = "Ethernet0" - read_side = 1 + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + def get_mux_direction(self): + return 1 - class PortInstanceHelper(): - def __init__(self): - self.EEPROM_ERROR = -1 + patched_util.get.return_value = PortInstanceHelper() - def get_mux_direction(self): - return 1 + rc = update_appdb_port_mux_cable_response_table( + logical_port_name, asic_index, appl_db, read_side) + assert(rc == None) - patched_util.get.return_value = PortInstanceHelper() + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + def test_update_appdb_port_mux_cable_response_table_active_side_not_read_side(self): + asic_index = 0 + appl_db = "TEST_DB" + logical_port_name = "Ethernet0" + read_side = 2 - rc = update_appdb_port_mux_cable_response_table( - logical_port_name, asic_index, appl_db, read_side) - assert(rc == None) + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - def test_update_appdb_port_mux_cable_response_table_active_side_not_read_side(self): - asic_index = 0 - appl_db = "TEST_DB" - logical_port_name = "Ethernet0" - read_side = 2 + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + def get_mux_direction(self): + return 1 - class PortInstanceHelper(): - def __init__(self): - self.EEPROM_ERROR = -1 + patched_util.get.return_value = PortInstanceHelper() - def get_mux_direction(self): - return 1 + rc = update_appdb_port_mux_cable_response_table( + logical_port_name, asic_index, appl_db, read_side) + assert(rc == None) - patched_util.get.return_value = PortInstanceHelper() + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + def test_update_appdb_port_mux_cable_response_table_active_side_status_unknown(self): + asic_index = 0 + appl_db = "TEST_DB" + logical_port_name = "Ethernet0" + read_side = 1 - rc = update_appdb_port_mux_cable_response_table( - logical_port_name, asic_index, appl_db, read_side) - assert(rc == None) + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - def test_update_appdb_port_mux_cable_response_table_active_side_status_unknown(self): - asic_index = 0 - appl_db = "TEST_DB" - logical_port_name = "Ethernet0" - read_side = 1 + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + def get_mux_direction(self): + return 4 - class PortInstanceHelper(): - def __init__(self): - self.EEPROM_ERROR = -1 + patched_util.get.return_value = PortInstanceHelper() - def get_mux_direction(self): - return 4 + rc = update_appdb_port_mux_cable_response_table( + logical_port_name, asic_index, appl_db, read_side) + assert(rc == None) - patched_util.get.return_value = PortInstanceHelper() + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=False)) + def test_update_appdb_port_mux_cable_response_table_no_presence_status_unknown(self): + asic_index = 0 + appl_db = "TEST_DB" + logical_port_name = "Ethernet0" + read_side = 1 - rc = update_appdb_port_mux_cable_response_table( - logical_port_name, asic_index, appl_db, read_side) - assert(rc == None) + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=False)) - def test_update_appdb_port_mux_cable_response_table_no_presence_status_unknown(self): - asic_index = 0 - appl_db = "TEST_DB" - logical_port_name = "Ethernet0" - read_side = 1 + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + def get_mux_direction(self): + return 4 - class PortInstanceHelper(): - def __init__(self): - self.EEPROM_ERROR = -1 + patched_util.get.return_value = PortInstanceHelper() - def get_mux_direction(self): - return 4 + rc = update_appdb_port_mux_cable_response_table( + logical_port_name, asic_index, appl_db, read_side) + assert(rc == None) - patched_util.get.return_value = PortInstanceHelper() + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0, 1, 2])) + def test_update_appdb_port_mux_cable_response_table_invalid_ycable_mapping(self): + asic_index = 0 + appl_db = "TEST_DB" + logical_port_name = "Ethernet0" + read_side = 1 - rc = update_appdb_port_mux_cable_response_table( - logical_port_name, asic_index, appl_db, read_side) - assert(rc == None) + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0, 1, 2])) - def test_update_appdb_port_mux_cable_response_table_invalid_ycable_mapping(self): - asic_index = 0 - appl_db = "TEST_DB" - logical_port_name = "Ethernet0" - read_side = 1 + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + def get_mux_direction(self): + return 4 - class PortInstanceHelper(): - def __init__(self): - self.EEPROM_ERROR = -1 + patched_util.get.return_value = PortInstanceHelper() - def get_mux_direction(self): - return 4 + rc = update_appdb_port_mux_cable_response_table( + logical_port_name, asic_index, appl_db, read_side) + assert(rc == None) - patched_util.get.return_value = PortInstanceHelper() + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0, 1, 2])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + def test_read_y_cable_and_update_statedb_port_tbl_invalid_ycable_mapping(self): - rc = update_appdb_port_mux_cable_response_table( - logical_port_name, asic_index, appl_db, read_side) - assert(rc == None) + logical_port_name = "Ethernet0" + statedb_port_tbl = {} + asic_index = 0 + appl_db = "TEST_DB" - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0, 1, 2])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - def test_read_y_cable_and_update_statedb_port_tbl_invalid_ycable_mapping(self): + statedb_port_tbl[asic_index] = swsscommon.Table( + appl_db[asic_index], "STATEDB_PORT_TABLE") - logical_port_name = "Ethernet0" - statedb_port_tbl = {} - asic_index = 0 - appl_db = "TEST_DB" + rc = read_y_cable_and_update_statedb_port_tbl( + logical_port_name, statedb_port_tbl[asic_index]) + assert(rc == None) - statedb_port_tbl[asic_index] = swsscommon.Table( - appl_db[asic_index], "STATEDB_PORT_TABLE") + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_read_y_cable_and_update_statedb_port_tbl_port_instance_none(self): - rc = read_y_cable_and_update_statedb_port_tbl( - logical_port_name, statedb_port_tbl[asic_index]) - assert(rc == None) + logical_port_name = "Ethernet0" + statedb_port_tbl = {} + asic_index = 0 + appl_db = "TEST_DB" - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_read_y_cable_and_update_statedb_port_tbl_port_instance_none(self): + statedb_port_tbl[asic_index] = swsscommon.Table( + appl_db[asic_index], "STATEDB_PORT_TABLE") - logical_port_name = "Ethernet0" - statedb_port_tbl = {} - asic_index = 0 - appl_db = "TEST_DB" + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + def mock_get(): + pass - statedb_port_tbl[asic_index] = swsscommon.Table( - appl_db[asic_index], "STATEDB_PORT_TABLE") + patched_util.get.return_value = mock_get() + rc = read_y_cable_and_update_statedb_port_tbl( + logical_port_name, statedb_port_tbl[asic_index]) + assert(rc == None) - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - def mock_get(): - pass + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=False)) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_read_y_cable_and_update_statedb_port_tbl_get_presence_false(self): - patched_util.get.return_value = mock_get() - rc = read_y_cable_and_update_statedb_port_tbl( - logical_port_name, statedb_port_tbl[asic_index]) - assert(rc == None) + logical_port_name = "Ethernet0" + statedb_port_tbl = {} + asic_index = 0 + appl_db = "TEST_DB" - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=False)) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_read_y_cable_and_update_statedb_port_tbl_get_presence_false(self): + statedb_port_tbl[asic_index] = swsscommon.Table( + appl_db[asic_index], "STATEDB_PORT_TABLE") - logical_port_name = "Ethernet0" - statedb_port_tbl = {} - asic_index = 0 - appl_db = "TEST_DB" + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + def mock_get(): + pass - statedb_port_tbl[asic_index] = swsscommon.Table( - appl_db[asic_index], "STATEDB_PORT_TABLE") + patched_util.get.return_value = mock_get() + rc = read_y_cable_and_update_statedb_port_tbl( + logical_port_name, statedb_port_tbl[asic_index]) + assert(rc == None) - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - def mock_get(): - pass + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_read_y_cable_and_update_statedb_port_tbl_port_instance_get_read_side_exception(self): - patched_util.get.return_value = mock_get() - rc = read_y_cable_and_update_statedb_port_tbl( - logical_port_name, statedb_port_tbl[asic_index]) - assert(rc == None) + logical_port_name = "Ethernet0" + statedb_port_tbl = {} + asic_index = 0 + appl_db = "TEST_DB" - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_read_y_cable_and_update_statedb_port_tbl_port_instance_get_read_side_exception(self): + statedb_port_tbl[asic_index] = swsscommon.Table( + appl_db[asic_index], "STATEDB_PORT_TABLE") - logical_port_name = "Ethernet0" - statedb_port_tbl = {} - asic_index = 0 - appl_db = "TEST_DB" + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 - statedb_port_tbl[asic_index] = swsscommon.Table( - appl_db[asic_index], "STATEDB_PORT_TABLE") + # Defining function without self argument creates an exception, + # which is what we want for this test. + def get_read_side(): + pass - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - class PortInstanceHelper(): - def __init__(self): - self.EEPROM_ERROR = -1 + patched_util.get.return_value = PortInstanceHelper() + rc = read_y_cable_and_update_statedb_port_tbl( + logical_port_name, statedb_port_tbl[asic_index]) + assert(rc == None) - # Defining function without self argument creates an exception, - # which is what we want for this test. - def get_read_side(): - pass + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_read_y_cable_and_update_statedb_port_tbl_port_instance_get_mux_dir_exception(self): - patched_util.get.return_value = PortInstanceHelper() - rc = read_y_cable_and_update_statedb_port_tbl( - logical_port_name, statedb_port_tbl[asic_index]) - assert(rc == None) + logical_port_name = "Ethernet0" + statedb_port_tbl = {} + asic_index = 0 + appl_db = "TEST_DB" - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_read_y_cable_and_update_statedb_port_tbl_port_instance_get_mux_dir_exception(self): + statedb_port_tbl[asic_index] = swsscommon.Table( + appl_db[asic_index], "STATEDB_PORT_TABLE") - logical_port_name = "Ethernet0" - statedb_port_tbl = {} - asic_index = 0 - appl_db = "TEST_DB" + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 - statedb_port_tbl[asic_index] = swsscommon.Table( - appl_db[asic_index], "STATEDB_PORT_TABLE") + def get_read_side(self): + return 1 - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - class PortInstanceHelper(): - def __init__(self): - self.EEPROM_ERROR = -1 + # Defining function without self argument creates an exception, + # which is what we want for this test. + def get_mux_direction(): + pass - def get_read_side(self): - return 1 + patched_util.get.return_value = PortInstanceHelper() + rc = read_y_cable_and_update_statedb_port_tbl( + logical_port_name, statedb_port_tbl[asic_index]) + assert(rc == None) - # Defining function without self argument creates an exception, - # which is what we want for this test. - def get_mux_direction(): - pass + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_read_y_cable_and_update_statedb_port_tbl_port_instance_status_active(self): - patched_util.get.return_value = PortInstanceHelper() - rc = read_y_cable_and_update_statedb_port_tbl( - logical_port_name, statedb_port_tbl[asic_index]) - assert(rc == None) + logical_port_name = "Ethernet0" + statedb_port_tbl = {} + asic_index = 0 + appl_db = "TEST_DB" - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_read_y_cable_and_update_statedb_port_tbl_port_instance_status_active(self): + statedb_port_tbl[asic_index] = swsscommon.Table( + appl_db[asic_index], "STATEDB_PORT_TABLE") - logical_port_name = "Ethernet0" - statedb_port_tbl = {} - asic_index = 0 - appl_db = "TEST_DB" + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 - statedb_port_tbl[asic_index] = swsscommon.Table( - appl_db[asic_index], "STATEDB_PORT_TABLE") + def get_read_side(self): + return 1 - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - class PortInstanceHelper(): - def __init__(self): - self.EEPROM_ERROR = -1 + def get_mux_direction(self): + return 1 - def get_read_side(self): - return 1 + patched_util.get.return_value = PortInstanceHelper() + rc = read_y_cable_and_update_statedb_port_tbl( + logical_port_name, statedb_port_tbl[asic_index]) + assert(rc == None) - def get_mux_direction(self): - return 1 + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_read_y_cable_and_update_statedb_port_tbl_port_instance_status_standby(self): - patched_util.get.return_value = PortInstanceHelper() - rc = read_y_cable_and_update_statedb_port_tbl( - logical_port_name, statedb_port_tbl[asic_index]) - assert(rc == None) + logical_port_name = "Ethernet0" + statedb_port_tbl = {} + asic_index = 0 + appl_db = "TEST_DB" - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_read_y_cable_and_update_statedb_port_tbl_port_instance_status_standby(self): + statedb_port_tbl[asic_index] = swsscommon.Table( + appl_db[asic_index], "STATEDB_PORT_TABLE") - logical_port_name = "Ethernet0" - statedb_port_tbl = {} - asic_index = 0 - appl_db = "TEST_DB" + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 - statedb_port_tbl[asic_index] = swsscommon.Table( - appl_db[asic_index], "STATEDB_PORT_TABLE") + def get_read_side(self): + return 1 - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - class PortInstanceHelper(): - def __init__(self): - self.EEPROM_ERROR = -1 + def get_mux_direction(self): + return 2 - def get_read_side(self): - return 1 + patched_util.get.return_value = PortInstanceHelper() + rc = read_y_cable_and_update_statedb_port_tbl( + logical_port_name, statedb_port_tbl[asic_index]) + assert(rc == None) - def get_mux_direction(self): - return 2 + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_read_y_cable_and_update_statedb_port_tbl_port_instance_status_unknown(self): - patched_util.get.return_value = PortInstanceHelper() - rc = read_y_cable_and_update_statedb_port_tbl( - logical_port_name, statedb_port_tbl[asic_index]) - assert(rc == None) + logical_port_name = "Ethernet0" + statedb_port_tbl = {} + asic_index = 0 + appl_db = "TEST_DB" - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_read_y_cable_and_update_statedb_port_tbl_port_instance_status_unknown(self): + statedb_port_tbl[asic_index] = swsscommon.Table( + appl_db[asic_index], "STATEDB_PORT_TABLE") - logical_port_name = "Ethernet0" - statedb_port_tbl = {} - asic_index = 0 - appl_db = "TEST_DB" + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 - statedb_port_tbl[asic_index] = swsscommon.Table( - appl_db[asic_index], "STATEDB_PORT_TABLE") + def get_read_side(self): + return 1 - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - class PortInstanceHelper(): - def __init__(self): - self.EEPROM_ERROR = -1 + def get_mux_direction(self): + return 0 - def get_read_side(self): - return 1 + patched_util.get.return_value = PortInstanceHelper() + rc = read_y_cable_and_update_statedb_port_tbl( + logical_port_name, statedb_port_tbl[asic_index]) + assert(rc == None) - def get_mux_direction(self): - return 0 + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_create_tables_and_insert_mux_unknown_entries(self): + + state_db = {} + asic_index = 0 + logical_port_name = "Ethernet0" + + y_cable_tbl = {} + static_tbl = {} + mux_tbl = {} + + rc = create_tables_and_insert_mux_unknown_entries( + state_db, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name) + assert(rc == None) + + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_check_identifier_presence_and_update_mux_table_entry_status_false(self): + + asic_index = 0 + logical_port_name = "Ethernet0" + status = False + fvs = [('state', "manual")] + state_db = {} + test_db = "TEST_DB" + y_cable_tbl = {} + static_tbl = {} + mux_tbl = {} + port_tbl = {} + y_cable_presence = True + + y_cable_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], swsscommon.STATE_HW_MUX_CABLE_TABLE_NAME) + static_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], MUX_CABLE_STATIC_INFO_TABLE) + mux_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], MUX_CABLE_INFO_TABLE) + port_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], "PORT_INFO_TABLE") + port_tbl[asic_index].get.return_value = (status, fvs) + + rc = check_identifier_presence_and_update_mux_table_entry( + state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) + assert(rc == None) + + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_check_identifier_presence_and_update_mux_table_entry_state_absent(self): + + asic_index = 0 + logical_port_name = "Ethernet0" + status = True + fvs = [('badstate', "auto")] + state_db = {} + test_db = "TEST_DB" + y_cable_tbl = {} + static_tbl = {} + mux_tbl = {} + port_tbl = {} + y_cable_presence = True + + y_cable_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], swsscommon.STATE_HW_MUX_CABLE_TABLE_NAME) + static_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], MUX_CABLE_STATIC_INFO_TABLE) + mux_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], MUX_CABLE_INFO_TABLE) + port_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], "PORT_INFO_TABLE") + port_tbl[asic_index].get.return_value = (status, fvs) + + rc = check_identifier_presence_and_update_mux_table_entry( + state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) + assert(rc == None) + + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_check_identifier_presence_and_update_mux_table_entry_bad_state_value(self): + + asic_index = 0 + logical_port_name = "Ethernet0" + status = True + fvs = [('state', "badvalue")] + state_db = {} + test_db = "TEST_DB" + y_cable_tbl = {} + static_tbl = {} + mux_tbl = {} + port_tbl = {} + y_cable_presence = True + + y_cable_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], swsscommon.STATE_HW_MUX_CABLE_TABLE_NAME) + static_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], MUX_CABLE_STATIC_INFO_TABLE) + mux_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], MUX_CABLE_INFO_TABLE) + port_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], "PORT_INFO_TABLE") + port_tbl[asic_index].get.return_value = (status, fvs) + + rc = check_identifier_presence_and_update_mux_table_entry( + state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) + assert(rc == None) + + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=False)) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_check_identifier_presence_and_update_mux_table_entry_no_presence(self): + + asic_index = 0 + logical_port_name = "Ethernet0" + status = True + fvs = [('state', "auto"), ('read_side', 1)] + state_db = {} + test_db = "TEST_DB" + y_cable_tbl = {} + static_tbl = {} + mux_tbl = {} + port_tbl = {} + y_cable_presence = True + + y_cable_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], swsscommon.STATE_HW_MUX_CABLE_TABLE_NAME) + static_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], MUX_CABLE_STATIC_INFO_TABLE) + mux_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], MUX_CABLE_INFO_TABLE) + port_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], "PORT_INFO_TABLE") + port_tbl[asic_index].get.return_value = (status, fvs) + + rc = check_identifier_presence_and_update_mux_table_entry( + state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) + assert(rc == None) + + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_check_identifier_presence_and_update_mux_table_entry_no_port_info(self): + + asic_index = 0 + logical_port_name = "Ethernet0" + status = True + fvs = [('state', "auto"), ('read_side', 1)] + state_db = {} + test_db = "TEST_DB" + y_cable_tbl = {} + static_tbl = {} + mux_tbl = {} + port_tbl = {} + y_cable_presence = True + + y_cable_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], swsscommon.STATE_HW_MUX_CABLE_TABLE_NAME) + static_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], MUX_CABLE_STATIC_INFO_TABLE) + mux_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], MUX_CABLE_INFO_TABLE) + port_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], "PORT_INFO_TABLE") + port_tbl[asic_index].get.return_value = (status, fvs) + + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: + patched_util.get_transceiver_info_dict.return_value = None - patched_util.get.return_value = PortInstanceHelper() - rc = read_y_cable_and_update_statedb_port_tbl( - logical_port_name, statedb_port_tbl[asic_index]) - assert(rc == None) + rc = check_identifier_presence_and_update_mux_table_entry( + state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) + assert(rc == None) - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_create_tables_and_insert_mux_unknown_entries(self): + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0, 1, 2])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_check_identifier_presence_and_update_mux_table_entry_multiple_port_instances(self): + + asic_index = 0 + logical_port_name = "Ethernet0" + status = True + fvs = [('state', "auto"), ('read_side', 1)] + state_db = {} + test_db = "TEST_DB" + y_cable_tbl = {} + static_tbl = {} + mux_tbl = {} + port_tbl = {} + y_cable_presence = True + + y_cable_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], swsscommon.STATE_HW_MUX_CABLE_TABLE_NAME) + static_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], MUX_CABLE_STATIC_INFO_TABLE) + mux_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], MUX_CABLE_INFO_TABLE) + port_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], "PORT_INFO_TABLE") + port_tbl[asic_index].get.return_value = (status, fvs) + + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: + patched_util.get_transceiver_info_dict.return_value = { + 'manufacturer': 'Microsoft', 'model': 'simulated'} - state_db = {} - asic_index = 0 - logical_port_name = "Ethernet0" + rc = check_identifier_presence_and_update_mux_table_entry( + state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) + assert(rc == None) - y_cable_tbl = {} - static_tbl = {} - mux_tbl = {} + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_check_identifier_presence_and_update_mux_table_entry_no_vendor_port_info(self): + + asic_index = 0 + logical_port_name = "Ethernet0" + status = True + fvs = [('state', "auto"), ('read_side', 1)] + state_db = {} + test_db = "TEST_DB" + y_cable_tbl = {} + static_tbl = {} + mux_tbl = {} + port_tbl = {} + y_cable_presence = True + + y_cable_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], swsscommon.STATE_HW_MUX_CABLE_TABLE_NAME) + static_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], MUX_CABLE_STATIC_INFO_TABLE) + mux_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], MUX_CABLE_INFO_TABLE) + port_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], "PORT_INFO_TABLE") + port_tbl[asic_index].get.return_value = (status, fvs) + + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: + patched_util.get_transceiver_info_dict.return_value = { + 'bad_manufacturer': 'Microsoft', 'model': 'simulated'} - rc = create_tables_and_insert_mux_unknown_entries( - state_db, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name) + rc = check_identifier_presence_and_update_mux_table_entry( + state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) assert(rc == None) - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_check_identifier_presence_and_update_mux_table_entry_status_false(self): - - asic_index = 0 - logical_port_name = "Ethernet0" - status = False - fvs = [('state', "manual")] - state_db = {} - test_db = "TEST_DB" - y_cable_tbl = {} - static_tbl = {} - mux_tbl = {} - port_tbl = {} - y_cable_presence = True - - y_cable_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], swsscommon.STATE_HW_MUX_CABLE_TABLE_NAME) - static_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], MUX_CABLE_STATIC_INFO_TABLE) - mux_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], MUX_CABLE_INFO_TABLE) - port_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], "PORT_INFO_TABLE") - port_tbl[asic_index].get.return_value = (status, fvs) + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_check_identifier_presence_and_update_mux_table_entry_no_model_port_info(self): + + asic_index = 0 + logical_port_name = "Ethernet0" + status = True + fvs = [('state', "auto"), ('read_side', 1)] + state_db = {} + test_db = "TEST_DB" + y_cable_tbl = {} + static_tbl = {} + mux_tbl = {} + port_tbl = {} + y_cable_presence = True + + y_cable_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], swsscommon.STATE_HW_MUX_CABLE_TABLE_NAME) + static_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], MUX_CABLE_STATIC_INFO_TABLE) + mux_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], MUX_CABLE_INFO_TABLE) + port_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], "PORT_INFO_TABLE") + port_tbl[asic_index].get.return_value = (status, fvs) + + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: + patched_util.get_transceiver_info_dict.return_value = { + 'manufacturer': 'Microsoft', 'bad_model': 'simulated'} rc = check_identifier_presence_and_update_mux_table_entry( state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) assert(rc == None) - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_check_identifier_presence_and_update_mux_table_entry_state_absent(self): + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_check_identifier_presence_and_update_mux_table_entry_invalid_vendor_port_info(self): + + asic_index = 0 + logical_port_name = "Ethernet0" + status = True + fvs = [('state', "auto"), ('read_side', 1)] + state_db = {} + test_db = "TEST_DB" + y_cable_tbl = {} + static_tbl = {} + mux_tbl = {} + port_tbl = {} + y_cable_presence = True + + y_cable_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], swsscommon.STATE_HW_MUX_CABLE_TABLE_NAME) + static_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], MUX_CABLE_STATIC_INFO_TABLE) + mux_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], MUX_CABLE_INFO_TABLE) + port_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], "PORT_INFO_TABLE") + port_tbl[asic_index].get.return_value = (status, fvs) + + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: + patched_util.get_transceiver_info_dict.return_value = { + 'manufacturer': 'not_Microsoft', 'model': 'simulated'} - asic_index = 0 - logical_port_name = "Ethernet0" - status = True - fvs = [('badstate', "auto")] - state_db = {} - test_db = "TEST_DB" - y_cable_tbl = {} - static_tbl = {} - mux_tbl = {} - port_tbl = {} - y_cable_presence = True - - y_cable_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], swsscommon.STATE_HW_MUX_CABLE_TABLE_NAME) - static_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], MUX_CABLE_STATIC_INFO_TABLE) - mux_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], MUX_CABLE_INFO_TABLE) - port_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], "PORT_INFO_TABLE") - port_tbl[asic_index].get.return_value = (status, fvs) + rc = check_identifier_presence_and_update_mux_table_entry( + state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) + assert(rc == None) + + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_check_identifier_presence_and_update_mux_table_entry_invalid_model_port_info(self): + + asic_index = 0 + logical_port_name = "Ethernet0" + status = True + fvs = [('state', "auto"), ('read_side', 1)] + + state_db = {} + test_db = "TEST_DB" + y_cable_tbl = {} + static_tbl = {} + mux_tbl = {} + port_tbl = {} + y_cable_presence = True + + y_cable_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], swsscommon.STATE_HW_MUX_CABLE_TABLE_NAME) + static_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], MUX_CABLE_STATIC_INFO_TABLE) + mux_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], MUX_CABLE_INFO_TABLE) + port_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], "PORT_INFO_TABLE") + port_tbl[asic_index].get.return_value = (status, fvs) + + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: + patched_util.get_transceiver_info_dict.return_value = { + 'manufacturer': 'Microsoft', 'model': 'bad_model1'} rc = check_identifier_presence_and_update_mux_table_entry( - state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) + state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) assert(rc == None) - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_check_identifier_presence_and_update_mux_table_entry_bad_state_value(self): + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_check_identifier_presence_and_update_mux_table_entry_module_dir_none(self): + + asic_index = 0 + logical_port_name = "Ethernet0" + status = True + fvs = [('state', "auto"), ('read_side', 1)] + + state_db = {} + test_db = "TEST_DB" + y_cable_tbl = {} + static_tbl = {} + mux_tbl = {} + port_tbl = {} + y_cable_presence = True + + y_cable_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], swsscommon.STATE_HW_MUX_CABLE_TABLE_NAME) + static_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], MUX_CABLE_STATIC_INFO_TABLE) + mux_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], MUX_CABLE_INFO_TABLE) + port_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], "PORT_INFO_TABLE") + port_tbl[asic_index].get.return_value = (status, fvs) + + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: + patched_util.get_transceiver_info_dict.return_value = { + 'manufacturer': 'not_Microsoft', 'model': 'simulated'} + + with patch('sonic_y_cable.y_cable_vendor_mapping.mapping') as mock_mapping: + mock_mapping.get.return_value = None - asic_index = 0 - logical_port_name = "Ethernet0" - status = True - fvs = [('state', "badvalue")] - state_db = {} - test_db = "TEST_DB" - y_cable_tbl = {} - static_tbl = {} - mux_tbl = {} - port_tbl = {} - y_cable_presence = True - - y_cable_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], swsscommon.STATE_HW_MUX_CABLE_TABLE_NAME) - static_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], MUX_CABLE_STATIC_INFO_TABLE) - mux_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], MUX_CABLE_INFO_TABLE) - port_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], "PORT_INFO_TABLE") - port_tbl[asic_index].get.return_value = (status, fvs) + rc = check_identifier_presence_and_update_mux_table_entry( + state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) + assert(rc == None) + + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('sonic_y_cable.y_cable_vendor_mapping.mapping.get', MagicMock(return_value={"Microsoft": {"module": "test_module"}})) + def test_check_identifier_presence_and_update_mux_table_entry_module_none(self): + + asic_index = 0 + logical_port_name = "Ethernet0" + status = True + fvs = [('state', "auto"), ('read_side', 1)] + + state_db = {} + test_db = "TEST_DB" + y_cable_tbl = {} + static_tbl = {} + mux_tbl = {} + port_tbl = {} + y_cable_presence = True + + y_cable_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], swsscommon.STATE_HW_MUX_CABLE_TABLE_NAME) + static_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], MUX_CABLE_STATIC_INFO_TABLE) + mux_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], MUX_CABLE_INFO_TABLE) + port_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], "PORT_INFO_TABLE") + port_tbl[asic_index].get.return_value = (status, fvs) + + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: + patched_util.get_transceiver_info_dict.return_value = { + 'manufacturer': 'not_Microsoft', 'model': 'model1'} rc = check_identifier_presence_and_update_mux_table_entry( - state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) + state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) assert(rc == None) - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=False)) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_check_identifier_presence_and_update_mux_table_entry_no_presence(self): - - asic_index = 0 - logical_port_name = "Ethernet0" - status = True - fvs = [('state', "auto"), ('read_side', 1)] - state_db = {} - test_db = "TEST_DB" - y_cable_tbl = {} - static_tbl = {} - mux_tbl = {} - port_tbl = {} - y_cable_presence = True - - y_cable_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], swsscommon.STATE_HW_MUX_CABLE_TABLE_NAME) - static_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], MUX_CABLE_STATIC_INFO_TABLE) - mux_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], MUX_CABLE_INFO_TABLE) - port_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], "PORT_INFO_TABLE") - port_tbl[asic_index].get.return_value = (status, fvs) + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('sonic_y_cable.y_cable_vendor_mapping.mapping.get', MagicMock(return_value={"simulated": "microsoft.y_cable_simulated"})) + def test_check_identifier_presence_and_update_mux_table_entry_module_microsoft(self): + + asic_index = 0 + logical_port_name = "Ethernet0" + status = True + fvs = [('state', "auto"), ('read_side', 1)] + + state_db = {} + test_db = "TEST_DB" + y_cable_tbl = {} + static_tbl = {} + mux_tbl = {} + port_tbl = {} + y_cable_presence = [True] + + y_cable_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], swsscommon.STATE_HW_MUX_CABLE_TABLE_NAME) + static_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], MUX_CABLE_STATIC_INFO_TABLE) + mux_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], MUX_CABLE_INFO_TABLE) + port_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], "PORT_INFO_TABLE") + port_tbl[asic_index].get.return_value = (status, fvs) + + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: + patched_util.get_transceiver_info_dict.return_value = { + 'manufacturer': 'microsoft', 'model': 'simulated'} + + sys.modules['builtins.getattr'] = MagicMock() + rc = check_identifier_presence_and_update_mux_table_entry( + state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) + assert(rc == None) + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('sonic_y_cable.y_cable_vendor_mapping.mapping.get', MagicMock(return_value={"simulated": "microsoft.y_cable_simulated"})) + def test_check_identifier_presence_and_update_mux_table_entry_module_microsoft_y_cable_presence_false(self): + + asic_index = 0 + logical_port_name = "Ethernet0" + status = True + fvs = [('state', "auto"), ('read_side', 1)] + + state_db = {} + test_db = "TEST_DB" + y_cable_tbl = {} + static_tbl = {} + mux_tbl = {} + port_tbl = {} + y_cable_presence = [False] + + port_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], "PORT_INFO_TABLE") + port_tbl[asic_index].get.return_value = (status, fvs) + + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: + patched_util.get_transceiver_info_dict.return_value = { + 'manufacturer': 'microsoft', 'model': 'simulated'} + + sys.modules['builtins.getattr'] = MagicMock() rc = check_identifier_presence_and_update_mux_table_entry( - state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) + state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) assert(rc == None) - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_check_identifier_presence_and_update_mux_table_entry_no_port_info(self): + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_check_identifier_presence_and_delete_mux_table_entry(self): + + asic_index = 0 + logical_port_name = "Ethernet0" + status = True + fvs = [('state', "auto"), ('read_side', 1)] + + state_db = {} + test_db = "TEST_DB" + y_cable_tbl = {} + static_tbl = {} + mux_tbl = {} + port_tbl = {} + y_cable_presence = [True] + delete_change_event = [True] + + port_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], "PORT_INFO_TABLE") + port_tbl[asic_index].get.return_value = (status, fvs) + + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as port_instance: + rc = check_identifier_presence_and_delete_mux_table_entry( + state_db, port_tbl, asic_index, logical_port_name, y_cable_presence, delete_change_event) + assert(rc == None) - asic_index = 0 - logical_port_name = "Ethernet0" - status = True - fvs = [('state', "auto"), ('read_side', 1)] - state_db = {} - test_db = "TEST_DB" - y_cable_tbl = {} - static_tbl = {} - mux_tbl = {} - port_tbl = {} - y_cable_presence = True - - y_cable_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], swsscommon.STATE_HW_MUX_CABLE_TABLE_NAME) - static_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], MUX_CABLE_STATIC_INFO_TABLE) - mux_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], MUX_CABLE_INFO_TABLE) - port_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], "PORT_INFO_TABLE") - port_tbl[asic_index].get.return_value = (status, fvs) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_chassis') + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') + @patch('swsscommon.swsscommon.Table') + def test_init_ports_status_for_y_cable(self, platform_chassis, platform_sfp, mock_swsscommon_table): - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: - patched_util.get_transceiver_info_dict.return_value = None + platform_sfp = MagicMock() + platform_chassis = MagicMock() - rc = check_identifier_presence_and_update_mux_table_entry( - state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) - assert(rc == None) + mock_logical_port_name = [""] - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0, 1, 2])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_check_identifier_presence_and_update_mux_table_entry_multiple_port_instances(self): + def mock_get_asic_id(mock_logical_port_name): + return 0 - asic_index = 0 - logical_port_name = "Ethernet0" - status = True - fvs = [('state', "auto"), ('read_side', 1)] - state_db = {} - test_db = "TEST_DB" - y_cable_tbl = {} - static_tbl = {} - mux_tbl = {} - port_tbl = {} - y_cable_presence = True - - y_cable_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], swsscommon.STATE_HW_MUX_CABLE_TABLE_NAME) - static_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], MUX_CABLE_STATIC_INFO_TABLE) - mux_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], MUX_CABLE_INFO_TABLE) - port_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], "PORT_INFO_TABLE") - port_tbl[asic_index].get.return_value = (status, fvs) + y_cable_presence = [True] - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: - patched_util.get_transceiver_info_dict.return_value = { - 'manufacturer': 'Microsoft', 'model': 'simulated'} + mock_table = MagicMock() + mock_table.getKeys = MagicMock(return_value=['Ethernet0', 'Ethernet4']) + mock_swsscommon_table.return_value = mock_table - rc = check_identifier_presence_and_update_mux_table_entry( - state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) - assert(rc == None) + rc = init_ports_status_for_y_cable(platform_sfp, platform_chassis, + y_cable_presence, stop_event=threading.Event()) - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_check_identifier_presence_and_update_mux_table_entry_no_vendor_port_info(self): + assert(rc == None) - asic_index = 0 - logical_port_name = "Ethernet0" - status = True - fvs = [('state', "auto"), ('read_side', 1)] - state_db = {} - test_db = "TEST_DB" - y_cable_tbl = {} - static_tbl = {} - mux_tbl = {} - port_tbl = {} - y_cable_presence = True - - y_cable_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], swsscommon.STATE_HW_MUX_CABLE_TABLE_NAME) - static_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], MUX_CABLE_STATIC_INFO_TABLE) - mux_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], MUX_CABLE_INFO_TABLE) - port_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], "PORT_INFO_TABLE") - port_tbl[asic_index].get.return_value = (status, fvs) + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('swsscommon.swsscommon.Table') + def test_change_ports_status_for_y_cable_change_event(self, mock_swsscommon_table): - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: - patched_util.get_transceiver_info_dict.return_value = { - 'bad_manufacturer': 'Microsoft', 'model': 'simulated'} + mock_logical_port_name = [""] - rc = check_identifier_presence_and_update_mux_table_entry( - state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) - assert(rc == None) + def mock_get_asic_id(mock_logical_port_name): + return 0 - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_check_identifier_presence_and_update_mux_table_entry_no_model_port_info(self): + y_cable_presence = [True] + logical_port_dict = {'Ethernet0': '1'} - asic_index = 0 - logical_port_name = "Ethernet0" - status = True - fvs = [('state', "auto"), ('read_side', 1)] - state_db = {} - test_db = "TEST_DB" - y_cable_tbl = {} - static_tbl = {} - mux_tbl = {} - port_tbl = {} - y_cable_presence = True - - y_cable_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], swsscommon.STATE_HW_MUX_CABLE_TABLE_NAME) - static_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], MUX_CABLE_STATIC_INFO_TABLE) - mux_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], MUX_CABLE_INFO_TABLE) - port_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], "PORT_INFO_TABLE") - port_tbl[asic_index].get.return_value = (status, fvs) + mock_table = MagicMock() + mock_table.getKeys = MagicMock(return_value=['Ethernet0', 'Ethernet4']) + mock_table.get = MagicMock( + side_effect=[(True, (('index', 1), )), (True, (('index', 2), ))]) + mock_swsscommon_table.return_value = mock_table - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: - patched_util.get_transceiver_info_dict.return_value = { - 'manufacturer': 'Microsoft', 'bad_model': 'simulated'} + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: - rc = check_identifier_presence_and_update_mux_table_entry( - state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) - assert(rc == None) + patched_util.get_asic_id_for_logical_port.return_value = 0 + + change_ports_status_for_y_cable_change_event( + logical_port_dict, y_cable_presence, stop_event=threading.Event()) + + mock_swsscommon_table.assert_called() @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_check_identifier_presence_and_update_mux_table_entry_invalid_vendor_port_info(self): + @patch('swsscommon.swsscommon.Table') + def test_change_ports_status_for_y_cable_change_event_sfp_removed(self, mock_swsscommon_table): - asic_index = 0 - logical_port_name = "Ethernet0" - status = True - fvs = [('state', "auto"), ('read_side', 1)] - state_db = {} - test_db = "TEST_DB" - y_cable_tbl = {} - static_tbl = {} - mux_tbl = {} - port_tbl = {} - y_cable_presence = True - - y_cable_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], swsscommon.STATE_HW_MUX_CABLE_TABLE_NAME) - static_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], MUX_CABLE_STATIC_INFO_TABLE) - mux_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], MUX_CABLE_INFO_TABLE) - port_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], "PORT_INFO_TABLE") - port_tbl[asic_index].get.return_value = (status, fvs) + mock_logical_port_name = [""] - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: - patched_util.get_transceiver_info_dict.return_value = { - 'manufacturer': 'not_Microsoft', 'model': 'simulated'} + def mock_get_asic_id(mock_logical_port_name): + return 0 - rc = check_identifier_presence_and_update_mux_table_entry( - state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) - assert(rc == None) + y_cable_presence = [True] + logical_port_dict = {'Ethernet0': '1'} - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_check_identifier_presence_and_update_mux_table_entry_invalid_model_port_info(self): + mock_table = MagicMock() + mock_table.getKeys = MagicMock(return_value=['Ethernet0', 'Ethernet4']) + mock_table.get = MagicMock( + side_effect=[(True, (('index', 1), )), (True, (('index', 2), ))]) + mock_swsscommon_table.return_value = mock_table - asic_index = 0 - logical_port_name = "Ethernet0" - status = True - fvs = [('state', "auto"), ('read_side', 1)] + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: - state_db = {} - test_db = "TEST_DB" - y_cable_tbl = {} - static_tbl = {} - mux_tbl = {} - port_tbl = {} - y_cable_presence = True - - y_cable_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], swsscommon.STATE_HW_MUX_CABLE_TABLE_NAME) - static_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], MUX_CABLE_STATIC_INFO_TABLE) - mux_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], MUX_CABLE_INFO_TABLE) - port_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], "PORT_INFO_TABLE") - port_tbl[asic_index].get.return_value = (status, fvs) + patched_util.get_asic_id_for_logical_port.return_value = 0 + change_ports_status_for_y_cable_change_event( + logical_port_dict, y_cable_presence, stop_event=threading.Event()) - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: - patched_util.get_transceiver_info_dict.return_value = { - 'manufacturer': 'Microsoft', 'model': 'bad_model1'} + mock_swsscommon_table.assert_called() - rc = check_identifier_presence_and_update_mux_table_entry( - state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) - assert(rc == None) + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('swsscommon.swsscommon.Table') + def test_change_ports_status_for_y_cable_change_event_sfp_unknown(self, mock_swsscommon_table): - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_check_identifier_presence_and_update_mux_table_entry_module_dir_none(self): + mock_logical_port_name = [""] - asic_index = 0 - logical_port_name = "Ethernet0" - status = True - fvs = [('state', "auto"), ('read_side', 1)] + def mock_get_asic_id(mock_logical_port_name): + return 0 - state_db = {} - test_db = "TEST_DB" - y_cable_tbl = {} - static_tbl = {} - mux_tbl = {} - port_tbl = {} - y_cable_presence = True - - y_cable_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], swsscommon.STATE_HW_MUX_CABLE_TABLE_NAME) - static_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], MUX_CABLE_STATIC_INFO_TABLE) - mux_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], MUX_CABLE_INFO_TABLE) - port_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], "PORT_INFO_TABLE") - port_tbl[asic_index].get.return_value = (status, fvs) + y_cable_presence = [True] + logical_port_dict = {'Ethernet0': '2'} - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: - patched_util.get_transceiver_info_dict.return_value = { - 'manufacturer': 'not_Microsoft', 'model': 'simulated'} + mock_table = MagicMock() + mock_table.getKeys = MagicMock(return_value=['Ethernet0', 'Ethernet4']) + mock_table.get = MagicMock( + side_effect=[(True, (('index', 1), )), (True, (('index', 2), ))]) + mock_swsscommon_table.return_value = mock_table - with patch('sonic_y_cable.y_cable_vendor_mapping.mapping') as mock_mapping: - mock_mapping.get.return_value = None + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: - rc = check_identifier_presence_and_update_mux_table_entry( - state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) - assert(rc == None) + patched_util.get_asic_id_for_logical_port.return_value = 0 + change_ports_status_for_y_cable_change_event( + logical_port_dict, y_cable_presence, stop_event=threading.Event()) - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('sonic_y_cable.y_cable_vendor_mapping.mapping.get', MagicMock(return_value={"Microsoft": {"module": "test_module"}})) - def test_check_identifier_presence_and_update_mux_table_entry_module_none(self): + mock_swsscommon_table.assert_called() - asic_index = 0 - logical_port_name = "Ethernet0" - status = True - fvs = [('state', "auto"), ('read_side', 1)] + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + def test_delete_ports_status_for_y_cable(self, mock_swsscommon_table): - state_db = {} - test_db = "TEST_DB" - y_cable_tbl = {} - static_tbl = {} - mux_tbl = {} - port_tbl = {} - y_cable_presence = True - - y_cable_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], swsscommon.STATE_HW_MUX_CABLE_TABLE_NAME) - static_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], MUX_CABLE_STATIC_INFO_TABLE) - mux_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], MUX_CABLE_INFO_TABLE) - port_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], "PORT_INFO_TABLE") - port_tbl[asic_index].get.return_value = (status, fvs) + mock_table = MagicMock() + mock_table.getKeys = MagicMock(return_value=['Ethernet0', 'Ethernet4']) + mock_table.get = MagicMock( + side_effect=[(True, (('index', 1), )), (True, (('index', 2), ))]) + mock_swsscommon_table.return_value = mock_table - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: - patched_util.get_transceiver_info_dict.return_value = { - 'manufacturer': 'not_Microsoft', 'model': 'model1'} + mock_logical_port_name = [""] - rc = check_identifier_presence_and_update_mux_table_entry( - state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) - assert(rc == None) + def mock_get_asic_id(mock_logical_port_name): + return 0 - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('sonic_y_cable.y_cable_vendor_mapping.mapping.get', MagicMock(return_value={"simulated": "microsoft.y_cable_simulated"})) - def test_check_identifier_presence_and_update_mux_table_entry_module_microsoft(self): + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: - asic_index = 0 - logical_port_name = "Ethernet0" - status = True - fvs = [('state', "auto"), ('read_side', 1)] + patched_util.logical.return_value = ['Ethernet0', 'Ethernet4'] + patched_util.get_asic_id_for_logical_port.return_value = 0 - state_db = {} - test_db = "TEST_DB" - y_cable_tbl = {} - static_tbl = {} - mux_tbl = {} - port_tbl = {} - y_cable_presence = [True] - - y_cable_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], swsscommon.STATE_HW_MUX_CABLE_TABLE_NAME) - static_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], MUX_CABLE_STATIC_INFO_TABLE) - mux_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], MUX_CABLE_INFO_TABLE) - port_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], "PORT_INFO_TABLE") - port_tbl[asic_index].get.return_value = (status, fvs) + rc = delete_ports_status_for_y_cable() - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: - patched_util.get_transceiver_info_dict.return_value = { - 'manufacturer': 'microsoft', 'model': 'simulated'} + mock_swsscommon_table.assert_called() - sys.modules['builtins.getattr'] = MagicMock() - rc = check_identifier_presence_and_update_mux_table_entry( - state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) - assert(rc == None) + def test_check_identifier_presence_and_update_mux_info_entry(self): + asic_index = 0 + logical_port_name = "Ethernet0" - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('sonic_y_cable.y_cable_vendor_mapping.mapping.get', MagicMock(return_value={"simulated": "microsoft.y_cable_simulated"})) - def test_check_identifier_presence_and_update_mux_table_entry_module_microsoft_y_cable_presence_false(self): + state_db = {} + test_db = "TEST_DB" + mux_tbl = {} - asic_index = 0 - logical_port_name = "Ethernet0" - status = True - fvs = [('state', "auto"), ('read_side', 1)] + mux_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], MUX_CABLE_INFO_TABLE) + + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: - state_db = {} - test_db = "TEST_DB" - y_cable_tbl = {} - static_tbl = {} - mux_tbl = {} - port_tbl = {} - y_cable_presence = [False] + patched_util.logical.return_value = ['Ethernet0', 'Ethernet4'] + rc = check_identifier_presence_and_update_mux_info_entry( + state_db, mux_tbl, asic_index, logical_port_name) + assert(rc == None) - port_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], "PORT_INFO_TABLE") - port_tbl[asic_index].get.return_value = (status, fvs) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + def test_get_firmware_dict(self, port_instance): - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: - patched_util.get_transceiver_info_dict.return_value = { - 'manufacturer': 'microsoft', 'model': 'simulated'} + port_instance = MagicMock() + port_instance.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + port_instance.download_firmware_status = 1 - sys.modules['builtins.getattr'] = MagicMock() - rc = check_identifier_presence_and_update_mux_table_entry( - state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) - assert(rc == None) + physical_port = 1 + target = "simulated_target" + side = "a" + mux_info_dict = {} + logical_port_name = "Ethernet0" - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_check_identifier_presence_and_delete_mux_table_entry(self): + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: + + patched_util.get_asic_id_for_logical_port.return_value = 0 - asic_index = 0 - logical_port_name = "Ethernet0" status = True fvs = [('state', "auto"), ('read_side', 1)] + Table = MagicMock() + Table.get.return_value = (status, fvs) - state_db = {} - test_db = "TEST_DB" - y_cable_tbl = {} - static_tbl = {} - mux_tbl = {} - port_tbl = {} - y_cable_presence = [True] - delete_change_event = [True] - - port_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], "PORT_INFO_TABLE") - port_tbl[asic_index].get.return_value = (status, fvs) - - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as port_instance: - rc = check_identifier_presence_and_delete_mux_table_entry( - state_db, port_tbl, asic_index, logical_port_name, y_cable_presence, delete_change_event) - assert(rc == None) + rc = get_firmware_dict( + physical_port, port_instance, target, side, mux_info_dict, logical_port_name) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_chassis') - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') - @patch('swsscommon.swsscommon.Table') - def test_init_ports_status_for_y_cable(self, platform_chassis, platform_sfp, mock_swsscommon_table): + assert(mux_info_dict['version_a_active'] == None) + assert(mux_info_dict['version_a_inactive'] == None) + assert(mux_info_dict['version_a_next'] == None) - platform_sfp = MagicMock() - platform_chassis = MagicMock() + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + def test_get_firmware_dict_asic_error(self, port_instance): - mock_logical_port_name = [""] + port_instance = MagicMock() + port_instance.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + port_instance.download_firmware_status = 1 - def mock_get_asic_id(mock_logical_port_name): - return 0 + physical_port = 1 + target = "simulated_target" + side = "a" + mux_info_dict = {} + logical_port_name = "Ethernet0" - y_cable_presence = [True] + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: - mock_table = MagicMock() - mock_table.getKeys = MagicMock(return_value=['Ethernet0', 'Ethernet4']) - mock_swsscommon_table.return_value = mock_table + patched_util.get_asic_id_for_logical_port.return_value = 0 - rc = init_ports_status_for_y_cable(platform_sfp, platform_chassis, - y_cable_presence, stop_event=threading.Event()) + status = True + fvs = [('state', "auto"), ('read_side', 1)] + Table = MagicMock() + Table.get.return_value = (status, fvs) + swsscommon.Table.return_value.get.return_value = ( + False, {"read_side": "2"}) - assert(rc == None) + rc = get_firmware_dict( + physical_port, port_instance, target, side, mux_info_dict, logical_port_name) - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('swsscommon.swsscommon.Table') - def test_change_ports_status_for_y_cable_change_event(self, mock_swsscommon_table): + assert(mux_info_dict['version_a_active'] == "N/A") + assert(mux_info_dict['version_a_inactive'] == "N/A") + assert(mux_info_dict['version_a_next'] == "N/A") - mock_logical_port_name = [""] + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + def test_get_firmware_dict_download_status_failed_exception(self, port_instance): - def mock_get_asic_id(mock_logical_port_name): - return 0 + port_instance = MagicMock() + port_instance.FIRMWARE_DOWNLOAD_STATUS_FAILED = -1 + port_instance.download_firmware_status = -1 + port_instance.get_firmware_version = MagicMock( + side_effect=NotImplementedError) - y_cable_presence = [True] - logical_port_dict = {'Ethernet0': '1'} + physical_port = 1 + target = "simulated_target" + side = "a" + mux_info_dict = {} + logical_port_name = "Ethernet0" - mock_table = MagicMock() - mock_table.getKeys = MagicMock(return_value=['Ethernet0', 'Ethernet4']) - mock_table.get = MagicMock( - side_effect=[(True, (('index', 1), )), (True, (('index', 2), ))]) - mock_swsscommon_table.return_value = mock_table + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: + patched_util.get_asic_id_for_logical_port.return_value = 0 - patched_util.get_asic_id_for_logical_port.return_value = 0 + status = True + fvs = [('state', "auto"), ('read_side', 1)] + Table = MagicMock() + Table.get.return_value = (status, fvs) - change_ports_status_for_y_cable_change_event( - logical_port_dict, y_cable_presence, stop_event=threading.Event()) + rc = get_firmware_dict( + physical_port, port_instance, target, side, mux_info_dict, logical_port_name) - mock_swsscommon_table.assert_called() + assert(mux_info_dict['version_a_active'] == "N/A") + assert(mux_info_dict['version_a_inactive'] == "N/A") + assert(mux_info_dict['version_a_next'] == "N/A") - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('swsscommon.swsscommon.Table') - def test_change_ports_status_for_y_cable_change_event_sfp_removed(self, mock_swsscommon_table): + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + def test_get_firmware_dict_download_status_failed(self, port_instance): - mock_logical_port_name = [""] + port_instance = MagicMock() + port_instance.FIRMWARE_DOWNLOAD_STATUS_FAILED = -1 + port_instance.download_firmware_status = -1 + port_instance.get_firmware_version = MagicMock( + return_value={"version_active": "2021", "version_inactive": "2020", "version_next": "2022"}) - def mock_get_asic_id(mock_logical_port_name): - return 0 + physical_port = 1 + target = "simulated_target" + side = "a" + mux_info_dict = {} + logical_port_name = "Ethernet0" - y_cable_presence = [True] - logical_port_dict = {'Ethernet0': '1'} + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: - mock_table = MagicMock() - mock_table.getKeys = MagicMock(return_value=['Ethernet0', 'Ethernet4']) - mock_table.get = MagicMock( - side_effect=[(True, (('index', 1), )), (True, (('index', 2), ))]) - mock_swsscommon_table.return_value = mock_table + patched_util.get_asic_id_for_logical_port.return_value = 0 - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: + status = True + fvs = [('state', "auto"), ('read_side', 1)] + Table = MagicMock() + Table.get.return_value = (status, fvs) - patched_util.get_asic_id_for_logical_port.return_value = 0 - change_ports_status_for_y_cable_change_event( - logical_port_dict, y_cable_presence, stop_event=threading.Event()) + rc = get_firmware_dict( + physical_port, port_instance, target, side, mux_info_dict, logical_port_name) - mock_swsscommon_table.assert_called() + assert(mux_info_dict['version_a_active'] == "2021") + assert(mux_info_dict['version_a_inactive'] == "2020") + assert(mux_info_dict['version_a_next'] == "2022") - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('swsscommon.swsscommon.Table') - def test_change_ports_status_for_y_cable_change_event_sfp_unknown(self, mock_swsscommon_table): + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') + def test_get_muxcable_info(self, platform_sfputil): + physical_port = 20 - mock_logical_port_name = [""] + logical_port_name = "Ethernet20" + swsscommon.Table.return_value.get.return_value = ( + True, {"read_side": "1"}) + platform_sfputil.get_asic_id_for_logical_port = 0 - def mock_get_asic_id(mock_logical_port_name): - return 0 + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - y_cable_presence = [True] - logical_port_dict = {'Ethernet0': '2'} + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 + self.TARGET_NIC = 1 + self.TARGET_TOR_A = 1 + self.TARGET_TOR_B = 1 + self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + self.FIRMWARE_DOWNLOAD_STATUS_FAILED = 2 + self.download_firmware_status = 0 + self.MUX_TOGGLE_STATUS_INPROGRESS = 1 + self.MUX_TOGGLE_STATUS_FAILED = 2 + self.MUX_TOGGLE_STATUS_NOT_INITIATED_OR_FINISHED = 2 + self.mux_toggle_status = 0 + self.SWITCH_COUNT_MANUAL = "manual" + self.SWITCH_COUNT_AUTO = "auto" - mock_table = MagicMock() - mock_table.getKeys = MagicMock(return_value=['Ethernet0', 'Ethernet4']) - mock_table.get = MagicMock( - side_effect=[(True, (('index', 1), )), (True, (('index', 2), ))]) - mock_swsscommon_table.return_value = mock_table + def get_active_linked_tor_side(self): + return 1 - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: + def get_mux_direction(self): + return 1 - patched_util.get_asic_id_for_logical_port.return_value = 0 - change_ports_status_for_y_cable_change_event( - logical_port_dict, y_cable_presence, stop_event=threading.Event()) + def get_switch_count_total(self, switch_count): + return 1 - mock_swsscommon_table.assert_called() + def get_eye_heights(self, tgt_tor): + return 500 - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - def test_delete_ports_status_for_y_cable(self, mock_swsscommon_table): - - mock_table = MagicMock() - mock_table.getKeys = MagicMock(return_value=['Ethernet0', 'Ethernet4']) - mock_table.get = MagicMock( - side_effect=[(True, (('index', 1), )), (True, (('index', 2), ))]) - mock_swsscommon_table.return_value = mock_table - - mock_logical_port_name = [""] - - def mock_get_asic_id(mock_logical_port_name): - return 0 - - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: - - patched_util.logical.return_value = ['Ethernet0', 'Ethernet4'] - patched_util.get_asic_id_for_logical_port.return_value = 0 - - rc = delete_ports_status_for_y_cable() - - mock_swsscommon_table.assert_called() - - def test_check_identifier_presence_and_update_mux_info_entry(self): - asic_index = 0 - logical_port_name = "Ethernet0" + def is_link_active(self, tgt_nic): + return True - state_db = {} - test_db = "TEST_DB" - mux_tbl = {} + def get_local_temperature(self): + return 22.75 - mux_tbl[asic_index] = swsscommon.Table( - test_db[asic_index], MUX_CABLE_INFO_TABLE) + def get_local_voltage(self): + return 0.5 - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: - - patched_util.logical.return_value = ['Ethernet0', 'Ethernet4'] - rc = check_identifier_presence_and_update_mux_info_entry( - state_db, mux_tbl, asic_index, logical_port_name) - assert(rc == None) - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - def test_get_firmware_dict(self, port_instance): + def get_nic_voltage(self): + return 2.7 - port_instance = MagicMock() - port_instance.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - port_instance.download_firmware_status = 1 + def get_nic_temperature(self): + return 20 - physical_port = 1 - target = "simulated_target" - side = "a" - mux_info_dict = {} - logical_port_name = "Ethernet0" + patched_util.get.return_value = PortInstanceHelper() with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: - patched_util.get_asic_id_for_logical_port.return_value = 0 - status = True - fvs = [('state', "auto"), ('read_side', 1)] - Table = MagicMock() - Table.get.return_value = (status, fvs) - - rc = get_firmware_dict( - physical_port, port_instance, target, side, mux_info_dict, logical_port_name) - - assert(mux_info_dict['version_a_active'] == None) - assert(mux_info_dict['version_a_inactive'] == None) - assert(mux_info_dict['version_a_next'] == None) - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - def test_get_firmware_dict_asic_error(self, port_instance): + rc = get_muxcable_info(physical_port, logical_port_name) - port_instance = MagicMock() - port_instance.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - port_instance.download_firmware_status = 1 + assert(rc['tor_active'] == 'active') + assert(rc['mux_direction'] == 'self') + assert(rc['internal_voltage'] == 0.5) - physical_port = 1 - target = "simulated_target" - side = "a" - mux_info_dict = {} - logical_port_name = "Ethernet0" + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') + def test_get_muxcable_info_peer_side(self, platform_sfputil): + physical_port = 20 - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: - - patched_util.get_asic_id_for_logical_port.return_value = 0 - - status = True - fvs = [('state', "auto"), ('read_side', 1)] - Table = MagicMock() - Table.get.return_value = (status, fvs) - swsscommon.Table.return_value.get.return_value = ( - False, {"read_side": "2"}) + logical_port_name = "Ethernet20" + platform_sfputil.get_asic_id_for_logical_port = 0 + swsscommon.Table.return_value.get.return_value = ( + True, {"read_side": "2"}) - rc = get_firmware_dict( - physical_port, port_instance, target, side, mux_info_dict, logical_port_name) + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - assert(mux_info_dict['version_a_active'] == "N/A") - assert(mux_info_dict['version_a_inactive'] == "N/A") - assert(mux_info_dict['version_a_next'] == "N/A") + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 + self.TARGET_NIC = 1 + self.TARGET_TOR_A = 1 + self.TARGET_TOR_B = 1 + self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + self.FIRMWARE_DOWNLOAD_STATUS_FAILED = 2 + self.download_firmware_status = 0 + self.MUX_TOGGLE_STATUS_INPROGRESS = 1 + self.MUX_TOGGLE_STATUS_FAILED = 2 + self.MUX_TOGGLE_STATUS_NOT_INITIATED_OR_FINISHED = 2 + self.mux_toggle_status = 0 + self.SWITCH_COUNT_MANUAL = "manual" + self.SWITCH_COUNT_AUTO = "auto" - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - def test_get_firmware_dict_download_status_failed_exception(self, port_instance): - - port_instance = MagicMock() - port_instance.FIRMWARE_DOWNLOAD_STATUS_FAILED = -1 - port_instance.download_firmware_status = -1 - port_instance.get_firmware_version = MagicMock( - side_effect=NotImplementedError) + def get_active_linked_tor_side(self): + return 1 - physical_port = 1 - target = "simulated_target" - side = "a" - mux_info_dict = {} - logical_port_name = "Ethernet0" + def get_mux_direction(self): + return 1 - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: + def get_switch_count_total(self, switch_count): + return 1 - patched_util.get_asic_id_for_logical_port.return_value = 0 + def get_eye_heights(self, tgt_tor): + return 500 - status = True - fvs = [('state', "auto"), ('read_side', 1)] - Table = MagicMock() - Table.get.return_value = (status, fvs) + def is_link_active(self, tgt_nic): + return True - rc = get_firmware_dict( - physical_port, port_instance, target, side, mux_info_dict, logical_port_name) + def get_local_temperature(self): + return 22.75 - assert(mux_info_dict['version_a_active'] == "N/A") - assert(mux_info_dict['version_a_inactive'] == "N/A") - assert(mux_info_dict['version_a_next'] == "N/A") + def get_local_voltage(self): + return 0.5 - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - def test_get_firmware_dict_download_status_failed(self, port_instance): + def get_nic_voltage(self): + return 2.7 - port_instance = MagicMock() - port_instance.FIRMWARE_DOWNLOAD_STATUS_FAILED = -1 - port_instance.download_firmware_status = -1 - port_instance.get_firmware_version = MagicMock( - return_value={"version_active": "2021", "version_inactive": "2020", "version_next": "2022"}) + def get_nic_temperature(self): + return 20 - physical_port = 1 - target = "simulated_target" - side = "a" - mux_info_dict = {} - logical_port_name = "Ethernet0" + patched_util.get.return_value = PortInstanceHelper() with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: - patched_util.get_asic_id_for_logical_port.return_value = 0 - status = True - fvs = [('state', "auto"), ('read_side', 1)] - Table = MagicMock() - Table.get.return_value = (status, fvs) - - rc = get_firmware_dict( - physical_port, port_instance, target, side, mux_info_dict, logical_port_name) - - assert(mux_info_dict['version_a_active'] == "2021") - assert(mux_info_dict['version_a_inactive'] == "2020") - assert(mux_info_dict['version_a_next'] == "2022") - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') - def test_get_muxcable_info(self, platform_sfputil): - physical_port = 20 - - logical_port_name = "Ethernet20" - swsscommon.Table.return_value.get.return_value = ( - True, {"read_side": "1"}) - platform_sfputil.get_asic_id_for_logical_port = 0 - - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - - class PortInstanceHelper(): - def __init__(self): - self.EEPROM_ERROR = -1 - self.TARGET_NIC = 1 - self.TARGET_TOR_A = 1 - self.TARGET_TOR_B = 1 - self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - self.FIRMWARE_DOWNLOAD_STATUS_FAILED = 2 - self.download_firmware_status = 0 - self.MUX_TOGGLE_STATUS_INPROGRESS = 1 - self.MUX_TOGGLE_STATUS_FAILED = 2 - self.MUX_TOGGLE_STATUS_NOT_INITIATED_OR_FINISHED = 2 - self.mux_toggle_status = 0 - self.SWITCH_COUNT_MANUAL = "manual" - self.SWITCH_COUNT_AUTO = "auto" - - def get_active_linked_tor_side(self): - return 1 - - def get_mux_direction(self): - return 1 - - def get_switch_count_total(self, switch_count): - return 1 - - def get_eye_heights(self, tgt_tor): - return 500 - - def is_link_active(self, tgt_nic): - return True - - def get_local_temperature(self): - return 22.75 - - def get_local_voltage(self): - return 0.5 - - def get_nic_voltage(self): - return 2.7 - - def get_nic_temperature(self): - return 20 - - patched_util.get.return_value = PortInstanceHelper() - - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: - patched_util.get_asic_id_for_logical_port.return_value = 0 - - rc = get_muxcable_info(physical_port, logical_port_name) - - assert(rc['tor_active'] == 'active') - assert(rc['mux_direction'] == 'self') - assert(rc['internal_voltage'] == 0.5) - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') - def test_get_muxcable_info_peer_side(self, platform_sfputil): - physical_port = 20 - - logical_port_name = "Ethernet20" - platform_sfputil.get_asic_id_for_logical_port = 0 - swsscommon.Table.return_value.get.return_value = ( - True, {"read_side": "2"}) - - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - - class PortInstanceHelper(): - def __init__(self): - self.EEPROM_ERROR = -1 - self.TARGET_NIC = 1 - self.TARGET_TOR_A = 1 - self.TARGET_TOR_B = 1 - self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - self.FIRMWARE_DOWNLOAD_STATUS_FAILED = 2 - self.download_firmware_status = 0 - self.MUX_TOGGLE_STATUS_INPROGRESS = 1 - self.MUX_TOGGLE_STATUS_FAILED = 2 - self.MUX_TOGGLE_STATUS_NOT_INITIATED_OR_FINISHED = 2 - self.mux_toggle_status = 0 - self.SWITCH_COUNT_MANUAL = "manual" - self.SWITCH_COUNT_AUTO = "auto" - - def get_active_linked_tor_side(self): - return 1 - - def get_mux_direction(self): - return 1 - - def get_switch_count_total(self, switch_count): - return 1 + rc = get_muxcable_info(physical_port, logical_port_name) - def get_eye_heights(self, tgt_tor): - return 500 + assert(rc['tor_active'] == 'standby') + assert(rc['mux_direction'] == 'peer') + assert(rc['internal_voltage'] == 0.5) - def is_link_active(self, tgt_nic): - return True + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_get_muxcable_info_exceptions(self, platform_sfputil): + physical_port = 20 - def get_local_temperature(self): - return 22.75 + logical_port_name = "Ethernet20" + platform_sfputil.get_asic_id_for_logical_port = 0 - def get_local_voltage(self): - return 0.5 + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - def get_nic_voltage(self): - return 2.7 + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 + self.TARGET_NIC = 1 + self.TARGET_TOR_A = 1 + self.TARGET_TOR_B = 1 + self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + self.FIRMWARE_DOWNLOAD_STATUS_FAILED = 2 + self.download_firmware_status = 0 + self.MUX_TOGGLE_STATUS_INPROGRESS = 1 + self.MUX_TOGGLE_STATUS_FAILED = 2 + self.MUX_TOGGLE_STATUS_NOT_INITIATED_OR_FINISHED = 2 + self.mux_toggle_status = 0 + self.SWITCH_COUNT_MANUAL = "manual" + self.SWITCH_COUNT_AUTO = "auto" - def get_nic_temperature(self): - return 20 + def get_active_linked_tor_side(): + return 1 - patched_util.get.return_value = PortInstanceHelper() + def get_mux_direction(): + return 1 - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: - patched_util.get_asic_id_for_logical_port.return_value = 0 + def get_switch_count_total(self, switch_count): + return 1 - rc = get_muxcable_info(physical_port, logical_port_name) + def get_eye_heights(tgt_tor): + return 500 - assert(rc['tor_active'] == 'standby') - assert(rc['mux_direction'] == 'peer') - assert(rc['internal_voltage'] == 0.5) + def is_link_active(self, tgt_nic): + return True - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_get_muxcable_info_exceptions(self, platform_sfputil): - physical_port = 20 - - logical_port_name = "Ethernet20" - platform_sfputil.get_asic_id_for_logical_port = 0 - - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - - class PortInstanceHelper(): - def __init__(self): - self.EEPROM_ERROR = -1 - self.TARGET_NIC = 1 - self.TARGET_TOR_A = 1 - self.TARGET_TOR_B = 1 - self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - self.FIRMWARE_DOWNLOAD_STATUS_FAILED = 2 - self.download_firmware_status = 0 - self.MUX_TOGGLE_STATUS_INPROGRESS = 1 - self.MUX_TOGGLE_STATUS_FAILED = 2 - self.MUX_TOGGLE_STATUS_NOT_INITIATED_OR_FINISHED = 2 - self.mux_toggle_status = 0 - self.SWITCH_COUNT_MANUAL = "manual" - self.SWITCH_COUNT_AUTO = "auto" - - def get_active_linked_tor_side(): - return 1 - - def get_mux_direction(): - return 1 - - def get_switch_count_total(self, switch_count): - return 1 - - def get_eye_heights(tgt_tor): - return 500 - - def is_link_active(self, tgt_nic): - return True - - def get_local_temperature(): - return 22.75 - - def get_local_voltage(): - return 0.5 - - def get_nic_voltage(): - return 2.7 - - def get_nic_temperature(): - return 20 - - patched_util.get.return_value = PortInstanceHelper() - - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: - patched_util.get_asic_id_for_logical_port.return_value = 0 - - rc = get_muxcable_info(physical_port, logical_port_name) + def get_local_temperature(): + return 22.75 - assert(rc['tor_active'] == 'unknown') - assert(rc['mux_direction'] == 'unknown') - assert(rc['self_eye_height_lane1'] == 'N/A') + def get_local_voltage(): + return 0.5 - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_get_muxcable_info_true_exceptions_peer_side(self, platform_sfputil): - physical_port = 20 - - logical_port_name = "Ethernet20" - platform_sfputil.get_asic_id_for_logical_port = 0 - swsscommon.Table.return_value.get.return_value = ( - True, {"read_side": "2"}) - - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + def get_nic_voltage(): + return 2.7 - class PortInstanceHelper(): - def __init__(self): - self.EEPROM_ERROR = -1 - self.TARGET_NIC = 1 - self.TARGET_TOR_A = 1 - self.TARGET_TOR_B = 1 - self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - self.FIRMWARE_DOWNLOAD_STATUS_FAILED = 2 - self.download_firmware_status = 0 - self.MUX_TOGGLE_STATUS_INPROGRESS = 1 - self.MUX_TOGGLE_STATUS_NOT_INITIATED_OR_FINISHED = 2 - self.MUX_TOGGLE_STATUS_FAILED = 2 - self.mux_toggle_status = 0 - self.SWITCH_COUNT_MANUAL = "manual" - self.SWITCH_COUNT_AUTO = "auto" + def get_nic_temperature(): + return 20 - def get_active_linked_tor_side(self): - raise NotImplementedError + patched_util.get.return_value = PortInstanceHelper() - def get_mux_direction(self): - raise NotImplementedError - - def get_switch_count_total(self, switch_count): - raise NotImplementedError - - def get_eye_heights(self, tgt_tor): - raise NotImplementedError - - def is_link_active(self, tgt_nic): - return False + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: + patched_util.get_asic_id_for_logical_port.return_value = 0 - def get_local_temperature(self): - raise NotImplementedError + rc = get_muxcable_info(physical_port, logical_port_name) - def get_local_voltage(self): - raise NotImplementedError + assert(rc['tor_active'] == 'unknown') + assert(rc['mux_direction'] == 'unknown') + assert(rc['self_eye_height_lane1'] == 'N/A') - def get_nic_voltage(self): - raise NotImplementedError + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_get_muxcable_info_true_exceptions_peer_side(self, platform_sfputil): + physical_port = 20 - def get_nic_temperature(self): - raise NotImplementedError + logical_port_name = "Ethernet20" + platform_sfputil.get_asic_id_for_logical_port = 0 + swsscommon.Table.return_value.get.return_value = ( + True, {"read_side": "2"}) - patched_util.get.return_value = PortInstanceHelper() + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: - patched_util.get_asic_id_for_logical_port.return_value = 0 + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 + self.TARGET_NIC = 1 + self.TARGET_TOR_A = 1 + self.TARGET_TOR_B = 1 + self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + self.FIRMWARE_DOWNLOAD_STATUS_FAILED = 2 + self.download_firmware_status = 0 + self.MUX_TOGGLE_STATUS_INPROGRESS = 1 + self.MUX_TOGGLE_STATUS_NOT_INITIATED_OR_FINISHED = 2 + self.MUX_TOGGLE_STATUS_FAILED = 2 + self.mux_toggle_status = 0 + self.SWITCH_COUNT_MANUAL = "manual" + self.SWITCH_COUNT_AUTO = "auto" - rc = get_muxcable_info(physical_port, logical_port_name) + def get_active_linked_tor_side(self): + raise NotImplementedError - assert(rc['tor_active'] == 'unknown') - assert(rc['mux_direction'] == 'unknown') - assert(rc['self_eye_height_lane1'] == 'N/A') + def get_mux_direction(self): + raise NotImplementedError - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_get_muxcable_info_true_exceptions(self, platform_sfputil): - physical_port = 20 + def get_switch_count_total(self, switch_count): + raise NotImplementedError - logical_port_name = "Ethernet20" - platform_sfputil.get_asic_id_for_logical_port = 0 + def get_eye_heights(self, tgt_tor): + raise NotImplementedError - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + def is_link_active(self, tgt_nic): + return False - class PortInstanceHelper(): - def __init__(self): - self.EEPROM_ERROR = -1 - self.TARGET_NIC = 1 - self.TARGET_TOR_A = 1 - self.TARGET_TOR_B = 1 - self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - self.FIRMWARE_DOWNLOAD_STATUS_FAILED = 2 - self.download_firmware_status = 0 - self.MUX_TOGGLE_STATUS_INPROGRESS = 1 - self.MUX_TOGGLE_STATUS_FAILED = 2 - self.MUX_TOGGLE_STATUS_NOT_INITIATED_OR_FINISHED = 2 - self.mux_toggle_status = 0 - self.SWITCH_COUNT_MANUAL = "manual" - self.SWITCH_COUNT_AUTO = "auto" + def get_local_temperature(self): + raise NotImplementedError - def get_active_linked_tor_side(self): - raise NotImplementedError + def get_local_voltage(self): + raise NotImplementedError - def get_mux_direction(self): - raise NotImplementedError + def get_nic_voltage(self): + raise NotImplementedError - def get_switch_count_total(self, switch_count): - raise NotImplementedError + def get_nic_temperature(self): + raise NotImplementedError - def get_eye_heights(self, tgt_tor): - raise NotImplementedError + patched_util.get.return_value = PortInstanceHelper() - def is_link_active(self, tgt_nic): - return False + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: + patched_util.get_asic_id_for_logical_port.return_value = 0 - def get_local_temperature(self): - raise NotImplementedError + rc = get_muxcable_info(physical_port, logical_port_name) - def get_local_voltage(self): - raise NotImplementedError + assert(rc['tor_active'] == 'unknown') + assert(rc['mux_direction'] == 'unknown') + assert(rc['self_eye_height_lane1'] == 'N/A') - def get_nic_voltage(self): - raise NotImplementedError + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_get_muxcable_info_true_exceptions(self, platform_sfputil): + physical_port = 20 - def get_nic_temperature(self): - raise NotImplementedError + logical_port_name = "Ethernet20" + platform_sfputil.get_asic_id_for_logical_port = 0 - patched_util.get.return_value = PortInstanceHelper() + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: - patched_util.get_asic_id_for_logical_port.return_value = 0 + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 + self.TARGET_NIC = 1 + self.TARGET_TOR_A = 1 + self.TARGET_TOR_B = 1 + self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + self.FIRMWARE_DOWNLOAD_STATUS_FAILED = 2 + self.download_firmware_status = 0 + self.MUX_TOGGLE_STATUS_INPROGRESS = 1 + self.MUX_TOGGLE_STATUS_FAILED = 2 + self.MUX_TOGGLE_STATUS_NOT_INITIATED_OR_FINISHED = 2 + self.mux_toggle_status = 0 + self.SWITCH_COUNT_MANUAL = "manual" + self.SWITCH_COUNT_AUTO = "auto" - rc = get_muxcable_info(physical_port, logical_port_name) + def get_active_linked_tor_side(self): + raise NotImplementedError - assert(rc['tor_active'] == 'unknown') - assert(rc['mux_direction'] == 'unknown') - assert(rc['self_eye_height_lane1'] == 'N/A') + def get_mux_direction(self): + raise NotImplementedError - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_get_muxcable_info_exceptions_peer_side(self, platform_sfputil): - physical_port = 20 + def get_switch_count_total(self, switch_count): + raise NotImplementedError - logical_port_name = "Ethernet20" - platform_sfputil.get_asic_id_for_logical_port = 0 - swsscommon.Table.return_value.get.return_value = ( - True, {"read_side": "2"}) + def get_eye_heights(self, tgt_tor): + raise NotImplementedError - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + def is_link_active(self, tgt_nic): + return False - class PortInstanceHelper(): - def __init__(self): - self.EEPROM_ERROR = -1 - self.TARGET_NIC = 1 - self.TARGET_TOR_A = 1 - self.TARGET_TOR_B = 1 - self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - self.FIRMWARE_DOWNLOAD_STATUS_FAILED = 2 - self.download_firmware_status = 0 - self.MUX_TOGGLE_STATUS_INPROGRESS = 1 - self.MUX_TOGGLE_STATUS_NOT_INITIATED_OR_FINISHED = 2 - self.mux_toggle_status = 0 - self.SWITCH_COUNT_MANUAL = "manual" - self.SWITCH_COUNT_AUTO = "auto" + def get_local_temperature(self): + raise NotImplementedError - def get_active_linked_tor_side(): - return 1 + def get_local_voltage(self): + raise NotImplementedError - def get_mux_direction(): - return 1 + def get_nic_voltage(self): + raise NotImplementedError - def get_switch_count_total(self, switch_count): - return 1 + def get_nic_temperature(self): + raise NotImplementedError - def get_eye_heights(tgt_tor): - return 500 + patched_util.get.return_value = PortInstanceHelper() - def is_link_active(self, tgt_nic): - return True + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: + patched_util.get_asic_id_for_logical_port.return_value = 0 - def get_local_temperature(): - return 22.75 + rc = get_muxcable_info(physical_port, logical_port_name) - def get_local_voltage(): - return 0.5 + assert(rc['tor_active'] == 'unknown') + assert(rc['mux_direction'] == 'unknown') + assert(rc['self_eye_height_lane1'] == 'N/A') - def get_nic_voltage(): - return 2.7 + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_get_muxcable_info_exceptions_peer_side(self, platform_sfputil): + physical_port = 20 - def get_nic_temperature(): - return 20 + logical_port_name = "Ethernet20" + platform_sfputil.get_asic_id_for_logical_port = 0 + swsscommon.Table.return_value.get.return_value = ( + True, {"read_side": "2"}) - patched_util.get.return_value = PortInstanceHelper() + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: - patched_util.get_asic_id_for_logical_port.return_value = 0 + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 + self.TARGET_NIC = 1 + self.TARGET_TOR_A = 1 + self.TARGET_TOR_B = 1 + self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + self.FIRMWARE_DOWNLOAD_STATUS_FAILED = 2 + self.download_firmware_status = 0 + self.MUX_TOGGLE_STATUS_INPROGRESS = 1 + self.MUX_TOGGLE_STATUS_NOT_INITIATED_OR_FINISHED = 2 + self.mux_toggle_status = 0 + self.SWITCH_COUNT_MANUAL = "manual" + self.SWITCH_COUNT_AUTO = "auto" - rc = get_muxcable_info(physical_port, logical_port_name) + def get_active_linked_tor_side(): + return 1 - assert(rc['tor_active'] == 'unknown') - assert(rc['mux_direction'] == 'unknown') - assert(rc['self_eye_height_lane1'] == 'N/A') + def get_mux_direction(): + return 1 - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_get_muxcable_static_info(self, platform_sfputil): - physical_port = 0 + def get_switch_count_total(self, switch_count): + return 1 - logical_port_name = "Ethernet0" + def get_eye_heights(tgt_tor): + return 500 - platform_sfputil.get_asic_id_for_logical_port = 0 - swsscommon.Table.return_value.get.return_value = ( - True, {"read_side": "1"}) - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - class PortInstanceHelper(): - def __init__(self): - self.EEPROM_ERROR = -1 - self.TARGET_NIC = 0 - self.TARGET_TOR_A = 1 - self.TARGET_TOR_B = 2 - self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - self.download_firmware_status = 1 - self.MUX_TOGGLE_STATUS_INPROGRESS = 1 - self.MUX_TOGGLE_STATUS_FAILED = 2 - self.MUX_TOGGLE_STATUS_NOT_INITIATED_OR_FINISHED = 2 - self.mux_toggle_status = 0 - self.SWITCH_COUNT_MANUAL = "manual" - self.SWITCH_COUNT_AUTO = "auto" - - def get_target_cursor_values(self, i, tgt): - if (tgt == self.TARGET_NIC): - return ([1, 7, 7, 1, 0]) - elif (tgt == self.TARGET_TOR_A): - return ([17, 17, 17, 17, 17]) - elif (tgt == self.TARGET_TOR_B): - return ([-17, -17, -17, -17, -17]) - - patched_util.get.return_value = PortInstanceHelper() - - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: - patched_util.get_asic_id_for_logical_port.return_value = 0 - rc = get_muxcable_static_info(physical_port, logical_port_name) - - assert (rc['read_side'] == 'tor1') - assert (rc['nic_lane1_precursor1'] == 1) - assert (rc['nic_lane1_precursor2'] == 7) - assert (rc['nic_lane1_maincursor'] == 7) - assert (rc['nic_lane1_postcursor1'] == 1) - assert (rc['nic_lane1_postcursor2'] == 0) - - assert (rc['nic_lane2_precursor1'] == 1) - assert (rc['nic_lane2_precursor2'] == 7) - assert (rc['nic_lane2_maincursor'] == 7) - assert (rc['nic_lane2_postcursor1'] == 1) - assert (rc['nic_lane2_postcursor2'] == 0) - - assert (rc['tor_self_lane1_precursor1'] == 17) - assert (rc['tor_self_lane1_precursor2'] == 17) - assert (rc['tor_self_lane1_maincursor'] == 17) - assert (rc['tor_self_lane1_postcursor1'] == 17) - assert (rc['tor_self_lane1_postcursor2'] == 17) - - assert (rc['tor_self_lane2_precursor1'] == 17) - assert (rc['tor_self_lane2_precursor2'] == 17) - assert (rc['tor_self_lane2_maincursor'] == 17) - assert (rc['tor_self_lane2_postcursor1'] == 17) - assert (rc['tor_self_lane2_postcursor2'] == 17) - - assert (rc['tor_peer_lane1_precursor1'] == -17) - assert (rc['tor_peer_lane1_precursor2'] == -17) - assert (rc['tor_peer_lane1_maincursor'] == -17) - assert (rc['tor_peer_lane1_postcursor1'] == -17) - assert (rc['tor_peer_lane1_postcursor2'] == -17) - - assert (rc['tor_peer_lane2_precursor1'] == -17) - assert (rc['tor_peer_lane2_precursor2'] == -17) - assert (rc['tor_peer_lane2_maincursor'] == -17) - assert (rc['tor_peer_lane2_postcursor1'] == -17) - assert (rc['tor_peer_lane2_postcursor2'] == -17) - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_get_muxcable_static_info_read_side_peer(self, platform_sfputil): - physical_port = 0 + def is_link_active(self, tgt_nic): + return True - logical_port_name = "Ethernet0" + def get_local_temperature(): + return 22.75 - #swsscommon.Table = MagicMock() - # this patch is already done as global instance - platform_sfputil.get_asic_id_for_logical_port = 0 - swsscommon.Table.return_value.get.return_value = ( - True, {"read_side": "2"}) - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - class PortInstanceHelper(): - def __init__(self): - self.EEPROM_ERROR = -1 - self.TARGET_NIC = 0 - self.TARGET_TOR_A = 1 - self.TARGET_TOR_B = 2 - self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - self.download_firmware_status = 1 - self.MUX_TOGGLE_STATUS_INPROGRESS = 1 - self.MUX_TOGGLE_STATUS_FAILED = 2 - self.MUX_TOGGLE_STATUS_NOT_INITIATED_OR_FINISHED = 2 - self.mux_toggle_status = 0 - self.SWITCH_COUNT_MANUAL = "manual" - self.SWITCH_COUNT_AUTO = "auto" - - def get_target_cursor_values(self, i, tgt): - if (tgt == self.TARGET_NIC): - return ([1, 7, 7, 1, 0]) - elif (tgt == self.TARGET_TOR_A): - return ([-17, -17, -17, -17, -17]) - elif (tgt == self.TARGET_TOR_B): - return ([-17, -17, -17, -17, -17]) - - patched_util.get.return_value = PortInstanceHelper() - - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: - patched_util.get_asic_id_for_logical_port.return_value = 0 - rc = get_muxcable_static_info(physical_port, logical_port_name) - - assert (rc['read_side'] == 'tor2') - assert (rc['nic_lane1_precursor1'] == 1) - assert (rc['nic_lane1_precursor2'] == 7) - assert (rc['nic_lane1_maincursor'] == 7) - assert (rc['nic_lane1_postcursor1'] == 1) - assert (rc['nic_lane1_postcursor2'] == 0) - - assert (rc['nic_lane2_precursor1'] == 1) - assert (rc['nic_lane2_precursor2'] == 7) - assert (rc['nic_lane2_maincursor'] == 7) - assert (rc['nic_lane2_postcursor1'] == 1) - assert (rc['nic_lane2_postcursor2'] == 0) - - assert (rc['tor_self_lane1_precursor1'] == -17) - assert (rc['tor_self_lane1_precursor2'] == -17) - assert (rc['tor_self_lane1_maincursor'] == -17) - assert (rc['tor_self_lane1_postcursor1'] == -17) - assert (rc['tor_self_lane1_postcursor2'] == -17) - - assert (rc['tor_self_lane2_precursor1'] == -17) - assert (rc['tor_self_lane2_precursor2'] == -17) - assert (rc['tor_self_lane2_maincursor'] == -17) - assert (rc['tor_self_lane2_postcursor1'] == -17) - assert (rc['tor_self_lane2_postcursor2'] == -17) - - assert (rc['tor_peer_lane1_precursor1'] == -17) - assert (rc['tor_peer_lane1_precursor2'] == -17) - assert (rc['tor_peer_lane1_maincursor'] == -17) - assert (rc['tor_peer_lane1_postcursor1'] == -17) - assert (rc['tor_peer_lane1_postcursor2'] == -17) - - assert (rc['tor_peer_lane2_precursor1'] == -17) - assert (rc['tor_peer_lane2_precursor2'] == -17) - assert (rc['tor_peer_lane2_maincursor'] == -17) - assert (rc['tor_peer_lane2_postcursor1'] == -17) - assert (rc['tor_peer_lane2_postcursor2'] == -17) - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_get_muxcable_static_info_read_side_peer_exceptions(self, platform_sfputil): - physical_port = 0 + def get_local_voltage(): + return 0.5 - logical_port_name = "Ethernet0" + def get_nic_voltage(): + return 2.7 - #swsscommon.Table = MagicMock() - # this patch is already done as global instance - platform_sfputil.get_asic_id_for_logical_port = 0 - swsscommon.Table.return_value.get.return_value = ( - True, {"read_side": "2"}) - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - class PortInstanceHelper(): - def __init__(self): - self.EEPROM_ERROR = -1 - self.TARGET_NIC = 0 - self.TARGET_TOR_A = 1 - self.TARGET_TOR_B = 2 - self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - self.download_firmware_status = 1 - self.MUX_TOGGLE_STATUS_INPROGRESS = 1 - self.MUX_TOGGLE_STATUS_FAILED = 2 - self.MUX_TOGGLE_STATUS_NOT_INITIATED_OR_FINISHED = 2 - self.mux_toggle_status = 0 - self.SWITCH_COUNT_MANUAL = "manual" - self.SWITCH_COUNT_AUTO = "auto" - - def get_target_cursor_values(self, i, tgt): - raise NotImplementedError - - patched_util.get.return_value = PortInstanceHelper() - - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: - patched_util.get_asic_id_for_logical_port.return_value = 0 - rc = get_muxcable_static_info(physical_port, logical_port_name) - - assert (rc['read_side'] == 'tor2') - assert (rc['nic_lane1_precursor1'] == "N/A") - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - def test_task_download_firmware_worker(self, port_instance, mock_swsscommon_table): - port = "Ethernet0" - physical_port = 0 - file_full_path = "/path/to/file" + def get_nic_temperature(): + return 20 - def mock_download_fw(filepath): - return 0 + patched_util.get.return_value = PortInstanceHelper() - port_instance.download_firmware = mock_download_fw + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: + patched_util.get_asic_id_for_logical_port.return_value = 0 - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table + rc = get_muxcable_info(physical_port, logical_port_name) + + assert(rc['tor_active'] == 'unknown') + assert(rc['mux_direction'] == 'unknown') + assert(rc['self_eye_height_lane1'] == 'N/A') + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_get_muxcable_static_info(self, platform_sfputil): + physical_port = 0 + + logical_port_name = "Ethernet0" + + platform_sfputil.get_asic_id_for_logical_port = 0 + swsscommon.Table.return_value.get.return_value = ( + True, {"read_side": "1"}) + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 + self.TARGET_NIC = 0 + self.TARGET_TOR_A = 1 + self.TARGET_TOR_B = 2 + self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + self.download_firmware_status = 1 + self.MUX_TOGGLE_STATUS_INPROGRESS = 1 + self.MUX_TOGGLE_STATUS_FAILED = 2 + self.MUX_TOGGLE_STATUS_NOT_INITIATED_OR_FINISHED = 2 + self.mux_toggle_status = 0 + self.SWITCH_COUNT_MANUAL = "manual" + self.SWITCH_COUNT_AUTO = "auto" + + def get_target_cursor_values(self, i, tgt): + if (tgt == self.TARGET_NIC): + return ([1, 7, 7, 1, 0]) + elif (tgt == self.TARGET_TOR_A): + return ([17, 17, 17, 17, 17]) + elif (tgt == self.TARGET_TOR_B): + return ([-17, -17, -17, -17, -17]) + + patched_util.get.return_value = PortInstanceHelper() - xcvrd_down_fw_rsp_tbl = mock_swsscommon_table - xcvrd_down_fw_cmd_sts_tbl = mock_swsscommon_table + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: + patched_util.get_asic_id_for_logical_port.return_value = 0 + rc = get_muxcable_static_info(physical_port, logical_port_name) + + assert (rc['read_side'] == 'tor1') + assert (rc['nic_lane1_precursor1'] == 1) + assert (rc['nic_lane1_precursor2'] == 7) + assert (rc['nic_lane1_maincursor'] == 7) + assert (rc['nic_lane1_postcursor1'] == 1) + assert (rc['nic_lane1_postcursor2'] == 0) + + assert (rc['nic_lane2_precursor1'] == 1) + assert (rc['nic_lane2_precursor2'] == 7) + assert (rc['nic_lane2_maincursor'] == 7) + assert (rc['nic_lane2_postcursor1'] == 1) + assert (rc['nic_lane2_postcursor2'] == 0) + + assert (rc['tor_self_lane1_precursor1'] == 17) + assert (rc['tor_self_lane1_precursor2'] == 17) + assert (rc['tor_self_lane1_maincursor'] == 17) + assert (rc['tor_self_lane1_postcursor1'] == 17) + assert (rc['tor_self_lane1_postcursor2'] == 17) + + assert (rc['tor_self_lane2_precursor1'] == 17) + assert (rc['tor_self_lane2_precursor2'] == 17) + assert (rc['tor_self_lane2_maincursor'] == 17) + assert (rc['tor_self_lane2_postcursor1'] == 17) + assert (rc['tor_self_lane2_postcursor2'] == 17) + + assert (rc['tor_peer_lane1_precursor1'] == -17) + assert (rc['tor_peer_lane1_precursor2'] == -17) + assert (rc['tor_peer_lane1_maincursor'] == -17) + assert (rc['tor_peer_lane1_postcursor1'] == -17) + assert (rc['tor_peer_lane1_postcursor2'] == -17) + + assert (rc['tor_peer_lane2_precursor1'] == -17) + assert (rc['tor_peer_lane2_precursor2'] == -17) + assert (rc['tor_peer_lane2_maincursor'] == -17) + assert (rc['tor_peer_lane2_postcursor1'] == -17) + assert (rc['tor_peer_lane2_postcursor2'] == -17) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_get_muxcable_static_info_read_side_peer(self, platform_sfputil): + physical_port = 0 + + logical_port_name = "Ethernet0" + + #swsscommon.Table = MagicMock() + # this patch is already done as global instance + platform_sfputil.get_asic_id_for_logical_port = 0 + swsscommon.Table.return_value.get.return_value = ( + True, {"read_side": "2"}) + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 + self.TARGET_NIC = 0 + self.TARGET_TOR_A = 1 + self.TARGET_TOR_B = 2 + self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + self.download_firmware_status = 1 + self.MUX_TOGGLE_STATUS_INPROGRESS = 1 + self.MUX_TOGGLE_STATUS_FAILED = 2 + self.MUX_TOGGLE_STATUS_NOT_INITIATED_OR_FINISHED = 2 + self.mux_toggle_status = 0 + self.SWITCH_COUNT_MANUAL = "manual" + self.SWITCH_COUNT_AUTO = "auto" + + def get_target_cursor_values(self, i, tgt): + if (tgt == self.TARGET_NIC): + return ([1, 7, 7, 1, 0]) + elif (tgt == self.TARGET_TOR_A): + return ([-17, -17, -17, -17, -17]) + elif (tgt == self.TARGET_TOR_B): + return ([-17, -17, -17, -17, -17]) + + patched_util.get.return_value = PortInstanceHelper() - rc = {} + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: + patched_util.get_asic_id_for_logical_port.return_value = 0 + rc = get_muxcable_static_info(physical_port, logical_port_name) + + assert (rc['read_side'] == 'tor2') + assert (rc['nic_lane1_precursor1'] == 1) + assert (rc['nic_lane1_precursor2'] == 7) + assert (rc['nic_lane1_maincursor'] == 7) + assert (rc['nic_lane1_postcursor1'] == 1) + assert (rc['nic_lane1_postcursor2'] == 0) + + assert (rc['nic_lane2_precursor1'] == 1) + assert (rc['nic_lane2_precursor2'] == 7) + assert (rc['nic_lane2_maincursor'] == 7) + assert (rc['nic_lane2_postcursor1'] == 1) + assert (rc['nic_lane2_postcursor2'] == 0) + + assert (rc['tor_self_lane1_precursor1'] == -17) + assert (rc['tor_self_lane1_precursor2'] == -17) + assert (rc['tor_self_lane1_maincursor'] == -17) + assert (rc['tor_self_lane1_postcursor1'] == -17) + assert (rc['tor_self_lane1_postcursor2'] == -17) + + assert (rc['tor_self_lane2_precursor1'] == -17) + assert (rc['tor_self_lane2_precursor2'] == -17) + assert (rc['tor_self_lane2_maincursor'] == -17) + assert (rc['tor_self_lane2_postcursor1'] == -17) + assert (rc['tor_self_lane2_postcursor2'] == -17) + + assert (rc['tor_peer_lane1_precursor1'] == -17) + assert (rc['tor_peer_lane1_precursor2'] == -17) + assert (rc['tor_peer_lane1_maincursor'] == -17) + assert (rc['tor_peer_lane1_postcursor1'] == -17) + assert (rc['tor_peer_lane1_postcursor2'] == -17) + + assert (rc['tor_peer_lane2_precursor1'] == -17) + assert (rc['tor_peer_lane2_precursor2'] == -17) + assert (rc['tor_peer_lane2_maincursor'] == -17) + assert (rc['tor_peer_lane2_postcursor1'] == -17) + assert (rc['tor_peer_lane2_postcursor2'] == -17) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_get_muxcable_static_info_read_side_peer_exceptions(self, platform_sfputil): + physical_port = 0 + + logical_port_name = "Ethernet0" + + #swsscommon.Table = MagicMock() + # this patch is already done as global instance + platform_sfputil.get_asic_id_for_logical_port = 0 + swsscommon.Table.return_value.get.return_value = ( + True, {"read_side": "2"}) + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 + self.TARGET_NIC = 0 + self.TARGET_TOR_A = 1 + self.TARGET_TOR_B = 2 + self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + self.download_firmware_status = 1 + self.MUX_TOGGLE_STATUS_INPROGRESS = 1 + self.MUX_TOGGLE_STATUS_FAILED = 2 + self.MUX_TOGGLE_STATUS_NOT_INITIATED_OR_FINISHED = 2 + self.mux_toggle_status = 0 + self.SWITCH_COUNT_MANUAL = "manual" + self.SWITCH_COUNT_AUTO = "auto" + + def get_target_cursor_values(self, i, tgt): + raise NotImplementedError + + patched_util.get.return_value = PortInstanceHelper() - task_download_firmware_worker(port, physical_port, port_instance, file_full_path, - xcvrd_down_fw_rsp_tbl, xcvrd_down_fw_cmd_sts_tbl, rc) + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: + patched_util.get_asic_id_for_logical_port.return_value = 0 + rc = get_muxcable_static_info(physical_port, logical_port_name) + + assert (rc['read_side'] == 'tor2') + assert (rc['nic_lane1_precursor1'] == "N/A") + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + def test_task_download_firmware_worker(self, port_instance, mock_swsscommon_table): + port = "Ethernet0" + physical_port = 0 + file_full_path = "/path/to/file" + + def mock_download_fw(filepath): + return 0 + + port_instance.download_firmware = mock_download_fw + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_down_fw_rsp_tbl = mock_swsscommon_table + xcvrd_down_fw_cmd_sts_tbl = mock_swsscommon_table + + rc = {} + + task_download_firmware_worker(port, physical_port, port_instance, file_full_path, + xcvrd_down_fw_rsp_tbl, xcvrd_down_fw_cmd_sts_tbl, rc) + + assert(rc[0] == 0) + + def test_set_show_firmware_fields(self): + + mux_info_dict = {} + xcvrd_show_fw_res_tbl = Table("STATE_DB", "XCVRD_SHOW_FW_RES") + mux_info_dict['version_self_active'] = '0.8' + mux_info_dict['version_self_inactive'] = '0.7' + mux_info_dict['version_self_next'] = '0.7' + mux_info_dict['version_peer_active'] = '0.8' + mux_info_dict['version_peer_inactive'] = '0.7' + mux_info_dict['version_peer_next'] = '0.7' + mux_info_dict['version_nic_active'] = '0.8' + mux_info_dict['version_nic_inactive'] = '0.7' + mux_info_dict['version_nic_next'] = '0.7' + rc = set_show_firmware_fields( + "Ethernet0", mux_info_dict, xcvrd_show_fw_res_tbl) + + assert(rc == 0) + + @patch('sonic_py_common.device_info.get_paths_to_platform_and_hwsku_dirs', MagicMock(return_value=('/tmp', None))) + @patch('swsscommon.swsscommon.WarmStart', MagicMock()) + @patch('ycable.ycable.platform_sfputil', MagicMock()) + @patch('ycable.ycable.DaemonYcable.load_platform_util', MagicMock()) + def test_DaemonYcable_init_deinit(self): + ycable = DaemonYcable(SYSLOG_IDENTIFIER) + ycable.init() + ycable.deinit() + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "enable", {"mode_value": "0", + "lane_mask": "0", + "direction": "0"}))) + def test_handle_config_prbs_cmd_arg_tbl_notification_no_port(self, port_instance, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_config_prbs_cmd_arg_tbl = mock_swsscommon_table + xcvrd_config_prbs_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_prbs_rsp_tbl = mock_swsscommon_table + asic_index = 0 + port = "Ethernet0" + fvp = {"config_prbs": True} + + rc = handle_config_prbs_cmd_arg_tbl_notification( + fvp, xcvrd_config_prbs_cmd_arg_tbl, xcvrd_config_prbs_cmd_sts_tbl, xcvrd_config_prbs_rsp_tbl, asic_index, port) + assert(rc == -1) + + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "enable", {"mode_value": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + def test_handle_config_prbs_cmd_arg_tbl_notification_no_instance(self, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_config_prbs_cmd_arg_tbl = mock_swsscommon_table + xcvrd_config_prbs_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_prbs_rsp_tbl = mock_swsscommon_table + asic_index = 0 + port = "Ethernet0" + fvp = {"config_prbs": True} + + rc = handle_config_prbs_cmd_arg_tbl_notification( + fvp, xcvrd_config_prbs_cmd_arg_tbl, xcvrd_config_prbs_cmd_sts_tbl, xcvrd_config_prbs_rsp_tbl, asic_index, port) + assert(rc == -1) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "enable", {"mode_value": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_config_prbs_cmd_arg_tbl_notification_with_instance_enable(self, port_instance, mock_swsscommon_table, port_instance_helper): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_config_prbs_cmd_arg_tbl = mock_swsscommon_table + xcvrd_config_prbs_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_prbs_rsp_tbl = mock_swsscommon_table + port_instance = MagicMock() + port_instance.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + port_instance.PRBS_DIRECTION_BOTH = 2 + port_instance.enable_prbs_mode.return_value = True + port_instance.disable_prbs_mode.return_value = True + port_instance_helper = port_instance + + asic_index = 0 + port = "Ethernet0" + fvp = {"config_prbs": True} + + rc = handle_config_prbs_cmd_arg_tbl_notification( + fvp, xcvrd_config_prbs_cmd_arg_tbl, xcvrd_config_prbs_cmd_sts_tbl, xcvrd_config_prbs_rsp_tbl, asic_index, port) + assert(rc == None) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "disable", {"mode_value": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_config_prbs_cmd_arg_tbl_notification_with_instance_disable(self, port_instance, mock_swsscommon_table, port_instance_helper): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_config_prbs_cmd_arg_tbl = mock_swsscommon_table + xcvrd_config_prbs_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_prbs_rsp_tbl = mock_swsscommon_table + port_instance = MagicMock() + port_instance.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + port_instance.PRBS_DIRECTION_BOTH = 2 + port_instance.enable_prbs_mode.return_value = True + port_instance.disable_prbs_mode.return_value = True + port_instance_helper = port_instance + + asic_index = 0 + port = "Ethernet0" + fvp = {"config_prbs": True} + + rc = handle_config_prbs_cmd_arg_tbl_notification( + fvp, xcvrd_config_prbs_cmd_arg_tbl, xcvrd_config_prbs_cmd_sts_tbl, xcvrd_config_prbs_rsp_tbl, asic_index, port) + assert(rc == None) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "reset", {"mode_value": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_config_prbs_cmd_arg_tbl_notification_with_instance_reset(self, port_instance, mock_swsscommon_table, port_instance_helper): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_config_prbs_cmd_arg_tbl = mock_swsscommon_table + xcvrd_config_prbs_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_prbs_rsp_tbl = mock_swsscommon_table + port_instance = MagicMock() + port_instance.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + port_instance.PRBS_DIRECTION_BOTH = 2 + port_instance.enable_prbs_mode.return_value = True + port_instance.disable_prbs_mode.return_value = True + port_instance.reset.return_value = True + port_instance_helper = port_instance + + asic_index = 0 + port = "Ethernet0" + fvp = {"config_prbs": True} + + rc = handle_config_prbs_cmd_arg_tbl_notification( + fvp, xcvrd_config_prbs_cmd_arg_tbl, xcvrd_config_prbs_cmd_sts_tbl, xcvrd_config_prbs_rsp_tbl, asic_index, port) + assert(rc == None) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "anlt", {"mode": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_config_prbs_cmd_arg_tbl_notification_with_instance_anlt_enable(self, port_instance, mock_swsscommon_table, port_instance_helper): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_config_prbs_cmd_arg_tbl = mock_swsscommon_table + xcvrd_config_prbs_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_prbs_rsp_tbl = mock_swsscommon_table + port_instance = MagicMock() + port_instance.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + port_instance.PRBS_DIRECTION_BOTH = 2 + port_instance.enable_prbs_mode.return_value = True + port_instance.disable_prbs_mode.return_value = True + port_instance.reset.return_value = True + port_instance.set_anlt.return_value = True + port_instance_helper = port_instance + + asic_index = 0 + port = "Ethernet0" + fvp = {"config_prbs": True} + + rc = handle_config_prbs_cmd_arg_tbl_notification( + fvp, xcvrd_config_prbs_cmd_arg_tbl, xcvrd_config_prbs_cmd_sts_tbl, xcvrd_config_prbs_rsp_tbl, asic_index, port) + assert(rc == None) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "anlt", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_config_prbs_cmd_arg_tbl_notification_with_instance_anlt_disable(self, port_instance, mock_swsscommon_table, port_instance_helper): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_config_prbs_cmd_arg_tbl = mock_swsscommon_table + xcvrd_config_prbs_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_prbs_rsp_tbl = mock_swsscommon_table + port_instance = MagicMock() + port_instance.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + port_instance.PRBS_DIRECTION_BOTH = 2 + port_instance.enable_prbs_mode.return_value = True + port_instance.disable_prbs_mode.return_value = True + port_instance.reset.return_value = True + port_instance.set_anlt.return_value = True + port_instance_helper = port_instance + + asic_index = 0 + port = "Ethernet0" + fvp = {"config_prbs": True} + + rc = handle_config_prbs_cmd_arg_tbl_notification( + fvp, xcvrd_config_prbs_cmd_arg_tbl, xcvrd_config_prbs_cmd_sts_tbl, xcvrd_config_prbs_rsp_tbl, asic_index, port) + assert(rc == -1) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"mode": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_config_prbs_cmd_arg_tbl_notification_with_instance_fec_enable(self, port_instance, mock_swsscommon_table, port_instance_helper): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_config_prbs_cmd_arg_tbl = mock_swsscommon_table + xcvrd_config_prbs_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_prbs_rsp_tbl = mock_swsscommon_table + port_instance = MagicMock() + port_instance.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + port_instance.PRBS_DIRECTION_BOTH = 2 + port_instance.enable_prbs_mode.return_value = True + port_instance.disable_prbs_mode.return_value = True + port_instance.reset.return_value = True + port_instance.set_fec_mode.return_value = True + port_instance_helper = port_instance + + asic_index = 0 + port = "Ethernet0" + fvp = {"config_prbs": True} + + rc = handle_config_prbs_cmd_arg_tbl_notification( + fvp, xcvrd_config_prbs_cmd_arg_tbl, xcvrd_config_prbs_cmd_sts_tbl, xcvrd_config_prbs_rsp_tbl, asic_index, port) + assert(rc == None) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_config_prbs_cmd_arg_tbl_notification_with_instance_fec_disable(self, port_instance, mock_swsscommon_table, port_instance_helper): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_config_prbs_cmd_arg_tbl = mock_swsscommon_table + xcvrd_config_prbs_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_prbs_rsp_tbl = mock_swsscommon_table + port_instance = MagicMock() + port_instance.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + port_instance.PRBS_DIRECTION_BOTH = 2 + port_instance.enable_prbs_mode.return_value = True + port_instance.disable_prbs_mode.return_value = True + port_instance.reset.return_value = True + port_instance.set_fec_mode.return_value = True + port_instance_helper = port_instance + + asic_index = 0 + port = "Ethernet0" + fvp = {"config_prbs": True} + + rc = handle_config_prbs_cmd_arg_tbl_notification( + fvp, xcvrd_config_prbs_cmd_arg_tbl, xcvrd_config_prbs_cmd_sts_tbl, xcvrd_config_prbs_rsp_tbl, asic_index, port) + assert(rc == -1) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_config_prbs_cmd_arg_tbl_notification_else_value(self, port_instance, mock_swsscommon_table, port_instance_helper): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_config_prbs_cmd_arg_tbl = mock_swsscommon_table + xcvrd_config_prbs_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_prbs_rsp_tbl = mock_swsscommon_table + port_instance = MagicMock() + port_instance.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + port_instance.PRBS_DIRECTION_BOTH = 2 + port_instance.enable_prbs_mode.return_value = True + port_instance.disable_prbs_mode.return_value = True + port_instance.reset.return_value = True + port_instance.set_fec_mode.return_value = True + port_instance_helper = port_instance + + asic_index = 0 + port = "Ethernet0" + fvp = {"config_abc": True} + + rc = handle_config_prbs_cmd_arg_tbl_notification( + fvp, xcvrd_config_prbs_cmd_arg_tbl, xcvrd_config_prbs_cmd_sts_tbl, xcvrd_config_prbs_rsp_tbl, asic_index, port) + assert(rc == None) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_config_loop_cmd_arg_tbl_notification_else_value(self, port_instance, mock_swsscommon_table, port_instance_helper): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_config_loop_cmd_arg_tbl = mock_swsscommon_table + xcvrd_config_loop_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_loop_rsp_tbl = mock_swsscommon_table + port_instance = MagicMock() + port_instance.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + port_instance.PRBS_DIRECTION_BOTH = 2 + port_instance.enable_prbs_mode.return_value = True + port_instance.disable_prbs_mode.return_value = True + port_instance.reset.return_value = True + port_instance.set_fec_mode.return_value = True + port_instance_helper = port_instance + + asic_index = 0 + port = "Ethernet0" + fvp = {"config_abc": True} + + rc = handle_config_loop_cmd_arg_tbl_notification( + fvp, xcvrd_config_loop_cmd_arg_tbl, xcvrd_config_loop_cmd_sts_tbl, xcvrd_config_loop_rsp_tbl, asic_index, port) + assert(rc == None) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_config_loop_cmd_arg_tbl_notification_else_value(self, port_instance, mock_swsscommon_table, port_instance_helper): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_config_loop_cmd_arg_tbl = mock_swsscommon_table + xcvrd_config_loop_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_loop_rsp_tbl = mock_swsscommon_table + port_instance = MagicMock() + port_instance.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + port_instance.PRBS_DIRECTION_BOTH = 2 + port_instance.enable_prbs_mode.return_value = True + port_instance.disable_prbs_mode.return_value = True + port_instance.reset.return_value = True + port_instance.set_fec_mode.return_value = True + port_instance_helper = port_instance + + asic_index = 0 + port = "Ethernet0" + fvp = {"config_loop": True} + + rc = handle_config_loop_cmd_arg_tbl_notification( + fvp, xcvrd_config_loop_cmd_arg_tbl, xcvrd_config_loop_cmd_sts_tbl, xcvrd_config_loop_rsp_tbl, asic_index, port) + assert(rc == None) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + def test_handle_config_loop_cmd_arg_tbl_notification_no_port(self, port_instance, mock_swsscommon_table, port_instance_helper): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_config_loop_cmd_arg_tbl = mock_swsscommon_table + xcvrd_config_loop_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_loop_rsp_tbl = mock_swsscommon_table + port_instance = MagicMock() + port_instance.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + port_instance.PRBS_DIRECTION_BOTH = 2 + port_instance.enable_prbs_mode.return_value = True + port_instance.disable_prbs_mode.return_value = True + port_instance.reset.return_value = True + port_instance.set_fec_mode.return_value = True + port_instance_helper = port_instance + + asic_index = 0 + port = "Ethernet0" + fvp = {"config_loop": True} + + rc = handle_config_loop_cmd_arg_tbl_notification( + fvp, xcvrd_config_loop_cmd_arg_tbl, xcvrd_config_loop_cmd_sts_tbl, xcvrd_config_loop_rsp_tbl, asic_index, port) + assert(rc == -1) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_config_loop_cmd_arg_tbl_notification_no_instance(self, port_instance, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_config_loop_cmd_arg_tbl = mock_swsscommon_table + xcvrd_config_loop_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_loop_rsp_tbl = mock_swsscommon_table + port_instance = MagicMock() + port_instance.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + port_instance.PRBS_DIRECTION_BOTH = 2 + port_instance.enable_prbs_mode.return_value = True + port_instance.disable_prbs_mode.return_value = True + port_instance.reset.return_value = True + port_instance.set_fec_mode.return_value = True + port_instance_helper = port_instance + + asic_index = 0 + port = "Ethernet0" + fvp = {"config_loop": True} + + rc = handle_config_loop_cmd_arg_tbl_notification( + fvp, xcvrd_config_loop_cmd_arg_tbl, xcvrd_config_loop_cmd_sts_tbl, xcvrd_config_loop_rsp_tbl, asic_index, port) + assert(rc == -1) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "enable", {"enable": "0", + "lane_mask": "0", + "mode_value": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_config_loop_cmd_arg_tbl_notification_enable(self, port_instance, mock_swsscommon_table, port_instance_helper): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_config_loop_cmd_arg_tbl = mock_swsscommon_table + xcvrd_config_loop_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_loop_rsp_tbl = mock_swsscommon_table + port_instance = MagicMock() + port_instance.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + port_instance.PRBS_DIRECTION_BOTH = 2 + port_instance.enable_loopback_mode.return_value = True + port_instance.disable_loopback_mode.return_value = True + port_instance.reset.return_value = True + port_instance.set_fec_mode.return_value = True + port_instance_helper = port_instance + + asic_index = 0 + port = "Ethernet0" + fvp = {"config_loop": True} + + rc = handle_config_loop_cmd_arg_tbl_notification( + fvp, xcvrd_config_loop_cmd_arg_tbl, xcvrd_config_loop_cmd_sts_tbl, xcvrd_config_loop_rsp_tbl, asic_index, port) + assert(rc == None) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "disable", {"disable": "0", + "lane_mask": "0", + "mode_value": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_config_loop_cmd_arg_tbl_notification_disable(self, port_instance, mock_swsscommon_table, port_instance_helper): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_config_loop_cmd_arg_tbl = mock_swsscommon_table + xcvrd_config_loop_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_loop_rsp_tbl = mock_swsscommon_table + port_instance = MagicMock() + port_instance.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + port_instance.PRBS_DIRECTION_BOTH = 2 + port_instance.enable_loopback_mode.return_value = True + port_instance.disable_loopback_mode.return_value = True + port_instance.reset.return_value = True + port_instance.set_fec_mode.return_value = True + port_instance_helper = port_instance + + asic_index = 0 + port = "Ethernet0" + fvp = {"config_loop": True} + + rc = handle_config_loop_cmd_arg_tbl_notification( + fvp, xcvrd_config_loop_cmd_arg_tbl, xcvrd_config_loop_cmd_sts_tbl, xcvrd_config_loop_rsp_tbl, asic_index, port) + assert(rc == None) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_show_event_cmd_arg_tbl_notification_else_value(self, port_instance, mock_swsscommon_table, port_instance_helper): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_show_event_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_event_rsp_tbl = mock_swsscommon_table + xcvrd_show_event_res_tbl = mock_swsscommon_table + port_instance = MagicMock() + port_instance.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + port_instance.PRBS_DIRECTION_BOTH = 2 + port_instance.enable_prbs_mode.return_value = True + port_instance.disable_prbs_mode.return_value = True + port_instance.reset.return_value = True + port_instance.set_fec_mode.return_value = True + port_instance_helper = port_instance + + asic_index = 0 + port = "Ethernet0" + fvp = {"config_loop": True} + + rc = handle_show_event_cmd_arg_tbl_notification( + fvp, xcvrd_show_event_cmd_sts_tbl, xcvrd_show_event_rsp_tbl, xcvrd_show_event_res_tbl, asic_index, port) + assert(rc == None) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_show_event_cmd_arg_tbl_notification_get_log(self, port_instance, mock_swsscommon_table, port_instance_helper): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_show_event_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_event_rsp_tbl = mock_swsscommon_table + xcvrd_show_event_res_tbl = mock_swsscommon_table + port_instance = MagicMock() + port_instance.get_event_log.return_value = ["log 1", "log 2"] + + asic_index = 0 + port = "Ethernet0" + fvp = {"show_event": True} + + rc = handle_show_event_cmd_arg_tbl_notification( + fvp, xcvrd_show_event_cmd_sts_tbl, xcvrd_show_event_rsp_tbl, xcvrd_show_event_res_tbl, asic_index, port) + assert(rc == None) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_show_event_cmd_arg_tbl_notification_get_actual_log(self, port_instance, mock_swsscommon_table, port_instance_helper): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_show_event_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_event_rsp_tbl = mock_swsscommon_table + xcvrd_show_event_res_tbl = mock_swsscommon_table + port_instance = MagicMock() + port_instance.get_event_log.return_value = ["log 1", "log 2"] + port_instance_helper.return_value = port_instance + asic_index = 0 + port = "Ethernet0" + fvp = {"show_event": True} + + rc = handle_show_event_cmd_arg_tbl_notification( + fvp, xcvrd_show_event_cmd_sts_tbl, xcvrd_show_event_rsp_tbl, xcvrd_show_event_res_tbl, asic_index, port) + assert(rc == None) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_show_event_cmd_arg_tbl_notification_get_no_log(self, port_instance, mock_swsscommon_table, port_instance_helper): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_show_event_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_event_rsp_tbl = mock_swsscommon_table + xcvrd_show_event_res_tbl = mock_swsscommon_table + port_instance = MagicMock() + port_instance.get_event_log.return_value = Exception( + NotImplementedError) + + asic_index = 0 + port = "Ethernet0" + fvp = {"show_event": True} + + rc = handle_show_event_cmd_arg_tbl_notification( + fvp, xcvrd_show_event_cmd_sts_tbl, xcvrd_show_event_rsp_tbl, xcvrd_show_event_res_tbl, asic_index, port) + assert(rc == None) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_show_event_cmd_arg_tbl_notification_no_port(self, port_instance, mock_swsscommon_table, port_instance_helper): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_show_event_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_event_rsp_tbl = mock_swsscommon_table + xcvrd_show_event_res_tbl = mock_swsscommon_table + port_instance = MagicMock() + port_instance.get_event_log.return_value = ["log 1", "log 2"] + port_instance_helper = port_instance + + asic_index = 0 + port = "Ethernet0" + fvp = {"show_event": True} + + rc = handle_show_event_cmd_arg_tbl_notification( + fvp, xcvrd_show_event_cmd_sts_tbl, xcvrd_show_event_rsp_tbl, xcvrd_show_event_res_tbl, asic_index, port) + assert(rc == -1) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + def test_handle_show_event_cmd_arg_tbl_notification_no_instance(self, port_instance, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_show_event_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_event_rsp_tbl = mock_swsscommon_table + xcvrd_show_event_res_tbl = mock_swsscommon_table + port_instance = MagicMock() + port_instance.get_event_log.return_value = ["log 1", "log 2"] + + asic_index = 0 + port = "Ethernet0" + fvp = {"show_event": True} + + rc = handle_show_event_cmd_arg_tbl_notification( + fvp, xcvrd_show_event_cmd_sts_tbl, xcvrd_show_event_rsp_tbl, xcvrd_show_event_res_tbl, asic_index, port) + assert(rc == -1) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_get_fec_cmd_arg_tbl_notification_no_status(self, port_instance, mock_swsscommon_table, port_instance_helper): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_show_fec_rsp_tbl = mock_swsscommon_table + xcvrd_show_fec_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_fec_res_tbl = mock_swsscommon_table + port_instance = MagicMock() + + asic_index = 0 + port = "Ethernet0" + fvp = {"show_event": True} + + rc = handle_get_fec_cmd_arg_tbl_notification( + fvp, xcvrd_show_fec_rsp_tbl, xcvrd_show_fec_cmd_sts_tbl, xcvrd_show_fec_res_tbl, asic_index, port) + assert(rc == None) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_get_fec_cmd_arg_tbl_notification_no_port(self, port_instance, mock_swsscommon_table, port_instance_helper): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_show_fec_rsp_tbl = mock_swsscommon_table + xcvrd_show_fec_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_fec_res_tbl = mock_swsscommon_table + port_instance = MagicMock() + + asic_index = 0 + port = "Ethernet0" + fvp = {"get_fec": True} + + rc = handle_get_fec_cmd_arg_tbl_notification( + fvp, xcvrd_show_fec_rsp_tbl, xcvrd_show_fec_cmd_sts_tbl, xcvrd_show_fec_res_tbl, asic_index, port) + assert(rc == -1) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_get_fec_cmd_arg_tbl_notification_no_instance(self, port_instance, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_show_fec_rsp_tbl = mock_swsscommon_table + xcvrd_show_fec_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_fec_res_tbl = mock_swsscommon_table + port_instance = MagicMock() + port_instance_helper = port_instance + + asic_index = 0 + port = "Ethernet0" + fvp = {"get_fec": True} + + rc = handle_get_fec_cmd_arg_tbl_notification( + fvp, xcvrd_show_fec_rsp_tbl, xcvrd_show_fec_cmd_sts_tbl, xcvrd_show_fec_res_tbl, asic_index, port) + assert(rc == -1) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_get_fec_cmd_arg_tbl_notification_get_result(self, port_instance, mock_swsscommon_table, port_instance_helper): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_show_fec_rsp_tbl = mock_swsscommon_table + xcvrd_show_fec_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_fec_res_tbl = mock_swsscommon_table + port_instance = MagicMock() + port_instance.get_fec_mode.return_value = 0 + port_instance.get_anlt.return_value = 0 + port_instance.get_speed.return_value = 0 + + asic_index = 0 + port = "Ethernet0" + fvp = {"get_fec": True} + + rc = handle_get_fec_cmd_arg_tbl_notification( + fvp, xcvrd_show_fec_rsp_tbl, xcvrd_show_fec_cmd_sts_tbl, xcvrd_show_fec_res_tbl, asic_index, port) + assert(rc == None) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_get_fec_cmd_arg_tbl_notification_no_status(self, port_instance, mock_swsscommon_table, port_instance_helper): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_show_ber_cmd_arg_tbl = mock_swsscommon_table + xcvrd_show_ber_rsp_tbl = mock_swsscommon_table + xcvrd_show_ber_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_ber_res_tbl = mock_swsscommon_table + port_instance = MagicMock() + + asic_index = 0 + port = "Ethernet0" + fvp = {"show_event": True} + + rc = handle_show_ber_cmd_arg_tbl_notification( + fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port) + assert(rc == None) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_get_fec_cmd_arg_tbl_notification_no_port(self, port_instance, mock_swsscommon_table, port_instance_helper): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_show_ber_cmd_arg_tbl = mock_swsscommon_table + xcvrd_show_ber_rsp_tbl = mock_swsscommon_table + xcvrd_show_ber_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_ber_res_tbl = mock_swsscommon_table + port_instance = MagicMock() + + asic_index = 0 + port = "Ethernet0" + fvp = {"get_ber": True} + + rc = handle_show_ber_cmd_arg_tbl_notification( + fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port) + assert(rc == -1) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_get_fec_cmd_arg_tbl_notification_no_instance(self, port_instance, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_show_ber_cmd_arg_tbl = mock_swsscommon_table + xcvrd_show_ber_rsp_tbl = mock_swsscommon_table + xcvrd_show_ber_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_ber_res_tbl = mock_swsscommon_table + port_instance = MagicMock() + + asic_index = 0 + port = "Ethernet0" + fvp = {"get_ber": True} + + rc = handle_show_ber_cmd_arg_tbl_notification( + fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port) + assert(rc == -1) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "ber", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_get_fec_cmd_arg_tbl_notification_get_ber(self, port_instance, mock_swsscommon_table, port_instance_helper): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_show_ber_cmd_arg_tbl = mock_swsscommon_table + xcvrd_show_ber_rsp_tbl = mock_swsscommon_table + xcvrd_show_ber_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_ber_res_tbl = mock_swsscommon_table + port_instance = MagicMock() + port_instance.get_ber_info.return_value = ["100", "200"] + + asic_index = 0 + port = "Ethernet0" + fvp = {"get_ber": True} + + rc = handle_show_ber_cmd_arg_tbl_notification( + fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port) + assert(rc == None) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "eye", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_get_fec_cmd_arg_tbl_notification_get_eye(self, port_instance, mock_swsscommon_table, port_instance_helper): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_show_ber_cmd_arg_tbl = mock_swsscommon_table + xcvrd_show_ber_rsp_tbl = mock_swsscommon_table + xcvrd_show_ber_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_ber_res_tbl = mock_swsscommon_table + port_instance = MagicMock() + port_instance.get_eye_info.return_value = ["100", "200"] + + asic_index = 0 + port = "Ethernet0" + fvp = {"get_ber": True} + + rc = handle_show_ber_cmd_arg_tbl_notification( + fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port) + assert(rc == None) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec_stats", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_get_fec_cmd_arg_tbl_notification_get_fec_stats(self, port_instance, mock_swsscommon_table, port_instance_helper): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_show_ber_cmd_arg_tbl = mock_swsscommon_table + xcvrd_show_ber_rsp_tbl = mock_swsscommon_table + xcvrd_show_ber_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_ber_res_tbl = mock_swsscommon_table + port_instance = MagicMock() + port_instance.get_fec_stats.return_value = {"100": "200"} + + asic_index = 0 + port = "Ethernet0" + fvp = {"get_ber": True} + + rc = handle_show_ber_cmd_arg_tbl_notification( + fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port) + assert(rc == None) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "pcs_stats", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_get_fec_cmd_arg_tbl_notification_get_pcs_stats(self, port_instance, mock_swsscommon_table, port_instance_helper): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_show_ber_cmd_arg_tbl = mock_swsscommon_table + xcvrd_show_ber_rsp_tbl = mock_swsscommon_table + xcvrd_show_ber_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_ber_res_tbl = mock_swsscommon_table + port_instance = MagicMock() + port_instance.get_pcs_stats.return_value = {"100": "200"} + + asic_index = 0 + port = "Ethernet0" + fvp = {"get_ber": True} + + rc = handle_show_ber_cmd_arg_tbl_notification( + fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port) + assert(rc == None) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "cable_alive", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_get_fec_cmd_arg_tbl_notification_get_alive_status(self, port_instance, mock_swsscommon_table, port_instance_helper): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_show_ber_cmd_arg_tbl = mock_swsscommon_table + xcvrd_show_ber_rsp_tbl = mock_swsscommon_table + xcvrd_show_ber_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_ber_res_tbl = mock_swsscommon_table + port_instance = MagicMock() + port_instance.get_alive_status.return_value = True + + asic_index = 0 + port = "Ethernet0" + fvp = {"get_ber": True} + + rc = handle_show_ber_cmd_arg_tbl_notification( + fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port) + assert(rc == None) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "debug_dump", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_get_fec_cmd_arg_tbl_notification_get_debug_dump_registers(self, port_instance, mock_swsscommon_table, port_instance_helper): - assert(rc[0] == 0) + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table - def test_set_show_firmware_fields(self): + xcvrd_show_ber_cmd_arg_tbl = mock_swsscommon_table + xcvrd_show_ber_rsp_tbl = mock_swsscommon_table + xcvrd_show_ber_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_ber_res_tbl = mock_swsscommon_table + port_instance = MagicMock() + port_instance.debug_dump_registers.return_value = {"register1": "100"} - mux_info_dict = {} - xcvrd_show_fw_res_tbl = Table("STATE_DB", "XCVRD_SHOW_FW_RES") - mux_info_dict['version_self_active'] = '0.8' - mux_info_dict['version_self_inactive'] = '0.7' - mux_info_dict['version_self_next'] = '0.7' - mux_info_dict['version_peer_active'] = '0.8' - mux_info_dict['version_peer_inactive'] = '0.7' - mux_info_dict['version_peer_next'] = '0.7' - mux_info_dict['version_nic_active'] = '0.8' - mux_info_dict['version_nic_inactive'] = '0.7' - mux_info_dict['version_nic_next'] = '0.7' - rc = set_show_firmware_fields( - "Ethernet0", mux_info_dict, xcvrd_show_fw_res_tbl) + asic_index = 0 + port = "Ethernet0" + fvp = {"get_ber": True} - assert(rc == 0) + rc = handle_show_ber_cmd_arg_tbl_notification( + fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port) + assert(rc == None) + """ - @patch('sonic_py_common.device_info.get_paths_to_platform_and_hwsku_dirs', MagicMock(return_value=('/tmp', None))) - @patch('swsscommon.swsscommon.WarmStart', MagicMock()) - @patch('ycable.ycable.platform_sfputil', MagicMock()) - @patch('ycable.ycable.DaemonYcable.load_platform_util', MagicMock()) - def test_DaemonYcable_init_deinit(self): - ycable = DaemonYcable(SYSLOG_IDENTIFIER) - ycable.init() - ycable.deinit() + def handle_config_firmware_roll_cmd_arg_tbl_notification(fvp, xcvrd_roll_fw_cmd_sts_tbl, xcvrd_roll_fw_rsp_tbl, asic_index, port): - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "enable", {"mode_value": "0", - "lane_mask": "0", - "direction": "0"}))) - def test_handle_config_prbs_cmd_arg_tbl_notification_no_port(self, port_instance, mock_swsscommon_table): + fvp_dict = dict(fvp) - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - xcvrd_config_prbs_cmd_arg_tbl = mock_swsscommon_table - xcvrd_config_prbs_cmd_sts_tbl = mock_swsscommon_table - xcvrd_config_prbs_rsp_tbl = mock_swsscommon_table - asic_index = 0 - port = "Ethernet0" - fvp = {"config_prbs": True} + if "rollback_firmware" in fvp_dict: + file_name = fvp_dict["rollback_firmware"] + status = 'False' - rc = handle_config_prbs_cmd_arg_tbl_notification( - fvp, xcvrd_config_prbs_cmd_arg_tbl, xcvrd_config_prbs_cmd_sts_tbl, xcvrd_config_prbs_rsp_tbl, asic_index, port) - assert(rc == -1) + if file_name == 'null': + file_full_path = None + else: + file_full_path = '/usr/share/sonic/firmware/{}'.format(file_name) + if not os.path.isfile(file_full_path): + helper_logger.log_error("Error: cli cmd mux rollback firmware file does not exist port {} file {}".format(port, file_name)) + set_result_and_delete_port('status', status, xcvrd_roll_fw_cmd_sts_tbl[asic_index], xcvrd_roll_fw_rsp_tbl[asic_index], port) + break - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "enable", {"mode_value": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - def test_handle_config_prbs_cmd_arg_tbl_notification_no_instance(self, mock_swsscommon_table): - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - xcvrd_config_prbs_cmd_arg_tbl = mock_swsscommon_table - xcvrd_config_prbs_cmd_sts_tbl = mock_swsscommon_table - xcvrd_config_prbs_rsp_tbl = mock_swsscommon_table - asic_index = 0 - port = "Ethernet0" - fvp = {"config_prbs": True} + physical_port = get_ycable_physical_port_from_logical_port(port) + if physical_port is None or physical_port == PHYSICAL_PORT_MAPPING_ERROR: + # error scenario update table accordingly + helper_logger.log_warning("Error: Could not get physical port for cli cmd mux rollback firmware port {}".format(port)) + set_result_and_delete_port('status', status, xcvrd_roll_fw_cmd_sts_tbl[asic_index], xcvrd_roll_fw_rsp_tbl[asic_index], port) + break - rc = handle_config_prbs_cmd_arg_tbl_notification( - fvp, xcvrd_config_prbs_cmd_arg_tbl, xcvrd_config_prbs_cmd_sts_tbl, xcvrd_config_prbs_rsp_tbl, asic_index, port) - assert(rc == -1) + port_instance = get_ycable_port_instance_from_logical_port(port) + if port_instance is None or port_instance in port_mapping_error_values: + # error scenario update table accordingly + helper_logger.log_warning("Error: Could not get port instance for cli cmd mux rollback firmware port {}".format(port)) + set_result_and_delete_port('status', status, xcvrd_roll_fw_cmd_sts_tbl[asic_index], xcvrd_roll_fw_rsp_tbl[asic_index], port) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "enable", {"mode_value": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_config_prbs_cmd_arg_tbl_notification_with_instance_enable(self, port_instance, mock_swsscommon_table, port_instance_helper): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_config_prbs_cmd_arg_tbl = mock_swsscommon_table - xcvrd_config_prbs_cmd_sts_tbl = mock_swsscommon_table - xcvrd_config_prbs_rsp_tbl = mock_swsscommon_table - port_instance = MagicMock() - port_instance.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - port_instance.PRBS_DIRECTION_BOTH = 2 - port_instance.enable_prbs_mode.return_value = True - port_instance.disable_prbs_mode.return_value = True - port_instance_helper = port_instance - - asic_index = 0 - port = "Ethernet0" - fvp = {"config_prbs": True} - - rc = handle_config_prbs_cmd_arg_tbl_notification( - fvp, xcvrd_config_prbs_cmd_arg_tbl, xcvrd_config_prbs_cmd_sts_tbl, xcvrd_config_prbs_rsp_tbl, asic_index, port) - assert(rc == None) + with y_cable_port_locks[physical_port]: + try: + status = port_instance.rollback_firmware(file_full_path) + except Exception as e: + status = -1 + helper_logger.log_warning("Failed to execute the rollback_firmware API for port {} due to {}".format(physical_port,repr(e))) + set_result_and_delete_port('status', status, xcvrd_roll_fw_cmd_sts_tbl[asic_index], xcvrd_roll_fw_rsp_tbl[asic_index], port) + else: + helper_logger.log_error("Wrong param for cli cmd mux rollback firmware port {}".format(port)) + set_result_and_delete_port('status', 'False', xcvrd_roll_fw_cmd_sts_tbl[asic_index], xcvrd_roll_fw_rsp_tbl[asic_index], port) + """ + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_config_firmware_roll_cmd_arg_tbl_notification_no_port(self, port_instance, mock_swsscommon_table, port_instance_helper): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_down_fw_cmd_sts_tbl = mock_swsscommon_table + xcvrd_down_fw_rsp_tbl = mock_swsscommon_table + port_instance = MagicMock() + + asic_index = 0 + port = "Ethernet0" + fvp = {"rollback_firmware": "null"} + + rc = handle_config_firmware_roll_cmd_arg_tbl_notification( + fvp, xcvrd_down_fw_cmd_sts_tbl, xcvrd_down_fw_rsp_tbl, asic_index, port) + assert(rc == -1) + + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_config_firmware_roll_cmd_arg_tbl_notification_no_instance(self, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_down_fw_cmd_sts_tbl = mock_swsscommon_table + xcvrd_down_fw_rsp_tbl = mock_swsscommon_table + + asic_index = 0 + port = "Ethernet0" + fvp = {"rollback_firmware": "null"} + + rc = handle_config_firmware_roll_cmd_arg_tbl_notification( + fvp, xcvrd_down_fw_cmd_sts_tbl, xcvrd_down_fw_rsp_tbl, asic_index, port) + assert(rc == -1) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_config_firmware_roll_cmd_arg_tbl_notification_with_instance(self, port_instance, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_down_fw_cmd_sts_tbl = mock_swsscommon_table + xcvrd_down_fw_rsp_tbl = mock_swsscommon_table + port_instance = MagicMock() + + asic_index = 0 + port = "Ethernet0" + fvp = {"rollback_firmware": "null"} + + rc = handle_config_firmware_roll_cmd_arg_tbl_notification( + fvp, xcvrd_down_fw_cmd_sts_tbl, xcvrd_down_fw_rsp_tbl, asic_index, port) + assert(rc == None) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_config_firmware_roll_cmd_arg_tbl_notification_no_port_and_instance(self, port_instance, mock_swsscommon_table, port_instance_helper): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_down_fw_cmd_sts_tbl = mock_swsscommon_table + xcvrd_down_fw_rsp_tbl = mock_swsscommon_table + port_instance = MagicMock() + + asic_index = 0 + port = "Ethernet0" + fvp = {"rollback_firmware": "null"} + + rc = handle_config_firmware_roll_cmd_arg_tbl_notification( + fvp, xcvrd_down_fw_cmd_sts_tbl, xcvrd_down_fw_rsp_tbl, asic_index, port) + assert(rc == -1) + + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('os.path.isfile', MagicMock(return_value=True)) + def test_handle_config_firmware_down_cmd_arg_tbl_notification_no_port(self, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_down_fw_cmd_sts_tbl = mock_swsscommon_table + xcvrd_down_fw_rsp_tbl = mock_swsscommon_table + + asic_index = 0 + task_download_firmware_thread = {} + port = "Ethernet0" + fvp = {"download_firmware": "null"} + + rc = handle_config_firmware_down_cmd_arg_tbl_notification( + fvp, xcvrd_down_fw_cmd_sts_tbl, xcvrd_down_fw_rsp_tbl, asic_index, port, task_download_firmware_thread) + assert(rc == -1) + + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('os.path.isfile', MagicMock(return_value=True)) + def test_handle_config_firmware_down_cmd_arg_tbl_notification_else_condition(self, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_down_fw_cmd_sts_tbl = mock_swsscommon_table + xcvrd_down_fw_rsp_tbl = mock_swsscommon_table + + asic_index = 0 + task_download_firmware_thread = {} + port = "Ethernet0" + fvp = {"downoad_firmware": "null"} + + rc = handle_config_firmware_down_cmd_arg_tbl_notification( + fvp, xcvrd_down_fw_cmd_sts_tbl, xcvrd_down_fw_rsp_tbl, asic_index, port, task_download_firmware_thread) + assert(rc == None) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('threading.Thread') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('os.path.isfile', MagicMock(return_value=True)) + def test_handle_config_firmware_down_cmd_arg_tbl_notification_with_instance(self, port_instance, mock_swsscommon_table, port_instance_helper, thread_obj): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_down_fw_cmd_sts_tbl = mock_swsscommon_table + xcvrd_down_fw_rsp_tbl = mock_swsscommon_table + port_instance = MagicMock() + thread_instance = MagicMock() + thread_instance.start = MagicMock() + thread_obj = thread_instance + port_instance_helper = port_instance + + asic_index = 0 + task_download_firmware_thread = {} + port = "Ethernet0" + fvp = {"download_firmware": "null"} + + rc = handle_config_firmware_down_cmd_arg_tbl_notification( + fvp, xcvrd_down_fw_cmd_sts_tbl, xcvrd_down_fw_rsp_tbl, asic_index, port, task_download_firmware_thread) + assert(rc == None) + + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('os.path.isfile', MagicMock(return_value=True)) + def test_handle_config_firmware_down_cmd_arg_tbl_notification_no_instance(self, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_down_fw_cmd_sts_tbl = mock_swsscommon_table + xcvrd_down_fw_rsp_tbl = mock_swsscommon_table + + asic_index = 0 + task_download_firmware_thread = {} + port = "Ethernet0" + fvp = {"download_firmware": "null"} + + rc = handle_config_firmware_down_cmd_arg_tbl_notification( + fvp, xcvrd_down_fw_cmd_sts_tbl, xcvrd_down_fw_rsp_tbl, asic_index, port, task_download_firmware_thread) + assert(rc == -1) + + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('os.path.isfile', MagicMock(return_value=True)) + def test_handle_config_firmware_acti_cmd_arg_tbl_notification_no_port(self, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_down_fw_cmd_sts_tbl = mock_swsscommon_table + xcvrd_down_fw_rsp_tbl = mock_swsscommon_table + xcvrd_acti_fw_cmd_arg_tbl = mock_swsscommon_table + + asic_index = 0 + task_download_firmware_thread = {} + port = "Ethernet0" + fvp = {"activate_firmware": "null"} + + rc = handle_config_firmware_acti_cmd_arg_tbl_notification( + fvp, xcvrd_down_fw_cmd_sts_tbl, xcvrd_down_fw_rsp_tbl, xcvrd_acti_fw_cmd_arg_tbl, asic_index, port) + assert(rc == -1) + + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('os.path.isfile', MagicMock(return_value=True)) + def test_handle_config_firmware_acti_cmd_arg_tbl_notification_else_condition(self, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_down_fw_cmd_sts_tbl = mock_swsscommon_table + xcvrd_down_fw_rsp_tbl = mock_swsscommon_table + xcvrd_acti_fw_cmd_arg_tbl = mock_swsscommon_table + + asic_index = 0 + task_download_firmware_thread = {} + port = "Ethernet0" + fvp = {"down_firmware": "null"} + + rc = handle_config_firmware_acti_cmd_arg_tbl_notification( + fvp, xcvrd_down_fw_cmd_sts_tbl, xcvrd_down_fw_rsp_tbl, xcvrd_acti_fw_cmd_arg_tbl, asic_index, port) + assert(rc == None) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "activate_firmware", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('os.path.isfile', MagicMock(return_value=True)) + @patch('time.sleep', MagicMock(return_value=True)) + def test_handle_config_firmware_acti_cmd_arg_tbl_notification_with_instance(self, port_instance, mock_swsscommon_table, port_instance_helper): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_down_fw_cmd_sts_tbl = mock_swsscommon_table + xcvrd_down_fw_rsp_tbl = mock_swsscommon_table + xcvrd_acti_fw_cmd_arg_tbl = mock_swsscommon_table + port_instance = MagicMock() + port_instance.activate_firmware = MagicMock(return_value=True) + thread_instance = MagicMock() + thread_instance.start = MagicMock() + thread_obj = thread_instance + port_instance_helper = port_instance + + asic_index = 0 + task_download_firmware_thread = {} + port = "Ethernet0" + fvp = {"activate_firmware": "null"} + + rc = handle_config_firmware_acti_cmd_arg_tbl_notification( + fvp, xcvrd_down_fw_cmd_sts_tbl, xcvrd_down_fw_rsp_tbl, xcvrd_acti_fw_cmd_arg_tbl, asic_index, port) + assert(rc == None) + + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('os.path.isfile', MagicMock(return_value=True)) + def test_handle_config_firmware_acti_cmd_arg_tbl_notification_no_instance(self, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_down_fw_cmd_sts_tbl = mock_swsscommon_table + xcvrd_down_fw_rsp_tbl = mock_swsscommon_table + xcvrd_acti_fw_cmd_arg_tbl = mock_swsscommon_table + + asic_index = 0 + task_download_firmware_thread = {} + port = "Ethernet0" + fvp = {"activate_firmware": "null"} + + rc = handle_config_firmware_acti_cmd_arg_tbl_notification( + fvp, xcvrd_down_fw_cmd_sts_tbl, xcvrd_down_fw_rsp_tbl, xcvrd_acti_fw_cmd_arg_tbl, asic_index, port) + assert(rc == -1) + + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('os.path.isfile', MagicMock(return_value=True)) + def test_handle_show_firmware_show_cmd_arg_tbl_notification_no_port(self, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_down_fw_cmd_sts_tbl = mock_swsscommon_table + xcvrd_down_fw_rsp_tbl = mock_swsscommon_table + xcvrd_acti_fw_cmd_arg_tbl = mock_swsscommon_table + xcvrd_show_fw_res_tbl = mock_swsscommon_table + + asic_index = 0 + task_download_firmware_thread = {} + port = "Ethernet0" + fvp = {"firmware_version": "null"} + + rc = handle_show_firmware_show_cmd_arg_tbl_notification( + fvp, xcvrd_down_fw_cmd_sts_tbl, xcvrd_down_fw_rsp_tbl, xcvrd_show_fw_res_tbl, asic_index, port) + assert(rc == -1) + + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('os.path.isfile', MagicMock(return_value=True)) + def test_handle_show_firmware_show_cmd_arg_tbl_notification_else_condition(self, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_down_fw_cmd_sts_tbl = mock_swsscommon_table + xcvrd_down_fw_rsp_tbl = mock_swsscommon_table + xcvrd_acti_fw_cmd_arg_tbl = mock_swsscommon_table + xcvrd_show_fw_res_tbl = mock_swsscommon_table + + asic_index = 0 + task_download_firmware_thread = {} + port = "Ethernet0" + fvp = {"down_firmware": "null"} + + rc = handle_show_firmware_show_cmd_arg_tbl_notification( + fvp, xcvrd_down_fw_cmd_sts_tbl, xcvrd_down_fw_rsp_tbl, xcvrd_show_fw_res_tbl, asic_index, port) + assert(rc == None) + + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "activate_firmware", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('os.path.isfile', MagicMock(return_value=True)) + @patch('time.sleep', MagicMock(return_value=True)) + def test_handle_show_firmware_show_cmd_arg_tbl_notification_with_instance(self, mock_swsscommon_table, platform_sfputil): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_down_fw_cmd_sts_tbl = mock_swsscommon_table + xcvrd_down_fw_rsp_tbl = mock_swsscommon_table + xcvrd_acti_fw_cmd_arg_tbl = mock_swsscommon_table + xcvrd_show_fw_res_tbl = mock_swsscommon_table + asic_index = 0 + task_download_firmware_thread = {} + port = "Ethernet0" + platform_sfputil.get_asic_id_for_logical_port = 0 + fvp = {"firmware_version": "null"} + + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 + self.TARGET_NIC = 1 + self.TARGET_TOR_A = 1 + self.TARGET_TOR_B = 1 + self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + self.FIRMWARE_DOWNLOAD_STATUS_FAILED = 2 + self.download_firmware_status = 0 + self.MUX_TOGGLE_STATUS_INPROGRESS = 1 + self.MUX_TOGGLE_STATUS_FAILED = 2 + self.MUX_TOGGLE_STATUS_NOT_INITIATED_OR_FINISHED = 2 + self.mux_toggle_status = 0 + self.SWITCH_COUNT_MANUAL = "manual" + self.SWITCH_COUNT_AUTO = "auto" + + def get_read_side(self): + return 1 + + # Defining function without self argument creates an exception, + # which is what we want for this test. + def get_mux_direction(): + pass - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "disable", {"mode_value": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_config_prbs_cmd_arg_tbl_notification_with_instance_disable(self, port_instance, mock_swsscommon_table, port_instance_helper): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_config_prbs_cmd_arg_tbl = mock_swsscommon_table - xcvrd_config_prbs_cmd_sts_tbl = mock_swsscommon_table - xcvrd_config_prbs_rsp_tbl = mock_swsscommon_table - port_instance = MagicMock() - port_instance.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - port_instance.PRBS_DIRECTION_BOTH = 2 - port_instance.enable_prbs_mode.return_value = True - port_instance.disable_prbs_mode.return_value = True - port_instance_helper = port_instance - - asic_index = 0 - port = "Ethernet0" - fvp = {"config_prbs": True} - - rc = handle_config_prbs_cmd_arg_tbl_notification( - fvp, xcvrd_config_prbs_cmd_arg_tbl, xcvrd_config_prbs_cmd_sts_tbl, xcvrd_config_prbs_rsp_tbl, asic_index, port) + patched_util.get.return_value = PortInstanceHelper() + rc = handle_show_firmware_show_cmd_arg_tbl_notification( + fvp, xcvrd_down_fw_cmd_sts_tbl, xcvrd_down_fw_rsp_tbl, xcvrd_show_fw_res_tbl, asic_index, port) assert(rc == None) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "reset", {"mode_value": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_config_prbs_cmd_arg_tbl_notification_with_instance_reset(self, port_instance, mock_swsscommon_table, port_instance_helper): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_config_prbs_cmd_arg_tbl = mock_swsscommon_table - xcvrd_config_prbs_cmd_sts_tbl = mock_swsscommon_table - xcvrd_config_prbs_rsp_tbl = mock_swsscommon_table - port_instance = MagicMock() - port_instance.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - port_instance.PRBS_DIRECTION_BOTH = 2 - port_instance.enable_prbs_mode.return_value = True - port_instance.disable_prbs_mode.return_value = True - port_instance.reset.return_value = True - port_instance_helper = port_instance - - asic_index = 0 - port = "Ethernet0" - fvp = {"config_prbs": True} - - rc = handle_config_prbs_cmd_arg_tbl_notification( - fvp, xcvrd_config_prbs_cmd_arg_tbl, xcvrd_config_prbs_cmd_sts_tbl, xcvrd_config_prbs_rsp_tbl, asic_index, port) - assert(rc == None) + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('os.path.isfile', MagicMock(return_value=True)) + def test_handle_show_firmware_show_cmd_arg_tbl_notification_no_instance(self, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_down_fw_cmd_sts_tbl = mock_swsscommon_table + xcvrd_down_fw_rsp_tbl = mock_swsscommon_table + xcvrd_acti_fw_cmd_arg_tbl = mock_swsscommon_table + xcvrd_show_fw_res_tbl = mock_swsscommon_table + + asic_index = 0 + task_download_firmware_thread = {} + port = "Ethernet0" + fvp = {"firmware_version": "null"} + + rc = handle_show_firmware_show_cmd_arg_tbl_notification( + fvp, xcvrd_down_fw_cmd_sts_tbl, xcvrd_down_fw_rsp_tbl, xcvrd_show_fw_res_tbl, asic_index, port) + assert(rc == -1) + + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('os.path.isfile', MagicMock(return_value=True)) + def test_handle_config_mux_switchmode_cmd_arg_tbl_notification_no_port(self, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_config_hwmode_swmode_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_hwmode_swmode_rsp_tbl = mock_swsscommon_table + xcvrd_acti_fw_cmd_arg_tbl = mock_swsscommon_table + xcvrd_show_fw_res_tbl = mock_swsscommon_table + + asic_index = 0 + task_download_firmware_thread = {} + port = "Ethernet0" + fvp = {"config": "null"} + + rc = handle_config_mux_switchmode_arg_tbl_notification( + fvp, xcvrd_config_hwmode_swmode_cmd_sts_tbl, xcvrd_config_hwmode_swmode_rsp_tbl, asic_index, port) + assert(rc == -1) + + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('os.path.isfile', MagicMock(return_value=True)) + def test_handle_config_mux_switchmode_cmd_arg_tbl_notification_else_condition(self, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_config_hwmode_swmode_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_hwmode_swmode_rsp_tbl = mock_swsscommon_table + + asic_index = 0 + task_download_firmware_thread = {} + port = "Ethernet0" + fvp = {"down_firmware": "null"} + + rc = handle_config_mux_switchmode_arg_tbl_notification( + fvp, xcvrd_config_hwmode_swmode_cmd_sts_tbl, xcvrd_config_hwmode_swmode_rsp_tbl, asic_index, port) + assert(rc == None) + + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "activate_firmware", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('os.path.isfile', MagicMock(return_value=True)) + @patch('time.sleep', MagicMock(return_value=True)) + def test_handle_config_mux_switchmode_cmd_arg_tbl_notification_with_instance_manual(self, mock_swsscommon_table, platform_sfputil): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_config_hwmode_swmode_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_hwmode_swmode_rsp_tbl = mock_swsscommon_table + asic_index = 0 + task_download_firmware_thread = {} + port = "Ethernet0" + platform_sfputil.get_asic_id_for_logical_port = 0 + fvp = {"config": "manual"} + + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 + self.TARGET_NIC = 1 + self.TARGET_TOR_A = 1 + self.TARGET_TOR_B = 1 + self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + self.FIRMWARE_DOWNLOAD_STATUS_FAILED = 2 + self.download_firmware_status = 0 + self.SWITCH_COUNT_MANUAL = "manual" + self.SWITCH_COUNT_AUTO = "auto" + self.SWITCHING_MODE_MANUAL = "manual" + + def get_read_side(self): + return 1 + + def set_switching_mode(self, mode): + return True + + # Defining function without self argument creates an exception, + # which is what we want for this test. + def get_mux_direction(): + pass - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "anlt", {"mode": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_config_prbs_cmd_arg_tbl_notification_with_instance_anlt_enable(self, port_instance, mock_swsscommon_table, port_instance_helper): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_config_prbs_cmd_arg_tbl = mock_swsscommon_table - xcvrd_config_prbs_cmd_sts_tbl = mock_swsscommon_table - xcvrd_config_prbs_rsp_tbl = mock_swsscommon_table - port_instance = MagicMock() - port_instance.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - port_instance.PRBS_DIRECTION_BOTH = 2 - port_instance.enable_prbs_mode.return_value = True - port_instance.disable_prbs_mode.return_value = True - port_instance.reset.return_value = True - port_instance.set_anlt.return_value = True - port_instance_helper = port_instance - - asic_index = 0 - port = "Ethernet0" - fvp = {"config_prbs": True} - - rc = handle_config_prbs_cmd_arg_tbl_notification( - fvp, xcvrd_config_prbs_cmd_arg_tbl, xcvrd_config_prbs_cmd_sts_tbl, xcvrd_config_prbs_rsp_tbl, asic_index, port) + patched_util.get.return_value = PortInstanceHelper() + rc = handle_config_mux_switchmode_arg_tbl_notification( + fvp, xcvrd_config_hwmode_swmode_cmd_sts_tbl, xcvrd_config_hwmode_swmode_rsp_tbl, asic_index, port) assert(rc == None) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "anlt", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_config_prbs_cmd_arg_tbl_notification_with_instance_anlt_disable(self, port_instance, mock_swsscommon_table, port_instance_helper): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_config_prbs_cmd_arg_tbl = mock_swsscommon_table - xcvrd_config_prbs_cmd_sts_tbl = mock_swsscommon_table - xcvrd_config_prbs_rsp_tbl = mock_swsscommon_table - port_instance = MagicMock() - port_instance.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - port_instance.PRBS_DIRECTION_BOTH = 2 - port_instance.enable_prbs_mode.return_value = True - port_instance.disable_prbs_mode.return_value = True - port_instance.reset.return_value = True - port_instance.set_anlt.return_value = True - port_instance_helper = port_instance - - asic_index = 0 - port = "Ethernet0" - fvp = {"config_prbs": True} - - rc = handle_config_prbs_cmd_arg_tbl_notification( - fvp, xcvrd_config_prbs_cmd_arg_tbl, xcvrd_config_prbs_cmd_sts_tbl, xcvrd_config_prbs_rsp_tbl, asic_index, port) - assert(rc == -1) - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"mode": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_config_prbs_cmd_arg_tbl_notification_with_instance_fec_enable(self, port_instance, mock_swsscommon_table, port_instance_helper): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_config_prbs_cmd_arg_tbl = mock_swsscommon_table - xcvrd_config_prbs_cmd_sts_tbl = mock_swsscommon_table - xcvrd_config_prbs_rsp_tbl = mock_swsscommon_table - port_instance = MagicMock() - port_instance.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - port_instance.PRBS_DIRECTION_BOTH = 2 - port_instance.enable_prbs_mode.return_value = True - port_instance.disable_prbs_mode.return_value = True - port_instance.reset.return_value = True - port_instance.set_fec_mode.return_value = True - port_instance_helper = port_instance - - asic_index = 0 - port = "Ethernet0" - fvp = {"config_prbs": True} - - rc = handle_config_prbs_cmd_arg_tbl_notification( - fvp, xcvrd_config_prbs_cmd_arg_tbl, xcvrd_config_prbs_cmd_sts_tbl, xcvrd_config_prbs_rsp_tbl, asic_index, port) - assert(rc == None) + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('os.path.isfile', MagicMock(return_value=True)) + def test_handle_config_mux_switchmode_cmd_arg_tbl_notification_no_instance(self, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_config_hwmode_swmode_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_hwmode_swmode_rsp_tbl = mock_swsscommon_table + xcvrd_show_hwmode_swmode_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_hwmode_swmode_rsp_tbl = mock_swsscommon_table + + asic_index = 0 + task_download_firmware_thread = {} + port = "Ethernet0" + fvp = {"config": "manual"} + + rc = handle_config_mux_switchmode_arg_tbl_notification( + fvp, xcvrd_config_hwmode_swmode_cmd_sts_tbl, xcvrd_config_hwmode_swmode_rsp_tbl, asic_index, port) + assert(rc == -1) + + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "activate_firmware", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('os.path.isfile', MagicMock(return_value=True)) + @patch('time.sleep', MagicMock(return_value=True)) + def test_handle_config_mux_switchmode_cmd_arg_tbl_notification_with_instance_auto(self, mock_swsscommon_table, platform_sfputil): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_config_hwmode_swmode_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_hwmode_swmode_rsp_tbl = mock_swsscommon_table + xcvrd_show_hwmode_swmode_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_hwmode_swmode_rsp_tbl = mock_swsscommon_table + asic_index = 0 + task_download_firmware_thread = {} + port = "Ethernet0" + platform_sfputil.get_asic_id_for_logical_port = 0 + fvp = {"config": "auto"} + + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 + self.TARGET_NIC = 1 + self.TARGET_TOR_A = 1 + self.TARGET_TOR_B = 1 + self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + self.FIRMWARE_DOWNLOAD_STATUS_FAILED = 2 + self.download_firmware_status = 0 + self.SWITCH_COUNT_MANUAL = "manual" + self.SWITCH_COUNT_AUTO = "auto" + self.SWITCHING_MODE_MANUAL = "manual" + self.SWITCHING_MODE_AUTO = "auto" + + def get_read_side(self): + return 1 + + def set_switching_mode(self, mode): + return True + + # Defining function without self argument creates an exception, + # which is what we want for this test. + def get_mux_direction(): + pass - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_config_prbs_cmd_arg_tbl_notification_with_instance_fec_disable(self, port_instance, mock_swsscommon_table, port_instance_helper): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_config_prbs_cmd_arg_tbl = mock_swsscommon_table - xcvrd_config_prbs_cmd_sts_tbl = mock_swsscommon_table - xcvrd_config_prbs_rsp_tbl = mock_swsscommon_table - port_instance = MagicMock() - port_instance.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - port_instance.PRBS_DIRECTION_BOTH = 2 - port_instance.enable_prbs_mode.return_value = True - port_instance.disable_prbs_mode.return_value = True - port_instance.reset.return_value = True - port_instance.set_fec_mode.return_value = True - port_instance_helper = port_instance - - asic_index = 0 - port = "Ethernet0" - fvp = {"config_prbs": True} - - rc = handle_config_prbs_cmd_arg_tbl_notification( - fvp, xcvrd_config_prbs_cmd_arg_tbl, xcvrd_config_prbs_cmd_sts_tbl, xcvrd_config_prbs_rsp_tbl, asic_index, port) - assert(rc == -1) - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_config_prbs_cmd_arg_tbl_notification_else_value(self, port_instance, mock_swsscommon_table, port_instance_helper): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_config_prbs_cmd_arg_tbl = mock_swsscommon_table - xcvrd_config_prbs_cmd_sts_tbl = mock_swsscommon_table - xcvrd_config_prbs_rsp_tbl = mock_swsscommon_table - port_instance = MagicMock() - port_instance.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - port_instance.PRBS_DIRECTION_BOTH = 2 - port_instance.enable_prbs_mode.return_value = True - port_instance.disable_prbs_mode.return_value = True - port_instance.reset.return_value = True - port_instance.set_fec_mode.return_value = True - port_instance_helper = port_instance - - asic_index = 0 - port = "Ethernet0" - fvp = {"config_abc": True} - - rc = handle_config_prbs_cmd_arg_tbl_notification( - fvp, xcvrd_config_prbs_cmd_arg_tbl, xcvrd_config_prbs_cmd_sts_tbl, xcvrd_config_prbs_rsp_tbl, asic_index, port) + patched_util.get.return_value = PortInstanceHelper() + rc = handle_config_mux_switchmode_arg_tbl_notification( + fvp, xcvrd_config_hwmode_swmode_cmd_sts_tbl, xcvrd_config_hwmode_swmode_rsp_tbl, asic_index, port) assert(rc == None) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_config_loop_cmd_arg_tbl_notification_else_value(self, port_instance, mock_swsscommon_table, port_instance_helper): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_config_loop_cmd_arg_tbl = mock_swsscommon_table - xcvrd_config_loop_cmd_sts_tbl = mock_swsscommon_table - xcvrd_config_loop_rsp_tbl = mock_swsscommon_table - port_instance = MagicMock() - port_instance.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - port_instance.PRBS_DIRECTION_BOTH = 2 - port_instance.enable_prbs_mode.return_value = True - port_instance.disable_prbs_mode.return_value = True - port_instance.reset.return_value = True - port_instance.set_fec_mode.return_value = True - port_instance_helper = port_instance - - asic_index = 0 - port = "Ethernet0" - fvp = {"config_abc": True} - - rc = handle_config_loop_cmd_arg_tbl_notification( - fvp, xcvrd_config_loop_cmd_arg_tbl, xcvrd_config_loop_cmd_sts_tbl, xcvrd_config_loop_rsp_tbl, asic_index, port) - assert(rc == None) + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('os.path.isfile', MagicMock(return_value=True)) + def test_handle_show_mux_switchmode_cmd_arg_tbl_notification_no_port(self, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_config_hwmode_swmode_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_hwmode_swmode_rsp_tbl = mock_swsscommon_table + xcvrd_show_hwmode_swmode_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_hwmode_swmode_rsp_tbl = mock_swsscommon_table + + asic_index = 0 + task_download_firmware_thread = {} + port = "Ethernet0" + fvp = {"state": "null"} + + rc = handle_show_hwmode_swmode_cmd_arg_tbl_notification( + fvp, xcvrd_show_hwmode_swmode_cmd_sts_tbl, xcvrd_show_hwmode_swmode_rsp_tbl, asic_index, port) + assert(rc == -1) + + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('os.path.isfile', MagicMock(return_value=True)) + def test_handle_show_mux_switchmode_cmd_arg_tbl_notification_else_condition(self, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_config_hwmode_swmode_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_hwmode_swmode_rsp_tbl = mock_swsscommon_table + xcvrd_show_hwmode_swmode_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_hwmode_swmode_rsp_tbl = mock_swsscommon_table + + asic_index = 0 + task_download_firmware_thread = {} + port = "Ethernet0" + fvp = {"down_firmware": "null"} + + rc = handle_show_hwmode_swmode_cmd_arg_tbl_notification( + fvp, xcvrd_show_hwmode_swmode_cmd_sts_tbl, xcvrd_show_hwmode_swmode_rsp_tbl, asic_index, port) + assert(rc == None) + + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "activate_firmware", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('os.path.isfile', MagicMock(return_value=True)) + @patch('time.sleep', MagicMock(return_value=True)) + def test_handle_show_mux_switchmode_cmd_arg_tbl_notification_with_instance_manual(self, mock_swsscommon_table, platform_sfputil): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_config_hwmode_swmode_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_hwmode_swmode_rsp_tbl = mock_swsscommon_table + xcvrd_show_hwmode_swmode_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_hwmode_swmode_rsp_tbl = mock_swsscommon_table + asic_index = 0 + task_download_firmware_thread = {} + port = "Ethernet0" + platform_sfputil.get_asic_id_for_logical_port = 0 + fvp = {"state": "manual"} + + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 + self.TARGET_NIC = 1 + self.TARGET_TOR_A = 1 + self.TARGET_TOR_B = 1 + self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + self.FIRMWARE_DOWNLOAD_STATUS_FAILED = 2 + self.download_firmware_status = 0 + self.SWITCH_COUNT_MANUAL = "manual" + self.SWITCH_COUNT_AUTO = 0 + self.SWITCHING_MODE_MANUAL = 0 + self.SWITCHING_MODE_AUTO = 1 + + def get_read_side(self): + return 1 + + def get_switching_mode(self): + return 0 - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_config_loop_cmd_arg_tbl_notification_else_value(self, port_instance, mock_swsscommon_table, port_instance_helper): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_config_loop_cmd_arg_tbl = mock_swsscommon_table - xcvrd_config_loop_cmd_sts_tbl = mock_swsscommon_table - xcvrd_config_loop_rsp_tbl = mock_swsscommon_table - port_instance = MagicMock() - port_instance.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - port_instance.PRBS_DIRECTION_BOTH = 2 - port_instance.enable_prbs_mode.return_value = True - port_instance.disable_prbs_mode.return_value = True - port_instance.reset.return_value = True - port_instance.set_fec_mode.return_value = True - port_instance_helper = port_instance - - asic_index = 0 - port = "Ethernet0" - fvp = {"config_loop": True} - - rc = handle_config_loop_cmd_arg_tbl_notification( - fvp, xcvrd_config_loop_cmd_arg_tbl, xcvrd_config_loop_cmd_sts_tbl, xcvrd_config_loop_rsp_tbl, asic_index, port) - assert(rc == None) + # Defining function without self argument creates an exception, + # which is what we want for this test. + def get_mux_direction(): + pass - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - def test_handle_config_loop_cmd_arg_tbl_notification_no_port(self, port_instance, mock_swsscommon_table, port_instance_helper): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_config_loop_cmd_arg_tbl = mock_swsscommon_table - xcvrd_config_loop_cmd_sts_tbl = mock_swsscommon_table - xcvrd_config_loop_rsp_tbl = mock_swsscommon_table - port_instance = MagicMock() - port_instance.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - port_instance.PRBS_DIRECTION_BOTH = 2 - port_instance.enable_prbs_mode.return_value = True - port_instance.disable_prbs_mode.return_value = True - port_instance.reset.return_value = True - port_instance.set_fec_mode.return_value = True - port_instance_helper = port_instance - - asic_index = 0 - port = "Ethernet0" - fvp = {"config_loop": True} - - rc = handle_config_loop_cmd_arg_tbl_notification( - fvp, xcvrd_config_loop_cmd_arg_tbl, xcvrd_config_loop_cmd_sts_tbl, xcvrd_config_loop_rsp_tbl, asic_index, port) - assert(rc == -1) - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_config_loop_cmd_arg_tbl_notification_no_instance(self, port_instance, mock_swsscommon_table): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_config_loop_cmd_arg_tbl = mock_swsscommon_table - xcvrd_config_loop_cmd_sts_tbl = mock_swsscommon_table - xcvrd_config_loop_rsp_tbl = mock_swsscommon_table - port_instance = MagicMock() - port_instance.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - port_instance.PRBS_DIRECTION_BOTH = 2 - port_instance.enable_prbs_mode.return_value = True - port_instance.disable_prbs_mode.return_value = True - port_instance.reset.return_value = True - port_instance.set_fec_mode.return_value = True - port_instance_helper = port_instance - - asic_index = 0 - port = "Ethernet0" - fvp = {"config_loop": True} - - rc = handle_config_loop_cmd_arg_tbl_notification( - fvp, xcvrd_config_loop_cmd_arg_tbl, xcvrd_config_loop_cmd_sts_tbl, xcvrd_config_loop_rsp_tbl, asic_index, port) - assert(rc == -1) - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "enable", {"enable": "0", - "lane_mask": "0", - "mode_value": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_config_loop_cmd_arg_tbl_notification_enable(self, port_instance, mock_swsscommon_table, port_instance_helper): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_config_loop_cmd_arg_tbl = mock_swsscommon_table - xcvrd_config_loop_cmd_sts_tbl = mock_swsscommon_table - xcvrd_config_loop_rsp_tbl = mock_swsscommon_table - port_instance = MagicMock() - port_instance.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - port_instance.PRBS_DIRECTION_BOTH = 2 - port_instance.enable_loopback_mode.return_value = True - port_instance.disable_loopback_mode.return_value = True - port_instance.reset.return_value = True - port_instance.set_fec_mode.return_value = True - port_instance_helper = port_instance - - asic_index = 0 - port = "Ethernet0" - fvp = {"config_loop": True} - - rc = handle_config_loop_cmd_arg_tbl_notification( - fvp, xcvrd_config_loop_cmd_arg_tbl, xcvrd_config_loop_cmd_sts_tbl, xcvrd_config_loop_rsp_tbl, asic_index, port) + patched_util.get.return_value = PortInstanceHelper() + rc = handle_show_hwmode_swmode_cmd_arg_tbl_notification( + fvp, xcvrd_show_hwmode_swmode_cmd_sts_tbl, xcvrd_show_hwmode_swmode_rsp_tbl, asic_index, port) assert(rc == None) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "disable", {"disable": "0", - "lane_mask": "0", - "mode_value": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_config_loop_cmd_arg_tbl_notification_disable(self, port_instance, mock_swsscommon_table, port_instance_helper): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_config_loop_cmd_arg_tbl = mock_swsscommon_table - xcvrd_config_loop_cmd_sts_tbl = mock_swsscommon_table - xcvrd_config_loop_rsp_tbl = mock_swsscommon_table - port_instance = MagicMock() - port_instance.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - port_instance.PRBS_DIRECTION_BOTH = 2 - port_instance.enable_loopback_mode.return_value = True - port_instance.disable_loopback_mode.return_value = True - port_instance.reset.return_value = True - port_instance.set_fec_mode.return_value = True - port_instance_helper = port_instance - - asic_index = 0 - port = "Ethernet0" - fvp = {"config_loop": True} - - rc = handle_config_loop_cmd_arg_tbl_notification( - fvp, xcvrd_config_loop_cmd_arg_tbl, xcvrd_config_loop_cmd_sts_tbl, xcvrd_config_loop_rsp_tbl, asic_index, port) - assert(rc == None) + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('os.path.isfile', MagicMock(return_value=True)) + def test_handle_show_mux_switchmode_cmd_arg_tbl_notification_no_instance(self, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_config_hwmode_swmode_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_hwmode_swmode_rsp_tbl = mock_swsscommon_table + xcvrd_show_hwmode_swmode_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_hwmode_swmode_rsp_tbl = mock_swsscommon_table + + asic_index = 0 + task_download_firmware_thread = {} + port = "Ethernet0" + fvp = {"state": "manual"} + + rc = handle_show_hwmode_swmode_cmd_arg_tbl_notification( + fvp, xcvrd_show_hwmode_swmode_cmd_sts_tbl, xcvrd_show_hwmode_swmode_rsp_tbl, asic_index, port) + assert(rc == -1) + + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "activate_firmware", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('os.path.isfile', MagicMock(return_value=True)) + @patch('time.sleep', MagicMock(return_value=True)) + def test_handle_show_mux_switchmode_cmd_arg_tbl_notification_with_instance_auto(self, mock_swsscommon_table, platform_sfputil): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_config_hwmode_swmode_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_hwmode_swmode_rsp_tbl = mock_swsscommon_table + xcvrd_show_hwmode_swmode_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_hwmode_swmode_rsp_tbl = mock_swsscommon_table + asic_index = 0 + task_download_firmware_thread = {} + port = "Ethernet0" + platform_sfputil.get_asic_id_for_logical_port = 0 + fvp = {"state": "auto"} + + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 + self.TARGET_NIC = 1 + self.TARGET_TOR_A = 1 + self.TARGET_TOR_B = 1 + self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + self.FIRMWARE_DOWNLOAD_STATUS_FAILED = 2 + self.download_firmware_status = 0 + self.SWITCH_COUNT_MANUAL = "manual" + self.SWITCH_COUNT_AUTO = "auto" + self.SWITCHING_MODE_MANUAL = 0 + self.SWITCHING_MODE_AUTO = 1 + + def get_read_side(self): + return 1 + + def get_switching_mode(self): + return 1 + + # Defining function without self argument creates an exception, + # which is what we want for this test. + def get_mux_direction(): + pass - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_show_event_cmd_arg_tbl_notification_else_value(self, port_instance, mock_swsscommon_table, port_instance_helper): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_show_event_cmd_sts_tbl = mock_swsscommon_table - xcvrd_show_event_rsp_tbl = mock_swsscommon_table - xcvrd_show_event_res_tbl = mock_swsscommon_table - port_instance = MagicMock() - port_instance.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - port_instance.PRBS_DIRECTION_BOTH = 2 - port_instance.enable_prbs_mode.return_value = True - port_instance.disable_prbs_mode.return_value = True - port_instance.reset.return_value = True - port_instance.set_fec_mode.return_value = True - port_instance_helper = port_instance - - asic_index = 0 - port = "Ethernet0" - fvp = {"config_loop": True} - - rc = handle_show_event_cmd_arg_tbl_notification( - fvp, xcvrd_show_event_cmd_sts_tbl, xcvrd_show_event_rsp_tbl, xcvrd_show_event_res_tbl, asic_index, port) + patched_util.get.return_value = PortInstanceHelper() + rc = handle_show_hwmode_swmode_cmd_arg_tbl_notification( + fvp, xcvrd_show_hwmode_swmode_cmd_sts_tbl, xcvrd_show_hwmode_swmode_rsp_tbl, asic_index, port) assert(rc == None) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_show_event_cmd_arg_tbl_notification_get_log(self, port_instance, mock_swsscommon_table, port_instance_helper): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_show_event_cmd_sts_tbl = mock_swsscommon_table - xcvrd_show_event_rsp_tbl = mock_swsscommon_table - xcvrd_show_event_res_tbl = mock_swsscommon_table - port_instance = MagicMock() - port_instance.get_event_log.return_value = ["log 1", "log 2"] - - asic_index = 0 - port = "Ethernet0" - fvp = {"show_event": True} + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('os.path.isfile', MagicMock(return_value=True)) + def test_handle_config_mux_state_cmd_arg_tbl_notification_no_port(self, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_config_hwmode_state_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_hwmode_state_rsp_tbl = mock_swsscommon_table + + asic_index = 0 + task_download_firmware_thread = {} + port = "Ethernet0" + fvp = {"config": "active"} + + rc = handle_config_hwmode_state_cmd_arg_tbl_notification( + fvp, xcvrd_config_hwmode_state_cmd_sts_tbl, xcvrd_config_hwmode_state_rsp_tbl, asic_index, port) + assert(rc == -1) + + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('os.path.isfile', MagicMock(return_value=True)) + def test_handle_show_mux_switchmode_cmd_arg_tbl_notification_else_condition(self, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_config_hwmode_state_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_hwmode_state_rsp_tbl = mock_swsscommon_table + + asic_index = 0 + task_download_firmware_thread = {} + port = "Ethernet0" + fvp = {"down_firmware": "null"} + + rc = handle_config_hwmode_state_cmd_arg_tbl_notification( + fvp, xcvrd_config_hwmode_state_cmd_sts_tbl, xcvrd_config_hwmode_state_rsp_tbl, asic_index, port) + assert(rc == None) + + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "activate_firmware", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('os.path.isfile', MagicMock(return_value=True)) + @patch('time.sleep', MagicMock(return_value=True)) + def test_handle_config_mux_state_cmd_arg_tbl_notification_with_instance_manual(self, mock_swsscommon_table, platform_sfputil): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_config_hwmode_state_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_hwmode_state_rsp_tbl = mock_swsscommon_table + asic_index = 0 + task_download_firmware_thread = {} + port = "Ethernet0" + platform_sfputil.get_asic_id_for_logical_port = 0 + fvp = {"config": "active"} + + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 + self.TARGET_NIC = 1 + self.TARGET_TOR_A = 1 + self.TARGET_TOR_B = 1 + self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + self.FIRMWARE_DOWNLOAD_STATUS_FAILED = 2 + self.download_firmware_status = 0 + self.SWITCH_COUNT_MANUAL = "manual" + self.SWITCH_COUNT_AUTO = 0 + self.SWITCHING_MODE_MANUAL = 0 + self.SWITCHING_MODE_AUTO = 1 + + def get_read_side(self): + return 1 + + def get_switching_mode(self): + return 0 - rc = handle_show_event_cmd_arg_tbl_notification( - fvp, xcvrd_show_event_cmd_sts_tbl, xcvrd_show_event_rsp_tbl, xcvrd_show_event_res_tbl, asic_index, port) - assert(rc == None) + # Defining function without self argument creates an exception, + # which is what we want for this test. + def get_mux_direction(): + pass - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_show_event_cmd_arg_tbl_notification_get_actual_log(self, port_instance, mock_swsscommon_table, port_instance_helper): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_show_event_cmd_sts_tbl = mock_swsscommon_table - xcvrd_show_event_rsp_tbl = mock_swsscommon_table - xcvrd_show_event_res_tbl = mock_swsscommon_table - port_instance = MagicMock() - port_instance.get_event_log.return_value = ["log 1", "log 2"] - port_instance_helper.return_value = port_instance - asic_index = 0 - port = "Ethernet0" - fvp = {"show_event": True} - - rc = handle_show_event_cmd_arg_tbl_notification( - fvp, xcvrd_show_event_cmd_sts_tbl, xcvrd_show_event_rsp_tbl, xcvrd_show_event_res_tbl, asic_index, port) + patched_util.get.return_value = PortInstanceHelper() + rc = handle_config_hwmode_state_cmd_arg_tbl_notification( + fvp, xcvrd_config_hwmode_state_cmd_sts_tbl, xcvrd_config_hwmode_state_rsp_tbl, asic_index, port) assert(rc == None) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_show_event_cmd_arg_tbl_notification_get_no_log(self, port_instance, mock_swsscommon_table, port_instance_helper): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('os.path.isfile', MagicMock(return_value=True)) + def test_handle_config_mux_state_cmd_arg_tbl_notification_no_instance(self, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_config_hwmode_state_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_hwmode_state_rsp_tbl = mock_swsscommon_table + + asic_index = 0 + task_download_firmware_thread = {} + port = "Ethernet0" + fvp = {"config": "active"} + + rc = handle_config_hwmode_state_cmd_arg_tbl_notification( + fvp, xcvrd_config_hwmode_state_cmd_sts_tbl, xcvrd_config_hwmode_state_rsp_tbl, asic_index, port) + assert(rc == -1) + + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "activate_firmware", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('os.path.isfile', MagicMock(return_value=True)) + @patch('time.sleep', MagicMock(return_value=True)) + def test_handle_config_mux_state_cmd_arg_tbl_notification_with_instance_auto(self, mock_swsscommon_table, platform_sfputil): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_config_hwmode_state_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_hwmode_state_rsp_tbl = mock_swsscommon_table + asic_index = 0 + task_download_firmware_thread = {} + port = "Ethernet0" + platform_sfputil.get_asic_id_for_logical_port = 0 + fvp = {"config": "active"} + + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 + self.TARGET_NIC = 1 + self.TARGET_TOR_A = 1 + self.TARGET_TOR_B = 1 + self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + self.FIRMWARE_DOWNLOAD_STATUS_FAILED = 2 + self.download_firmware_status = 0 + self.SWITCH_COUNT_MANUAL = "manual" + self.SWITCH_COUNT_AUTO = "auto" + self.SWITCHING_MODE_MANUAL = 0 + self.SWITCHING_MODE_AUTO = 1 + + def get_read_side(self): + return 1 + + def get_switching_mode(self): + return 1 + + # Defining function without self argument creates an exception, + # which is what we want for this test. + def get_mux_direction(): + pass - xcvrd_show_event_cmd_sts_tbl = mock_swsscommon_table - xcvrd_show_event_rsp_tbl = mock_swsscommon_table - xcvrd_show_event_res_tbl = mock_swsscommon_table - port_instance = MagicMock() - port_instance.get_event_log.return_value = Exception( - NotImplementedError) + patched_util.get.return_value = PortInstanceHelper() + rc = handle_config_hwmode_state_cmd_arg_tbl_notification( + fvp, xcvrd_config_hwmode_state_cmd_sts_tbl, xcvrd_config_hwmode_state_rsp_tbl, asic_index, port) + assert(rc == None) - asic_index = 0 - port = "Ethernet0" - fvp = {"show_event": True} + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('os.path.isfile', MagicMock(return_value=True)) + def test_handle_show_mux_state_cmd_arg_tbl_notification_no_port(self, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_show_hwmode_dir_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_hwmode_dir_rsp_tbl = mock_swsscommon_table + xcvrd_show_hwmode_dir_res_tbl = mock_swsscommon_table + + asic_index = 0 + task_download_firmware_thread = {} + port = "Ethernet0" + fvp = {"state": "active"} + + rc = handle_show_hwmode_state_cmd_arg_tbl_notification( + fvp, xcvrd_show_hwmode_dir_cmd_sts_tbl, xcvrd_show_hwmode_dir_rsp_tbl, xcvrd_show_hwmode_dir_res_tbl, asic_index, port) + assert(rc == -1) + + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('os.path.isfile', MagicMock(return_value=True)) + def test_handle_show_mux_state_cmd_arg_tbl_notification_else_condition(self, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_show_hwmode_dir_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_hwmode_dir_rsp_tbl = mock_swsscommon_table + xcvrd_show_hwmode_dir_res_tbl = mock_swsscommon_table + xcvrd_config_hwmode_state_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_hwmode_state_rsp_tbl = mock_swsscommon_table + + asic_index = 0 + task_download_firmware_thread = {} + port = "Ethernet0" + fvp = {"down_firmware": "null"} + + rc = handle_show_hwmode_state_cmd_arg_tbl_notification( + fvp, xcvrd_show_hwmode_dir_cmd_sts_tbl, xcvrd_show_hwmode_dir_rsp_tbl, xcvrd_show_hwmode_dir_res_tbl, asic_index, port) + assert(rc == None) + + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "activate_firmware", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('os.path.isfile', MagicMock(return_value=True)) + @patch('time.sleep', MagicMock(return_value=True)) + def test_handle_show_mux_state_cmd_arg_tbl_notification_with_instance_manual(self, mock_swsscommon_table, platform_sfputil): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_show_hwmode_dir_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_hwmode_dir_rsp_tbl = mock_swsscommon_table + xcvrd_show_hwmode_dir_res_tbl = mock_swsscommon_table + xcvrd_config_hwmode_state_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_hwmode_state_rsp_tbl = mock_swsscommon_table + asic_index = 0 + task_download_firmware_thread = {} + port = "Ethernet0" + platform_sfputil.get_asic_id_for_logical_port = 0 + fvp = {"state": "active"} + + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 + self.TARGET_NIC = 1 + self.TARGET_TOR_A = 1 + self.TARGET_TOR_B = 1 + self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + self.FIRMWARE_DOWNLOAD_STATUS_FAILED = 2 + self.download_firmware_status = 0 + self.SWITCH_COUNT_MANUAL = "manual" + self.SWITCH_COUNT_AUTO = 0 + self.SWITCHING_MODE_MANUAL = 0 + self.SWITCHING_MODE_AUTO = 1 + + def get_read_side(self): + return 1 + + def get_mux_direction(self): + return 1 + + def get_switching_mode(self): + return 0 - rc = handle_show_event_cmd_arg_tbl_notification( - fvp, xcvrd_show_event_cmd_sts_tbl, xcvrd_show_event_rsp_tbl, xcvrd_show_event_res_tbl, asic_index, port) + patched_util.get.return_value = PortInstanceHelper() + rc = handle_show_hwmode_state_cmd_arg_tbl_notification( + fvp, xcvrd_show_hwmode_dir_cmd_sts_tbl, xcvrd_show_hwmode_dir_rsp_tbl, xcvrd_show_hwmode_dir_res_tbl, asic_index, port) assert(rc == None) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_show_event_cmd_arg_tbl_notification_no_port(self, port_instance, mock_swsscommon_table, port_instance_helper): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('os.path.isfile', MagicMock(return_value=True)) + def test_handle_show_mux_state_cmd_arg_tbl_notification_no_instance(self, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_show_hwmode_dir_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_hwmode_dir_rsp_tbl = mock_swsscommon_table + xcvrd_show_hwmode_dir_res_tbl = mock_swsscommon_table + + asic_index = 0 + task_download_firmware_thread = {} + port = "Ethernet0" + fvp = {"state": "active"} + + rc = handle_show_hwmode_state_cmd_arg_tbl_notification( + fvp, xcvrd_show_hwmode_dir_cmd_sts_tbl, xcvrd_show_hwmode_dir_rsp_tbl, xcvrd_show_hwmode_dir_res_tbl, asic_index, port) + assert(rc == -1) + + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "activate_firmware", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('os.path.isfile', MagicMock(return_value=True)) + @patch('time.sleep', MagicMock(return_value=True)) + def test_handle_show_mux_state_cmd_arg_tbl_notification_with_instance_auto(self, mock_swsscommon_table, platform_sfputil): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_config_hwmode_state_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_hwmode_state_rsp_tbl = mock_swsscommon_table + xcvrd_show_hwmode_dir_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_hwmode_dir_rsp_tbl = mock_swsscommon_table + xcvrd_show_hwmode_dir_res_tbl = mock_swsscommon_table + asic_index = 0 + task_download_firmware_thread = {} + port = "Ethernet0" + platform_sfputil.get_asic_id_for_logical_port = 0 + fvp = {"state": "active"} + + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 + self.TARGET_NIC = 1 + self.TARGET_TOR_A = 1 + self.TARGET_TOR_B = 1 + self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + self.FIRMWARE_DOWNLOAD_STATUS_FAILED = 2 + self.download_firmware_status = 0 + self.SWITCH_COUNT_MANUAL = "manual" + self.SWITCH_COUNT_AUTO = "auto" + self.SWITCHING_MODE_MANUAL = 0 + self.SWITCHING_MODE_AUTO = 1 + + def get_read_side(self): + return 1 + + def get_switching_mode(self): + return 1 + + def get_mux_direction(self): + return 2 + + patched_util.get.return_value = PortInstanceHelper() + rc = handle_show_hwmode_state_cmd_arg_tbl_notification( + fvp, xcvrd_show_hwmode_dir_cmd_sts_tbl, xcvrd_show_hwmode_dir_rsp_tbl, xcvrd_show_hwmode_dir_res_tbl, asic_index, port) + assert(rc == None) - xcvrd_show_event_cmd_sts_tbl = mock_swsscommon_table - xcvrd_show_event_rsp_tbl = mock_swsscommon_table - xcvrd_show_event_res_tbl = mock_swsscommon_table - port_instance = MagicMock() - port_instance.get_event_log.return_value = ["log 1", "log 2"] - port_instance_helper = port_instance + def test_get_mux_cable_static_info_without_presence(self): - asic_index = 0 - port = "Ethernet0" - fvp = {"show_event": True} + rc = get_muxcable_static_info_without_presence() - rc = handle_show_event_cmd_arg_tbl_notification( - fvp, xcvrd_show_event_cmd_sts_tbl, xcvrd_show_event_rsp_tbl, xcvrd_show_event_res_tbl, asic_index, port) - assert(rc == -1) + assert(rc['read_side'] == '-1') + assert(rc['nic_lane1_precursor1'] == 'N/A') + assert(rc['nic_lane1_precursor1'] == 'N/A') + assert(rc['nic_lane1_postcursor1'] == 'N/A') + assert(rc['nic_lane1_postcursor2'] == 'N/A') + assert(rc != None) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - def test_handle_show_event_cmd_arg_tbl_notification_no_instance(self, port_instance, mock_swsscommon_table): - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table + @patch('ycable.ycable_utilities.y_cable_helper.disable_telemetry') + def test_handle_ycable_enable_disable_tel_notification(self, patch): - xcvrd_show_event_cmd_sts_tbl = mock_swsscommon_table - xcvrd_show_event_rsp_tbl = mock_swsscommon_table - xcvrd_show_event_res_tbl = mock_swsscommon_table - port_instance = MagicMock() - port_instance.get_event_log.return_value = ["log 1", "log 2"] + fvp_m = {"disable_telemetry": "True"} + rc = handle_ycable_enable_disable_tel_notification(fvp_m, "Y_CABLE") + assert(rc == None) - asic_index = 0 - port = "Ethernet0" - fvp = {"show_event": True} + def test_handle_ycable_enable_disable_tel_notification_probe(self): - rc = handle_show_event_cmd_arg_tbl_notification( - fvp, xcvrd_show_event_cmd_sts_tbl, xcvrd_show_event_rsp_tbl, xcvrd_show_event_res_tbl, asic_index, port) - assert(rc == -1) + fvp_m = {"log_verbosity": "notice"} + rc = handle_ycable_enable_disable_tel_notification(fvp_m, "Y_CABLE") + assert(rc == None) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_get_fec_cmd_arg_tbl_notification_no_status(self, port_instance, mock_swsscommon_table, port_instance_helper): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_show_fec_rsp_tbl = mock_swsscommon_table - xcvrd_show_fec_cmd_sts_tbl = mock_swsscommon_table - xcvrd_show_fec_res_tbl = mock_swsscommon_table - port_instance = MagicMock() - - asic_index = 0 - port = "Ethernet0" - fvp = {"show_event": True} - - rc = handle_get_fec_cmd_arg_tbl_notification( - fvp, xcvrd_show_fec_rsp_tbl, xcvrd_show_fec_cmd_sts_tbl, xcvrd_show_fec_res_tbl, asic_index, port) - assert(rc == None) - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_get_fec_cmd_arg_tbl_notification_no_port(self, port_instance, mock_swsscommon_table, port_instance_helper): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_show_fec_rsp_tbl = mock_swsscommon_table - xcvrd_show_fec_cmd_sts_tbl = mock_swsscommon_table - xcvrd_show_fec_res_tbl = mock_swsscommon_table - port_instance = MagicMock() - - asic_index = 0 - port = "Ethernet0" - fvp = {"get_fec": True} - - rc = handle_get_fec_cmd_arg_tbl_notification( - fvp, xcvrd_show_fec_rsp_tbl, xcvrd_show_fec_cmd_sts_tbl, xcvrd_show_fec_res_tbl, asic_index, port) - assert(rc == -1) - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_get_fec_cmd_arg_tbl_notification_no_instance(self, port_instance, mock_swsscommon_table): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_show_fec_rsp_tbl = mock_swsscommon_table - xcvrd_show_fec_cmd_sts_tbl = mock_swsscommon_table - xcvrd_show_fec_res_tbl = mock_swsscommon_table - port_instance = MagicMock() - port_instance_helper = port_instance - - asic_index = 0 - port = "Ethernet0" - fvp = {"get_fec": True} - - rc = handle_get_fec_cmd_arg_tbl_notification( - fvp, xcvrd_show_fec_rsp_tbl, xcvrd_show_fec_cmd_sts_tbl, xcvrd_show_fec_res_tbl, asic_index, port) - assert(rc == -1) - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_get_fec_cmd_arg_tbl_notification_get_result(self, port_instance, mock_swsscommon_table, port_instance_helper): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_show_fec_rsp_tbl = mock_swsscommon_table - xcvrd_show_fec_cmd_sts_tbl = mock_swsscommon_table - xcvrd_show_fec_res_tbl = mock_swsscommon_table - port_instance = MagicMock() - port_instance.get_fec_mode.return_value = 0 - port_instance.get_anlt.return_value = 0 - port_instance.get_speed.return_value = 0 - - asic_index = 0 - port = "Ethernet0" - fvp = {"get_fec": True} - - rc = handle_get_fec_cmd_arg_tbl_notification( - fvp, xcvrd_show_fec_rsp_tbl, xcvrd_show_fec_cmd_sts_tbl, xcvrd_show_fec_res_tbl, asic_index, port) - assert(rc == None) - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_get_fec_cmd_arg_tbl_notification_no_status(self, port_instance, mock_swsscommon_table, port_instance_helper): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_show_ber_cmd_arg_tbl = mock_swsscommon_table - xcvrd_show_ber_rsp_tbl = mock_swsscommon_table - xcvrd_show_ber_cmd_sts_tbl = mock_swsscommon_table - xcvrd_show_ber_res_tbl = mock_swsscommon_table - port_instance = MagicMock() - - asic_index = 0 - port = "Ethernet0" - fvp = {"show_event": True} - - rc = handle_show_ber_cmd_arg_tbl_notification( - fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port) - assert(rc == None) - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_get_fec_cmd_arg_tbl_notification_no_port(self, port_instance, mock_swsscommon_table, port_instance_helper): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_show_ber_cmd_arg_tbl = mock_swsscommon_table - xcvrd_show_ber_rsp_tbl = mock_swsscommon_table - xcvrd_show_ber_cmd_sts_tbl = mock_swsscommon_table - xcvrd_show_ber_res_tbl = mock_swsscommon_table - port_instance = MagicMock() - - asic_index = 0 - port = "Ethernet0" - fvp = {"get_ber": True} - - rc = handle_show_ber_cmd_arg_tbl_notification( - fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port) - assert(rc == -1) - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_get_fec_cmd_arg_tbl_notification_no_instance(self, port_instance, mock_swsscommon_table): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_show_ber_cmd_arg_tbl = mock_swsscommon_table - xcvrd_show_ber_rsp_tbl = mock_swsscommon_table - xcvrd_show_ber_cmd_sts_tbl = mock_swsscommon_table - xcvrd_show_ber_res_tbl = mock_swsscommon_table - port_instance = MagicMock() - - asic_index = 0 - port = "Ethernet0" - fvp = {"get_ber": True} - - rc = handle_show_ber_cmd_arg_tbl_notification( - fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port) - assert(rc == -1) - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "ber", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_get_fec_cmd_arg_tbl_notification_get_ber(self, port_instance, mock_swsscommon_table, port_instance_helper): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_show_ber_cmd_arg_tbl = mock_swsscommon_table - xcvrd_show_ber_rsp_tbl = mock_swsscommon_table - xcvrd_show_ber_cmd_sts_tbl = mock_swsscommon_table - xcvrd_show_ber_res_tbl = mock_swsscommon_table - port_instance = MagicMock() - port_instance.get_ber_info.return_value = ["100", "200"] - - asic_index = 0 - port = "Ethernet0" - fvp = {"get_ber": True} - - rc = handle_show_ber_cmd_arg_tbl_notification( - fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port) - assert(rc == None) - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "eye", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_get_fec_cmd_arg_tbl_notification_get_eye(self, port_instance, mock_swsscommon_table, port_instance_helper): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_show_ber_cmd_arg_tbl = mock_swsscommon_table - xcvrd_show_ber_rsp_tbl = mock_swsscommon_table - xcvrd_show_ber_cmd_sts_tbl = mock_swsscommon_table - xcvrd_show_ber_res_tbl = mock_swsscommon_table - port_instance = MagicMock() - port_instance.get_eye_info.return_value = ["100", "200"] - - asic_index = 0 - port = "Ethernet0" - fvp = {"get_ber": True} - - rc = handle_show_ber_cmd_arg_tbl_notification( - fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port) - assert(rc == None) - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec_stats", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_get_fec_cmd_arg_tbl_notification_get_fec_stats(self, port_instance, mock_swsscommon_table, port_instance_helper): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_show_ber_cmd_arg_tbl = mock_swsscommon_table - xcvrd_show_ber_rsp_tbl = mock_swsscommon_table - xcvrd_show_ber_cmd_sts_tbl = mock_swsscommon_table - xcvrd_show_ber_res_tbl = mock_swsscommon_table - port_instance = MagicMock() - port_instance.get_fec_stats.return_value = {"100": "200"} - - asic_index = 0 - port = "Ethernet0" - fvp = {"get_ber": True} - - rc = handle_show_ber_cmd_arg_tbl_notification( - fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port) - assert(rc == None) - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "pcs_stats", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_get_fec_cmd_arg_tbl_notification_get_pcs_stats(self, port_instance, mock_swsscommon_table, port_instance_helper): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_show_ber_cmd_arg_tbl = mock_swsscommon_table - xcvrd_show_ber_rsp_tbl = mock_swsscommon_table - xcvrd_show_ber_cmd_sts_tbl = mock_swsscommon_table - xcvrd_show_ber_res_tbl = mock_swsscommon_table - port_instance = MagicMock() - port_instance.get_pcs_stats.return_value = {"100": "200"} - - asic_index = 0 - port = "Ethernet0" - fvp = {"get_ber": True} - - rc = handle_show_ber_cmd_arg_tbl_notification( - fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port) - assert(rc == None) - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "cable_alive", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_get_fec_cmd_arg_tbl_notification_get_alive_status(self, port_instance, mock_swsscommon_table, port_instance_helper): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_show_ber_cmd_arg_tbl = mock_swsscommon_table - xcvrd_show_ber_rsp_tbl = mock_swsscommon_table - xcvrd_show_ber_cmd_sts_tbl = mock_swsscommon_table - xcvrd_show_ber_res_tbl = mock_swsscommon_table - port_instance = MagicMock() - port_instance.get_alive_status.return_value = True - - asic_index = 0 - port = "Ethernet0" - fvp = {"get_ber": True} - - rc = handle_show_ber_cmd_arg_tbl_notification( - fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port) - assert(rc == None) - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "debug_dump", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_get_fec_cmd_arg_tbl_notification_get_debug_dump_registers(self, port_instance, mock_swsscommon_table, port_instance_helper): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_show_ber_cmd_arg_tbl = mock_swsscommon_table - xcvrd_show_ber_rsp_tbl = mock_swsscommon_table - xcvrd_show_ber_cmd_sts_tbl = mock_swsscommon_table - xcvrd_show_ber_res_tbl = mock_swsscommon_table - port_instance = MagicMock() - port_instance.debug_dump_registers.return_value = {"register1": "100"} - - asic_index = 0 - port = "Ethernet0" - fvp = {"get_ber": True} - - rc = handle_show_ber_cmd_arg_tbl_notification( - fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port) - assert(rc == None) - """ - - def handle_config_firmware_roll_cmd_arg_tbl_notification(fvp, xcvrd_roll_fw_cmd_sts_tbl, xcvrd_roll_fw_rsp_tbl, asic_index, port): - - fvp_dict = dict(fvp) - - - if "rollback_firmware" in fvp_dict: - file_name = fvp_dict["rollback_firmware"] - status = 'False' - - if file_name == 'null': - file_full_path = None - else: - file_full_path = '/usr/share/sonic/firmware/{}'.format(file_name) - if not os.path.isfile(file_full_path): - helper_logger.log_error("Error: cli cmd mux rollback firmware file does not exist port {} file {}".format(port, file_name)) - set_result_and_delete_port('status', status, xcvrd_roll_fw_cmd_sts_tbl[asic_index], xcvrd_roll_fw_rsp_tbl[asic_index], port) - break - - - - physical_port = get_ycable_physical_port_from_logical_port(port) - if physical_port is None or physical_port == PHYSICAL_PORT_MAPPING_ERROR: - # error scenario update table accordingly - helper_logger.log_warning("Error: Could not get physical port for cli cmd mux rollback firmware port {}".format(port)) - set_result_and_delete_port('status', status, xcvrd_roll_fw_cmd_sts_tbl[asic_index], xcvrd_roll_fw_rsp_tbl[asic_index], port) - break - - port_instance = get_ycable_port_instance_from_logical_port(port) - if port_instance is None or port_instance in port_mapping_error_values: - # error scenario update table accordingly - helper_logger.log_warning("Error: Could not get port instance for cli cmd mux rollback firmware port {}".format(port)) - set_result_and_delete_port('status', status, xcvrd_roll_fw_cmd_sts_tbl[asic_index], xcvrd_roll_fw_rsp_tbl[asic_index], port) - - with y_cable_port_locks[physical_port]: - try: - status = port_instance.rollback_firmware(file_full_path) - except Exception as e: - status = -1 - helper_logger.log_warning("Failed to execute the rollback_firmware API for port {} due to {}".format(physical_port,repr(e))) - set_result_and_delete_port('status', status, xcvrd_roll_fw_cmd_sts_tbl[asic_index], xcvrd_roll_fw_rsp_tbl[asic_index], port) - else: - helper_logger.log_error("Wrong param for cli cmd mux rollback firmware port {}".format(port)) - set_result_and_delete_port('status', 'False', xcvrd_roll_fw_cmd_sts_tbl[asic_index], xcvrd_roll_fw_rsp_tbl[asic_index], port) - """ - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_config_firmware_roll_cmd_arg_tbl_notification_no_port(self, port_instance, mock_swsscommon_table, port_instance_helper): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_down_fw_cmd_sts_tbl = mock_swsscommon_table - xcvrd_down_fw_rsp_tbl = mock_swsscommon_table - port_instance = MagicMock() - - asic_index = 0 - port = "Ethernet0" - fvp = {"rollback_firmware": "null"} - - rc = handle_config_firmware_roll_cmd_arg_tbl_notification( - fvp, xcvrd_down_fw_cmd_sts_tbl, xcvrd_down_fw_rsp_tbl, asic_index, port) - assert(rc == -1) - - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_config_firmware_roll_cmd_arg_tbl_notification_no_instance(self, mock_swsscommon_table): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_down_fw_cmd_sts_tbl = mock_swsscommon_table - xcvrd_down_fw_rsp_tbl = mock_swsscommon_table - - asic_index = 0 - port = "Ethernet0" - fvp = {"rollback_firmware": "null"} - - rc = handle_config_firmware_roll_cmd_arg_tbl_notification( - fvp, xcvrd_down_fw_cmd_sts_tbl, xcvrd_down_fw_rsp_tbl, asic_index, port) - assert(rc == -1) - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_config_firmware_roll_cmd_arg_tbl_notification_with_instance(self, port_instance, mock_swsscommon_table): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_down_fw_cmd_sts_tbl = mock_swsscommon_table - xcvrd_down_fw_rsp_tbl = mock_swsscommon_table - port_instance = MagicMock() - - asic_index = 0 - port = "Ethernet0" - fvp = {"rollback_firmware": "null"} - - rc = handle_config_firmware_roll_cmd_arg_tbl_notification( - fvp, xcvrd_down_fw_cmd_sts_tbl, xcvrd_down_fw_rsp_tbl, asic_index, port) - assert(rc == None) - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_config_firmware_roll_cmd_arg_tbl_notification_no_port_and_instance(self, port_instance, mock_swsscommon_table, port_instance_helper): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_down_fw_cmd_sts_tbl = mock_swsscommon_table - xcvrd_down_fw_rsp_tbl = mock_swsscommon_table - port_instance = MagicMock() - - asic_index = 0 - port = "Ethernet0" - fvp = {"rollback_firmware": "null"} - - rc = handle_config_firmware_roll_cmd_arg_tbl_notification( - fvp, xcvrd_down_fw_cmd_sts_tbl, xcvrd_down_fw_rsp_tbl, asic_index, port) - assert(rc == -1) - - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('os.path.isfile', MagicMock(return_value=True)) - def test_handle_config_firmware_down_cmd_arg_tbl_notification_no_port(self, mock_swsscommon_table): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_down_fw_cmd_sts_tbl = mock_swsscommon_table - xcvrd_down_fw_rsp_tbl = mock_swsscommon_table - - asic_index = 0 - task_download_firmware_thread = {} - port = "Ethernet0" - fvp = {"download_firmware": "null"} - - rc = handle_config_firmware_down_cmd_arg_tbl_notification( - fvp, xcvrd_down_fw_cmd_sts_tbl, xcvrd_down_fw_rsp_tbl, asic_index, port, task_download_firmware_thread) - assert(rc == -1) - - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('os.path.isfile', MagicMock(return_value=True)) - def test_handle_config_firmware_down_cmd_arg_tbl_notification_else_condition(self, mock_swsscommon_table): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_down_fw_cmd_sts_tbl = mock_swsscommon_table - xcvrd_down_fw_rsp_tbl = mock_swsscommon_table - - asic_index = 0 - task_download_firmware_thread = {} - port = "Ethernet0" - fvp = {"downoad_firmware": "null"} - - rc = handle_config_firmware_down_cmd_arg_tbl_notification( - fvp, xcvrd_down_fw_cmd_sts_tbl, xcvrd_down_fw_rsp_tbl, asic_index, port, task_download_firmware_thread) - assert(rc == None) - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') - @patch('threading.Thread') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('os.path.isfile', MagicMock(return_value=True)) - def test_handle_config_firmware_down_cmd_arg_tbl_notification_with_instance(self, port_instance, mock_swsscommon_table, port_instance_helper, thread_obj): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_down_fw_cmd_sts_tbl = mock_swsscommon_table - xcvrd_down_fw_rsp_tbl = mock_swsscommon_table - port_instance = MagicMock() - thread_instance = MagicMock() - thread_instance.start = MagicMock() - thread_obj = thread_instance - port_instance_helper = port_instance - - asic_index = 0 - task_download_firmware_thread = {} - port = "Ethernet0" - fvp = {"download_firmware": "null"} - - rc = handle_config_firmware_down_cmd_arg_tbl_notification( - fvp, xcvrd_down_fw_cmd_sts_tbl, xcvrd_down_fw_rsp_tbl, asic_index, port, task_download_firmware_thread) - assert(rc == None) - - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('os.path.isfile', MagicMock(return_value=True)) - def test_handle_config_firmware_down_cmd_arg_tbl_notification_no_instance(self, mock_swsscommon_table): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_down_fw_cmd_sts_tbl = mock_swsscommon_table - xcvrd_down_fw_rsp_tbl = mock_swsscommon_table - - asic_index = 0 - task_download_firmware_thread = {} - port = "Ethernet0" - fvp = {"download_firmware": "null"} - - rc = handle_config_firmware_down_cmd_arg_tbl_notification( - fvp, xcvrd_down_fw_cmd_sts_tbl, xcvrd_down_fw_rsp_tbl, asic_index, port, task_download_firmware_thread) - assert(rc == -1) - - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('os.path.isfile', MagicMock(return_value=True)) - def test_handle_config_firmware_acti_cmd_arg_tbl_notification_no_port(self, mock_swsscommon_table): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_down_fw_cmd_sts_tbl = mock_swsscommon_table - xcvrd_down_fw_rsp_tbl = mock_swsscommon_table - xcvrd_acti_fw_cmd_arg_tbl = mock_swsscommon_table - - asic_index = 0 - task_download_firmware_thread = {} - port = "Ethernet0" - fvp = {"activate_firmware": "null"} - - rc = handle_config_firmware_acti_cmd_arg_tbl_notification( - fvp, xcvrd_down_fw_cmd_sts_tbl, xcvrd_down_fw_rsp_tbl, xcvrd_acti_fw_cmd_arg_tbl, asic_index, port) - assert(rc == -1) - - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('os.path.isfile', MagicMock(return_value=True)) - def test_handle_config_firmware_acti_cmd_arg_tbl_notification_else_condition(self, mock_swsscommon_table): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_down_fw_cmd_sts_tbl = mock_swsscommon_table - xcvrd_down_fw_rsp_tbl = mock_swsscommon_table - xcvrd_acti_fw_cmd_arg_tbl = mock_swsscommon_table - - asic_index = 0 - task_download_firmware_thread = {} - port = "Ethernet0" - fvp = {"down_firmware": "null"} - - rc = handle_config_firmware_acti_cmd_arg_tbl_notification( - fvp, xcvrd_down_fw_cmd_sts_tbl, xcvrd_down_fw_rsp_tbl, xcvrd_acti_fw_cmd_arg_tbl, asic_index, port) - assert(rc == None) - - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "activate_firmware", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('os.path.isfile', MagicMock(return_value=True)) - @patch('time.sleep', MagicMock(return_value=True)) - def test_handle_config_firmware_acti_cmd_arg_tbl_notification_with_instance(self, port_instance, mock_swsscommon_table, port_instance_helper): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_down_fw_cmd_sts_tbl = mock_swsscommon_table - xcvrd_down_fw_rsp_tbl = mock_swsscommon_table - xcvrd_acti_fw_cmd_arg_tbl = mock_swsscommon_table - port_instance = MagicMock() - port_instance.activate_firmware = MagicMock(return_value=True) - thread_instance = MagicMock() - thread_instance.start = MagicMock() - thread_obj = thread_instance - port_instance_helper = port_instance - - asic_index = 0 - task_download_firmware_thread = {} - port = "Ethernet0" - fvp = {"activate_firmware": "null"} - - rc = handle_config_firmware_acti_cmd_arg_tbl_notification( - fvp, xcvrd_down_fw_cmd_sts_tbl, xcvrd_down_fw_rsp_tbl, xcvrd_acti_fw_cmd_arg_tbl, asic_index, port) - assert(rc == None) - - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('os.path.isfile', MagicMock(return_value=True)) - def test_handle_config_firmware_acti_cmd_arg_tbl_notification_no_instance(self, mock_swsscommon_table): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_down_fw_cmd_sts_tbl = mock_swsscommon_table - xcvrd_down_fw_rsp_tbl = mock_swsscommon_table - xcvrd_acti_fw_cmd_arg_tbl = mock_swsscommon_table - - asic_index = 0 - task_download_firmware_thread = {} - port = "Ethernet0" - fvp = {"activate_firmware": "null"} - - rc = handle_config_firmware_acti_cmd_arg_tbl_notification( - fvp, xcvrd_down_fw_cmd_sts_tbl, xcvrd_down_fw_rsp_tbl, xcvrd_acti_fw_cmd_arg_tbl, asic_index, port) - assert(rc == -1) - - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('os.path.isfile', MagicMock(return_value=True)) - def test_handle_show_firmware_show_cmd_arg_tbl_notification_no_port(self, mock_swsscommon_table): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_down_fw_cmd_sts_tbl = mock_swsscommon_table - xcvrd_down_fw_rsp_tbl = mock_swsscommon_table - xcvrd_acti_fw_cmd_arg_tbl = mock_swsscommon_table - xcvrd_show_fw_res_tbl = mock_swsscommon_table - - asic_index = 0 - task_download_firmware_thread = {} - port = "Ethernet0" - fvp = {"firmware_version": "null"} - - rc = handle_show_firmware_show_cmd_arg_tbl_notification( - fvp, xcvrd_down_fw_cmd_sts_tbl, xcvrd_down_fw_rsp_tbl, xcvrd_show_fw_res_tbl, asic_index, port) - assert(rc == -1) - - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('os.path.isfile', MagicMock(return_value=True)) - def test_handle_show_firmware_show_cmd_arg_tbl_notification_else_condition(self, mock_swsscommon_table): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_down_fw_cmd_sts_tbl = mock_swsscommon_table - xcvrd_down_fw_rsp_tbl = mock_swsscommon_table - xcvrd_acti_fw_cmd_arg_tbl = mock_swsscommon_table - xcvrd_show_fw_res_tbl = mock_swsscommon_table - - asic_index = 0 - task_download_firmware_thread = {} - port = "Ethernet0" - fvp = {"down_firmware": "null"} - - rc = handle_show_firmware_show_cmd_arg_tbl_notification( - fvp, xcvrd_down_fw_cmd_sts_tbl, xcvrd_down_fw_rsp_tbl, xcvrd_show_fw_res_tbl, asic_index, port) - assert(rc == None) - - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "activate_firmware", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('os.path.isfile', MagicMock(return_value=True)) - @patch('time.sleep', MagicMock(return_value=True)) - def test_handle_show_firmware_show_cmd_arg_tbl_notification_with_instance(self, mock_swsscommon_table, platform_sfputil): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_down_fw_cmd_sts_tbl = mock_swsscommon_table - xcvrd_down_fw_rsp_tbl = mock_swsscommon_table - xcvrd_acti_fw_cmd_arg_tbl = mock_swsscommon_table - xcvrd_show_fw_res_tbl = mock_swsscommon_table - asic_index = 0 - task_download_firmware_thread = {} - port = "Ethernet0" - platform_sfputil.get_asic_id_for_logical_port = 0 - fvp = {"firmware_version": "null"} - - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - class PortInstanceHelper(): - def __init__(self): - self.EEPROM_ERROR = -1 - self.TARGET_NIC = 1 - self.TARGET_TOR_A = 1 - self.TARGET_TOR_B = 1 - self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - self.FIRMWARE_DOWNLOAD_STATUS_FAILED = 2 - self.download_firmware_status = 0 - self.MUX_TOGGLE_STATUS_INPROGRESS = 1 - self.MUX_TOGGLE_STATUS_FAILED = 2 - self.MUX_TOGGLE_STATUS_NOT_INITIATED_OR_FINISHED = 2 - self.mux_toggle_status = 0 - self.SWITCH_COUNT_MANUAL = "manual" - self.SWITCH_COUNT_AUTO = "auto" - - def get_read_side(self): - return 1 - - # Defining function without self argument creates an exception, - # which is what we want for this test. - def get_mux_direction(): - pass - - patched_util.get.return_value = PortInstanceHelper() - rc = handle_show_firmware_show_cmd_arg_tbl_notification( - fvp, xcvrd_down_fw_cmd_sts_tbl, xcvrd_down_fw_rsp_tbl, xcvrd_show_fw_res_tbl, asic_index, port) - assert(rc == None) - - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('os.path.isfile', MagicMock(return_value=True)) - def test_handle_show_firmware_show_cmd_arg_tbl_notification_no_instance(self, mock_swsscommon_table): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_down_fw_cmd_sts_tbl = mock_swsscommon_table - xcvrd_down_fw_rsp_tbl = mock_swsscommon_table - xcvrd_acti_fw_cmd_arg_tbl = mock_swsscommon_table - xcvrd_show_fw_res_tbl = mock_swsscommon_table - - asic_index = 0 - task_download_firmware_thread = {} - port = "Ethernet0" - fvp = {"firmware_version": "null"} - - rc = handle_show_firmware_show_cmd_arg_tbl_notification( - fvp, xcvrd_down_fw_cmd_sts_tbl, xcvrd_down_fw_rsp_tbl, xcvrd_show_fw_res_tbl, asic_index, port) - assert(rc == -1) - - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('os.path.isfile', MagicMock(return_value=True)) - def test_handle_config_mux_switchmode_cmd_arg_tbl_notification_no_port(self, mock_swsscommon_table): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_config_hwmode_swmode_cmd_sts_tbl = mock_swsscommon_table - xcvrd_config_hwmode_swmode_rsp_tbl = mock_swsscommon_table - xcvrd_acti_fw_cmd_arg_tbl = mock_swsscommon_table - xcvrd_show_fw_res_tbl = mock_swsscommon_table - - asic_index = 0 - task_download_firmware_thread = {} - port = "Ethernet0" - fvp = {"config": "null"} - - rc = handle_config_mux_switchmode_arg_tbl_notification( - fvp, xcvrd_config_hwmode_swmode_cmd_sts_tbl, xcvrd_config_hwmode_swmode_rsp_tbl, asic_index, port) - assert(rc == -1) - - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('os.path.isfile', MagicMock(return_value=True)) - def test_handle_config_mux_switchmode_cmd_arg_tbl_notification_else_condition(self, mock_swsscommon_table): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_config_hwmode_swmode_cmd_sts_tbl = mock_swsscommon_table - xcvrd_config_hwmode_swmode_rsp_tbl = mock_swsscommon_table - - asic_index = 0 - task_download_firmware_thread = {} - port = "Ethernet0" - fvp = {"down_firmware": "null"} - - rc = handle_config_mux_switchmode_arg_tbl_notification( - fvp, xcvrd_config_hwmode_swmode_cmd_sts_tbl, xcvrd_config_hwmode_swmode_rsp_tbl, asic_index, port) - assert(rc == None) - - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "activate_firmware", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('os.path.isfile', MagicMock(return_value=True)) - @patch('time.sleep', MagicMock(return_value=True)) - def test_handle_config_mux_switchmode_cmd_arg_tbl_notification_with_instance_manual(self, mock_swsscommon_table, platform_sfputil): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_config_hwmode_swmode_cmd_sts_tbl = mock_swsscommon_table - xcvrd_config_hwmode_swmode_rsp_tbl = mock_swsscommon_table - asic_index = 0 - task_download_firmware_thread = {} - port = "Ethernet0" - platform_sfputil.get_asic_id_for_logical_port = 0 - fvp = {"config": "manual"} - - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - class PortInstanceHelper(): - def __init__(self): - self.EEPROM_ERROR = -1 - self.TARGET_NIC = 1 - self.TARGET_TOR_A = 1 - self.TARGET_TOR_B = 1 - self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - self.FIRMWARE_DOWNLOAD_STATUS_FAILED = 2 - self.download_firmware_status = 0 - self.SWITCH_COUNT_MANUAL = "manual" - self.SWITCH_COUNT_AUTO = "auto" - self.SWITCHING_MODE_MANUAL = "manual" - - def get_read_side(self): - return 1 - - def set_switching_mode(self, mode): - return True - - # Defining function without self argument creates an exception, - # which is what we want for this test. - def get_mux_direction(): - pass - - patched_util.get.return_value = PortInstanceHelper() - rc = handle_config_mux_switchmode_arg_tbl_notification( - fvp, xcvrd_config_hwmode_swmode_cmd_sts_tbl, xcvrd_config_hwmode_swmode_rsp_tbl, asic_index, port) - assert(rc == None) - - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('os.path.isfile', MagicMock(return_value=True)) - def test_handle_config_mux_switchmode_cmd_arg_tbl_notification_no_instance(self, mock_swsscommon_table): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_config_hwmode_swmode_cmd_sts_tbl = mock_swsscommon_table - xcvrd_config_hwmode_swmode_rsp_tbl = mock_swsscommon_table - xcvrd_show_hwmode_swmode_cmd_sts_tbl = mock_swsscommon_table - xcvrd_show_hwmode_swmode_rsp_tbl = mock_swsscommon_table - - asic_index = 0 - task_download_firmware_thread = {} - port = "Ethernet0" - fvp = {"config": "manual"} - - rc = handle_config_mux_switchmode_arg_tbl_notification( - fvp, xcvrd_config_hwmode_swmode_cmd_sts_tbl, xcvrd_config_hwmode_swmode_rsp_tbl, asic_index, port) - assert(rc == -1) - - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "activate_firmware", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('os.path.isfile', MagicMock(return_value=True)) - @patch('time.sleep', MagicMock(return_value=True)) - def test_handle_config_mux_switchmode_cmd_arg_tbl_notification_with_instance_auto(self, mock_swsscommon_table, platform_sfputil): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_config_hwmode_swmode_cmd_sts_tbl = mock_swsscommon_table - xcvrd_config_hwmode_swmode_rsp_tbl = mock_swsscommon_table - xcvrd_show_hwmode_swmode_cmd_sts_tbl = mock_swsscommon_table - xcvrd_show_hwmode_swmode_rsp_tbl = mock_swsscommon_table - asic_index = 0 - task_download_firmware_thread = {} - port = "Ethernet0" - platform_sfputil.get_asic_id_for_logical_port = 0 - fvp = {"config": "auto"} - - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - class PortInstanceHelper(): - def __init__(self): - self.EEPROM_ERROR = -1 - self.TARGET_NIC = 1 - self.TARGET_TOR_A = 1 - self.TARGET_TOR_B = 1 - self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - self.FIRMWARE_DOWNLOAD_STATUS_FAILED = 2 - self.download_firmware_status = 0 - self.SWITCH_COUNT_MANUAL = "manual" - self.SWITCH_COUNT_AUTO = "auto" - self.SWITCHING_MODE_MANUAL = "manual" - self.SWITCHING_MODE_AUTO = "auto" - - def get_read_side(self): - return 1 - - def set_switching_mode(self, mode): - return True - - # Defining function without self argument creates an exception, - # which is what we want for this test. - def get_mux_direction(): - pass - - patched_util.get.return_value = PortInstanceHelper() - rc = handle_config_mux_switchmode_arg_tbl_notification( - fvp, xcvrd_config_hwmode_swmode_cmd_sts_tbl, xcvrd_config_hwmode_swmode_rsp_tbl, asic_index, port) - assert(rc == None) - - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('os.path.isfile', MagicMock(return_value=True)) - def test_handle_show_mux_switchmode_cmd_arg_tbl_notification_no_port(self, mock_swsscommon_table): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_config_hwmode_swmode_cmd_sts_tbl = mock_swsscommon_table - xcvrd_config_hwmode_swmode_rsp_tbl = mock_swsscommon_table - xcvrd_show_hwmode_swmode_cmd_sts_tbl = mock_swsscommon_table - xcvrd_show_hwmode_swmode_rsp_tbl = mock_swsscommon_table - - asic_index = 0 - task_download_firmware_thread = {} - port = "Ethernet0" - fvp = {"state": "null"} - - rc = handle_show_hwmode_swmode_cmd_arg_tbl_notification( - fvp, xcvrd_show_hwmode_swmode_cmd_sts_tbl, xcvrd_show_hwmode_swmode_rsp_tbl, asic_index, port) - assert(rc == -1) - - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('os.path.isfile', MagicMock(return_value=True)) - def test_handle_show_mux_switchmode_cmd_arg_tbl_notification_else_condition(self, mock_swsscommon_table): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_config_hwmode_swmode_cmd_sts_tbl = mock_swsscommon_table - xcvrd_config_hwmode_swmode_rsp_tbl = mock_swsscommon_table - xcvrd_show_hwmode_swmode_cmd_sts_tbl = mock_swsscommon_table - xcvrd_show_hwmode_swmode_rsp_tbl = mock_swsscommon_table - - asic_index = 0 - task_download_firmware_thread = {} - port = "Ethernet0" - fvp = {"down_firmware": "null"} - - rc = handle_show_hwmode_swmode_cmd_arg_tbl_notification( - fvp, xcvrd_show_hwmode_swmode_cmd_sts_tbl, xcvrd_show_hwmode_swmode_rsp_tbl, asic_index, port) - assert(rc == None) - - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "activate_firmware", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('os.path.isfile', MagicMock(return_value=True)) - @patch('time.sleep', MagicMock(return_value=True)) - def test_handle_show_mux_switchmode_cmd_arg_tbl_notification_with_instance_manual(self, mock_swsscommon_table, platform_sfputil): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_config_hwmode_swmode_cmd_sts_tbl = mock_swsscommon_table - xcvrd_config_hwmode_swmode_rsp_tbl = mock_swsscommon_table - xcvrd_show_hwmode_swmode_cmd_sts_tbl = mock_swsscommon_table - xcvrd_show_hwmode_swmode_rsp_tbl = mock_swsscommon_table - asic_index = 0 - task_download_firmware_thread = {} - port = "Ethernet0" - platform_sfputil.get_asic_id_for_logical_port = 0 - fvp = {"state": "manual"} - - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - class PortInstanceHelper(): - def __init__(self): - self.EEPROM_ERROR = -1 - self.TARGET_NIC = 1 - self.TARGET_TOR_A = 1 - self.TARGET_TOR_B = 1 - self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - self.FIRMWARE_DOWNLOAD_STATUS_FAILED = 2 - self.download_firmware_status = 0 - self.SWITCH_COUNT_MANUAL = "manual" - self.SWITCH_COUNT_AUTO = 0 - self.SWITCHING_MODE_MANUAL = 0 - self.SWITCHING_MODE_AUTO = 1 - - def get_read_side(self): - return 1 - - def get_switching_mode(self): - return 0 - - # Defining function without self argument creates an exception, - # which is what we want for this test. - def get_mux_direction(): - pass - - patched_util.get.return_value = PortInstanceHelper() - rc = handle_show_hwmode_swmode_cmd_arg_tbl_notification( - fvp, xcvrd_show_hwmode_swmode_cmd_sts_tbl, xcvrd_show_hwmode_swmode_rsp_tbl, asic_index, port) - assert(rc == None) - - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('os.path.isfile', MagicMock(return_value=True)) - def test_handle_show_mux_switchmode_cmd_arg_tbl_notification_no_instance(self, mock_swsscommon_table): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_config_hwmode_swmode_cmd_sts_tbl = mock_swsscommon_table - xcvrd_config_hwmode_swmode_rsp_tbl = mock_swsscommon_table - xcvrd_show_hwmode_swmode_cmd_sts_tbl = mock_swsscommon_table - xcvrd_show_hwmode_swmode_rsp_tbl = mock_swsscommon_table - - asic_index = 0 - task_download_firmware_thread = {} - port = "Ethernet0" - fvp = {"state": "manual"} - - rc = handle_show_hwmode_swmode_cmd_arg_tbl_notification( - fvp, xcvrd_show_hwmode_swmode_cmd_sts_tbl, xcvrd_show_hwmode_swmode_rsp_tbl, asic_index, port) - assert(rc == -1) - - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "activate_firmware", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('os.path.isfile', MagicMock(return_value=True)) - @patch('time.sleep', MagicMock(return_value=True)) - def test_handle_show_mux_switchmode_cmd_arg_tbl_notification_with_instance_auto(self, mock_swsscommon_table, platform_sfputil): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_config_hwmode_swmode_cmd_sts_tbl = mock_swsscommon_table - xcvrd_config_hwmode_swmode_rsp_tbl = mock_swsscommon_table - xcvrd_show_hwmode_swmode_cmd_sts_tbl = mock_swsscommon_table - xcvrd_show_hwmode_swmode_rsp_tbl = mock_swsscommon_table - asic_index = 0 - task_download_firmware_thread = {} - port = "Ethernet0" - platform_sfputil.get_asic_id_for_logical_port = 0 - fvp = {"state": "auto"} - - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - class PortInstanceHelper(): - def __init__(self): - self.EEPROM_ERROR = -1 - self.TARGET_NIC = 1 - self.TARGET_TOR_A = 1 - self.TARGET_TOR_B = 1 - self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - self.FIRMWARE_DOWNLOAD_STATUS_FAILED = 2 - self.download_firmware_status = 0 - self.SWITCH_COUNT_MANUAL = "manual" - self.SWITCH_COUNT_AUTO = "auto" - self.SWITCHING_MODE_MANUAL = 0 - self.SWITCHING_MODE_AUTO = 1 - - def get_read_side(self): - return 1 - - def get_switching_mode(self): - return 1 - - # Defining function without self argument creates an exception, - # which is what we want for this test. - def get_mux_direction(): - pass - - patched_util.get.return_value = PortInstanceHelper() - rc = handle_show_hwmode_swmode_cmd_arg_tbl_notification( - fvp, xcvrd_show_hwmode_swmode_cmd_sts_tbl, xcvrd_show_hwmode_swmode_rsp_tbl, asic_index, port) - assert(rc == None) - - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('os.path.isfile', MagicMock(return_value=True)) - def test_handle_config_mux_state_cmd_arg_tbl_notification_no_port(self, mock_swsscommon_table): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_config_hwmode_state_cmd_sts_tbl = mock_swsscommon_table - xcvrd_config_hwmode_state_rsp_tbl = mock_swsscommon_table - - asic_index = 0 - task_download_firmware_thread = {} - port = "Ethernet0" - fvp = {"config": "active"} - - rc = handle_config_hwmode_state_cmd_arg_tbl_notification( - fvp, xcvrd_config_hwmode_state_cmd_sts_tbl, xcvrd_config_hwmode_state_rsp_tbl, asic_index, port) - assert(rc == -1) - - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('os.path.isfile', MagicMock(return_value=True)) - def test_handle_show_mux_switchmode_cmd_arg_tbl_notification_else_condition(self, mock_swsscommon_table): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_config_hwmode_state_cmd_sts_tbl = mock_swsscommon_table - xcvrd_config_hwmode_state_rsp_tbl = mock_swsscommon_table - - asic_index = 0 - task_download_firmware_thread = {} - port = "Ethernet0" - fvp = {"down_firmware": "null"} - - rc = handle_config_hwmode_state_cmd_arg_tbl_notification( - fvp, xcvrd_config_hwmode_state_cmd_sts_tbl, xcvrd_config_hwmode_state_rsp_tbl, asic_index, port) - assert(rc == None) - - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "activate_firmware", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('os.path.isfile', MagicMock(return_value=True)) - @patch('time.sleep', MagicMock(return_value=True)) - def test_handle_config_mux_state_cmd_arg_tbl_notification_with_instance_manual(self, mock_swsscommon_table, platform_sfputil): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_config_hwmode_state_cmd_sts_tbl = mock_swsscommon_table - xcvrd_config_hwmode_state_rsp_tbl = mock_swsscommon_table - asic_index = 0 - task_download_firmware_thread = {} - port = "Ethernet0" - platform_sfputil.get_asic_id_for_logical_port = 0 - fvp = {"config": "active"} - - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - class PortInstanceHelper(): - def __init__(self): - self.EEPROM_ERROR = -1 - self.TARGET_NIC = 1 - self.TARGET_TOR_A = 1 - self.TARGET_TOR_B = 1 - self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - self.FIRMWARE_DOWNLOAD_STATUS_FAILED = 2 - self.download_firmware_status = 0 - self.SWITCH_COUNT_MANUAL = "manual" - self.SWITCH_COUNT_AUTO = 0 - self.SWITCHING_MODE_MANUAL = 0 - self.SWITCHING_MODE_AUTO = 1 - - def get_read_side(self): - return 1 - - def get_switching_mode(self): - return 0 - - # Defining function without self argument creates an exception, - # which is what we want for this test. - def get_mux_direction(): - pass - - patched_util.get.return_value = PortInstanceHelper() - rc = handle_config_hwmode_state_cmd_arg_tbl_notification( - fvp, xcvrd_config_hwmode_state_cmd_sts_tbl, xcvrd_config_hwmode_state_rsp_tbl, asic_index, port) - assert(rc == None) - - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('os.path.isfile', MagicMock(return_value=True)) - def test_handle_config_mux_state_cmd_arg_tbl_notification_no_instance(self, mock_swsscommon_table): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_config_hwmode_state_cmd_sts_tbl = mock_swsscommon_table - xcvrd_config_hwmode_state_rsp_tbl = mock_swsscommon_table - - asic_index = 0 - task_download_firmware_thread = {} - port = "Ethernet0" - fvp = {"config": "active"} - - rc = handle_config_hwmode_state_cmd_arg_tbl_notification( - fvp, xcvrd_config_hwmode_state_cmd_sts_tbl, xcvrd_config_hwmode_state_rsp_tbl, asic_index, port) - assert(rc == -1) - - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "activate_firmware", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('os.path.isfile', MagicMock(return_value=True)) - @patch('time.sleep', MagicMock(return_value=True)) - def test_handle_config_mux_state_cmd_arg_tbl_notification_with_instance_auto(self, mock_swsscommon_table, platform_sfputil): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_config_hwmode_state_cmd_sts_tbl = mock_swsscommon_table - xcvrd_config_hwmode_state_rsp_tbl = mock_swsscommon_table - asic_index = 0 - task_download_firmware_thread = {} - port = "Ethernet0" - platform_sfputil.get_asic_id_for_logical_port = 0 - fvp = {"config": "active"} - - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - class PortInstanceHelper(): - def __init__(self): - self.EEPROM_ERROR = -1 - self.TARGET_NIC = 1 - self.TARGET_TOR_A = 1 - self.TARGET_TOR_B = 1 - self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - self.FIRMWARE_DOWNLOAD_STATUS_FAILED = 2 - self.download_firmware_status = 0 - self.SWITCH_COUNT_MANUAL = "manual" - self.SWITCH_COUNT_AUTO = "auto" - self.SWITCHING_MODE_MANUAL = 0 - self.SWITCHING_MODE_AUTO = 1 - - def get_read_side(self): - return 1 - - def get_switching_mode(self): - return 1 - - # Defining function without self argument creates an exception, - # which is what we want for this test. - def get_mux_direction(): - pass - - patched_util.get.return_value = PortInstanceHelper() - rc = handle_config_hwmode_state_cmd_arg_tbl_notification( - fvp, xcvrd_config_hwmode_state_cmd_sts_tbl, xcvrd_config_hwmode_state_rsp_tbl, asic_index, port) - assert(rc == None) - - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('os.path.isfile', MagicMock(return_value=True)) - def test_handle_show_mux_state_cmd_arg_tbl_notification_no_port(self, mock_swsscommon_table): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_show_hwmode_dir_cmd_sts_tbl = mock_swsscommon_table - xcvrd_show_hwmode_dir_rsp_tbl = mock_swsscommon_table - xcvrd_show_hwmode_dir_res_tbl = mock_swsscommon_table - - asic_index = 0 - task_download_firmware_thread = {} - port = "Ethernet0" - fvp = {"state": "active"} - - rc = handle_show_hwmode_state_cmd_arg_tbl_notification( - fvp, xcvrd_show_hwmode_dir_cmd_sts_tbl, xcvrd_show_hwmode_dir_rsp_tbl, xcvrd_show_hwmode_dir_res_tbl, asic_index, port) - assert(rc == -1) - - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('os.path.isfile', MagicMock(return_value=True)) - def test_handle_show_mux_state_cmd_arg_tbl_notification_else_condition(self, mock_swsscommon_table): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_show_hwmode_dir_cmd_sts_tbl = mock_swsscommon_table - xcvrd_show_hwmode_dir_rsp_tbl = mock_swsscommon_table - xcvrd_show_hwmode_dir_res_tbl = mock_swsscommon_table - xcvrd_config_hwmode_state_cmd_sts_tbl = mock_swsscommon_table - xcvrd_config_hwmode_state_rsp_tbl = mock_swsscommon_table - - asic_index = 0 - task_download_firmware_thread = {} - port = "Ethernet0" - fvp = {"down_firmware": "null"} - - rc = handle_show_hwmode_state_cmd_arg_tbl_notification( - fvp, xcvrd_show_hwmode_dir_cmd_sts_tbl, xcvrd_show_hwmode_dir_rsp_tbl, xcvrd_show_hwmode_dir_res_tbl, asic_index, port) - assert(rc == None) - - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "activate_firmware", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('os.path.isfile', MagicMock(return_value=True)) - @patch('time.sleep', MagicMock(return_value=True)) - def test_handle_show_mux_state_cmd_arg_tbl_notification_with_instance_manual(self, mock_swsscommon_table, platform_sfputil): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_show_hwmode_dir_cmd_sts_tbl = mock_swsscommon_table - xcvrd_show_hwmode_dir_rsp_tbl = mock_swsscommon_table - xcvrd_show_hwmode_dir_res_tbl = mock_swsscommon_table - xcvrd_config_hwmode_state_cmd_sts_tbl = mock_swsscommon_table - xcvrd_config_hwmode_state_rsp_tbl = mock_swsscommon_table - asic_index = 0 - task_download_firmware_thread = {} - port = "Ethernet0" - platform_sfputil.get_asic_id_for_logical_port = 0 - fvp = {"state": "active"} - - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - class PortInstanceHelper(): - def __init__(self): - self.EEPROM_ERROR = -1 - self.TARGET_NIC = 1 - self.TARGET_TOR_A = 1 - self.TARGET_TOR_B = 1 - self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - self.FIRMWARE_DOWNLOAD_STATUS_FAILED = 2 - self.download_firmware_status = 0 - self.SWITCH_COUNT_MANUAL = "manual" - self.SWITCH_COUNT_AUTO = 0 - self.SWITCHING_MODE_MANUAL = 0 - self.SWITCHING_MODE_AUTO = 1 - - def get_read_side(self): - return 1 - - def get_mux_direction(self): - return 1 - - def get_switching_mode(self): - return 0 - - patched_util.get.return_value = PortInstanceHelper() - rc = handle_show_hwmode_state_cmd_arg_tbl_notification( - fvp, xcvrd_show_hwmode_dir_cmd_sts_tbl, xcvrd_show_hwmode_dir_rsp_tbl, xcvrd_show_hwmode_dir_res_tbl, asic_index, port) - assert(rc == None) - - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('os.path.isfile', MagicMock(return_value=True)) - def test_handle_show_mux_state_cmd_arg_tbl_notification_no_instance(self, mock_swsscommon_table): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_show_hwmode_dir_cmd_sts_tbl = mock_swsscommon_table - xcvrd_show_hwmode_dir_rsp_tbl = mock_swsscommon_table - xcvrd_show_hwmode_dir_res_tbl = mock_swsscommon_table - - asic_index = 0 - task_download_firmware_thread = {} - port = "Ethernet0" - fvp = {"state": "active"} - - rc = handle_show_hwmode_state_cmd_arg_tbl_notification( - fvp, xcvrd_show_hwmode_dir_cmd_sts_tbl, xcvrd_show_hwmode_dir_rsp_tbl, xcvrd_show_hwmode_dir_res_tbl, asic_index, port) - assert(rc == -1) - - @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') - @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "activate_firmware", {"modex": "0", - "lane_mask": "0", - "direction": "0"}))) - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) - @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - @patch('os.path.isfile', MagicMock(return_value=True)) - @patch('time.sleep', MagicMock(return_value=True)) - def test_handle_show_mux_state_cmd_arg_tbl_notification_with_instance_auto(self, mock_swsscommon_table, platform_sfputil): - - mock_table = MagicMock() - mock_swsscommon_table.return_value = mock_table - - xcvrd_config_hwmode_state_cmd_sts_tbl = mock_swsscommon_table - xcvrd_config_hwmode_state_rsp_tbl = mock_swsscommon_table - xcvrd_show_hwmode_dir_cmd_sts_tbl = mock_swsscommon_table - xcvrd_show_hwmode_dir_rsp_tbl = mock_swsscommon_table - xcvrd_show_hwmode_dir_res_tbl = mock_swsscommon_table - asic_index = 0 - task_download_firmware_thread = {} - port = "Ethernet0" - platform_sfputil.get_asic_id_for_logical_port = 0 - fvp = {"state": "active"} - - with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: - class PortInstanceHelper(): - def __init__(self): - self.EEPROM_ERROR = -1 - self.TARGET_NIC = 1 - self.TARGET_TOR_A = 1 - self.TARGET_TOR_B = 1 - self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 - self.FIRMWARE_DOWNLOAD_STATUS_FAILED = 2 - self.download_firmware_status = 0 - self.SWITCH_COUNT_MANUAL = "manual" - self.SWITCH_COUNT_AUTO = "auto" - self.SWITCHING_MODE_MANUAL = 0 - self.SWITCHING_MODE_AUTO = 1 - - def get_read_side(self): - return 1 - - def get_switching_mode(self): - return 1 - - def get_mux_direction(self): - return 2 - - patched_util.get.return_value = PortInstanceHelper() - rc = handle_show_hwmode_state_cmd_arg_tbl_notification( - fvp, xcvrd_show_hwmode_dir_cmd_sts_tbl, xcvrd_show_hwmode_dir_rsp_tbl, xcvrd_show_hwmode_dir_res_tbl, asic_index, port) - assert(rc == None) - - def test_get_mux_cable_static_info_without_presence(self): - - rc = get_muxcable_static_info_without_presence() - - assert(rc['read_side'] == '-1') - assert(rc['nic_lane1_precursor1'] == 'N/A') - assert(rc['nic_lane1_precursor1'] == 'N/A') - assert(rc['nic_lane1_postcursor1'] == 'N/A') - assert(rc['nic_lane1_postcursor2'] == 'N/A') - assert(rc != None) - - - @patch('ycable.ycable_utilities.y_cable_helper.disable_telemetry') - def test_handle_ycable_enable_disable_tel_notification(self, patch): - - fvp_m = {"disable_telemetry": "True"} - rc = handle_ycable_enable_disable_tel_notification(fvp_m, "Y_CABLE") - assert(rc == None) - - def test_handle_ycable_enable_disable_tel_notification_probe(self): - - fvp_m = {"log_verbosity": "notice"} - rc = handle_ycable_enable_disable_tel_notification(fvp_m, "Y_CABLE") - assert(rc == None) - - fvp_m = {"log_verbosity": "debug"} - rc = handle_ycable_enable_disable_tel_notification(fvp_m, "Y_CABLE") - assert(rc == None) + fvp_m = {"log_verbosity": "debug"} + rc = handle_ycable_enable_disable_tel_notification(fvp_m, "Y_CABLE") + assert(rc == None) diff --git a/sonic-ycabled/ycable/ycable_utilities/y_cable_helper.py b/sonic-ycabled/ycable/ycable_utilities/y_cable_helper.py index 2933a7769..57f99bc47 100644 --- a/sonic-ycabled/ycable/ycable_utilities/y_cable_helper.py +++ b/sonic-ycabled/ycable/ycable_utilities/y_cable_helper.py @@ -2526,106 +2526,6 @@ def handle_show_hwmode_state_cmd_arg_tbl_notification(fvp, xcvrd_show_hwmode_dir else: helper_logger.log_warning("Error: Wrong input param for cli command show mux hwmode muxdirection logical port {}".format(port)) set_result_and_delete_port('state', 'unknown', xcvrd_show_hwmode_dir_cmd_sts_tbl[asic_index], xcvrd_show_hwmode_dir_rsp_tbl[asic_index], port) - helper_logger.log_warning("command key not present in the notification fwd state handling port {}".format(port)) - - -def handle_hw_mux_cable_table_grpc_notification(fvp, hw_mux_cable_tbl, asic_index, grpc_metrics_tbl, peer, port): - - # entering this section signifies a gRPC start for state - # change request from swss so initiate recording in mux_metrics table - time_start = datetime.datetime.utcnow().strftime("%Y-%b-%d %H:%M:%S.%f") - # This check might be redundant, to check, the presence of this Port in keys - # in logical_port_list but keep for now for coherency - # also skip checking in logical_port_list inside sfp_util - - helper_logger.log_debug("Y_CABLE_DEBUG:recevied the notification mux hw state") - fvp_dict = dict(fvp) - toggle_side = "self" - - if "state" in fvp_dict: - # got a state change - new_state = fvp_dict["state"] - requested_status = new_state - if requested_status in ["active", "standby"]: - - (status, fvs) = hw_mux_cable_tbl[asic_index].get(port) - if status is False: - helper_logger.log_warning("Could not retreive fieldvalue pairs for {}, inside state_db table {}".format( - port, hw_mux_cable_tbl[asic_index].getTableName())) - return - helper_logger.log_debug("Y_CABLE_DEBUG processing the notification mux hw state port {}".format(port)) - mux_port_dict = dict(fvs) - old_state = mux_port_dict.get("state", None) - read_side = mux_port_dict.get("read_side", None) - curr_read_side = int(read_side) - # Now whatever is the state requested, call gRPC to update the soc state appropriately - if peer == True: - curr_read_side = 1-int(read_side) - toggle_side = "peer" - - if new_state == "active": - state_req = 1 - elif new_state == "standby": - state_req = 0 - - helper_logger.log_notice( - "calling RPC for hw mux_cable set state ispeer = {} port {} portid {} read_side {} state requested {}".format(peer, port, curr_read_side, read_side, new_state)) - - request = linkmgr_grpc_driver_pb2.AdminRequest(portid=[curr_read_side], state=[state_req]) - - stub = grpc_port_stubs.get(port, None) - if stub is None: - helper_logger.log_debug("Y_CABLE_DEBUG:stub is None for performing hw mux RPC port {}".format(port)) - retry_setup_grpc_channel_for_port(port, asic_index) - stub = grpc_port_stubs.get(port, None) - if stub is None: - helper_logger.log_warning( - "gRPC channel was initially not setup for performing hw mux set state RPC port {}, trying to set gRPC channel again also did not work, posting unknown state for stateDB:HW_MUX_CABLE_TABLE".format(port)) - active_side = new_state = 'unknown' - time_end = datetime.datetime.utcnow().strftime("%Y-%b-%d %H:%M:%S.%f") - fvs_metrics = swsscommon.FieldValuePairs([('xcvrd_switch_{}_{}_start'.format(toggle_side, new_state), str(time_start)), - ('xcvrd_switch_{}_{}_end'.format(toggle_side, new_state), str(time_end))]) - grpc_metrics_tbl[asic_index].set(port, fvs_metrics) - - fvs_updated = swsscommon.FieldValuePairs([('state', new_state), - ('read_side', read_side), - ('active_side', str(active_side))]) - hw_mux_cable_tbl[asic_index].set(port, fvs_updated) - return - - ret, response = try_grpc(stub.SetAdminForwardingPortState, SET_ADMIN_FORWARDING_TIMEOUT, request) - - if response is not None: - # Debug only, remove this section once Server side is Finalized - hw_response_port_ids = response.portid - hw_response_port_ids_state = response.state - helper_logger.log_notice( - "Set admin state RPC received response port {} port ids = {} curr_read_side {} read_side {}".format(port, hw_response_port_ids, curr_read_side, read_side)) - helper_logger.log_notice( - "Set admin state RPC received response port {} state values = {} curr_read_side {} read_side {}".format(port, hw_response_port_ids_state, curr_read_side, read_side)) - else: - helper_logger.log_notice("response was none hw_mux_cable_table_grpc_notification {} ".format(port)) - - active_side = parse_grpc_response_hw_mux_cable_change_state(ret, response, curr_read_side, port) - - if active_side == "unknown": - helper_logger.log_warning( - "ERR: Got a change event for updating gRPC but could not toggle the mux-direction for port {} state from {} to {}, writing unknown".format(port, old_state, new_state)) - new_state = 'unknown' - - time_end = datetime.datetime.utcnow().strftime("%Y-%b-%d %H:%M:%S.%f") - fvs_metrics = swsscommon.FieldValuePairs([('xcvrd_switch_{}_{}_start'.format(toggle_side, new_state), str(time_start)), - ('xcvrd_switch_{}_{}_end'.format(toggle_side, new_state), str(time_end))]) - grpc_metrics_tbl[asic_index].set(port, fvs_metrics) - - fvs_updated = swsscommon.FieldValuePairs([('state', new_state), - ('read_side', read_side), - ('active_side', str(active_side))]) - hw_mux_cable_tbl[asic_index].set(port, fvs_updated) - helper_logger.log_debug("Y_CABLE_DEBUG: processed the notification hw mux state cleanly {}".format(port)) - else: - helper_logger.log_info("Got a change event on port {} of table {} that does not contain state".format( - port, swsscommon.APP_HW_MUX_CABLE_TABLE_NAME)) def handle_ycable_enable_disable_tel_notification(fvp_m, key): From 48f65aaf37d85682e75296675a76a636b08b550e Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Tue, 9 Aug 2022 23:56:31 +0000 Subject: [PATCH 3/7] fix the diff Signed-off-by: vaibhav-dahiya --- sonic-ycabled/tests/test_y_cable_helper.py | 1 - 1 file changed, 1 deletion(-) diff --git a/sonic-ycabled/tests/test_y_cable_helper.py b/sonic-ycabled/tests/test_y_cable_helper.py index bab9a95ad..e0a4e8462 100644 --- a/sonic-ycabled/tests/test_y_cable_helper.py +++ b/sonic-ycabled/tests/test_y_cable_helper.py @@ -4744,7 +4744,6 @@ def test_get_mux_cable_static_info_without_presence(self): assert(rc['nic_lane1_precursor1'] == 'N/A') assert(rc['nic_lane1_postcursor1'] == 'N/A') assert(rc['nic_lane1_postcursor2'] == 'N/A') - assert(rc != None) @patch('ycable.ycable_utilities.y_cable_helper.disable_telemetry') From b19fd67715ea99ed36eb1d698c8ae38cfc016c1e Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Wed, 10 Aug 2022 17:49:12 +0000 Subject: [PATCH 4/7] fix pipelines Signed-off-by: vaibhav-dahiya --- azure-pipelines.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 3dc3d610e..8d4ce09d5 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -64,7 +64,7 @@ jobs: pipeline: 1 artifact: sonic-buildimage.vs runVersion: 'latestFromBranch' - runBranch: 'refs/heads/master' + runBranch: 'refs/heads/202012' displayName: "Download artifacts from latest sonic-buildimage build" - script: | From 84e521c893b018fe9a496631fe2fc12b565a7215 Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Wed, 10 Aug 2022 17:53:35 +0000 Subject: [PATCH 5/7] try removing the dependency Signed-off-by: vaibhav-dahiya --- azure-pipelines.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 8d4ce09d5..b95d2bc95 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -64,7 +64,7 @@ jobs: pipeline: 1 artifact: sonic-buildimage.vs runVersion: 'latestFromBranch' - runBranch: 'refs/heads/202012' + runBranch: 'refs/heads/master' displayName: "Download artifacts from latest sonic-buildimage build" - script: | @@ -85,7 +85,6 @@ jobs: sudo pip2 install swsssdk-2.0.1-py2-none-any.whl sudo pip2 install sonic_py_common-1.0-py2-none-any.whl sudo pip2 install sonic_config_engine-1.0-py2-none-any.whl - sudo pip2 install sonic_platform_common-1.0-py2-none-any.whl sudo pip3 install swsssdk-2.0.1-py3-none-any.whl sudo pip3 install sonic_py_common-1.0-py3-none-any.whl sudo pip3 install sonic_yang_mgmt-1.0-py3-none-any.whl From 6c3df9a38cc68b74711cbd12cc785c78c94d476b Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Wed, 10 Aug 2022 18:38:06 +0000 Subject: [PATCH 6/7] try changing id Signed-off-by: vaibhav-dahiya --- azure-pipelines.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index b95d2bc95..c47c6f165 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -61,10 +61,10 @@ jobs: inputs: source: specific project: build - pipeline: 1 + pipeline: 142 artifact: sonic-buildimage.vs runVersion: 'latestFromBranch' - runBranch: 'refs/heads/master' + runBranch: 'refs/heads/202012' displayName: "Download artifacts from latest sonic-buildimage build" - script: | @@ -85,6 +85,7 @@ jobs: sudo pip2 install swsssdk-2.0.1-py2-none-any.whl sudo pip2 install sonic_py_common-1.0-py2-none-any.whl sudo pip2 install sonic_config_engine-1.0-py2-none-any.whl + sudo pip2 install sonic_platform_common-1.0-py2-none-any.whl sudo pip3 install swsssdk-2.0.1-py3-none-any.whl sudo pip3 install sonic_py_common-1.0-py3-none-any.whl sudo pip3 install sonic_yang_mgmt-1.0-py3-none-any.whl From 6037a25705fe83489e196738b40b145b3e2a2c21 Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Wed, 10 Aug 2022 19:15:23 +0000 Subject: [PATCH 7/7] remove buster path Signed-off-by: vaibhav-dahiya --- azure-pipelines.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index c47c6f165..31daea209 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -92,7 +92,7 @@ jobs: sudo pip3 install sonic_yang_models-1.0-py3-none-any.whl sudo pip3 install sonic_config_engine-1.0-py3-none-any.whl sudo pip3 install sonic_platform_common-1.0-py3-none-any.whl - workingDirectory: $(Pipeline.Workspace)/target/python-wheels/buster/ + workingDirectory: $(Pipeline.Workspace)/target/python-wheels/ displayName: 'Install Python dependencies' # Python 2