Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[platform] Update 'show platform psustatus' tests to handle new expanded output #3040

Merged
merged 5 commits into from
Feb 26, 2021
Merged
Show file tree
Hide file tree
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
39 changes: 36 additions & 3 deletions tests/platform_tests/cli/test_show_platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# TODO: Add tests for `show platform firmware updates`
# TODO: Add tests for `show platform firmware version`

import json
import logging
import re

Expand Down Expand Up @@ -174,17 +175,49 @@ def test_show_platform_psustatus(duthosts, enum_supervisor_dut_hostname):

logging.info("Verifying output of '{}' on '{}' ...".format(cmd, duthost.hostname))
psu_status_output_lines = duthost.command(cmd)["stdout_lines"]
psu_line_pattern = re.compile(r"PSU\s+\d+\s+(OK|NOT OK|NOT PRESENT)")

# Check that all psus are showing valid status and also at-least one PSU is OK.
if "201811" in duthost.os_version or "201911" in duthost.os_version:
psu_line_pattern = re.compile(r"PSU\s+\d+\s+(OK|NOT OK|NOT PRESENT)")
else:
psu_line_pattern = re.compile(r"PSU\s+\d+\s+\w+\s+\w+\s+\w+\s+\w+\s+\w+\s+(OK|NOT OK|NOT PRESENT)\s+(green|amber|red|off)")

# Check that all PSUs are showing valid status and also at least one PSU is OK
num_psu_ok = 0

for line in psu_status_output_lines[2:]:
psu_match = psu_line_pattern.match(line)
pytest_assert(psu_match, "Unexpected PSU status output: '{}' on '{}'".format(line, duthost.hostname))
psu_status = psu_match.group(1)
if psu_status == "OK":
num_psu_ok += 1
pytest_assert(num_psu_ok > 0, " No PSU's are displayed with OK status on '{}'".format(duthost.hostname))

pytest_assert(num_psu_ok > 0, "No PSUs are displayed with OK status on '{}'".format(duthost.hostname))


def test_show_platform_psustatus_json(duthosts, rand_one_dut_hostname):
"""
@summary: Verify output of `show platform psustatus --json`
"""
duthost = duthosts[rand_one_dut_hostname]

if "201811" in duthost.os_version or "201911" in duthost.os_version:
pytest.skip("JSON output not available in this version")

logging.info("Check pmon daemon status")
pytest_assert(check_pmon_daemon_status(duthost), "Not all pmon daemons running.")

cmd = " ".join([CMD_SHOW_PLATFORM, "psustatus", "--json"])

logging.info("Verifying output of '{}' ...".format(cmd))
psu_status_output = duthost.command(cmd)["stdout"]
psu_info_list = json.loads(psu_status_output)

# TODO: Compare against expected platform-specific output
for psu_info in psu_info_list:
expected_keys = ["index", "name", "presence", "status", "led_status", "model", "serial", "voltage", "current", "power"]
pytest_assert(all(key in psu_info for key in expected_keys), "Expected key(s) missing from JSON output: '{}'".format(psu_status_output))
pytest_assert(psu_info["status"] in ["OK", "NOT OK", "NOT PRESENT"], "Unexpected PSU status value: '{}'".format(psu_info["status"]))
pytest_assert(psu_info["led_status"] in ["green", "amber", "red", "off"], "Unexpected PSU led_status value: '{}'".format(psu_info["led_status"]))


def verify_show_platform_fan_output(duthost, raw_output_lines):
Expand Down
31 changes: 23 additions & 8 deletions tests/platform_tests/test_platform_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
This script covers the test case 'Check platform information' in the SONiC platform test plan:
https://github.com/Azure/SONiC/blob/master/doc/pmon/sonic_platform_test_plan.md
"""
import json
import logging
import re
import time
Expand All @@ -20,6 +21,7 @@
]

CMD_PLATFORM_PSUSTATUS = "show platform psustatus"
CMD_PLATFORM_PSUSTATUS_JSON = "{} --json".format(CMD_PLATFORM_PSUSTATUS)
CMD_PLATFORM_FANSTATUS = "show platform fan"
CMD_PLATFORM_TEMPER = "show platform temperature"

Expand Down Expand Up @@ -145,7 +147,11 @@ def check_vendor_specific_psustatus(dut, psu_status_line):
if dut.facts["asic_type"] in ["mellanox"]:
from .mellanox.check_sysfs import check_psu_sysfs

psu_line_pattern = re.compile(r"PSU\s+(\d)+\s+(OK|NOT OK|NOT PRESENT)")
if "201811" in dut.os_version or "201911" in dut.os_version:
psu_line_pattern = re.compile(r"PSU\s+(\d)+\s+(OK|NOT OK|NOT PRESENT)")
else:
psu_line_pattern = re.compile(r"PSU\s+(\d+)\s+\w+\s+\w+\s+\w+\s+\w+\s+\w+\s+(OK|NOT OK|NOT PRESENT)\s+(green|amber|red|off)")

psu_match = psu_line_pattern.match(psu_status_line)
psu_id = psu_match.group(1)
psu_status = psu_match.group(2)
Expand All @@ -163,16 +169,25 @@ def turn_all_outlets_on(pdu_ctrl):


def check_all_psu_on(dut, psu_test_results):
cli_psu_status = dut.command(CMD_PLATFORM_PSUSTATUS)
power_off_psu_list = []
for line in cli_psu_status["stdout_lines"][2:]:
fields = line.split()
psu_test_results[fields[1]] = False
if " ".join(fields[2:]) == "NOT OK":
power_off_psu_list.append(fields[1])

if "201811" in dut.os_version or "201911" in dut.os_version:
cli_psu_status = dut.command(CMD_PLATFORM_PSUSTATUS)
for line in cli_psu_status["stdout_lines"][2:]:
fields = line.split()
psu_test_results[fields[1]] = False
if " ".join(fields[2:]) == "NOT OK":
power_off_psu_list.append(fields[1])
else:
# Use JSON output
cli_psu_status = dut.command(CMD_PLATFORM_PSUSTATUS_JSON)
psu_info_list = json.loads(cli_psu_status["stdout"])
for psu_info in psu_info_list:
if psu_info["status"] == "NOT OK":
power_off_psu_list.append(psu_info["index"])

if power_off_psu_list:
logging.warn('Power off PSU list: {}'.format(power_off_psu_list))
logging.warn('Powered off PSUs: {}'.format(power_off_psu_list))

return len(power_off_psu_list) == 0

Expand Down