Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the sfputil treats page number as decimal instead of hexadecimal #3147

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 6 additions & 26 deletions sfputil/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -703,10 +703,12 @@ def eeprom_hexdump(port, page):
if port:
if page is None:
page = 0
return_code, output = eeprom_hexdump_single_port(port, page)
return_code, output = eeprom_hexdump_single_port(port, int(str(page), base=16))
click.echo(output)
sys.exit(return_code)
else:
if page is not None:
page = int(str(page), base=16)
logical_port_list = natsorted(platform_sfputil.logical)
lines = []
for logical_port_name in logical_port_list:
Expand All @@ -729,7 +731,7 @@ def validate_eeprom_page(page):
int page
"""
try:
page = int(page)
page = int(page, base=16)
except ValueError:
click.echo('Please enter a numeric page number')
sys.exit(ERROR_NOT_IMPLEMENTED)
Expand Down Expand Up @@ -830,7 +832,7 @@ def eeprom_hexdump_pages_general(logical_port_name, pages, target_page):
tuple(0, dump string) if success else tuple(error_code, error_message)
"""
if target_page is not None:
lines = [f'EEPROM hexdump for port {logical_port_name} page {target_page}h']
lines = [f'EEPROM hexdump for port {logical_port_name} page {target_page:x}h']
else:
lines = [f'EEPROM hexdump for port {logical_port_name}']
physical_port = logical_port_to_physical_port_index(logical_port_name)
Expand Down Expand Up @@ -871,7 +873,7 @@ def eeprom_hexdump_pages_sff8472(logical_port_name, pages, target_page):
tuple(0, dump string) if success else tuple(error_code, error_message)
"""
if target_page is not None:
lines = [f'EEPROM hexdump for port {logical_port_name} page {target_page}h']
lines = [f'EEPROM hexdump for port {logical_port_name} page {target_page:x}h']
else:
lines = [f'EEPROM hexdump for port {logical_port_name}']
physical_port = logical_port_to_physical_port_index(logical_port_name)
Expand Down Expand Up @@ -928,28 +930,6 @@ def eeprom_dump_general(physical_port, page, flat_offset, size, page_offset, no_
return 0, ''.join('{:02x}'.format(x) for x in page_dump)



def eeprom_dump_general(physical_port, page, flat_offset, size, page_offset, no_format=False):
"""
Dump module EEPROM for given pages in hex format.
Args:
logical_port_name: logical port name
pages: a list of pages to be dumped. The list always include a default page list and the target_page input by
user
target_page: user input page number, optional. target_page is only for display purpose
Returns:
tuple(0, dump string) if success else tuple(error_code, error_message)
"""
sfp = platform_chassis.get_sfp(physical_port)
page_dump = sfp.read_eeprom(flat_offset, size)
if page_dump is None:
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}!'
if not no_format:
return 0, hexdump(EEPROM_DUMP_INDENT, page_dump, page_offset, start_newline=False)
else:
return 0, ''.join('{:02x}'.format(x) for x in page_dump)


def convert_byte_to_valid_ascii_char(byte):
if byte < 32 or 126 < byte:
return '.'
Expand Down
Loading