From 4a0c3235d99069f41f115b3b915ff6c28a7ce139 Mon Sep 17 00:00:00 2001 From: Prince George Date: Wed, 4 Aug 2021 15:31:45 +0000 Subject: [PATCH] [sfputil] Gracefully handle improper 'specification_compliance' field 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])