|
20 | 20 | ERROR_NOT_IMPLEMENTED = 5
|
21 | 21 | ERROR_INVALID_PORT = 6
|
22 | 22 |
|
| 23 | +FLAT_MEMORY_MODULE_EEPROM_SFP_INFO_DICT = { |
| 24 | + 'type': 'QSFP28 or later', |
| 25 | + 'type_abbrv_name': 'QSFP28', |
| 26 | + 'manufacturer': 'Mellanox', |
| 27 | + 'model': 'MCP1600-C003', |
| 28 | + 'vendor_rev': 'A2', |
| 29 | + 'serial': 'MT1636VS10561', |
| 30 | + 'vendor_oui': '00-02-c9', |
| 31 | + 'vendor_date': '2016-07-18', |
| 32 | + 'connector': 'No separable connector', |
| 33 | + 'encoding': '64B66B', |
| 34 | + 'ext_identifier': 'Power Class 1(1.5W max)', |
| 35 | + 'ext_rateselect_compliance': 'QSFP+ Rate Select Version 1', |
| 36 | + 'cable_type': 'Length Cable Assembly(m)', |
| 37 | + 'cable_length': '3', |
| 38 | + 'application_advertisement': 'N/A', |
| 39 | + 'specification_compliance': "{'10/40G Ethernet Compliance Code': '40GBASE-CR4'}", |
| 40 | + 'dom_capability': "{'Tx_power_support': 'no', 'Rx_power_support': 'no',\ |
| 41 | + 'Voltage_support': 'no', 'Temp_support': 'no'}", |
| 42 | + 'nominal_bit_rate': '255' |
| 43 | +} |
| 44 | +FLAT_MEMORY_MODULE_EEPROM = """Ethernet16: SFP EEPROM detected |
| 45 | + Application Advertisement: N/A |
| 46 | + Connector: No separable connector |
| 47 | + Encoding: 64B66B |
| 48 | + Extended Identifier: Power Class 1(1.5W max) |
| 49 | + Extended RateSelect Compliance: QSFP+ Rate Select Version 1 |
| 50 | + Identifier: QSFP28 or later |
| 51 | + Length Cable Assembly(m): 3 |
| 52 | + Nominal Bit Rate(100Mbs): 255 |
| 53 | + Specification compliance: |
| 54 | + 10/40G Ethernet Compliance Code: 40GBASE-CR4 |
| 55 | + Vendor Date Code(YYYY-MM-DD Lot): 2016-07-18 |
| 56 | + Vendor Name: Mellanox |
| 57 | + Vendor OUI: 00-02-c9 |
| 58 | + Vendor PN: MCP1600-C003 |
| 59 | + Vendor Rev: A2 |
| 60 | + Vendor SN: MT1636VS10561 |
| 61 | +""" |
| 62 | + |
23 | 63 | class TestSfputil(object):
|
24 | 64 | def test_format_dict_value_to_string(self):
|
25 | 65 | sorted_key_table = [
|
@@ -585,6 +625,39 @@ def test_show_eeprom_RJ45(self, mock_chassis):
|
585 | 625 | expected_output = "Ethernet16: SFP EEPROM is not applicable for RJ45 port\n\n\n"
|
586 | 626 | assert result.output == expected_output
|
587 | 627 |
|
| 628 | + @patch('sfputil.main.logical_port_to_physical_port_index', MagicMock(return_value=1)) |
| 629 | + @patch('sfputil.main.logical_port_name_to_physical_port_list', MagicMock(return_value=[1])) |
| 630 | + @patch('sfputil.main.platform_sfputil', MagicMock(is_logical_port=MagicMock(return_value=1))) |
| 631 | + @patch('sfputil.main.is_port_type_rj45', MagicMock(return_value=False)) |
| 632 | + @pytest.mark.parametrize("exception, xcvr_api_none, expected_output", [ |
| 633 | + (None, False, '''DOM values not supported for flat memory module\n\n'''), |
| 634 | + (NotImplementedError, False, '''API is currently not implemented for this platform\n\n'''), |
| 635 | + (None, True, '''API is none while getting DOM info!\n\n''') |
| 636 | + ]) |
| 637 | + @patch('sfputil.main.platform_chassis') |
| 638 | + def test_show_eeprom_dom_conditions(self, mock_chassis, exception, xcvr_api_none, expected_output): |
| 639 | + mock_sfp = MagicMock() |
| 640 | + mock_sfp.get_presence.return_value = True |
| 641 | + mock_sfp.get_transceiver_info.return_value = FLAT_MEMORY_MODULE_EEPROM_SFP_INFO_DICT |
| 642 | + mock_chassis.get_sfp.return_value = mock_sfp |
| 643 | + |
| 644 | + if exception: |
| 645 | + mock_chassis.get_sfp().get_xcvr_api.side_effect = exception |
| 646 | + elif xcvr_api_none: |
| 647 | + mock_chassis.get_sfp().get_xcvr_api.return_value = None |
| 648 | + else: |
| 649 | + mock_api = MagicMock() |
| 650 | + mock_chassis.get_sfp().get_xcvr_api.return_value = mock_api |
| 651 | + |
| 652 | + runner = CliRunner() |
| 653 | + result = runner.invoke(sfputil.cli.commands['show'].commands['eeprom'], ["-p", "Ethernet16", "-d"]) |
| 654 | + |
| 655 | + if exception or xcvr_api_none: |
| 656 | + assert result.exit_code == ERROR_NOT_IMPLEMENTED |
| 657 | + else: |
| 658 | + assert result.exit_code == 0 |
| 659 | + assert result.output == FLAT_MEMORY_MODULE_EEPROM + expected_output |
| 660 | + |
588 | 661 | @patch('sfputil.main.platform_chassis')
|
589 | 662 | @patch('sfputil.main.platform_sfputil', MagicMock(is_logical_port=MagicMock(return_value=0)))
|
590 | 663 | def test_show_eeprom_hexdump_invalid_port(self, mock_chassis):
|
|
0 commit comments