Esempio n. 1
0
def find_pf(driver, session=None):
    """
    Check if available PF exists to test

    :param driver: The driver name, for example "ixgbe"
    :param session: The session object to the host
    :raise: exceptions.TestError when no pf found
    :return: (interface name, pf device)
    """
    driver_dir = "/sys/bus/pci/drivers/%s" % driver
    cmd = "ls -d %s/000*" % driver_dir
    s_, output = utils_misc.cmd_status_output(cmd,
                                              shell=True,
                                              ignore_status=False,
                                              session=session)
    runner = None
    if session:
        runner = session.cmd
    pf_tmp = ()
    pf_devices = output.splitlines()
    for pf in pf_devices:
        cmd = "ls %s/net" % pf
        s_, tpm_iface_name = utils_misc.cmd_status_output(cmd,
                                                          shell=True,
                                                          ignore_status=False,
                                                          session=session)

        if (utils_net.get_net_if_operstate(tpm_iface_name.strip(),
                                           runner=runner) == "up"):
            pf_tmp = (tpm_iface_name.strip(), pf.strip().split('/')[-1])
            break

    if not pf_tmp:
        raise exceptions.TestError("NO available pf found.")
    return pf_tmp
Esempio n. 2
0
 def find_pf():
     pci_address = ""
     for pci in pci_dirs:
         temp_iface_name = os.listdir("%s/net" % pci)[0]
         operstate = utils_net.get_net_if_operstate(temp_iface_name)
         if operstate == "up":
             pf_iface_name = temp_iface_name
             pci_address = pci
             break
     if pci_address == "":
         return False
     else:
         return pci_address
Esempio n. 3
0
 def find_pf():
     pci_address = ""
     for pci in pci_dirs:
         temp_iface_name = os.listdir("%s/net" % pci)[0]
         operstate = utils_net.get_net_if_operstate(temp_iface_name)
         if operstate == "up":
             pf_iface_name = temp_iface_name
             pci_address = pci
             break
     if pci_address == "":
         return False
     else:
         return pci_address
Esempio n. 4
0
    def operstate_check(session, expect_status, guest_ifname=""):
        """
        Check Guest interface operstate
        """
        if params.get("os_type") == "linux":
            if_operstate = utils_net.get_net_if_operstate(guest_ifname, session.cmd_output_safe)
        else:
            if_operstate = utils_net.get_windows_nic_attribute(
                session, "macaddress", vm.get_mac_address(), "netconnectionstatus"
            )

        if if_operstate != expect_status:
            err_msg = "Guest interface %s status error, " % guest_ifname
            err_msg = "currently interface status is '%s', " % if_operstate
            err_msg += "but expect status is '%s'" % expect_status
            raise error.TestFail(err_msg)
        logging.info("Guest interface operstate '%s' is exactly as expected" % if_operstate)
Esempio n. 5
0
    def operstate_check(session, expect_status, guest_ifname=""):
        """
        Check Guest interface operstate
        """
        if params.get("os_type") == "linux":
            if_operstate = utils_net.get_net_if_operstate(
                guest_ifname, session.cmd)
        else:
            if_operstate = utils_net.get_windows_nic_attribute(
                session, "macaddress", vm.get_mac_address(),
                "netconnectionstatus")

        if if_operstate != expect_status:
            err_msg = "Guest interface %s status error, " % guest_ifname
            err_msg = "currently interface status is '%s', " % if_operstate
            err_msg += "but expect status is '%s'" % expect_status
            raise error.TestFail(err_msg)
        logging.info("Guest interface operstate '%s' is exactly as expected" %
                     if_operstate)
Esempio n. 6
0
def get_pf_info(session=None):
    """
    Get PFs information

    :param session: The session object to the host
    :raise: exceptions.TestError when command fails
    :return: dict, pfs' info.
        eg. {'3b:00.0': {'driver': 'ixgbe', 'pci_id': '0000:3b:00.0',
                         'iface': 'ens1f0', 'status': 'up'},
             '3b:00.1': {'driver': 'ixgbe', 'pci_id': '0000:3b:00.1',
                         'iface': 'ens1f1', 'status': 'down'}}

    """
    pf_info = {}
    status, output = utils_misc.cmd_status_output(
        "lspci |awk '/Ethernet/ {print $1}'", shell=True)
    if status or not output:
        raise exceptions.TestError(
            "Unable to get Ethernet controllers. status: %s,"
            "stdout: %s." % (status, output))
    for pci in output.split():
        _, output = utils_misc.cmd_status_output("lspci -v -s %s" % pci,
                                                 shell=True)
        if re.search("SR-IOV", output):
            pf_driver = re.search('driver in use: (.*)', output)[1]
            tmp_info = {'driver': pf_driver, 'pci_id': '0000:%s' % pci}

            iface_name = get_iface_name('0000:%s' % pci, session=session)
            runner = None if not session else session.cmd
            tmp_info.update({
                'iface':
                iface_name.strip(),
                'status':
                utils_net.get_net_if_operstate(iface_name.strip(),
                                               runner=runner)
            })
            pf_info.update({pci: tmp_info})
    LOG.debug("PF info: %s.", pf_info)
    return pf_info
Esempio n. 7
0
    def guest_interface_operstate_check(expect_status, guest_ifname=""):
        """
        Check Guest interface operstate
        """
        session = vm.wait_for_serial_login()

        os_type = params.get("os_type")
        if os_type == "linux":
            if_operstate = utils_net.get_net_if_operstate(guest_ifname,
                                                          session.cmd)
        else:
            if_operstate = utils_net.get_windows_nic_attribute(session,
                                                               "macaddress", vm.get_mac_address(), "netconnectionstatus")
        session.close()

        if if_operstate != expect_status:
            err_msg = "Guest interface %s status error, " % guest_ifname
            err_msg = "currently interface status is '%s', " % if_operstate
            err_msg += "but expect status is '%s'" % expect_status
            raise error.TestError(err_msg)
        logging.info("Guest interface operstate '%s' is exactly as expected" %
                     if_operstate)