|
18 | 18 | daemon_base.db_connect = MagicMock() |
19 | 19 | swsscommon.Table = MagicMock() |
20 | 20 | swsscommon.ProducerStateTable = MagicMock() |
| 21 | +swsscommon.SubscriberStateTable = MagicMock() |
| 22 | +swsscommon.SonicDBConfig = MagicMock() |
| 23 | +#swsscommon.Select = MagicMock() |
| 24 | + |
21 | 25 | sys.modules['sonic_y_cable'] = MagicMock() |
22 | 26 | sys.modules['sonic_y_cable.y_cable'] = MagicMock() |
23 | 27 |
|
@@ -219,9 +223,9 @@ def test_init_port_sfp_status_tbl(self): |
219 | 223 | init_port_sfp_status_tbl(stop_event) |
220 | 224 |
|
221 | 225 | @patch('xcvrd.xcvrd_utilities.y_cable_helper.y_cable_platform_sfputil', MagicMock(return_value=[0])) |
222 | | - @patch('y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) |
223 | | - @patch('y_cable_helper._wrapper_get_presence', MagicMock(return_value=True)) |
224 | | - @patch('y_cable_helper.get_muxcable_info', MagicMock(return_value={'tor_active': 'self', |
| 226 | + @patch('xcvrd.xcvrd_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) |
| 227 | + @patch('xcvrd.xcvrd_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) |
| 228 | + @patch('xcvrd.xcvrd_utilities.y_cable_helper.get_muxcable_info', MagicMock(return_value={'tor_active': 'self', |
225 | 229 | 'mux_direction': 'self', |
226 | 230 | 'manual_switch_count': '7', |
227 | 231 | 'auto_switch_count': '71', |
@@ -257,10 +261,11 @@ def test_post_port_mux_info_to_db(self): |
257 | 261 | rc = post_port_mux_info_to_db(logical_port_name, mux_tbl) |
258 | 262 | assert(rc != -1) |
259 | 263 |
|
| 264 | + |
260 | 265 | @patch('xcvrd.xcvrd_utilities.y_cable_helper.y_cable_platform_sfputil', MagicMock(return_value=[0])) |
261 | | - @patch('y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) |
262 | | - @patch('y_cable_helper._wrapper_get_presence', MagicMock(return_value=True)) |
263 | | - @patch('y_cable_helper.get_muxcable_static_info', MagicMock(return_value={'read_side': 'self', |
| 266 | + @patch('xcvrd.xcvrd_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) |
| 267 | + @patch('xcvrd.xcvrd_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) |
| 268 | + @patch('xcvrd.xcvrd_utilities.y_cable_helper.get_muxcable_static_info', MagicMock(return_value={'read_side': 'self', |
264 | 269 | 'nic_lane1_precursor1': '1', |
265 | 270 | 'nic_lane1_precursor2': '-7', |
266 | 271 | 'nic_lane1_maincursor': '-1', |
@@ -297,6 +302,65 @@ def test_post_port_mux_static_info_to_db(self): |
297 | 302 | rc = post_port_mux_static_info_to_db(logical_port_name, mux_tbl) |
298 | 303 | assert(rc != -1) |
299 | 304 |
|
| 305 | + def test_y_cable_helper_format_mapping_identifier1(self): |
| 306 | + rc = format_mapping_identifier("ABC ") |
| 307 | + assert(rc == "abc") |
| 308 | + |
| 309 | + def test_y_cable_wrapper_get_transceiver_info(self): |
| 310 | + with patch('xcvrd.xcvrd_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: |
| 311 | + patched_util.get_transceiver_info_dict.return_value = {'manufacturer': 'Microsoft', |
| 312 | + 'model': 'model1'} |
| 313 | + |
| 314 | + transceiver_dict = y_cable_wrapper_get_transceiver_info(1) |
| 315 | + vendor = transceiver_dict.get('manufacturer') |
| 316 | + model = transceiver_dict.get('model') |
| 317 | + |
| 318 | + assert(vendor == "Microsoft") |
| 319 | + assert(model == "model1") |
| 320 | + |
| 321 | + def test_y_cable_wrapper_get_presence(self): |
| 322 | + with patch('xcvrd.xcvrd_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util: |
| 323 | + patched_util.get_presence.return_value = True |
| 324 | + |
| 325 | + presence = y_cable_wrapper_get_presence(1) |
| 326 | + |
| 327 | + assert(presence == True) |
| 328 | + |
| 329 | + @patch('xcvrd.xcvrd_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) |
| 330 | + @patch('xcvrd.xcvrd_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) |
| 331 | + def test_get_ycable_physical_port_from_logical_port(self): |
| 332 | + |
| 333 | + instance = get_ycable_physical_port_from_logical_port("Ethernet0") |
| 334 | + |
| 335 | + assert(instance == 0) |
| 336 | + |
| 337 | + @patch('xcvrd.xcvrd_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) |
| 338 | + @patch('xcvrd.xcvrd_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True)) |
| 339 | + def test_get_ycable_port_instance_from_logical_port(self): |
| 340 | + |
| 341 | + with patch('xcvrd.xcvrd_utilities.y_cable_helper.y_cable_port_instances') as patched_util: |
| 342 | + patched_util.get.return_value = 0 |
| 343 | + instance = get_ycable_port_instance_from_logical_port("Ethernet0") |
| 344 | + |
| 345 | + assert(instance == 0) |
| 346 | + |
| 347 | + def test_set_show_firmware_fields(self): |
| 348 | + |
| 349 | + mux_info_dict = {} |
| 350 | + xcvrd_show_fw_res_tbl = Table("STATE_DB", "XCVRD_SHOW_FW_RES") |
| 351 | + mux_info_dict['version_self_active'] = '0.8' |
| 352 | + mux_info_dict['version_self_inactive'] = '0.7' |
| 353 | + mux_info_dict['version_self_next'] = '0.7' |
| 354 | + mux_info_dict['version_peer_active'] = '0.8' |
| 355 | + mux_info_dict['version_peer_inactive'] = '0.7' |
| 356 | + mux_info_dict['version_peer_next'] = '0.7' |
| 357 | + mux_info_dict['version_nic_active'] = '0.8' |
| 358 | + mux_info_dict['version_nic_inactive'] = '0.7' |
| 359 | + mux_info_dict['version_nic_next'] = '0.7' |
| 360 | + rc = set_show_firmware_fields("Ethernet0", mux_info_dict, xcvrd_show_fw_res_tbl) |
| 361 | + |
| 362 | + assert(rc == 0) |
| 363 | + |
300 | 364 | def test_get_media_settings_key(self): |
301 | 365 | xcvr_info_dict = { |
302 | 366 | 0: { |
|
0 commit comments