Skip to content

Commit

Permalink
[sfputil] Gracefully handle improper 'specification_compliance' field (
Browse files Browse the repository at this point in the history
…#1741)

Signed-off-by: Prince George <prgeor@microsoft.com>
  • Loading branch information
prgeor authored Aug 20, 2021
1 parent 103de86 commit c03342f
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions sfputil/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,15 @@ def convert_sfp_info_to_output_string(sfp_info_dict):
output += '{}{}: {}\n'.format(indent, QSFP_DATA_MAP[key], sfp_info_dict[key])
else:
output += '{}{}:\n'.format(indent, QSFP_DATA_MAP['specification_compliance'])
spefic_compliance_dict = eval(sfp_info_dict['specification_compliance'])
sorted_compliance_key_table = natsorted(spefic_compliance_dict)

spec_compliance_dict = {}
try:
spec_compliance_dict = ast.literal_eval(sfp_info_dict['specification_compliance'])
sorted_compliance_key_table = natsorted(spec_compliance_dict)
for compliance_key in sorted_compliance_key_table:
output += '{}{}: {}\n'.format((indent * 2), compliance_key, spefic_compliance_dict[compliance_key])
output += '{}{}: {}\n'.format((indent * 2), compliance_key, spec_compliance_dict[compliance_key])
except ValueError as e:
output += '{}N/A\n'.format((indent * 2))
else:
output += '{}{}: {}\n'.format(indent, QSFP_DATA_MAP[key], sfp_info_dict[key])

Expand Down

0 comments on commit c03342f

Please sign in to comment.