def test_show_platform_psustatus(duthosts, enum_supervisor_dut_hostname): """ @summary: Verify output of `show platform psustatus` """ duthost = duthosts[enum_supervisor_dut_hostname] logging.info("Check pmon daemon status on dut '{}'".format( duthost.hostname)) assert check_pmon_daemon_status( duthost), "Not all pmon daemons running on '{}'".format( duthost.hostname) cmd = " ".join([CMD_SHOW_PLATFORM, "psustatus"]) logging.info("Verifying output of '{}' on '{}' ...".format( cmd, duthost.hostname)) psu_status_output_lines = duthost.command(cmd)["stdout_lines"] psu_line_pattern = get_dut_psu_line_pattern(duthost) # 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(2) if psu_status == "OK": num_psu_ok += 1 pytest_assert( num_psu_ok > 0, "No PSUs are displayed with OK status on '{}'".format( duthost.hostname))
def test_turn_on_off_psu_and_check_psustatus(duthosts, enum_rand_one_per_hwsku_hostname, pdu_controller, ignore_particular_error_log): """ @summary: Turn off/on PSU and check PSU status using 'show platform psustatus' """ duthost = duthosts[enum_rand_one_per_hwsku_hostname] psu_line_pattern = get_dut_psu_line_pattern(duthost) psu_num = get_psu_num(duthost) pytest_require(psu_num >= 2, "At least 2 PSUs required for rest of the testing in this case") logging.info("Create PSU controller for testing") pdu_ctrl = pdu_controller pytest_require(pdu_ctrl, "No PSU controller for %s, skip rest of the testing in this case" % duthost.hostname) logging.info("To avoid DUT being shutdown, need to turn on PSUs that are not powered") turn_all_outlets_on(pdu_ctrl) logging.info("Initialize test results") psu_test_results = {} pytest_require(check_all_psu_on(duthost, psu_test_results), "Some PSU are still down, skip rest of the testing in this case") pytest_assert(len(psu_test_results.keys()) == psu_num, \ "In consistent PSU number output by '%s' and '%s'" % (CMD_PLATFORM_PSUSTATUS, "sudo psuutil numpsus")) logging.info("Start testing turn off/on PSUs") all_outlet_status = pdu_ctrl.get_outlet_status() pytest_require(all_outlet_status and len(all_outlet_status) >= 2, 'Skip the test, cannot get at least 2 outlet status: {}'.format(all_outlet_status)) for outlet in all_outlet_status: psu_under_test = None logging.info("Turn off outlet {}".format(outlet)) pdu_ctrl.turn_off_outlet(outlet) time.sleep(5) cli_psu_status = duthost.command(CMD_PLATFORM_PSUSTATUS) for line in cli_psu_status["stdout_lines"][2:]: psu_match = psu_line_pattern.match(line) pytest_assert(psu_match, "Unexpected PSU status output") if psu_match.group(2) != "OK": psu_under_test = psu_match.group(1) check_vendor_specific_psustatus(duthost, line, psu_line_pattern) pytest_assert(psu_under_test is not None, "No PSU is turned off") logging.info("Turn on outlet {}".format(outlet)) pdu_ctrl.turn_on_outlet(outlet) time.sleep(5) cli_psu_status = duthost.command(CMD_PLATFORM_PSUSTATUS) for line in cli_psu_status["stdout_lines"][2:]: psu_match = psu_line_pattern.match(line) pytest_assert(psu_match, "Unexpected PSU status output") if psu_match.group(1) == psu_under_test: pytest_assert(psu_match.group(2) == "OK", "Unexpected PSU status after turned it on") check_vendor_specific_psustatus(duthost, line, psu_line_pattern) psu_test_results[psu_under_test] = True for psu in psu_test_results: pytest_assert(psu_test_results[psu], "Test psu status of PSU %s failed" % psu)
def turn_off_outlet_and_check_thermal_control(dut, pdu_ctrl, outlet, mocker): """ @summary: Turn off PSUs, check all FAN speed are set to 100% according to thermal control policy file. """ logging.info("Turn off outlet %s" % str(outlet["outlet_id"])) pdu_ctrl.turn_off_outlet(outlet) time.sleep(5) psu_under_test = None psu_line_pattern = get_dut_psu_line_pattern(dut) cli_psu_status = dut.command(CMD_PLATFORM_PSUSTATUS) for line in cli_psu_status["stdout_lines"][2:]: psu_match = psu_line_pattern.match(line) pytest_assert(psu_match, "Unexpected PSU status output") if psu_match.group(2) != "OK": psu_under_test = psu_match.group(1) pytest_assert(psu_under_test is not None, "No PSU is turned off") logging.info('Wait and check all FAN speed turn to 100%...') pytest_assert(wait_until(THERMAL_CONTROL_TEST_WAIT_TIME, THERMAL_CONTROL_TEST_CHECK_INTERVAL, 0, mocker.check_all_fan_speed, 100), 'FAN speed not turn to 100% after PSU off') pdu_ctrl.turn_on_outlet(outlet) time.sleep(5)