From cbfdf0e3363f7ccf999f39be7264a68cc96e22b1 Mon Sep 17 00:00:00 2001 From: Kebo Liu Date: Sun, 21 Oct 2018 06:03:50 +0300 Subject: [PATCH] add logic to avoid access none present SFP --- sfputil/main.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/sfputil/main.py b/sfputil/main.py index df57a532f0..89cd5fcfdf 100644 --- a/sfputil/main.py +++ b/sfputil/main.py @@ -185,7 +185,11 @@ def port_eeprom_data_string_pretty(logical_port_name, dump_dom): for physical_port in physical_port_list: port_name = get_physical_port_name(logical_port_name, i, ganged) - eeprom_dict = platform_sfputil.get_eeprom_dict(physical_port) + if not platform_sfputil.get_presence(physical_port): + eeprom_dict = None + else: + eeprom_dict = platform_sfputil.get_eeprom_dict(physical_port) + if eeprom_dict is not None: eeprom_iface_dict = eeprom_dict.get('interface') iface_data_dict = eeprom_iface_dict.get('data') @@ -228,7 +232,10 @@ def port_eeprom_data_string_pretty_oneline(logical_port_name, ganged = True for physical_port in physical_port_list: - eeprom_dict = platform_sfputil.get_eeprom_dict(physical_port) + if not platform_sfputil.get_presence(physical_port): + eeprom_dict = None + else: + eeprom_dict = platform_sfputil.get_eeprom_dict(physical_port) # Only print detected sfp ports for oneline if eeprom_dict is not None: @@ -266,7 +273,11 @@ def port_eeprom_data_raw_string_pretty(logical_port_name): for physical_port in physical_port_list: port_name = get_physical_port_name(logical_port_name, i, ganged) - eeprom_raw = platform_sfputil.get_eeprom_raw(physical_port) + if not platform_sfputil.get_presence(physical_port): + eeprom_raw = None + else: + eeprom_raw = platform_sfputil.get_eeprom_raw(physical_port) + if eeprom_raw is None: result += get_sfp_eeprom_status_string(port_name, False) result += "\n"