Esempio n. 1
0
def run(test, params, env):
    """
    Verify open bios info.

    Step:
     1. Boot guest with qemu cli including "-prom-env 'auto-boot?=false'".
     2. SLOF will not boot automatically, it will go to the SLOF user
        interface directly, and the effect of "-prom-env 'auto-boot?=false'"
        is same with pressing "s" key during boot.
     3. In the SLOF terminal, input "boot" or "reset-all".
     4. SLOF will boot up successfully.
     5. Ping external host ip inside guest successfully.

    :param test: Qemu test object.
    :param params: Dictionary with the test.
    :param env: Dictionary with test environment.
    """
    def _send_custom_key():
        """ Send custom keyword to SLOF's user interface. """
        logging.info('Sending \"%s\" to SLOF user interface.', send_key)
        for key in send_key:
            key = 'minus' if key == '-' else key
            vm.send_key(key)
        vm.send_key('ret')

    vm = env.get_vm(params["main_vm"])
    send_key = params.get('send_key')
    end_str = params.get('slof_end_str', '0 >')
    vm.verify_alive()
    content, next_pos = slof.wait_for_loaded(vm, test, end_str=end_str)
    logging.info('SLOF stop at \'%s\'.', end_str)

    error_context.context("Enter to menu by sending \'%s\'." % send_key,
                          logging.info)
    _send_custom_key()
    content, _ = slof.wait_for_loaded(vm, test, next_pos, 'Trying to load')

    error_context.context("Try to log into guest '%s'." % vm.name,
                          logging.info)
    session = vm.wait_for_login(timeout=float(params["login_timeout"]))
    logging.info("log into guest '%s' successfully.", vm.name)

    error_context.context("Try to ping external host.", logging.info)
    extra_host_ip = utils_net.get_host_ip_address(params)
    session.cmd('ping %s -c 5' % extra_host_ip)
    logging.info("Ping host(%s) successfully.", extra_host_ip)

    session.close()
    vm.destroy(gracefully=True)
Esempio n. 2
0
def run(test, params, env):
    """
    Verify open bios info.

    Step:
     1. Boot guest with qemu cli including "-prom-env 'auto-boot?=false'".
     2. SLOF will not boot automatically, it will go to the SLOF user
        interface directly, and the effect of "-prom-env 'auto-boot?=false'"
        is same with pressing "s" key during boot.
     3. In the SLOF terminal, input "boot" or "reset-all".
     4. SLOF will boot up successfully.
     5. Ping external host ip inside guest successfully.

    :param test: Qemu test object.
    :param params: Dictionary with the test.
    :param env: Dictionary with test environment.
    """
    def _send_custom_key():
        """ Send custom keyword to SLOF's user interface. """
        logging.info('Sending \"%s\" to SLOF user interface.' % send_key)
        for key in send_key:
            key = 'minus' if key == '-' else key
            vm.send_key(key)
        vm.send_key('ret')

    vm = env.get_vm(params["main_vm"])
    send_key = params.get('send_key')
    end_str = params.get('slof_end_str', '0 >')
    vm.verify_alive()
    content, next_pos = slof.wait_for_loaded(vm, test, end_str=end_str)
    logging.info('SLOF stop at \'%s\'.' % end_str)

    error_context.context(
        "Enter to menu by sending \'%s\'." % send_key, logging.info)
    _send_custom_key()
    content, _ = slof.wait_for_loaded(vm, test, next_pos, 'Trying to load')

    error_context.context("Try to log into guest '%s'." % vm.name, logging.info)
    session = vm.wait_for_login(timeout=float(params["login_timeout"]))
    logging.info("log into guest '%s' successfully." % vm.name)

    error_context.context("Try to ping external host.", logging.info)
    extra_host_ip = utils_net.get_host_ip_address(params)
    session.cmd('ping %s -c 5' % extra_host_ip)
    logging.info("Ping host(%s) successfully." % extra_host_ip)

    session.close()
    vm.destroy(gracefully=True)
Esempio n. 3
0
    def _wait_for_login(cur_pos=0):
        """Wait for login guest."""
        content, next_pos = slof.wait_for_loaded(vm, test, cur_pos)
        error_context.context("Check the output of SLOF.", logging.info)
        slof.check_error(test, content)

        error_context.context("Try to log into guest '%s'." % vm.name,
                              logging.info)
        timeout = float(params.get("login_timeout", 240))
        session = vm.wait_for_login(timeout=timeout)
        logging.info("log into guest '%s' successfully." % vm.name)
        return session, next_pos
Esempio n. 4
0
    def _wait_for_login(cur_pos=0):
        """Wait for login guest."""
        content, next_pos = slof.wait_for_loaded(vm, test, cur_pos)
        error_context.context("Check the output of SLOF.", logging.info)
        slof.check_error(test, content)

        error_context.context("Try to log into guest '%s'." % vm.name,
                              logging.info)
        timeout = float(params.get("login_timeout", 240))
        session = vm.wait_for_login(timeout=timeout)
        logging.info("log into guest '%s' successfully.", vm.name)
        return session, next_pos
Esempio n. 5
0
def run(test, params, env):
    """
    Verify SLOF info with maxmem options.

    Step:
     1. Boot a guest with "maxmem=512G".
      a. Check no errors from output of SLOF.
      b. Log in guest successfully.
      c. Ping external host ip successfully.
     2. Shutdown the guest then boot it again with "maxmem=1024G".
      a. Check no errors from output of SLOF.
      b. Log in guest successfully.
      c. Ping external host ip successfully.

    :param test: Qemu test object.
    :param params: Dictionary with the test parameters.
    :param env: Dictionary with test environment.
    """
    start_pos = 0
    for mem in params['maxmem_mem_list'].split():
        params['maxmem_mem'] = mem

        env_process.preprocess_vm(test, params, env, params["main_vm"])
        vm = env.get_vm(params["main_vm"])
        vm.verify_alive()
        content, next_pos = slof.wait_for_loaded(vm, test, start_pos)

        error_context.context("Check the output of SLOF.", logging.info)
        slof.check_error(test, content)

        error_context.context("Try to log into guest '%s'." % vm.name,
                              logging.info)
        timeout = float(params.get("login_timeout", 240))
        session = vm.wait_for_login(timeout=timeout)
        logging.info("log into guest '%s' successfully." % vm.name)

        error_context.context("Try to ping external host.", logging.info)
        extra_host_ip = utils_net.get_host_ip_address(params)
        session.cmd('ping %s -c 5' % extra_host_ip)
        logging.info("Ping host(%s) successfully." % extra_host_ip)

        session.close()
        vm.destroy(gracefully=True)
        start_pos = next_pos
Esempio n. 6
0
def run(test, params, env):
    """
    Verify SLOF info when LUN ID greater than 255.

    Step:
     1. Boot a guest with scsi system disk which lun=0
     2. Check no any errors from output of slof.
     3. Could login guest.
     4. Could ping external host ip.
     5. Shutdown guest.
     6. Change the lun id of scsi disk greater than 255(e.g 300).
     7. Boot this guest again.
     8. Repeat to do step 2 ~ 4.

    :param test: Qemu test object.
    :param params: Dictionary with the test parameters.
    :param env: Dictionary with test environment.
    """
    params['start_vm'] = 'yes'
    start_pos = 0
    for params['drive_lun_image1'] in params['lun_ids'].split():
        env_process.preprocess_vm(test, params, env, params["main_vm"])
        vm = env.get_vm(params["main_vm"])
        vm.verify_alive()
        content, next_pos = slof.wait_for_loaded(vm, test, start_pos)

        error_context.context("Check the output of SLOF.", logging.info)
        slof.check_error(test, content)

        error_context.context("Try to log into guest '%s'." % vm.name,
                              logging.info)
        timeout = float(params.get("login_timeout", 240))
        session = vm.wait_for_login(timeout=timeout)
        logging.info("log into guest '%s' successfully.", vm.name)

        error_context.context("Try to ping external host.", logging.info)
        extra_host_ip = utils_net.get_host_ip_address(params)
        session.cmd('ping %s -c 5' % extra_host_ip)
        logging.info("Ping host(%s) successfully.", extra_host_ip)
        session.close()
        vm.destroy(gracefully=True)
        start_pos = next_pos
Esempio n. 7
0
def run(test, params, env):
    """
    Verify SLOF info when LUN ID greater than 255.

    Step:
     1. Boot a guest with scsi system disk which lun=0
     2. Check no any errors from output of slof.
     3. Could login guest.
     4. Could ping external host ip.
     5. Shutdown guest.
     6. Change the lun id of scsi disk greater than 255(e.g 300).
     7. Boot this guest again.
     8. Repeat to do step 2 ~ 4.

    :param test: Qemu test object.
    :param params: Dictionary with the test parameters.
    :param env: Dictionary with test environment.
    """
    params['start_vm'] = 'yes'
    start_pos = 0
    for params['drive_lun_image1'] in params['lun_ids'].split():
        env_process.preprocess_vm(test, params, env, params["main_vm"])
        vm = env.get_vm(params["main_vm"])
        vm.verify_alive()
        content, next_pos = slof.wait_for_loaded(vm, test, start_pos)

        error_context.context("Check the output of SLOF.", logging.info)
        slof.check_error(test, content)

        error_context.context("Try to log into guest '%s'." % vm.name,
                              logging.info)
        timeout = float(params.get("login_timeout", 240))
        session = vm.wait_for_login(timeout=timeout)
        logging.info("log into guest '%s' successfully." % vm.name)

        error_context.context("Try to ping external host.", logging.info)
        extra_host_ip = utils_net.get_host_ip_address(params)
        session.cmd('ping %s -c 5' % extra_host_ip)
        logging.info("Ping host(%s) successfully." % extra_host_ip)
        session.close()
        vm.destroy(gracefully=True)
        start_pos = next_pos
Esempio n. 8
0
def run(test, params, env):
    """
    Verify SLOF info with balloon.

    Step:
     1. Boot a guest with virtio-balloon and pci-bridge.
      1.1. Check if any error info in output of SLOF during booting.
      1.2. Guest could log in successfully.
     2. Check virtio balloon device and change its value
      2.1 Set the value of balloon.
      2.2 Guest could ping external host ip successfully.

    :param test: Qemu test object.
    :param params: Dictionary with the test .
    :param env: Dictionary with test environment.
    """
    def _get_qmp_port():
        """ Get the qmp monitor port. """
        qmp_ports = vm.get_monitors_by_type('qmp')
        if not qmp_ports:
            test.error("Incorrect configuration, no QMP monitor found.")
        return qmp_ports[0]

    def _check_balloon_info():
        """ Check virtio balloon device info. """
        error_context.context('Check virtio balloon device info.')
        balloon_size = qmp.query('balloon')['actual']
        logging.debug('The balloon size is %s', balloon_size)
        mem = int(params["mem"]) * 1024**2
        if int(balloon_size) != mem:
            test.error('The balloon size is not equal to %d' % mem)

    def _change_balloon_size():
        """ Change the ballloon size. """
        changed_ballon_size = int(params['balloon_size'])
        balloon_timeout = int(params['balloon_timeout'])
        error_context.context('Change the balloon size to %s' %
                              changed_ballon_size)
        qmp.balloon(changed_ballon_size)
        error_context.context('Check balloon size after changed.')
        if not utils_misc.wait_for(
                lambda: bool(changed_ballon_size == int(
                    qmp.query('balloon')['actual'])), balloon_timeout):
            test.fail('The balloon size is not changed to %s in %s sec.' %
                      (changed_ballon_size, balloon_timeout))
        logging.debug('The balloon size is %s after changed.',
                      changed_ballon_size)

    def _ping_host():
        """ Ping host from guest. """
        error_context.context("Try to ping external host.", logging.info)
        extra_host_ip = utils_net.get_host_ip_address(params)
        session.cmd('ping %s -c 5' % extra_host_ip)
        logging.info("Ping host(%s) successfully.", extra_host_ip)

    vm = env.get_vm(params["main_vm"])
    vm.verify_alive()
    content, _ = slof.wait_for_loaded(vm, test)

    error_context.context("Check the output of SLOF.", logging.info)
    slof.check_error(test, content)

    error_context.context("Try to log into guest '%s'." % vm.name,
                          logging.info)
    session = vm.wait_for_login(
        timeout=float(params.get("login_timeout", 240)))
    logging.info("log into guest '%s' successfully.", vm.name)

    qmp = _get_qmp_port()
    _check_balloon_info()
    _change_balloon_size()
    _ping_host()

    session.close()
    vm.destroy(gracefully=True)
Esempio n. 9
0
def run(test, params, env):
    """
    Verify that next-entry will get unset after reboot.

    Step:
     1) Check if any error info in output of SLOF during booting.
     2) Ensure the guest has at least two kernel versions.
     3) Set a boot next entry and check it.
     4) Reboot guest, check the kernel version and value of next_entry.
     5) Reboot guest again, continue to check the kernel version.

    :param test: Qemu test object.
    :param params: Dictionary with the test parameters.
    :param env: Dictionary with test environment.
    """
    def get_kernels_info():
        """ Get detailed information about each kernel version in the guest. """
        kernels_info = {}
        for kernel in kernel_list:
            grubby_info = session.cmd_output("grubby --info=%s" % kernel,
                                             print_func=logging.info)
            entry_dict = dict((item.replace('"', '').split("=", 1)
                               for item in grubby_info.splitlines()))
            kernels_info[int(entry_dict.pop("index"))] = entry_dict
        return kernels_info

    def check_kernel_version(k_index):
        """ Check whether the kernel version matches the kernel index. """
        current_kernel = session.cmd_output("uname -r").strip()
        if guest_kernels[k_index]["kernel"].split("-", 1)[1] != current_kernel:
            logging.debug("The current kernel version is: %s", current_kernel)
            test.fail("The current kernel version is different from expected")
        logging.info("The kernel version matches the kernel index")

    get_kernel_list_cmd = params["get_kernel_list_cmd"]
    vm = env.get_vm(params["main_vm"])
    vm.verify_alive()

    error_context.base_context("Check the output of SLOF.", logging.info)
    content = slof.wait_for_loaded(vm, test)[0]
    slof.check_error(test, content)
    session = vm.wait_for_login()

    logging.info("Ensure the guest has at least two kernel versions")
    kernel_list = session.cmd_output(get_kernel_list_cmd).splitlines()
    if len(kernel_list) < 2:
        test.cancel("This test requires at least two kernel versions in the "
                    "guest")
    if session.cmd_output("grubby --default-index").strip() != "0":
        logging.info("Ensure that the default kernel index of the guest is 0.")
        session.cmd("grubby --set-default-index=0")
        session = vm.reboot()

    guest_kernels = get_kernels_info()
    error_context.context(
        "Set a next boot entry other than the default one and"
        " check it", logging.info)
    next_entry = guest_kernels[1]["title"]
    session.cmd("grub2-reboot '%s'" % next_entry)
    grub_env = dict(
        (item.split("=", 1)
         for item in session.cmd_output("grub2-editenv list").splitlines()))
    grub_next_entry = grub_env["next_entry"]
    if grub_next_entry != next_entry:
        logging.debug("The 'next_entry' is: %s", grub_next_entry)
        test.fail("The next boot entry is not expected as we set")

    error_context.base_context(
        "Reboot guest, check the kernel version and "
        "'next_entry'", logging.info)
    session = vm.reboot(session)
    grub_env = dict(
        (item.split("=", 1)
         for item in session.cmd_output("grub2-editenv list").splitlines()))
    check_kernel_version(1)
    grub_next_entry = grub_env["next_entry"]
    if grub_next_entry:
        logging.debug("The 'next_entry' is: %s", grub_next_entry)
        test.fail("The 'next_entry' did not return to empty after reboot")

    error_context.context("Reboot guest again to check the kernel version")
    session = vm.reboot(session)
    check_kernel_version(0)

    session.close()
    vm.destroy(gracefully=True)
Esempio n. 10
0
def run(test, params, env):
    """
    Verify SLOF info with multi-devices.

    Step:
     1. Boot a guest by following ways:
      a. attach two pci-bridges
      b. multiple virtio-net-pci devices attached multiple pci-bridges
         by one to one.
     2. Check if any error info from output of SLOF.
     3. Guest could login sucessfully.
     4. Guest could ping external host ip.
     5. For virtio-net-pci scenario, check the number of NIC if equal to
        qemu command.

    :param test: Qemu test object.
    :param params: Dictionary with the test parameters.
    :param env: Dictionary with test environment.
    """
    if params['device_type'] == 'pci-bridge':
        for id in range(1, int(params['pci_bridge_num'])):
            params['pci_controllers'] += ' pci_bridge%d' % id
            params['type_pci_bridge%d' % id] = 'pci-bridge'
    elif params['device_type'] == 'virtio-net-pci':
        pci_num = int(params['pci_bridge_num'])
        nic_id = 0
        for pci_id in range(pci_num):
            params['pci_controllers'] += ' pci_bridge%d' % pci_id
            params['type_pci_bridge%d' % pci_id] = 'pci-bridge'
            nic_num_per_pci = int(params['nic_num_per_pci_bridge'])
            for i in range(nic_num_per_pci):
                params["nics"] = ' '.join([params["nics"], 'nic%d' % nic_id])
                params["nic_pci_bus_nic%d" % nic_id] = 'pci_bridge%d' % pci_id
                nic_id += 1

    params['start_vm'] = 'yes'
    env_process.preprocess_vm(test, params, env, params["main_vm"])
    vm = env.get_vm(params["main_vm"])
    vm.verify_alive()
    content, _ = slof.wait_for_loaded(vm, test)

    error_context.context("Check the output of SLOF.", logging.info)
    slof.check_error(test, content)

    error_context.context("Try to log into guest '%s'." % vm.name,
                          logging.info)
    timeout = float(params.get("login_timeout", 240))
    session = vm.wait_for_login(timeout=timeout)
    logging.info("log into guest '%s' successfully." % vm.name)

    error_context.context("Try to ping external host.", logging.info)
    extra_host_ip = utils_net.get_host_ip_address(params)
    session.cmd('ping %s -c 5' % extra_host_ip)
    logging.info("Ping host(%s) successfully." % extra_host_ip)

    if params['device_type'] == 'virtio-net-pci':
        nic_num = int(str(session.cmd_output(params['nic_check_cmd'])))
        error_context.context('Found %d ehternet controllers inside guest.'
                              % nic_num, logging.info)
        if (pci_num * nic_num_per_pci) != nic_num:
            test.fail(
                "The number of ethernet controllers is not equal to %s "
                "inside guest." % (pci_num * nic_num_per_pci))
        logging.info(
            'The number of ehternet controllers inside guest is equal to '
            'qemu command line(%d * %d).' % (pci_num, nic_num_per_pci))

    session.close()
    vm.destroy(gracefully=True)
Esempio n. 11
0
def run(test, params, env):
    """
    Verify the boot order from SLOF.

    Step:
     Scenario 1:
      1.1 Boot a guest with an empty disk, cdrom and nic, and don't
          specify disk bootindex=0, then set "order=cdn,once=n,menu=off,
          strict=off" for boot options.
      1.2 Check the boot order which should be nic->disk->cdrom->nic.
     Scenario 2:
      2.1 Boot a guest with an empty disk and nic, and don't specify
          this device bootindex=0, then set "order=cdn,once=n, menu=off,
          strict=off" for boot options.
      2.2 Check the boot order which should be nic->disk->nic.
     Scenario 3:
      3.1 Boot a guest with an empty disk, specify this device
          bootindex=0, then set "order=cdn,once=n,menu=off,strict=on" for
          boot options.
      3.2 Check the boot order which should be just disk.
     Scenario 4:
      4.1 Boot a guest with an empty disk and nic, specify this device
          bootindex=0, then set "order=cdn,once=n,menu=off,strict=off" for
          boot options.
      4.2 Check the boot order which should be disk->nic.

    :param test: Qemu test object.
    :param params: Dictionary with the test .
    :param env: Dictionary with test environment.
    """
    def _send_custom_key():
        """ Send custom keyword to SLOF's user interface. """
        logging.info('Sending \"%s\" to SLOF user interface.' % send_key)
        for key in send_key:
            key = 'minus' if key == '-' else key
            vm.send_key(key)
        vm.send_key('ret')

    def _verify_boot_order(order):
        """ Verify the order of booted devices. """
        for index, dev in enumerate(order.split()):
            args = device_map[dev]
            details = 'The device({}@{}) is not the {} bootable device.'.format(
                args[1], args[2], index)
            if not slof.verify_boot_device(
                    content, args[0], args[1], args[2], position=index):
                test.fail('Fail: ' + details)
            logging.info('Pass: '******'parent_bus')
    child_bus = params.get('child_bus')
    parent_bus_nic = params.get('parent_bus_nic')
    child_bus_nic = params.get('child_bus_nic')
    send_key = params.get('send_key')
    device_map = {
        'c': (parent_bus, child_bus, params.get('disk_addr')),
        'd': (parent_bus, child_bus, params.get('cdrom_addr')),
        'n': (parent_bus_nic, child_bus_nic, params.get('nic_addr'))
    }
    env_process.process(test, params, env, env_process.preprocess_image,
                        env_process.preprocess_vm)
    vm = env.get_vm(params["main_vm"])
    vm.verify_alive()

    content, next_pos = slof.wait_for_loaded(vm, test, end_str='0 >')
    _verify_boot_order(params['order_before_send_key'])
    if send_key in ('reset-all', 'boot'):
        error_context.context("Reboot guest by sending key.", logging.info)
        _send_custom_key()
        content, _ = slof.wait_for_loaded(vm, test, next_pos, end_str='0 >')
        _verify_boot_order(params['order_after_send_key'])
Esempio n. 12
0
def run(test, params, env):
    """
    Verify the boot order from SLOF.

    Step:
     Scenario 1:
      1.1 Boot a guest with an empty disk, cdrom and nic, and don't
          specify disk bootindex=0, then set "order=cdn,once=n,menu=off,
          strict=off" for boot options.
      1.2 Check the boot order which should be nic->disk->cdrom->nic.
     Scenario 2:
      2.1 Boot a guest with an empty disk and nic, and don't specify
          this device bootindex=0, then set "order=cdn,once=n, menu=off,
          strict=off" for boot options.
      2.2 Check the boot order which should be nic->disk->nic.
     Scenario 3:
      3.1 Boot a guest with an empty disk, specify this device
          bootindex=0, then set "order=cdn,once=n,menu=off,strict=on" for
          boot options.
      3.2 Check the boot order which should be just disk.
     Scenario 4:
      4.1 Boot a guest with an empty disk and nic, specify this device
          bootindex=0, then set "order=cdn,once=n,menu=off,strict=off" for
          boot options.
      4.2 Check the boot order which should be disk->nic.

    :param test: Qemu test object.
    :param params: Dictionary with the test .
    :param env: Dictionary with test environment.
    """
    def _send_custom_key():
        """ Send custom keyword to SLOF's user interface. """
        logging.info('Sending \"%s\" to SLOF user interface.' % send_key)
        for key in send_key:
            key = 'minus' if key == '-' else key
            vm.send_key(key)
        vm.send_key('ret')

    def _verify_boot_order(order):
        """ Verify the order of booted devices. """
        for index, dev in enumerate(order.split()):
            args = device_map[dev]
            details = 'The device({}@{}) is not the {} bootable device.'.format(
                args[1], args[2], index)
            if not slof.verify_boot_device(
                    content, args[0], args[1], args[2], position=index):
                test.fail('Fail: ' + details)
            logging.info('Pass: '******'parent_bus')
    child_bus = params.get('child_bus')
    parent_bus_nic = params.get('parent_bus_nic')
    child_bus_nic = params.get('child_bus_nic')
    send_key = params.get('send_key')
    device_map = {'c': (parent_bus, child_bus, params.get('disk_addr')),
                  'd': (parent_bus, child_bus, params.get('cdrom_addr')),
                  'n': (parent_bus_nic, child_bus_nic, params.get('nic_addr'))}
    env_process.process(
        test, params, env, env_process.preprocess_image, env_process.preprocess_vm)
    vm = env.get_vm(params["main_vm"])
    vm.verify_alive()

    content, next_pos = slof.wait_for_loaded(vm, test, end_str='0 >')
    _verify_boot_order(params['order_before_send_key'])
    if send_key in ('reset-all', 'boot'):
        error_context.context("Reboot guest by sending key.", logging.info)
        _send_custom_key()
        content, _ = slof.wait_for_loaded(vm, test, next_pos, end_str='0 >')
        _verify_boot_order(params['order_after_send_key'])
Esempio n. 13
0
def run(test, params, env):
    """
    Verify SLOF info by booting guest with different devices and options.

    Step:
     1. Boot a guest with different storage devices and others options.
        Including storage devices:
         a. virtio-blk
         b. virtio-blk with dataplane
         c. virtio-scsi
         d. vritio-scsi with dataplane
         e. spapr-vscsi
         g. virtio-scsi disk behind pci-bridge
         h. virtio-blk-pci disk behind pci-bridge
         i. virtio-blk with block size
         j. virtio-scsi with block size
     2. Check if any error info in output of SLOF during booting.
     3. Check if booted from specified storage device successfully by
        reading "Trying to load:  from: /xxx/xxx/xxx ..." from output of
        SLOF.
     4. Check if login guest successfully.
     5. Guest could ping external host ip.

    :param test: Qemu test object.
    :param params: Dictionary with the test parameters.
    :param env: Dictionary with test environment.
    """
    def _get_pci_bridge_addr(id):
        dev_info_list = re.findall(r'\s+-device pci-bridge,\S+\s+',
                                   vm.qemu_command)
        for dev_info in dev_info_list:
            if ('id=' + id) in dev_info:
                return re.search(r'(addr)=(\w+)', dev_info).group(2)

    def _verify_boot_status(boot_dev, content):
        dev_params = params.object_params(boot_dev)
        child_addr = dev_params.get('child_addr')
        sub_child_addr = dev_params.get('sub_child_addr', None)
        parent_bus = dev_params.get('parent_bus')
        child_bus = dev_params.get('child_bus')
        if child_bus == 'pci-bridge':
            pci_bus_id = params.get('pci_bus_image1', None)
            child_addr = _get_pci_bridge_addr(pci_bus_id)
        if sub_child_addr:
            fail_info = ('Failed to boot from %s device (%s@%s).' %
                         (boot_dev, child_addr, sub_child_addr))
            ret_info = ('Booted from %s device (%s@%s) successfully.' %
                        (boot_dev, child_addr, sub_child_addr))
        else:
            fail_info = ('Failed to boot from %s device(@%s).' %
                         (boot_dev, child_addr))
            ret_info = ('Booted from %s device(@%s) successfully.' %
                        (boot_dev, child_addr))
        if not slof.verify_boot_device(content, parent_bus, child_bus,
                                       child_addr, sub_child_addr):
            test.fail(fail_info)
        logging.info(ret_info)

    vm = env.get_vm(params['main_vm'])
    vm.verify_alive()
    content, _ = slof.wait_for_loaded(vm, test)

    error_context.context("Check the output of SLOF.", logging.info)
    slof.check_error(test, content)

    _verify_boot_status(params['boot_dev_type'], content)

    error_context.context("Try to log into guest '%s'." % vm.name,
                          logging.info)
    timeout = float(params.get("login_timeout", 240))
    session = vm.wait_for_login(timeout=timeout)
    logging.info("log into guest '%s' successfully.", vm.name)

    error_context.context("Try to ping external host.", logging.info)
    extra_host_ip = utils_net.get_host_ip_address(params)
    s, o = session.cmd_status_output('ping %s -c 5' % extra_host_ip)
    logging.debug(o)
    if s:
        test.fail("Failed to ping external host.")
    logging.info("Ping host(%s) successfully.", extra_host_ip)

    session.close()
    vm.destroy(gracefully=True)
Esempio n. 14
0
def run(test, params, env):
    """
    Verify SLOF info with balloon.

    Step:
     1. Boot a guest with virtio-balloon and pci-bridge.
      1.1. Check if any error info in output of SLOF during booting.
      1.2. Guest could log in successfully.
     2. Check virtio balloon device and change its value
      2.1 Set the value of balloon.
      2.2 Guest could ping external host ip successfully.

    :param test: Qemu test object.
    :param params: Dictionary with the test .
    :param env: Dictionary with test environment.
    """
    def _get_qmp_port():
        """ Get the qmp monitor port. """
        qmp_ports = vm.get_monitors_by_type('qmp')
        if not qmp_ports:
            test.error("Incorrect configuration, no QMP monitor found.")
        return qmp_ports[0]

    def _check_balloon_info():
        """ Check virtio balloon device info. """
        error_context.context('Check virtio balloon device info.')
        balloon_size = qmp.query('balloon')['actual']
        logging.debug('The balloon size is %s' % balloon_size)
        mem = int(params["mem"]) * 1024 ** 2
        if int(balloon_size) != mem:
            test.error(
                'The balloon size is not equal to %d' % mem)

    def _change_balloon_size():
        """ Change the ballloon size. """
        changed_ballon_size = int(params['balloon_size'])
        balloon_timeout = int(params['balloon_timeout'])
        error_context.context(
            'Change the balloon size to %s' % changed_ballon_size)
        qmp.balloon(changed_ballon_size)
        error_context.context('Check balloon size after changed.')
        if not utils_misc.wait_for(
                lambda: bool(
                    changed_ballon_size == int(
                        qmp.query('balloon')['actual'])), balloon_timeout):
            test.fail('The balloon size is not changed to %s in %s sec.'
                      % (changed_ballon_size, balloon_timeout))
        logging.debug(
            'The balloon size is %s after changed.' % changed_ballon_size)

    def _ping_host():
        """ Ping host from guest. """
        error_context.context("Try to ping external host.", logging.info)
        extra_host_ip = utils_net.get_host_ip_address(params)
        session.cmd('ping %s -c 5' % extra_host_ip)
        logging.info("Ping host(%s) successfully." % extra_host_ip)

    vm = env.get_vm(params["main_vm"])
    vm.verify_alive()
    content, _ = slof.wait_for_loaded(vm, test)

    error_context.context("Check the output of SLOF.", logging.info)
    slof.check_error(test, content)

    error_context.context("Try to log into guest '%s'." % vm.name, logging.info)
    session = vm.wait_for_login(timeout=float(params.get("login_timeout", 240)))
    logging.info("log into guest '%s' successfully." % vm.name)

    qmp = _get_qmp_port()
    _check_balloon_info()
    _change_balloon_size()
    _ping_host()

    session.close()
    vm.destroy(gracefully=True)
Esempio n. 15
0
def run(test, params, env):
    """
    Verify SLOF info with multi-devices.

    Step:
     1. Boot a guest by following ways:
      a. attach two pci-bridges
      b. multiple virtio-net-pci devices attached multiple pci-bridges
         by one to one.
     2. Check if any error info from output of SLOF.
     3. Guest could login sucessfully.
     4. Guest could ping external host ip.
     5. For virtio-net-pci scenario, check the number of NIC if equal to
        qemu command.

    :param test: Qemu test object.
    :param params: Dictionary with the test parameters.
    :param env: Dictionary with test environment.
    """
    if params['device_type'] == 'pci-bridge':
        for id in range(1, int(params['pci_bridge_num'])):
            params['pci_controllers'] += ' pci_bridge%d' % id
            params['type_pci_bridge%d' % id] = 'pci-bridge'
    elif params['device_type'] == 'virtio-net-pci':
        pci_num = int(params['pci_bridge_num'])
        nic_id = 0
        for pci_id in range(pci_num):
            params['pci_controllers'] += ' pci_bridge%d' % pci_id
            params['type_pci_bridge%d' % pci_id] = 'pci-bridge'
            nic_num_per_pci = int(params['nic_num_per_pci_bridge'])
            for i in range(nic_num_per_pci):
                params["nics"] = ' '.join([params["nics"], 'nic%d' % nic_id])
                params["nic_pci_bus_nic%d" % nic_id] = 'pci_bridge%d' % pci_id
                nic_id += 1

    params['start_vm'] = 'yes'
    env_process.preprocess_vm(test, params, env, params["main_vm"])
    vm = env.get_vm(params["main_vm"])
    vm.verify_alive()
    content, _ = slof.wait_for_loaded(vm, test)

    error_context.context("Check the output of SLOF.", logging.info)
    slof.check_error(test, content)

    error_context.context("Try to log into guest '%s'." % vm.name,
                          logging.info)
    timeout = float(params.get("login_timeout", 240))
    session = vm.wait_for_login(timeout=timeout)
    logging.info("log into guest '%s' successfully." % vm.name)

    error_context.context("Try to ping external host.", logging.info)
    extra_host_ip = utils_net.get_host_ip_address(params)
    session.cmd('ping %s -c 5' % extra_host_ip)
    logging.info("Ping host(%s) successfully." % extra_host_ip)

    if params['device_type'] == 'virtio-net-pci':
        nic_num = int(str(session.cmd_output(params['nic_check_cmd'])))
        error_context.context(
            'Found %d ehternet controllers inside guest.' % nic_num,
            logging.info)
        if (pci_num * nic_num_per_pci) != nic_num:
            test.fail("The number of ethernet controllers is not equal to %s "
                      "inside guest." % (pci_num * nic_num_per_pci))
        logging.info(
            'The number of ehternet controllers inside guest is equal to '
            'qemu command line(%d * %d).' % (pci_num, nic_num_per_pci))

    session.close()
    vm.destroy(gracefully=True)
Esempio n. 16
0
def run(test, params, env):
    """
    Verify SLOF info by booting guest with different devices and options.

    Step:
     1. Boot a guest with different storage devices and others options.
        Including storage devices:
         a. virtio-blk
         b. virtio-blk with dataplane
         c. virtio-scsi
         d. vritio-scsi with dataplane
         e. spapr-vscsi
         g. virtio-scsi disk behind pci-bridge
         h. virtio-blk-pci disk behind pci-bridge
         i. virtio-blk with block size
         j. virtio-scsi with block size
     2. Check if any error info in output of SLOF during booting.
     3. Check if booted from specified storage device successfully by
        reading "Trying to load:  from: /xxx/xxx/xxx ..." from output of
        SLOF.
     4. Check if login guest successfully.
     5. Guest could ping external host ip.

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

    def _get_pci_bridge_addr(id):
        dev_info_list = re.findall(r'\s+-device pci-bridge,\S+\s+',
                                   vm.qemu_command)
        for dev_info in dev_info_list:
            if ('id=' + id) in dev_info:
                return re.search(r'(addr)=(\w+)', dev_info).group(2)

    def _verify_boot_status(boot_dev, content):
        dev_params = params.object_params(boot_dev)
        child_addr = dev_params.get('child_addr')
        sub_child_addr = dev_params.get('sub_child_addr', None)
        parent_bus = dev_params.get('parent_bus')
        child_bus = dev_params.get('child_bus')
        if child_bus == 'pci-bridge':
            pci_bus_id = params.get('pci_bus_image1', None)
            child_addr = _get_pci_bridge_addr(pci_bus_id)
        if sub_child_addr:
            fail_info = ('Failed to boot from %s device (%s@%s).'
                         % (boot_dev, child_addr, sub_child_addr))
            ret_info = ('Booted from %s device (%s@%s) successfully.'
                        % (boot_dev, child_addr, sub_child_addr))
        else:
            fail_info = ('Failed to boot from %s device(@%s).' %
                         (boot_dev, child_addr))
            ret_info = ('Booted from %s device(@%s) successfully.' %
                        (boot_dev, child_addr))
        if not slof.verify_boot_device(content, parent_bus, child_bus,
                                       child_addr, sub_child_addr):
            test.fail(fail_info)
        logging.info(ret_info)

    vm = env.get_vm(params['main_vm'])
    vm.verify_alive()
    content, _ = slof.wait_for_loaded(vm, test)

    error_context.context("Check the output of SLOF.", logging.info)
    slof.check_error(test, content)

    _verify_boot_status(params['boot_dev_type'], content)

    error_context.context("Try to log into guest '%s'." % vm.name,
                          logging.info)
    timeout = float(params.get("login_timeout", 240))
    session = vm.wait_for_login(timeout=timeout)
    logging.info("log into guest '%s' successfully." % vm.name)

    error_context.context("Try to ping external host.", logging.info)
    extra_host_ip = utils_net.get_host_ip_address(params)
    s, o = session.cmd_status_output('ping %s -c 5' % extra_host_ip)
    logging.debug(o)
    if s:
        test.fail("Failed to ping external host.")
    logging.info("Ping host(%s) successfully." % extra_host_ip)

    session.close()
    vm.destroy(gracefully=True)