Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[xcvrd] initial support for integrating vendor specfic class objects for calling Y-Cable API's inside xcvrd #197

Merged
merged 17 commits into from
Aug 25, 2021
68 changes: 66 additions & 2 deletions sonic-xcvrd/tests/test_xcvrd.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
daemon_base.db_connect = MagicMock()
swsscommon.Table = MagicMock()
swsscommon.ProducerStateTable = MagicMock()
swsscommon.SubscriberStateTable = MagicMock()
swsscommon.SonicDBConfig = MagicMock()
#swsscommon.Select = MagicMock()

sys.modules['sonic_y_cable'] = MagicMock()
sys.modules['sonic_y_cable.y_cable'] = MagicMock()

Expand Down Expand Up @@ -217,7 +221,7 @@ def test_init_port_sfp_status_tbl(self):

@patch('xcvrd.xcvrd_utilities.y_cable_helper.y_cable_platform_sfputil', MagicMock(return_value=[0]))
@patch('xcvrd.xcvrd_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0]))
@patch('xcvrd.xcvrd_utilities.y_cable_helper._wrapper_get_presence', MagicMock(return_value=True))
@patch('xcvrd.xcvrd_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True))
@patch('xcvrd.xcvrd_utilities.y_cable_helper.get_muxcable_info', MagicMock(return_value={'tor_active': 'self',
'mux_direction': 'self',
'manual_switch_count': '7',
Expand Down Expand Up @@ -254,9 +258,10 @@ def test_post_port_mux_info_to_db(self):
rc = post_port_mux_info_to_db(logical_port_name, mux_tbl)
assert(rc != -1)


@patch('xcvrd.xcvrd_utilities.y_cable_helper.y_cable_platform_sfputil', MagicMock(return_value=[0]))
@patch('xcvrd.xcvrd_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0]))
@patch('xcvrd.xcvrd_utilities.y_cable_helper._wrapper_get_presence', MagicMock(return_value=True))
@patch('xcvrd.xcvrd_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True))
@patch('xcvrd.xcvrd_utilities.y_cable_helper.get_muxcable_static_info', MagicMock(return_value={'read_side': 'self',
'nic_lane1_precursor1': '1',
'nic_lane1_precursor2': '-7',
Expand Down Expand Up @@ -294,6 +299,65 @@ def test_post_port_mux_static_info_to_db(self):
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_wrapper_get_transceiver_info(self):
with patch('xcvrd.xcvrd_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")

def test_y_cable_wrapper_get_presence(self):
with patch('xcvrd.xcvrd_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util:
patched_util.get_presence.return_value = True

presence = y_cable_wrapper_get_presence(1)

assert(presence == True)

@patch('xcvrd.xcvrd_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0]))
@patch('xcvrd.xcvrd_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")

assert(instance == 0)

@patch('xcvrd.xcvrd_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0]))
@patch('xcvrd.xcvrd_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True))
def test_get_ycable_port_instance_from_logical_port(self):

with patch('xcvrd.xcvrd_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 == 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)

def test_get_media_settings_key(self):
xcvr_info_dict = {
0: {
Expand Down
Loading