Skip to content

Commit 8dbdc4b

Browse files
committed
Fix the sfputil treats page number as decimal instead of hexadecimal
sonic-net#3009 breaks the number base rule, treats the page number CLI input as decimal rather than hex, this is used to fix it. it also containes a redundancy function definition, so remove it. Signed-off-by: Yuanzhe, Liu <[email protected]>
1 parent 3d45c0c commit 8dbdc4b

File tree

1 file changed

+4
-24
lines changed

1 file changed

+4
-24
lines changed

sfputil/main.py

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -703,10 +703,12 @@ def eeprom_hexdump(port, page):
703703
if port:
704704
if page is None:
705705
page = 0
706-
return_code, output = eeprom_hexdump_single_port(port, page)
706+
return_code, output = eeprom_hexdump_single_port(port, int(str(page), base=16))
707707
click.echo(output)
708708
sys.exit(return_code)
709709
else:
710+
if page is not None:
711+
page = int(str(page), base=16)
710712
logical_port_list = natsorted(platform_sfputil.logical)
711713
lines = []
712714
for logical_port_name in logical_port_list:
@@ -729,7 +731,7 @@ def validate_eeprom_page(page):
729731
int page
730732
"""
731733
try:
732-
page = int(page)
734+
page = int(page, base=16)
733735
except ValueError:
734736
click.echo('Please enter a numeric page number')
735737
sys.exit(ERROR_NOT_IMPLEMENTED)
@@ -928,28 +930,6 @@ def eeprom_dump_general(physical_port, page, flat_offset, size, page_offset, no_
928930
return 0, ''.join('{:02x}'.format(x) for x in page_dump)
929931

930932

931-
932-
def eeprom_dump_general(physical_port, page, flat_offset, size, page_offset, no_format=False):
933-
"""
934-
Dump module EEPROM for given pages in hex format.
935-
Args:
936-
logical_port_name: logical port name
937-
pages: a list of pages to be dumped. The list always include a default page list and the target_page input by
938-
user
939-
target_page: user input page number, optional. target_page is only for display purpose
940-
Returns:
941-
tuple(0, dump string) if success else tuple(error_code, error_message)
942-
"""
943-
sfp = platform_chassis.get_sfp(physical_port)
944-
page_dump = sfp.read_eeprom(flat_offset, size)
945-
if page_dump is None:
946-
return ERROR_NOT_IMPLEMENTED, f'Error: Failed to read EEPROM for page {page:x}h, flat_offset {flat_offset}, page_offset {page_offset}, size {size}!'
947-
if not no_format:
948-
return 0, hexdump(EEPROM_DUMP_INDENT, page_dump, page_offset, start_newline=False)
949-
else:
950-
return 0, ''.join('{:02x}'.format(x) for x in page_dump)
951-
952-
953933
def convert_byte_to_valid_ascii_char(byte):
954934
if byte < 32 or 126 < byte:
955935
return '.'

0 commit comments

Comments
 (0)