seabios.py 3.8 KB
Newer Older
L
Lucas Meneghel Rodrigues 已提交
1 2
import re
import logging
3

4
from virttest import error_context
5
from virttest import utils_misc
6 7


8
@error_context.context_aware
9
def run(test, params, env):
10 11 12
    """
    KVM Seabios test:
    1) Start guest with sga bios
13
    2) Check the sga bios messages(optional)
14 15 16 17
    3) Restart the vm, verify it's reset(optional)
    4) Display and check the boot menu order
    5) Start guest from the specified boot entry
    6) Log into the guest to verify it's up
18

L
Lucas Meneghel Rodrigues 已提交
19 20 21
    :param test: QEMU test object
    :param params: Dictionary with the test parameters
    :param env: Dictionary with test environment.
22
    """
23 24 25 26 27 28
    def get_output(session_obj):
        """
        Use the function to short the lines in the scripts
        """
        return session_obj.get_stripped_output()

29 30 31 32 33 34 35
    def boot_menu():
        return re.search(boot_menu_hint, get_output(seabios_session))

    def boot_menu_check():
        return (len(re.findall(boot_menu_hint,
                               get_output(seabios_session))) > 1)

36
    error_context.context("Start guest with sga bios", logging.info)
37 38 39 40 41 42 43
    vm = env.get_vm(params["main_vm"])
    # Since the seabios is displayed in the beginning of guest boot,
    # booting guest here so that we can check all of sgabios/seabios
    # info, especially the correct time of sending boot menu key.
    vm.create()

    timeout = float(params.get("login_timeout", 240))
44
    boot_menu_key = params.get("boot_menu_key", 'esc')
45
    restart_key = params.get("restart_key")
46 47
    boot_menu_hint = params.get("boot_menu_hint")
    boot_device = params.get("boot_device", "")
48
    sgabios_info = params.get("sgabios_info")
49

50
    seabios_session = vm.logsessions['seabios']
51

52
    if sgabios_info:
53
        error_context.context("Display and check the SGABIOS info", logging.info)
54 55 56 57

        def info_check():
            return re.search(sgabios_info,
                             get_output(vm.serial_console))
58 59

        if not utils_misc.wait_for(info_check, timeout, 1):
60 61
            err_msg = "Cound not get sgabios message. The output"
            err_msg += " is %s" % get_output(vm.serial_console)
62
            test.fail(err_msg)
63

64 65
    if not (boot_menu_hint and utils_misc.wait_for(boot_menu, timeout, 1)):
        test.fail("Could not get boot menu message.")
66

67 68
    if restart_key:
        error_context.context("Restart vm and check it's ok", logging.info)
69
        seabios_text = get_output(seabios_session)
70 71 72 73
        headline = seabios_text.split("\n")[0] + "\n"
        headline_count = seabios_text.count(headline)

        vm.send_key(restart_key)
74 75 76

        def reboot_check():
            return get_output(seabios_session).count(headline) > headline_count
77 78

        if not utils_misc.wait_for(reboot_check, timeout, 1):
79
            test.fail("Could not restart the vm")
80

81 82 83 84 85
        if not (boot_menu_hint and utils_misc.wait_for(boot_menu_check, timeout, 1)):
            test.fail("Could not get boot menu message after rebooting")

    # Send boot menu key in monitor.
    vm.send_key(boot_menu_key)
86

87
    error_context.context("Display and check the boot menu order", logging.info)
88

89
    def get_list():
X
Xu Han 已提交
90
        return re.findall(r"^\d+\. (.*)\s", get_output(seabios_session), re.M)
91

92
    boot_list = utils_misc.wait_for(get_list, timeout, 1)
93 94

    if not boot_list:
95
        test.fail("Could not get boot entries list.")
96 97 98 99

    logging.info("Got boot menu entries: '%s'", boot_list)
    for i, v in enumerate(boot_list, start=1):
        if re.search(boot_device, v, re.I):
100 101
            error_context.context("Start guest from boot entry '%s'" % v,
                                  logging.info)
102 103 104
            vm.send_key(str(i))
            break
    else:
105 106
        test.fail("Could not get any boot entry match "
                  "pattern '%s'" % boot_device)
107

108
    error_context.context("Log into the guest to verify it's up")
109 110
    session = vm.wait_for_login(timeout=timeout)
    session.close()