Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 1 addition & 18 deletions tests/platform_tests/mellanox/test_check_sfp_presence.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,15 @@ def test_check_sfp_presence(duthost, conn_graph_facts):
"""This test case is to check SFP presence status with CLI and sysfs.
"""
ports_config = json.loads(duthost.command("sudo sonic-cfggen -d --var-json PORT")["stdout"])
sysfs_path = get_sfp_sysfs_path(duthost)
check_qsfp_sysfs_command = 'cat {}'.format(sysfs_path)
check_intf_presence_command = 'show interface transceiver presence {}'

logging.info("Use show interface status information")
for intf in conn_graph_facts["device_conn"]:
intf_lanes = ports_config[intf]["lanes"]
sfp_id = int(intf_lanes.split(",")[0])/4 + 1

check_presence_output = duthost.command(check_intf_presence_command.format(intf))
assert check_presence_output["rc"] == 0, "Failed to read interface %s transceiver presence" % intf
logging.info(str(check_presence_output["stdout_lines"][2]))
presence_list = check_presence_output["stdout_lines"][2].split()
logging.info(str(presence_list))
assert intf in presence_list, "Wrong interface name in the output %s" % str(presence_list)
assert 'Present' in presence_list, "Status is not expected, output %s" % str(presence_list)

check_sysfs_output = duthost.command(check_qsfp_sysfs_command.format(str(sfp_id)))
logging.info('output of check sysfs %s' % (str(check_sysfs_output)))
assert check_sysfs_output["rc"] == 0, "Failed to read sysfs of sfp%s." % str(sfp_id)
assert check_sysfs_output["stdout"] == '1', "Content of sysfs of sfp%s is not correct" % str(sfp_id)


def get_sfp_sysfs_path(ans_host):
file_exists = ans_host.stat(path='/var/run/hw-management/qsfp')
if file_exists['stat']['exists'] == True:
return '/var/run/hw-management/qsfp/qsfp{}_status'
else:
return '/var/run/hw-management/sfp/sfp{}_status'