Esempio n. 1
0
def run(test, params, env):
    """
    Hot-plug virtio-serial-pci and chardev and virtserialport

    1. Boot a guest without any device
    2. Hot plug virtio-serial-bus
    3. Hot add chardev 1
    4. Hot plug serial port on chardev 1
    5. Transfer data from host to guest via port
    6. Transfer data from guest to host via port

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

    vm = env.get_vm(params['main_vm'])
    os_type = params["os_type"]
    char_devices = add_chardev(vm, params)
    serials = params.objects('extra_serials')
    buses, serial_devices = get_buses_and_serial_devices(
        vm, params, char_devices, serials)
    vm.devices.simple_hotplug(buses[0], vm.monitor)
    vm.devices.simple_hotplug(char_devices[0], vm.monitor)
    vm.devices.simple_hotplug(serial_devices[0], vm.monitor)
    for device in serial_devices:
        add_virtio_ports_to_vm(vm, params, device)
    if os_type == "windows":
        driver_name = params["driver_name"]
        session = vm.wait_for_login()
        session = utils_test.qemu.windrv_check_running_verifier(
            session, vm, test, driver_name)
    params['file_transfer_serial_port'] = serials[0]
    transfer_data(params, vm, sender='both')
Esempio n. 2
0
def run(test, params, env):
    """
    Hot-plug virtio-serial-pci and virtserialport

    1. Boot a guest with 2 chardev, no serial port & no pci
    2. Hot plug virtio-serial-bus
    3. Hot add virtserialport, attached on chardev 1
    4. Hot plug another serial port on chardev 2 with "nr=1", should fail
    5. Hot plug the serial port again with "nr=2"
    6. Transfer data from host to guest via port1
    7. Transfer data from guest to host via port2

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

    params['serials'] = params.objects('serials')[0]
    vm = env.get_vm(params['main_vm'])
    char_devices = add_chardev(vm, params)
    for device in char_devices:
        extra_params = ' ' + device.cmdline()
        params['extra_params'] = params.get('extra_params', '') + extra_params
    params['start_vm'] = "yes"
    env_process.preprocess(test, params, env)
    vm = env.get_vm(params['main_vm'])
    vm.devices.insert(char_devices)
    serials = params.objects('extra_serials')
    buses = []
    serial_devices = []
    for index, serial_id in enumerate(serials):
        chardev_id = char_devices[index].get_qid()
        params['serial_name_%s' % serial_id] = serial_id
        devices = add_virtserial_device(vm, params, serial_id, chardev_id)
        for device in devices:
            if device.child_bus:
                buses.append(device)
            else:
                serial_devices.append(device)
    vm.devices.simple_hotplug(buses[0], vm.monitor)
    vm.devices.simple_hotplug(serial_devices[0], vm.monitor)
    pre_nr = serial_devices[0].get_param('nr')
    # Try hotplug different device with same 'nr'
    serial_devices[1].set_param('bus', serial_devices[0].get_param('bus'))
    serial_devices[1].set_param('nr', pre_nr)
    try:
        serial_devices[1].hotplug(vm.monitor)
    except QMPCmdError as e:
        if 'A port already exists at id %d' % pre_nr not in str(e.data):
            test.fail('Hotplug fail for %s, not as expected' % str(e.data))
    else:
        test.fail('Hotplug with same "nr" option success while should fail')
    serial_devices[1].set_param('nr', int(pre_nr) + 1)
    vm.devices.simple_hotplug(serial_devices[1], vm.monitor)
    for device in serial_devices:
        add_virtio_ports_to_vm(vm, params, device)
    params['file_transfer_serial_port'] = serials[0]
    transfer_data(params, vm, sender='host')
    params['file_transfer_serial_port'] = serials[1]
    transfer_data(params, vm, sender='guest')
Esempio n. 3
0
def run(test, params, env):
    """
    Hot-plug chardev and virtserialport

    1. Boot a guest with 1 virtconsole attached to pty backend
    2. Hot plug unix_socket backend
    3. Hot add virtserialport, attached on unix chardev
    4. Transfer data between host and guest via virtserialport
    5. Hot-unplug existed virt-serial-pci, this should success without crash

    :param test: kvm test object
    :param params: Dictionary with the test parameters
    :param env: Dictionary with test environment
    """
    vm = env.get_vm(params['main_vm'])
    char_devices = add_chardev(vm, params)
    serials = params.objects('extra_serials')
    serial_devices = get_buses_and_serial_devices(
        vm, params, char_devices, serials)[1]
    vm.devices.simple_hotplug(char_devices[0], vm.monitor)
    vm.devices.simple_hotplug(serial_devices[0], vm.monitor)
    for device in serial_devices:
        add_virtio_ports_to_vm(vm, params, device)
    params['file_transfer_serial_port'] = serials[0]
    transfer_data(params, vm, sender='both')
    if params.get("unplug_pci") == "yes":
        virtio_serial_pci = get_virtio_serial_pci(vm, serial_devices[0])
        vm.devices.simple_unplug(virtio_serial_pci, vm.monitor)
    vm.verify_kernel_crash()
Esempio n. 4
0
def run(test, params, env):
    """
    qemu should try to find a free port value by to=<port> with unix socket and tcp options:
    1) boot guest with socket 'host=127.0.0.1,port=num'
    2) query chardev and check port number
    3) boot another guest with socket 'host=127.0.0.1,port=num,to=num+'
    4) query chardev and check port number, should different from 2)
    :param test: QEMU test object
    :param params: Dictionary with the test parameters
    :param env: Dictionary with test environment.
    """

    chardev_infos = []
    vms = params.get("vms").split()
    _vm = env.get_vm(vms[0])
    char_device = add_chardev(_vm, params)[0]
    chardev_params = char_device.params
    for vm_ind, vm in enumerate(vms):
        if vm_ind == 1:
            host = chardev_params['host']
            chardev_to = utils_misc.find_free_ports(
                int(chardev_params['port']) + 1, 6000, 1, host)
            chardev_params['to'] = str(chardev_to[0])

        extra_params = ' ' + char_device.cmdline()
        params['extra_params_%s' %
               vm] = params.get('extra_params', '') + extra_params
        params['start_vm_%s' % vm] = "yes"
    env_process.preprocess(test, params, env)
    for vm in vms:
        _vm = env.get_vm(vm)
        chardev_infos.append(_vm.monitor.info("chardev"))
    _port, _to = int(chardev_params['port']), int(chardev_params['to'])
    for char_ind, chardevs in enumerate(chardev_infos):
        in_chardev = False
        for chardev in chardevs:
            if chardev['label'] == chardev_params['id']:
                tmp_pnum = int(
                    chardev['filename'].split(':')[-1].split(',')[0])
                error_context.context(
                    "Get port %d for vm%d from monitor" % (tmp_pnum, char_ind),
                    logging.info)
                break
        if char_ind == 0:
            error_context.context(
                "The expect port for vm%d is %d" % (char_ind, _port),
                logging.info)
            if tmp_pnum == _port:
                in_chardev = True
        else:
            error_context.context(
                "The expect port for vm%d is in [%d, %d]" %
                (char_ind, _port + 1, _to), logging.info)
            if tmp_pnum > _port and tmp_pnum <= _to:
                in_chardev = True
        assert in_chardev is True, 'The actual port does not match with the expect port in VM %d' % char_ind
def run(test, params, env):
    """
    Hot-plug max chardevs on one virtio-serial-pci

    1. Boot a guest without any device
    2. Hotplug virtio-serial-pci
    3. Hotplug 31 chardevs
    4. Hotadd 30 virtserialports attached every one chardev
    5. Transfer data between guest and host via all ports
    6. Hotplug one existed chardev
    7. Hotplug one existed virtserialport
    8. Hot-unplug virtserialport
    9. Hot-unplug chardev

    :param test: kvm test object
    :param params: Dictionary with the test parameters
    :param env: Dictionary with test environment
    """
    def run_serial_data_transfer():
        """
        Transfer data via every virtserialport.
        """
        for serial_port in serials:
            port_params = params.object_params(serial_port)
            if not port_params['serial_type'].startswith('virtserial'):
                continue
            logging.info("transfer data with port %s", serial_port)
            params['file_transfer_serial_port'] = serial_port
            transfer_data(params, vm, sender='both')

    def run_bg_test():
        """
        Set the operation of transferring data as background
        :return: return the background case thread if it's successful;
                 else raise error
        """
        stress_thread = utils_misc.InterruptedThread(run_serial_data_transfer)
        stress_thread.start()
        if not utils_misc.wait_for(
                lambda: driver_in_use.check_bg_running(vm, params),
                check_bg_timeout, 0, 1):
            test.fail("Backgroud test is not alive!")
        return stress_thread

    vm = env.get_vm(params["main_vm"])
    vm.verify_alive()
    os_type = params["os_type"]
    check_bg_timeout = float(params.get('check_bg_timeout', 120))
    num_chardev = int(params.get("numberic_chardev"))
    num_serial_ports = int(params.get("virtio_serial_ports"))
    sleep_time = float(params.get('sleep_time', 0.5))
    for i in range(1, num_chardev):
        params["extra_chardevs"] += ' channel%d' % i
        serial_name = 'port%d' % (i - 1)
        params['extra_serials'] = '%s %s' % (params.get('extra_serials',
                                                        ''), serial_name)
        params['serial_type_%s' % serial_name] = "virtserialport"
    char_devices = add_chardev(vm, params)
    serials = params.objects('extra_serials')
    buses, serial_devices = get_buses_and_serial_devices(
        vm, params, char_devices, serials)
    vm.devices.simple_hotplug(buses[0], vm.monitor)
    for i in range(0, num_chardev):
        vm.devices.simple_hotplug(char_devices[i], vm.monitor)
        if i < num_serial_ports:
            vm.devices.simple_hotplug(serial_devices[i], vm.monitor)
            time.sleep(sleep_time)
    for device in serial_devices:
        add_virtio_ports_to_vm(vm, params, device)
    if os_type == "windows":
        driver_name = params["driver_name"]
        session = vm.wait_for_login()
        session = utils_test.qemu.windrv_check_running_verifier(
            session, vm, test, driver_name)
    thread_transfer = run_bg_test()

    error_context.context("hotplug existed virtserialport and chardev",
                          logging.info)
    try:
        serial_devices[0].hotplug(vm.monitor, vm.devices.qemu_version)
    except QMPCmdError as e:
        if "Duplicate ID '%s' for device" % serial_devices[0] not in str(
                e.data):
            msg = ("Should fail to hotplug device %s with error Duplicate" %
                   serial_devices[0])
            test.fail(msg)
    else:
        msg = ("The device %s shoudn't be hotplugged successfully" %
               serial_devices[0])
        test.fail(msg)

    try:
        char_devices[0].hotplug(vm.monitor, vm.devices.qemu_version)
    except QMPCmdError as e:
        if "attempt to add duplicate property '%s'" % char_devices[0] \
                not in str(e.data):
            msg = ("Should fail to hotplug device %s with error Duplicate" %
                   char_devices[0])
            test.fail(msg)
    else:
        msg = ("The device %s shoudn't be hotplugged successfully" %
               char_devices[0])
        test.fail(msg)

    thread_transfer.join()
    if not thread_transfer.is_alive():
        error_context.context("hot-unplug all virtserialport and chardev",
                              logging.info)
        for i in range(0, num_chardev):
            if i < num_serial_ports:
                vm.devices.simple_unplug(serial_devices[i], vm.monitor)
            vm.devices.simple_unplug(char_devices[i], vm.monitor)
    vm.verify_kernel_crash()
def run(test, params, env):
    """
    Hot-plug virtio-serial-pci and virtserialport

    1. Boot a guest with 2 chardev, no serial port & no pci
    2. Hot plug virtio-serial-bus
    3. Hot add virtserialport, attached on chardev 1
    4. Hot plug another serial port on chardev 2 with "nr=1", should fail
    5. Hot plug the serial port again with "nr=2"
    6. Transfer data between guest and host via port1 and port2
    7. Reboot/system_reset/shudown guest after hotplug(optional)
    8. Transfer data between guest and host via port1 and port2
    9. Hot-unplug relative port1 and port2
    10. Hot-unplug virtio-serial-bus
    11. Reboot/system_reset/shudown/migration guest after hot-unplug(optional)
    12. Repeat step 2 to step 10 100 times

    :param test: kvm test object
    :param params: Dictionary with the test parameters
    :param env: Dictionary with test environment
    """
    def run_interrupt_test(interrupt_test):
        """
        Run interrupt test(reboot/shutdown/migration) after hot plug/unplug.

        :param interrupt_test: reboot/shutdown/migration test
        """

        session = vm.wait_for_login()
        globals().get(interrupt_test)(test, params, vm, session)
        session.close()

    def run_serial_data_transfer():
        """
        Transfer data between two ports.
        """

        params['file_transfer_serial_port'] = serials[0]
        transfer_data(params, vm, sender='host')
        params['file_transfer_serial_port'] = serials[1]
        transfer_data(params, vm, sender='guest')

    params['serials'] = params.objects('serials')[0]
    repeat_times = int(params.get("repeat_times", 1))
    interrupt_test_after_plug = params.get("interrupt_test_after_plug")
    interrupt_test_after_unplug = params.get("interrupt_test_after_unplug")
    vm = env.get_vm(params['main_vm'])
    char_devices = add_chardev(vm, params)
    for device in char_devices:
        extra_params = ' ' + device.cmdline()
        params['extra_params'] = params.get('extra_params', '') + extra_params
    params['start_vm'] = "yes"
    env_process.preprocess(test, params, env)
    vm = env.get_vm(params['main_vm'])
    # Make sure the guest boot successfully before hotplug
    vm.wait_for_login()
    vm.devices.insert(char_devices)
    serials = params.objects('extra_serials')
    buses, serial_devices = get_buses_and_serial_devices(
        vm, params, char_devices, serials)
    for i in range(repeat_times):
        error_context.context(
            "Hotplug/unplug serial devices the %s time" % (i + 1),
            test.log.info)
        vm.devices.simple_hotplug(buses[0], vm.monitor)
        vm.devices.simple_hotplug(serial_devices[0], vm.monitor)
        pre_nr = serial_devices[0].get_param('nr')

        # Try hotplug different device with same 'nr'
        if params.get("plug_same_nr") == "yes":
            serial_devices[1].set_param('bus',
                                        serial_devices[0].get_param('bus'))
            serial_devices[1].set_param('nr', pre_nr)
            try:
                serial_devices[1].hotplug(vm.monitor, vm.devices.qemu_version)
            except QMPCmdError as e:
                if 'A port already exists at id %d' % pre_nr not in str(
                        e.data):
                    test.fail('Hotplug fail for %s, not as expected' %
                              str(e.data))
            else:
                test.fail(
                    'Hotplug with same "nr" option success while should fail')
            serial_devices[1].set_param('nr', int(pre_nr) + 1)
        vm.devices.simple_hotplug(serial_devices[1], vm.monitor)
        for device in serial_devices:
            add_virtio_ports_to_vm(vm, params, device)

        run_serial_data_transfer()

        if interrupt_test_after_plug:
            test.log.info("Run %s after hotplug", interrupt_test_after_plug)
            run_interrupt_test(interrupt_test_after_plug)
            if not vm.is_alive():
                return
            run_serial_data_transfer()

        if params.get("unplug_pci") == "yes":
            vm.devices.simple_unplug(serial_devices[0], vm.monitor)
            vm.devices.simple_unplug(serial_devices[1], vm.monitor)
            out = vm.devices.simple_unplug(buses[0], vm.monitor)
            if out[1] is False:
                msg = "Hot-unplug device %s failed" % buses[0]
                test.fail(msg)
            if interrupt_test_after_unplug:
                test.log.info("Run %s after hot-unplug",
                              interrupt_test_after_unplug)
                run_interrupt_test(interrupt_test_after_unplug)
def run(test, params, env):
    """
    Hot-plug Various chardev

    1. Boot a guest without chardev, no serial port & no pci
    2. Hot plug Unix chardev backend
    3. Hot plug udp chardev backend
    4. Hot plug null backend
    5. Hot plug file backend
    6. Hot plug pty backend
    7. Hot plug ringbuf backend
    8. Write data to ringbuf
    9. Read data from ringbuf
    10. Hot-unplug Unix chardev backend
    11. Hot-unplug udp chardev backend
    12. Hot-unplug null backend
    13. Hot-unplug file backend
    14. Hot-unplug pty backend
    15. Hot-unplug ringbuf backend


    :param test: kvm test object
    :param params: Dictionary with the test parameters
    :param env: Dictionary with test environment
    """
    def cmd_qmp_log(vm, cmd, args):
        reply = vm.monitor.cmd_qmp(cmd, args)
        if "error" in reply:
            if reply["error"]["class"] == "CommandNotFound":
                test.error("qmp command %s not supported" % cmd)
            else:
                test.error("qmp error: %s" % reply["error"]["desc"])
        return reply

    vm = env.get_vm(params["main_vm"])
    vm.verify_alive()
    char_devices = add_chardev(vm, params)
    for char_device in char_devices:
        vm.devices.simple_hotplug(char_device, vm.monitor)
        chardev_id = char_device.get_qid()
        chardev_param = params.object_params(chardev_id)
        backend = chardev_param.get('chardev_backend', 'unix_socket')
        if backend == 'ringbuf':
            ringbuf_write_size = int(params.get('ringbuf_write_size'))
            ringbuf_read_size = int(params.get('ringbuf_read_size'))
            if ringbuf_write_size < ringbuf_read_size:
                test.error("data error:write_size %d must above read_size %d" %
                           (ringbuf_write_size, ringbuf_read_size))
            ringbuf_data = params.get('ringbuf_data')
            ringbuf_format = params.get('ringbuf_format')
            ringbuf_write = cmd_qmp_log(
                vm, "ringbuf-write", {
                    'device': chardev_id,
                    'data': ringbuf_data,
                    'format': ringbuf_format
                })
            ringbuf_read = cmd_qmp_log(
                vm, "ringbuf-read", {
                    'device': chardev_id,
                    'size': ringbuf_read_size,
                    'format': ringbuf_format
                })
            if ringbuf_data[:ringbuf_read_size] != ringbuf_read["return"]:
                test.fail("qmp error: can't find data \'%s\' in %s" %
                          (ringbuf_data[:ringbuf_read_size], ringbuf_read))
    for char_device in char_devices:
        vm.devices.simple_unplug(char_device, vm.monitor)
    vm.reboot()