Skip to content

Commit e038bc2

Browse files
authored
[xcvrd] initial support for integrating vendor specfic class objects for calling Y-Cable API's inside xcvrd (sonic-net#197)
Signed-off-by: vaibhav-dahiya [email protected] 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 <[email protected]>
1 parent 57e3d78 commit e038bc2

File tree

2 files changed

+1378
-210
lines changed

2 files changed

+1378
-210
lines changed

sonic-xcvrd/tests/test_xcvrd.py

+66-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
daemon_base.db_connect = MagicMock()
1818
swsscommon.Table = MagicMock()
1919
swsscommon.ProducerStateTable = MagicMock()
20+
swsscommon.SubscriberStateTable = MagicMock()
21+
swsscommon.SonicDBConfig = MagicMock()
22+
#swsscommon.Select = MagicMock()
23+
2024
sys.modules['sonic_y_cable'] = MagicMock()
2125
sys.modules['sonic_y_cable.y_cable'] = MagicMock()
2226

@@ -217,7 +221,7 @@ def test_init_port_sfp_status_tbl(self):
217221

218222
@patch('xcvrd.xcvrd_utilities.y_cable_helper.y_cable_platform_sfputil', MagicMock(return_value=[0]))
219223
@patch('xcvrd.xcvrd_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0]))
220-
@patch('xcvrd.xcvrd_utilities.y_cable_helper._wrapper_get_presence', MagicMock(return_value=True))
224+
@patch('xcvrd.xcvrd_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True))
221225
@patch('xcvrd.xcvrd_utilities.y_cable_helper.get_muxcable_info', MagicMock(return_value={'tor_active': 'self',
222226
'mux_direction': 'self',
223227
'manual_switch_count': '7',
@@ -254,9 +258,10 @@ def test_post_port_mux_info_to_db(self):
254258
rc = post_port_mux_info_to_db(logical_port_name, mux_tbl)
255259
assert(rc != -1)
256260

261+
257262
@patch('xcvrd.xcvrd_utilities.y_cable_helper.y_cable_platform_sfputil', MagicMock(return_value=[0]))
258263
@patch('xcvrd.xcvrd_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0]))
259-
@patch('xcvrd.xcvrd_utilities.y_cable_helper._wrapper_get_presence', MagicMock(return_value=True))
264+
@patch('xcvrd.xcvrd_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True))
260265
@patch('xcvrd.xcvrd_utilities.y_cable_helper.get_muxcable_static_info', MagicMock(return_value={'read_side': 'self',
261266
'nic_lane1_precursor1': '1',
262267
'nic_lane1_precursor2': '-7',
@@ -294,6 +299,65 @@ def test_post_port_mux_static_info_to_db(self):
294299
rc = post_port_mux_static_info_to_db(logical_port_name, mux_tbl)
295300
assert(rc != -1)
296301

302+
def test_y_cable_helper_format_mapping_identifier1(self):
303+
rc = format_mapping_identifier("ABC ")
304+
assert(rc == "abc")
305+
306+
def test_y_cable_wrapper_get_transceiver_info(self):
307+
with patch('xcvrd.xcvrd_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util:
308+
patched_util.get_transceiver_info_dict.return_value = {'manufacturer': 'Microsoft',
309+
'model': 'model1'}
310+
311+
transceiver_dict = y_cable_wrapper_get_transceiver_info(1)
312+
vendor = transceiver_dict.get('manufacturer')
313+
model = transceiver_dict.get('model')
314+
315+
assert(vendor == "Microsoft")
316+
assert(model == "model1")
317+
318+
def test_y_cable_wrapper_get_presence(self):
319+
with patch('xcvrd.xcvrd_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util:
320+
patched_util.get_presence.return_value = True
321+
322+
presence = y_cable_wrapper_get_presence(1)
323+
324+
assert(presence == True)
325+
326+
@patch('xcvrd.xcvrd_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0]))
327+
@patch('xcvrd.xcvrd_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True))
328+
def test_get_ycable_physical_port_from_logical_port(self):
329+
330+
instance = get_ycable_physical_port_from_logical_port("Ethernet0")
331+
332+
assert(instance == 0)
333+
334+
@patch('xcvrd.xcvrd_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0]))
335+
@patch('xcvrd.xcvrd_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True))
336+
def test_get_ycable_port_instance_from_logical_port(self):
337+
338+
with patch('xcvrd.xcvrd_utilities.y_cable_helper.y_cable_port_instances') as patched_util:
339+
patched_util.get.return_value = 0
340+
instance = get_ycable_port_instance_from_logical_port("Ethernet0")
341+
342+
assert(instance == 0)
343+
344+
def test_set_show_firmware_fields(self):
345+
346+
mux_info_dict = {}
347+
xcvrd_show_fw_res_tbl = Table("STATE_DB", "XCVRD_SHOW_FW_RES")
348+
mux_info_dict['version_self_active'] = '0.8'
349+
mux_info_dict['version_self_inactive'] = '0.7'
350+
mux_info_dict['version_self_next'] = '0.7'
351+
mux_info_dict['version_peer_active'] = '0.8'
352+
mux_info_dict['version_peer_inactive'] = '0.7'
353+
mux_info_dict['version_peer_next'] = '0.7'
354+
mux_info_dict['version_nic_active'] = '0.8'
355+
mux_info_dict['version_nic_inactive'] = '0.7'
356+
mux_info_dict['version_nic_next'] = '0.7'
357+
rc = set_show_firmware_fields("Ethernet0", mux_info_dict, xcvrd_show_fw_res_tbl)
358+
359+
assert(rc == 0)
360+
297361
def test_get_media_settings_key(self):
298362
xcvr_info_dict = {
299363
0: {

0 commit comments

Comments
 (0)