diff --git a/sfputil/main.py b/sfputil/main.py index dccbae60bb..ad0b1b3775 100644 --- a/sfputil/main.py +++ b/sfputil/main.py @@ -705,7 +705,7 @@ def eeprom_hexdump(port, page): page = 0 else: page = validate_eeprom_page(page) - return_code, output = eeprom_hexdump_single_port(port, int(str(page), base=16)) + return_code, output = eeprom_hexdump_single_port(port, page) click.echo(output) sys.exit(return_code) else: diff --git a/tests/sfputil_test.py b/tests/sfputil_test.py index 9eda8ca249..523848ec45 100644 --- a/tests/sfputil_test.py +++ b/tests/sfputil_test.py @@ -669,6 +669,96 @@ def test_show_eeprom_hexdump_read_eeprom_not_implemented(self, mock_chassis): expected_output = "Sfp.read_eeprom() is currently not implemented for this platform\n" assert result.output == expected_output + + @patch('sfputil.main.platform_chassis') + @patch('sfputil.main.logical_port_to_physical_port_index', MagicMock(return_value=1)) + @patch('sfputil.main.platform_sfputil', MagicMock(is_logical_port=MagicMock(return_value=1))) + @patch('sfputil.main.is_port_type_rj45', MagicMock(return_value=False)) + @patch('sfputil.main.isinstance', MagicMock(return_value=True)) + def test_show_eeprom_hexdump_processing_hex_page_number(self, mock_chassis): + lower_page_bytearray = bytearray([13, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 129, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) + upper_page0_bytearray = bytearray([13, 0, 35, 8, 0, 0, 0, 65, 128, 128, 245, 0, 0, 0, 0, 0, 0, 0, 1, 160, 77, 111, 108, 101, 120, 32, 73, 110, 99, 46, 32, 32, 32, 32, 32, 32, 7, 0, 9, 58, 49, 49, 49, 48, 52, 48, 49, 48, 53, 52, 32, 32, 32, 32, 32, 32, 32, 32, 3, 4, 0, 0, 70, 196, 0, 0, 0, 0, 54, 49, 49, 48, 51, 48, 57, 50, 57, 32, 32, 32, 32, 32, 32, 32, 49, 54, 48, 52, 49, 57, 32, 32, 0, 0, 0, 36, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) + page10_expected_output = '''EEPROM hexdump for port Ethernet0 page 10h + Lower page 0h + 00000000 0d 00 06 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| + 00000010 00 00 00 00 00 00 01 81 00 00 00 00 00 00 00 00 |................| + 00000020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| + 00000030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| + 00000040 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| + 00000050 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| + 00000060 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| + 00000070 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| + + Upper page 0h + 00000080 0d 00 23 08 00 00 00 41 80 80 f5 00 00 00 00 00 |..#....A........| + 00000090 00 00 01 a0 4d 6f 6c 65 78 20 49 6e 63 2e 20 20 |....Molex Inc. | + 000000a0 20 20 20 20 07 00 09 3a 31 31 31 30 34 30 31 30 | ...:11104010| + 000000b0 35 34 20 20 20 20 20 20 20 20 03 04 00 00 46 c4 |54 ....F.| + 000000c0 00 00 00 00 36 31 31 30 33 30 39 32 39 20 20 20 |....611030929 | + 000000d0 20 20 20 20 31 36 30 34 31 39 20 20 00 00 00 24 | 160419 ...$| + 000000e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| + 000000f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| + + Upper page 10h + 00000080 0d 00 23 08 00 00 00 41 80 80 f5 00 00 00 00 00 |..#....A........| + 00000090 00 00 01 a0 4d 6f 6c 65 78 20 49 6e 63 2e 20 20 |....Molex Inc. | + 000000a0 20 20 20 20 07 00 09 3a 31 31 31 30 34 30 31 30 | ...:11104010| + 000000b0 35 34 20 20 20 20 20 20 20 20 03 04 00 00 46 c4 |54 ....F.| + 000000c0 00 00 00 00 36 31 31 30 33 30 39 32 39 20 20 20 |....611030929 | + 000000d0 20 20 20 20 31 36 30 34 31 39 20 20 00 00 00 24 | 160419 ...$| + 000000e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| + 000000f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| + +''' + page11_expected_output = '''EEPROM hexdump for port Ethernet0 page 11h + Lower page 0h + 00000000 0d 00 06 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| + 00000010 00 00 00 00 00 00 01 81 00 00 00 00 00 00 00 00 |................| + 00000020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| + 00000030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| + 00000040 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| + 00000050 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| + 00000060 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| + 00000070 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| + + Upper page 0h + 00000080 0d 00 23 08 00 00 00 41 80 80 f5 00 00 00 00 00 |..#....A........| + 00000090 00 00 01 a0 4d 6f 6c 65 78 20 49 6e 63 2e 20 20 |....Molex Inc. | + 000000a0 20 20 20 20 07 00 09 3a 31 31 31 30 34 30 31 30 | ...:11104010| + 000000b0 35 34 20 20 20 20 20 20 20 20 03 04 00 00 46 c4 |54 ....F.| + 000000c0 00 00 00 00 36 31 31 30 33 30 39 32 39 20 20 20 |....611030929 | + 000000d0 20 20 20 20 31 36 30 34 31 39 20 20 00 00 00 24 | 160419 ...$| + 000000e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| + 000000f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| + + Upper page 11h + 00000080 0d 00 23 08 00 00 00 41 80 80 f5 00 00 00 00 00 |..#....A........| + 00000090 00 00 01 a0 4d 6f 6c 65 78 20 49 6e 63 2e 20 20 |....Molex Inc. | + 000000a0 20 20 20 20 07 00 09 3a 31 31 31 30 34 30 31 30 | ...:11104010| + 000000b0 35 34 20 20 20 20 20 20 20 20 03 04 00 00 46 c4 |54 ....F.| + 000000c0 00 00 00 00 36 31 31 30 33 30 39 32 39 20 20 20 |....611030929 | + 000000d0 20 20 20 20 31 36 30 34 31 39 20 20 00 00 00 24 | 160419 ...$| + 000000e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| + 000000f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| + +''' + def side_effect(offset, num_bytes): + if offset == 0: + return lower_page_bytearray + else: + return upper_page0_bytearray + mock_sfp = MagicMock() + mock_sfp.get_presence.return_value = True + mock_chassis.get_sfp = MagicMock(return_value=mock_sfp) + mock_sfp.read_eeprom = MagicMock(side_effect=side_effect) + runner = CliRunner() + result = runner.invoke(sfputil.cli.commands['show'].commands['eeprom-hexdump'], ["-p", "Ethernet0", "-n", "10"]) + assert result.exit_code == 0 + assert result.output == page10_expected_output + result = runner.invoke(sfputil.cli.commands['show'].commands['eeprom-hexdump'], ["-p", "Ethernet0", "-n", "11"]) + assert result.exit_code == 0 + assert result.output == page11_expected_output + @patch('sfputil.main.platform_chassis') @patch('sfputil.main.logical_port_to_physical_port_index', MagicMock(return_value=1)) @patch('sfputil.main.platform_sfputil', MagicMock(is_logical_port=MagicMock(return_value=1)))