From aa33644d3c9f94143bb3c5efba9e8474a27d5097 Mon Sep 17 00:00:00 2001 From: Stephen Sun <5379172+stephenxs@users.noreply.github.com> Date: Sat, 7 Sep 2019 06:12:45 +0800 Subject: [PATCH] [Mellanox] fix sfp issue in reading qsfp_status (#3386) There is a very low possibility that qsfp_status exists when opening it but doesn't when reading it a bit later. If this occurs an exception is raised. However, this should be treated as "not presence" rather than causing an exception, which can be achieved by putting it into try block. --- device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfputil.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfputil.py b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfputil.py index db1bea8a47..bfdb9ce482 100644 --- a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfputil.py +++ b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfputil.py @@ -8,6 +8,7 @@ try: import subprocess from sonic_sfp.sfputilbase import * import syslog + import sys except ImportError as e: raise ImportError("%s - required module not found" % str(e)) @@ -103,12 +104,11 @@ class SfpUtil(SfpUtilBase): try: reg_file = open(self.qsfp_sysfs_path + "qsfp{}_status".format(port_num + 1)) + content = reg_file.readline().rstrip() except IOError as e: - print "Error: unable to open file: %s" % str(e) + print >> sys.stderr, "Error: unable to access file: %s" % str(e) return False - content = reg_file.readline().rstrip() - # content is a string with the qsfp status if content == SFP_STATUS_INSERTED: return True @@ -127,7 +127,7 @@ class SfpUtil(SfpUtilBase): if 'LPM ON' in output: return True except subprocess.CalledProcessError as e: - print "Error! Unable to get LPM for {}, rc = {}, err msg: {}".format(port_num, e.returncode, e.output) + print >> sys.stderr, "Error! Unable to get LPM for {}, rc = {}, err msg: {}".format(port_num, e.returncode, e.output) return False return False