From c03342fe7afeea830ffc9201902f7de4b986bc03 Mon Sep 17 00:00:00 2001 From: Prince George <45705344+prgeor@users.noreply.github.com> Date: Fri, 20 Aug 2021 09:08:40 -0700 Subject: [PATCH] [sfputil] Gracefully handle improper 'specification_compliance' field (#1741) Signed-off-by: Prince George --- sfputil/main.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/sfputil/main.py b/sfputil/main.py index fd86d95337..3556eed76f 100644 --- a/sfputil/main.py +++ b/sfputil/main.py @@ -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])