|
9 | 9 | # TODO: Add tests for `show platform firmware updates`
|
10 | 10 | # TODO: Add tests for `show platform firmware version`
|
11 | 11 |
|
| 12 | +import json |
12 | 13 | import logging
|
13 | 14 | import re
|
14 | 15 |
|
@@ -174,17 +175,49 @@ def test_show_platform_psustatus(duthosts, enum_supervisor_dut_hostname):
|
174 | 175 |
|
175 | 176 | logging.info("Verifying output of '{}' on '{}' ...".format(cmd, duthost.hostname))
|
176 | 177 | psu_status_output_lines = duthost.command(cmd)["stdout_lines"]
|
177 |
| - psu_line_pattern = re.compile(r"PSU\s+\d+\s+(OK|NOT OK|NOT PRESENT)") |
178 | 178 |
|
179 |
| - # Check that all psus are showing valid status and also at-least one PSU is OK. |
| 179 | + if "201811" in duthost.os_version or "201911" in duthost.os_version: |
| 180 | + psu_line_pattern = re.compile(r"PSU\s+\d+\s+(OK|NOT OK|NOT PRESENT)") |
| 181 | + else: |
| 182 | + 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)") |
| 183 | + |
| 184 | + # Check that all PSUs are showing valid status and also at least one PSU is OK |
180 | 185 | num_psu_ok = 0
|
| 186 | + |
181 | 187 | for line in psu_status_output_lines[2:]:
|
182 | 188 | psu_match = psu_line_pattern.match(line)
|
183 | 189 | pytest_assert(psu_match, "Unexpected PSU status output: '{}' on '{}'".format(line, duthost.hostname))
|
184 | 190 | psu_status = psu_match.group(1)
|
185 | 191 | if psu_status == "OK":
|
186 | 192 | num_psu_ok += 1
|
187 |
| - pytest_assert(num_psu_ok > 0, " No PSU's are displayed with OK status on '{}'".format(duthost.hostname)) |
| 193 | + |
| 194 | + pytest_assert(num_psu_ok > 0, "No PSUs are displayed with OK status on '{}'".format(duthost.hostname)) |
| 195 | + |
| 196 | + |
| 197 | +def test_show_platform_psustatus_json(duthosts, rand_one_dut_hostname): |
| 198 | + """ |
| 199 | + @summary: Verify output of `show platform psustatus --json` |
| 200 | + """ |
| 201 | + duthost = duthosts[rand_one_dut_hostname] |
| 202 | + |
| 203 | + if "201811" in duthost.os_version or "201911" in duthost.os_version: |
| 204 | + pytest.skip("JSON output not available in this version") |
| 205 | + |
| 206 | + logging.info("Check pmon daemon status") |
| 207 | + pytest_assert(check_pmon_daemon_status(duthost), "Not all pmon daemons running.") |
| 208 | + |
| 209 | + cmd = " ".join([CMD_SHOW_PLATFORM, "psustatus", "--json"]) |
| 210 | + |
| 211 | + logging.info("Verifying output of '{}' ...".format(cmd)) |
| 212 | + psu_status_output = duthost.command(cmd)["stdout"] |
| 213 | + psu_info_list = json.loads(psu_status_output) |
| 214 | + |
| 215 | + # TODO: Compare against expected platform-specific output |
| 216 | + for psu_info in psu_info_list: |
| 217 | + expected_keys = ["index", "name", "presence", "status", "led_status", "model", "serial", "voltage", "current", "power"] |
| 218 | + pytest_assert(all(key in psu_info for key in expected_keys), "Expected key(s) missing from JSON output: '{}'".format(psu_status_output)) |
| 219 | + pytest_assert(psu_info["status"] in ["OK", "NOT OK", "NOT PRESENT"], "Unexpected PSU status value: '{}'".format(psu_info["status"])) |
| 220 | + pytest_assert(psu_info["led_status"] in ["green", "amber", "red", "off"], "Unexpected PSU led_status value: '{}'".format(psu_info["led_status"])) |
188 | 221 |
|
189 | 222 |
|
190 | 223 | def verify_show_platform_fan_output(duthost, raw_output_lines):
|
|
0 commit comments