Skip to content

Commit

Permalink
[xcvrd] initial support for integrating vendor specfic class objects …
Browse files Browse the repository at this point in the history
…for calling Y-Cable API's inside xcvrd (sonic-net#197)

Signed-off-by: vaibhav-dahiya vdahiya@microsoft.com

Description
This PR integrates vendor specific class objects inside xcvrd for Y-Cable API's to be called.
Detailed designed document can be found sonic-net/SONiC#757

Motivation and Context
Basically xcvrd now has an interface for Y-Cable to interact with PMON docker and HOST
which can be uniform across all vendors. As part of this refactor, we will be moving towards a model where only xcvrd interacts with the cables/transceivers, and host-side processes will communicate with xcvrd rather than with the devices directly with Y-Cable.

How Has This Been Tested?
Ran the changes on Arista7050cx3 switch, making changes inside the container.

Signed-off-by: vaibhav-dahiya <vdahiya@microsoft.com>
  • Loading branch information
vdahiya12 committed Aug 25, 2021
1 parent f3fc1ea commit 6dc4002
Show file tree
Hide file tree
Showing 2 changed files with 1,381 additions and 214 deletions.
76 changes: 70 additions & 6 deletions sonic-xcvrd/tests/test_xcvrd.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,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 @@ -219,9 +223,9 @@ def test_init_port_sfp_status_tbl(self):
init_port_sfp_status_tbl(stop_event)

@patch('xcvrd.xcvrd_utilities.y_cable_helper.y_cable_platform_sfputil', MagicMock(return_value=[0]))
@patch('y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0]))
@patch('y_cable_helper._wrapper_get_presence', MagicMock(return_value=True))
@patch('y_cable_helper.get_muxcable_info', MagicMock(return_value={'tor_active': 'self',
@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))
@patch('xcvrd.xcvrd_utilities.y_cable_helper.get_muxcable_info', MagicMock(return_value={'tor_active': 'self',
'mux_direction': 'self',
'manual_switch_count': '7',
'auto_switch_count': '71',
Expand Down Expand Up @@ -257,10 +261,11 @@ 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('y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0]))
@patch('y_cable_helper._wrapper_get_presence', MagicMock(return_value=True))
@patch('y_cable_helper.get_muxcable_static_info', MagicMock(return_value={'read_side': 'self',
@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))
@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',
'nic_lane1_maincursor': '-1',
Expand Down Expand Up @@ -297,6 +302,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

0 comments on commit 6dc4002

Please sign in to comment.