[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.
This commit is contained in:
Stephen Sun 2019-09-07 06:12:45 +08:00 committed by lguohan
parent ab1e505325
commit aa33644d3c

View File

@ -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,11 +104,10 @@ class SfpUtil(SfpUtilBase):
try:
reg_file = open(self.qsfp_sysfs_path + "qsfp{}_status".format(port_num + 1))
except IOError as e:
print "Error: unable to open file: %s" % str(e)
return False
content = reg_file.readline().rstrip()
except IOError as e:
print >> sys.stderr, "Error: unable to access file: %s" % str(e)
return False
# content is a string with the qsfp status
if content == SFP_STATUS_INSERTED:
@ -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