From 56a0cb8f2e62fe46753f897e3e46b1e6839bf06c Mon Sep 17 00:00:00 2001 From: Meina Li Date: Fri, 8 Sep 2023 01:44:19 -0400 Subject: [PATCH] guest_os_booting: add new case for guest bootmenu This PR mainly implements the function of bootmenu feature in guest. Signed-off-by: Meina Li --- .../guest_os_booting/boot_menu/bootmenu.cfg | 39 +++++++++++ .../guest_os_booting/boot_menu/bootmenu.py | 70 +++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 libvirt/tests/cfg/guest_os_booting/boot_menu/bootmenu.cfg create mode 100644 libvirt/tests/src/guest_os_booting/boot_menu/bootmenu.py diff --git a/libvirt/tests/cfg/guest_os_booting/boot_menu/bootmenu.cfg b/libvirt/tests/cfg/guest_os_booting/boot_menu/bootmenu.cfg new file mode 100644 index 0000000000..a2ac19afc1 --- /dev/null +++ b/libvirt/tests/cfg/guest_os_booting/boot_menu/bootmenu.cfg @@ -0,0 +1,39 @@ +- guest_os_booting.bootmenu: + type = bootmenu + start_vm = no + bootmenu_enable = "yes" + bootmenu_dict = {'bootmenu_enable': '%s', 'bootmenu_timeout': '%s', 'bios_useserial': 'yes'} + variants: + - positive_test: + status_error = "no" + variants: + - timeout_0: + directly_boot = "yes" + bootmenu_timeout = 0 + - timeout_6000: + bootmenu_timeout = 6000 + - timeout_65535: + bootmenu_timeout = 65535 + - disable_bootmenu: + directly_boot = "yes" + bootmenu_enable = "no" + - negative_test: + status_error = "yes" + variants: + - timeout_-2: + bootmenu_timeout = -2 + error_msg = " Invalid value for attribute 'timeout' in element 'bootmenu': '${bootmenu_timeout}'. Expected non-negative integer value" + - timeout_string: + bootmenu_timeout = "string" + error_msg = " Invalid value for attribute 'timeout' in element 'bootmenu': '${bootmenu_timeout}'. Expected non-negative integer value" + - timeout_65536: + bootmenu_timeout = 65536 + error_msg = "invalid value for boot menu timeout, must be in range [0,65535]" + variants: + - by_ovmf: + only q35 + firmware_type = "ovmf" + check_prompt = "BdsDxe: loading Boot0000 "UiApp" from Fv" + - by_seabios: + firmware_type = "seabios" + check_prompt = "Select boot device" diff --git a/libvirt/tests/src/guest_os_booting/boot_menu/bootmenu.py b/libvirt/tests/src/guest_os_booting/boot_menu/bootmenu.py new file mode 100644 index 0000000000..288338828e --- /dev/null +++ b/libvirt/tests/src/guest_os_booting/boot_menu/bootmenu.py @@ -0,0 +1,70 @@ +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright Red Hat +# +# SPDX-License-Identifier: GPL-2.0 + +# Author: Meina Li +# +import time + +from virttest import virsh +from virttest.libvirt_xml import vm_xml +from virttest.libvirt_xml import xcepts + +from provider.guest_os_booting import guest_os_booting_base as guest_os + + +def run(test, params, env): + """ + This case is to verify the boot menu element. + 1) Prepare a guest with boot menu element. + 2) Start and boot the guest. + """ + vm_name = guest_os.get_vm(params) + firmware_type = params.get("firmware_type") + bootmenu_timeout = params.get("bootmenu_timeout") + bootmenu_enable = params.get("bootmenu_enable") + bootmenu_dict = eval(params.get("bootmenu_dict") % (bootmenu_enable, bootmenu_timeout)) + check_prompt = params.get("check_prompt") + error_msg = params.get("error_msg", "") + status_error = "yes" == params.get("status_error", "no") + directly_boot = "yes" == params.get("directly_boot", "no") + virsh_dargs = {"debug": True, "ignore_status": True} + + vm = env.get_vm(vm_name) + vmxml = vm_xml.VMXML.new_from_inactive_dumpxml(vm_name) + bkxml = vmxml.copy() + + try: + try: + guest_os.prepare_os_xml(vm_name, bootmenu_dict) + except xcepts.LibvirtXMLError as details: + if error_msg and error_msg in str(details): + test.log.info("Get expected error message: %s.", error_msg) + else: + test.fail("Failed to define the guest because error:%s" % str(details)) + if not status_error: + if directly_boot: + guest_os.check_vm_startup(vm, vm_name) + else: + virsh.start(vm_name, "--paused", **virsh_dargs) + vm.create_serial_console() + vm.resume() + # Wait $bootmenu_timeout/1000 seconds before entering boot menu + sleep_time = int(bootmenu_timeout) / 1000 + time.sleep(sleep_time) + for _ in range(2): + vm.serial_console.sendcontrol('[') + vm.serial_console.read_until_any_line_matches([check_prompt], timeout=30, + internal_timeout=0.5) + test.log.info("Get check point as expected") + if firmware_type == "seabios": + vm.serial_console.send('1') + else: + virsh.destroy(vm_name) + virsh.start(vm_name, debug=True, ignore_status=False) + vm.wait_for_login().close() + finally: + bkxml.sync()