Esempio n. 1
0
def run(test, params, env):
    """
    Enable MULTI_QUEUE feature in guest

    1) Boot up VM with wrong queues number
    2) Check qemu not coredump
    3) Check the qemu can report the error

    :param test: QEMU test object.
    :param params: Dictionary with the test parameters.
    :param env: Dictionary with test environment.
    """
    vm_name = params["main_vm"]
    params["start_vm"] = "yes"
    nic_queues = int(params["queues"])
    try:
        error.context("Boot the vm using queues %s'" % nic_queues,
                      logging.info)
        env_process.preprocess_vm(test, params, env, vm_name)
        vm = env.get_vm(vm_name)
        vm.destroy()
        raise error.TestError("Qemu start up normally, "
                              "didn't quit as expect")
    except utils_net.NetError, exp:
        message = str(exp)
        # clean up tap device when qemu coredump to ensure,
        # to ensure next test has clean network envrioment
        if (hasattr(exp, 'ifname') and exp.ifname and
                exp.ifname in utils_net.get_host_iface()):
            try:
                bridge = params.get("netdst", "switch")
                utils_net.del_from_bridge(exp.ifname, bridge)
            except Exception as warning:
                logging.warn("Error occurent when clean tap " +
                             "device(%s)" % str(warning))
        error.context("Check Qemu not coredump", logging.info)
        if "(core dumped)" in message:
            raise error.TestFail("Qemu core dumped when boot "
                                 "with invalid parameters.")
        error.context("Check Qemu quit with except message", logging.info)
        if not re.search(params['key_words'], message, re.M | re.I):
            logging.info("Error message: %s" % message)
            raise error.TestFail("Can't detect expect error")
Esempio n. 2
0
def run(test, params, env):
    """
    Enable MULTI_QUEUE feature in guest

    1) Boot up VM with wrong queues number
    2) Check qemu not coredump
    3) Check the qemu can report the error

    :param test: QEMU test object.
    :param params: Dictionary with the test parameters.
    :param env: Dictionary with test environment.
    """
    vm_name = params["main_vm"]
    params["start_vm"] = "yes"
    nic_queues = int(params["queues"])
    try:
        error.context("Boot the vm using queues %s'" % nic_queues,
                      logging.info)
        env_process.preprocess_vm(test, params, env, vm_name)
        vm = env.get_vm(vm_name)
        vm.destroy()
        raise error.TestError("Qemu start up normally, "
                              "didn't quit as expect")
    except utils_net.NetError, exp:
        message = str(exp)
        # clean up tap device when qemu coredump to ensure,
        # to ensure next test has clean network envrioment
        if (hasattr(exp, 'ifname') and exp.ifname
                and exp.ifname in utils_net.get_host_iface()):
            try:
                bridge = params.get("netdst", "switch")
                utils_net.del_from_bridge(exp.ifname, bridge)
            except Exception as warning:
                logging.warn("Error occurent when clean tap " +
                             "device(%s)" % str(warning))
        error.context("Check Qemu not coredump", logging.info)
        if "(core dumped)" in message:
            raise error.TestFail("Qemu core dumped when boot "
                                 "with invalid parameters.")
        error.context("Check Qemu quit with except message", logging.info)
        if not re.search(params['key_words'], message, re.M | re.I):
            logging.info("Error message: %s" % message)
            raise error.TestFail("Can't detect expect error")
Esempio n. 3
0
def run(test, params, env):
    """
    Qemu host nic bonding test:
    1) Load bonding module with mode 802.3ad
    2) Bring up bond interface
    3) Add nics to bond interface
    4) Add a new bridge and add bond interface to it
    5) Get ip address for bridge
    6) Boot up guest with the bridge
    7) Checking guest netowrk via ping
    8) Start file transfer between guest and host
    9) Disable and enable physical interfaces during file transfer

    :param test: QEMU test object
    :param params: Dictionary with the test parameters
    :param env: Dictionary with test environment.
    """
    bond_iface = params.get("bond_iface", "bond0")
    bond_br_name = params.get("bond_br_name", "br_bond0")
    timeout = int(params.get("login_timeout", 240))
    remote_host = params.get("dsthost")
    ping_timeout = int(params.get("ping_timeout", 240))
    bonding_timeout = int(params.get("bonding_timeout", 1))
    params['netdst'] = bond_br_name

    error.context("Load bonding module with mode 802.3ad", logging.info)
    if not utils.system("lsmod|grep bonding", ignore_status=True):
        utils.system("modprobe -r bonding")

    utils.system("modprobe bonding mode=802.3ad")

    error.context("Bring up %s" % bond_iface, logging.info)
    host_ifaces = utils_net.get_host_iface()

    if bond_iface not in host_ifaces:
        raise error.TestError("Can not find bond0 in host")

    bond_iface = utils_net.Interface(bond_iface)
    bond_iface.up()
    bond_mac = bond_iface.get_mac()

    host_ph_iface_pre = params.get("host_ph_iface_prefix", "en")
    host_iface_bonding = int(params.get("host_iface_bonding", 2))

    host_ph_ifaces = [_ for _ in host_ifaces if re.match(host_ph_iface_pre, _)]

    if len(host_ph_ifaces) < 2 or len(host_ph_ifaces) < host_iface_bonding:
        raise error.TestErrorNA("Host need %s nics"
                                " at least." % host_iface_bonding)

    error.context("Add nics to %s" % bond_iface.name, logging.info)
    host_ifaces_bonding = host_ph_ifaces[:host_iface_bonding]
    ifenslave_cmd = "ifenslave %s" % bond_iface.name
    op_ifaces = []
    for host_iface_bonding in host_ifaces_bonding:
        op_ifaces.append(utils_net.Interface(host_iface_bonding))
        ifenslave_cmd += " %s" % host_iface_bonding
    utils.system(ifenslave_cmd)

    error.context("Add a new bridge and add %s to it." % bond_iface.name,
                  logging.info)
    bonding_bridge = utils_net.Bridge()
    if bond_br_name not in bonding_bridge.list_br():
        bonding_bridge.add_bridge(bond_br_name)
    bonding_bridge.add_port(bond_br_name, bond_iface.name)

    error.context("Get ip address for bridge", logging.info)
    utils.system("pkill dhclient; dhclient %s" % bond_br_name)

    error.context("Boot up guest with bridge %s" % bond_br_name, logging.info)
    params["start_vm"] = "yes"
    vm_name = params.get("main_vm")
    env_process.preprocess_vm(test, params, env, vm_name)
    vm = env.get_vm(vm_name)
    session = vm.wait_for_login(timeout=timeout)

    error.context("Checking guest netowrk via ping.", logging.info)
    ping_cmd = params.get("ping_cmd")
    ping_cmd = re.sub("REMOTE_HOST", remote_host, ping_cmd)
    session.cmd(ping_cmd, timeout=ping_timeout)

    error.context("Start file transfer", logging.info)
    f_transfer = utils.InterruptedThread(utils_test.run_virt_sub_test,
                                         args=(test, params, env,),
                                         kwargs={"sub_type": "file_transfer"})
    f_transfer.start()
    utils_misc.wait_for(lambda: utils.system_output("pidof scp",
                                                    ignore_status=True), 30)

    error.context("Disable and enable physical "
                  "interfaces in %s" % bond_br_name, logging.info)
    while True:
        for op_iface in op_ifaces:
            logging.debug("Turn down %s" % op_iface.name)
            op_iface.down()
            time.sleep(bonding_timeout)
            logging.debug("Bring up %s" % op_iface.name)
            op_iface.up()
            time.sleep(bonding_timeout)
        if not f_transfer.is_alive():
            break
    f_transfer.join()
Esempio n. 4
0
def run(test, params, env):
    """
    create/delete macvtap in host

    1) Verify no other macvtap share the physical network device.
    2) Create a macvtap device in host.
    3) Check configuraton of macvtap device.
    4) Ping out from host with the interface that create macvtap.
    5) Delete the macvtap device create in step 2.
    6) Ping out from host with the interface that create macvtap.

    :param test: QEMU test object.
    :param params: Dictionary with the test parameters.
    :param env: Dictionary with test environment.
    """

    ifname = params.get("macvtap_base_interface")
    macvtap_mode = params.get("macvtap_mode", "passthru")
    dest_host = params.get("dest_host")
    set_mac = params.get("set_mac", "yes") == "yes"
    macvtaps = []

    if not ifname:
        ifname = params.get("netdst")
    ifname = utils_net.get_macvtap_base_iface(ifname)

    error.context("Verify no other macvtap share the physical network device.",
                  logging.info)
    macvtap_devices = get_macvtap_device_on_ifname(ifname)
    for device in macvtap_devices:
        utils.system_output("ip link delete %s" % device)

    for mode in macvtap_mode.split():
        macvtap_name = "%s_01" % mode
        txt = "Create %s mode macvtap device %s on %s." % (mode, macvtap_name,
                                                           ifname)
        error.context(txt, logging.info)
        cmd = " ip link add link %s name %s type macvtap mode %s" % (
            ifname, macvtap_name, mode)
        utils.system(cmd, timeout=240)
        if set_mac:
            txt = "Determine and configure mac address of %s, " % macvtap_name
            txt += "Then link up it."
            error.context(txt, logging.info)
            mac = utils_net.generate_mac_address_simple()
            cmd = " ip link set %s address %s up" % (macvtap_name, mac)
            utils.system(cmd, timeout=240)

        error.context("Check configuraton of macvtap device", logging.info)
        check_cmd = " ip -d link show %s" % macvtap_name
        try:
            tap_info = utils.system_output(check_cmd, timeout=240)
        except error.CmdError:
            err = "Fail to create %s mode macvtap on %s" % (mode, ifname)
            raise error.TestFail(err)
        if set_mac:
            if mac not in tap_info:
                err = "Fail to set mac for %s" % macvtap_name
                raise error.TestFail(err)
        macvtaps.append(macvtap_name)

    if not dest_host:
        dest_host_get_cmd = "ip route | awk '/default/ { print $3 }'"
        dest_host_get_cmd = params.get("dest_host_get_cmd", dest_host_get_cmd)
        dest_host = utils.system_output(dest_host_get_cmd).split()[-1]

    txt = "Ping dest host %s from " % dest_host
    txt += "localhost with the interface %s" % ifname
    error.context(txt, logging.info)
    status, output = utils_test.ping(dest_host,
                                     10,
                                     interface=ifname,
                                     timeout=20)
    ratio = utils_test.get_loss_ratio(output)
    if "passthru" in macvtap_mode:
        ifnames = utils_net.get_host_iface()
        ifnames.remove(ifname)
        logging.info("ifnames = %s", ifnames)
        ips = []
        for name in ifnames:
            try:
                _ip = utils_net.get_ip_address_by_interface(name)
                if _ip != "127.0.0.1":
                    ips.append(_ip)
            except Exception:
                pass
        logging.info("ips = %s", ips)
        if not ips:
            if ratio != 100:
                err = "%s did not lost network connection after " % ifname
                err += " creating %s mode macvtap on it." % macvtap_mode
                raise error.TestFail(err)
        else:
            err = "%s is not the only network device in host" % ifname
            logging.debug(err)
    else:
        if ratio != 0:
            err = "Package lost during ping %s from %s " % (dest_host, ifname)
            err += "after creating %s mode macvtap on it." % macvtap_mode
            raise error.TestFail(err)

    for name in macvtaps:
        txt = "Delete macvtap device %s on %s." % (name, ifname)
        error.context(txt, logging.info)
        del_cmd = "ip link delete %s" % name
        utils.system(del_cmd)
        devices = get_macvtap_device_on_ifname(ifname)
        if name in devices:
            err = "Fail to delete macvtap %s on %s" % (name, ifname)
            raise error.TestFail(err)

    logging.info("dest_host = %s", dest_host)
    txt = "Ping dest host %s from " % dest_host
    txt += "localhost with the interface %s" % ifname
    error.context(txt, logging.info)
    status, output = utils_test.ping(dest_host,
                                     10,
                                     interface=ifname,
                                     timeout=20)
    if status != 0:
        raise error.TestFail("Ping failed, status: %s,"
                             " output: %s" % (status, output))
    ratio = utils_test.get_loss_ratio(output)
    if ratio != 0:
        err = "Package lost during ping %s from %s " % (dest_host, ifname)
        raise error.TestFail(err)
Esempio n. 5
0
def run(test, params, env):
    """
    Qemu host nic bonding test:
    1) Load bonding module with mode 802.3ad
    2) Bring up bond interface
    3) Add nics to bond interface
    4) Add a new bridge and add bond interface to it
    5) Get ip address for bridge
    6) Boot up guest with the bridge
    7) Checking guest netowrk via ping
    8) Start file transfer between guest and host
    9) Disable and enable physical interfaces during file transfer

    :param test: QEMU test object
    :param params: Dictionary with the test parameters
    :param env: Dictionary with test environment.
    """
    bond_iface = params.get("bond_iface", "bond0")
    bond_br_name = params.get("bond_br_name", "br_bond0")
    timeout = int(params.get("login_timeout", 240))
    remote_host = params.get("dsthost")
    ping_timeout = int(params.get("ping_timeout", 240))
    bonding_timeout = int(params.get("bonding_timeout", 1))
    bonding_mode = params.get("bonding_mode", "1")
    bonding_miimon = params.get("bonding_miimon", "100")
    bonding_max_bonds = params.get("bonding_max_bonds", "1")
    params['netdst'] = bond_br_name
    host_bridges = utils_net.Bridge()

    error_context.context("Load bonding module with mode 802.3ad",
                          logging.info)
    if not process.system("lsmod|grep bonding", ignore_status=True,
                          shell=True):
        process.system("modprobe -r bonding")

    process.system("modprobe bonding mode=%s miimon=%s max_bonds=%s" %
                   (bonding_mode, bonding_miimon, bonding_max_bonds))

    error_context.context("Bring up %s" % bond_iface, logging.info)
    host_ifaces = utils_net.get_host_iface()

    if bond_iface not in host_ifaces:
        test.error("Can not find %s in host" % bond_iface)

    bond_iface = utils_net.Interface(bond_iface)
    bond_iface.up()
    bond_mac = bond_iface.get_mac()

    host_ph_iface_pre = params.get("host_ph_iface_prefix", "en")
    host_iface_bonding = int(params.get("host_iface_bonding", 2))

    ph_ifaces = [_ for _ in host_ifaces if re.match(host_ph_iface_pre, _)]
    host_ph_ifaces = [_ for _ in ph_ifaces if utils_net.Interface(_).is_up()]

    ifaces_in_use = host_bridges.list_iface()
    host_ph_ifaces_un = list(set(host_ph_ifaces) - set(ifaces_in_use))

    if (len(host_ph_ifaces_un) < 2
            or len(host_ph_ifaces_un) < host_iface_bonding):
        test.cancel("Host need %s nics at least." % host_iface_bonding)

    error_context.context("Add nics to %s" % bond_iface.name, logging.info)
    host_ifaces_bonding = host_ph_ifaces_un[:host_iface_bonding]
    ifenslave_cmd = "ifenslave %s" % bond_iface.name
    op_ifaces = []
    for host_iface_bonding in host_ifaces_bonding:
        op_ifaces.append(utils_net.Interface(host_iface_bonding))
        ifenslave_cmd += " %s" % host_iface_bonding
    process.system(ifenslave_cmd)

    error_context.context(
        "Add a new bridge and add %s to it." % bond_iface.name, logging.info)
    if bond_br_name not in host_bridges.list_br():
        host_bridges.add_bridge(bond_br_name)
    host_bridges.add_port(bond_br_name, bond_iface.name)

    error_context.context("Get ip address for bridge", logging.info)
    process.system("dhclient -r; dhclient %s" % bond_br_name, shell=True)

    error_context.context("Boot up guest with bridge %s" % bond_br_name,
                          logging.info)
    params["start_vm"] = "yes"
    vm_name = params.get("main_vm")
    env_process.preprocess_vm(test, params, env, vm_name)
    vm = env.get_vm(vm_name)
    session = vm.wait_for_login(timeout=timeout)

    error_context.context("Checking guest netowrk via ping.", logging.info)
    ping_cmd = params.get("ping_cmd")
    ping_cmd = re.sub("REMOTE_HOST", remote_host, ping_cmd)
    session.cmd(ping_cmd, timeout=ping_timeout)

    error_context.context("Start file transfer", logging.info)
    f_transfer = utils_misc.InterruptedThread(
        utils_test.run_virt_sub_test,
        args=(
            test,
            params,
            env,
        ),
        kwargs={"sub_type": "file_transfer"})
    f_transfer.start()
    utils_misc.wait_for(
        lambda: process.system_output("pidof scp", ignore_status=True), 30)

    error_context.context(
        "Disable and enable physical "
        "interfaces in %s" % bond_br_name, logging.info)
    while True:
        for op_iface in op_ifaces:
            logging.debug("Turn down %s", op_iface.name)
            op_iface.down()
            time.sleep(bonding_timeout)
            logging.debug("Bring up %s", op_iface.name)
            op_iface.up()
            time.sleep(bonding_timeout)
        if not f_transfer.is_alive():
            break
    f_transfer.join()
def run(test, params, env):
    """
    create/delete macvtap in host

    1) Verify no other macvtap share the physical network device.
    2) Create a macvtap device in host.
    3) Check configuraton of macvtap device.
    4) Ping out from host with the interface that create macvtap.
    5) Delete the macvtap device create in step 2.
    6) Ping out from host with the interface that create macvtap.

    :param test: QEMU test object.
    :param params: Dictionary with the test parameters.
    :param env: Dictionary with test environment.
    """

    ifname = params.get("macvtap_base_interface")
    macvtap_mode = params.get("macvtap_mode", "passthru")
    dest_host = params.get("dest_host")
    set_mac = params.get("set_mac", "yes") == "yes"
    macvtaps = []

    if not ifname:
        ifname = params.get("netdst")
    ifname = utils_net.get_macvtap_base_iface(ifname)

    error.context("Verify no other macvtap share the physical network device.", logging.info)
    macvtap_devices = get_macvtap_device_on_ifname(ifname)
    for device in macvtap_devices:
        utils.system_output("ip link delete %s" % device)

    for mode in macvtap_mode.split():
        macvtap_name = "%s_01" % mode
        txt = "Create %s mode macvtap device %s on %s." % (mode, macvtap_name, ifname)
        error.context(txt, logging.info)
        cmd = " ip link add link %s name %s type macvtap mode %s" % (ifname, macvtap_name, mode)
        utils.system(cmd, timeout=240)
        if set_mac:
            txt = "Determine and configure mac address of %s, " % macvtap_name
            txt += "Then link up it."
            error.context(txt, logging.info)
            mac = utils_net.generate_mac_address_simple()
            cmd = " ip link set %s address %s up" % (macvtap_name, mac)
            utils.system(cmd, timeout=240)

        error.context("Check configuraton of macvtap device", logging.info)
        check_cmd = " ip -d link show %s" % macvtap_name
        try:
            tap_info = utils.system_output(check_cmd, timeout=240)
        except error.CmdError:
            err = "Fail to create %s mode macvtap on %s" % (mode, ifname)
            raise error.TestFail(err)
        if set_mac:
            if mac not in tap_info:
                err = "Fail to set mac for %s" % macvtap_name
                raise error.TestFail(err)
        macvtaps.append(macvtap_name)

    if not dest_host:
        dest_host_get_cmd = "ip route | awk '/default/ { print $3 }'"
        dest_host_get_cmd = params.get("dest_host_get_cmd", dest_host_get_cmd)
        dest_host = utils.system_output(dest_host_get_cmd).split()[-1]

    txt = "Ping dest host %s from " % dest_host
    txt += "localhost with the interface %s" % ifname
    error.context(txt, logging.info)
    status, output = utils_test.ping(dest_host, 10, interface=ifname, timeout=20)
    ratio = utils_test.get_loss_ratio(output)
    if "passthru" in macvtap_mode:
        ifnames = utils_net.get_host_iface()
        ifnames.remove(ifname)
        logging.info("ifnames = %s", ifnames)
        ips = []
        for name in ifnames:
            try:
                _ip = utils_net.get_ip_address_by_interface(name)
                if _ip != "127.0.0.1":
                    ips.append(_ip)
            except Exception:
                pass
        logging.info("ips = %s", ips)
        if not ips:
            if ratio != 100:
                err = "%s did not lost network connection after " % ifname
                err += " creating %s mode macvtap on it." % macvtap_mode
                raise error.TestFail(err)
        else:
            err = "%s is not the only network device in host" % ifname
            logging.debug(err)
    else:
        if ratio != 0:
            err = "Package lost during ping %s from %s " % (dest_host, ifname)
            err += "after creating %s mode macvtap on it." % macvtap_mode
            raise error.TestFail(err)

    for name in macvtaps:
        txt = "Delete macvtap device %s on %s." % (name, ifname)
        error.context(txt, logging.info)
        del_cmd = "ip link delete %s" % name
        utils.system(del_cmd)
        devices = get_macvtap_device_on_ifname(ifname)
        if name in devices:
            err = "Fail to delete macvtap %s on %s" % (name, ifname)
            raise error.TestFail(err)

    logging.info("dest_host = %s", dest_host)
    txt = "Ping dest host %s from " % dest_host
    txt += "localhost with the interface %s" % ifname
    error.context(txt, logging.info)
    status, output = utils_test.ping(dest_host, 10, interface=ifname, timeout=20)
    if status != 0:
        raise error.TestFail("Ping failed, status: %s," " output: %s" % (status, output))
    ratio = utils_test.get_loss_ratio(output)
    if ratio != 0:
        err = "Package lost during ping %s from %s " % (dest_host, ifname)
        raise error.TestFail(err)