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))
Esempio n. 2
0
def check_interfaces_and_services(dut,
                                  interfaces,
                                  xcvr_skip_list,
                                  reboot_type=None):
    """
    Perform a further check after reboot-cause, including transceiver status, interface status
    @param localhost: The Localhost object.
    @param dut: The AnsibleHost object of DUT.
    @param interfaces: DUT's interfaces defined by minigraph
    """
    logging.info("Wait until all critical services are fully started")
    wait_critical_processes(dut)

    if reboot_type is not None:
        logging.info("Check reboot cause")
        assert wait_until(MAX_WAIT_TIME_FOR_REBOOT_CAUSE, 20, check_reboot_cause, dut, reboot_type), \
            "got reboot-cause failed after rebooted by %s" % reboot_type

        if reboot_ctrl_dict[reboot_type]["test_reboot_cause_only"]:
            logging.info(
                "Further checking skipped for %s test which intends to verify reboot-cause only"
                % reboot_type)
            return

    if dut.is_supervisor_node():
        logging.info("skipping interfaces related check for supervisor")
    else:
        logging.info(
            "Wait {} seconds for all the transceivers to be detected".format(
                MAX_WAIT_TIME_FOR_INTERFACES))
        result = wait_until(MAX_WAIT_TIME_FOR_INTERFACES, 20,
                            check_all_interface_information, dut, interfaces,
                            xcvr_skip_list)
        assert result, "Not all transceivers are detected or interfaces are up in {} seconds".format(
            MAX_WAIT_TIME_FOR_INTERFACES)

        logging.info("Check transceiver status")
        for asic_index in dut.get_frontend_asic_ids():
            # Get the interfaces pertaining to that asic
            interface_list = get_port_map(dut, asic_index)
            interfaces_per_asic = {
                k: v
                for k, v in interface_list.items() if k in interfaces
            }
            check_transceiver_basic(dut, asic_index, interfaces_per_asic,
                                    xcvr_skip_list)

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

    if dut.facts["asic_type"] in ["mellanox"]:

        from .mellanox.check_hw_mgmt_service import check_hw_management_service
        from .mellanox.check_sysfs import check_sysfs

        logging.info("Check the hw-management service")
        check_hw_management_service(dut)

        logging.info("Check sysfs")
        check_sysfs(dut)
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"]

    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 PSUs are displayed with OK status on '{}'".format(duthost.hostname))
Esempio n. 4
0
def check_interfaces_and_services(dut, interfaces, reboot_type=None):
    """
    Perform a further check after reboot-cause, including transceiver status, interface status
    @param localhost: The Localhost object.
    @param dut: The AnsibleHost object of DUT.
    @param interfaces: DUT's interfaces defined by minigraph
    """
    logging.info("Wait until all critical services are fully started")
    wait_critical_processes(dut)

    if reboot_type is not None:
        logging.info("Check reboot cause")
        assert wait_until(MAX_WAIT_TIME_FOR_REBOOT_CAUSE, 20, check_reboot_cause, dut, reboot_type), \
            "got reboot-cause failed after rebooted by %s" % reboot_type

        if reboot_ctrl_dict[reboot_type]["test_reboot_cause_only"]:
            logging.info(
                "Further checking skipped for %s test which intends to verify reboot-cause only"
                % reboot_type)
            return

    logging.info("Wait %d seconds for all the transceivers to be detected" %
                 MAX_WAIT_TIME_FOR_INTERFACES)
    assert wait_until(MAX_WAIT_TIME_FOR_INTERFACES, 20, check_interface_information, dut, interfaces), \
        "Not all transceivers are detected or interfaces are up in %d seconds" % MAX_WAIT_TIME_FOR_INTERFACES

    logging.info("Check transceiver status")
    check_transceiver_basic(dut, interfaces)

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

    if dut.facts["asic_type"] in ["mellanox"]:

        from .mellanox.check_hw_mgmt_service import check_hw_management_service
        from .mellanox.check_sysfs import check_sysfs

        logging.info("Check the hw-management service")
        check_hw_management_service(dut)

        logging.info("Check sysfs")
        check_sysfs(dut)
Esempio n. 5
0
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
    if duthost.facts["platform"] == "x86_64-dellemc_z9332f_d1508-r0":
        led_status_list = ["N/A"]
    else:
        led_status_list = ["green", "amber", "red", "off"]
    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 led_status_list,
            "Unexpected PSU led_status value: '{}'".format(
                psu_info["led_status"]))