From 3f6c46c6d70e06868787a1cef862dad491fc77ad Mon Sep 17 00:00:00 2001 From: Meina Li Date: Mon, 18 Sep 2023 05:09:02 -0400 Subject: [PATCH] guest os booting: add new modular case for direct kernel boot Signed-off-by: Meina Li --- .../direct_kernel_boot/direct_kernel_boot.cfg | 11 ++++ .../direct_kernel_boot/direct_kernel_boot.py | 56 +++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 libvirt/tests/cfg/guest_os_booting/direct_kernel_boot/direct_kernel_boot.cfg create mode 100644 libvirt/tests/src/guest_os_booting/direct_kernel_boot/direct_kernel_boot.py diff --git a/libvirt/tests/cfg/guest_os_booting/direct_kernel_boot/direct_kernel_boot.cfg b/libvirt/tests/cfg/guest_os_booting/direct_kernel_boot/direct_kernel_boot.cfg new file mode 100644 index 0000000000..563c252244 --- /dev/null +++ b/libvirt/tests/cfg/guest_os_booting/direct_kernel_boot/direct_kernel_boot.cfg @@ -0,0 +1,11 @@ +- guest_os_booting.direct_kernel_boot: + type = direct_kernel_boot + start_vm = no + memory_value = 3573760 + repo_url = "EXAMPLE_REPO_URL" + initrd_url = "${repo_url}/images/pxeboot/initrd.img" + vmlinuz_url = "${repo_url}/images/pxeboot/vmlinuz" + direct_kernel_dict = {'cmdline': 'console=ttyS0 inst.repo=${repo_url}', 'initrd': '%s', 'kernel': '%s'} + variants: + - start_guest: + check_prompt = "Starting installer" diff --git a/libvirt/tests/src/guest_os_booting/direct_kernel_boot/direct_kernel_boot.py b/libvirt/tests/src/guest_os_booting/direct_kernel_boot/direct_kernel_boot.py new file mode 100644 index 0000000000..90124677cd --- /dev/null +++ b/libvirt/tests/src/guest_os_booting/direct_kernel_boot/direct_kernel_boot.py @@ -0,0 +1,56 @@ +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright Red Hat +# +# SPDX-License-Identifier: GPL-2.0 + +# Author: Meina Li +# +import os + +from avocado.utils.download import url_download + +from virttest import data_dir +from virttest.libvirt_xml import vm_xml + +from provider.guest_os_booting import guest_os_booting_base as guest_os + + +def run(test, params, env): + """ + This case is to verify the direct kernel boot. + 1) Prepare a guest with direct kernel boot. + 2) Start the guest. + 3) Save and restore the guest. + """ + vm_name = params.get("main_vm") + memory_value = int(params.get("memory_value", "2097152")) + initrd_url = params.get("initrd_url") + vmlinuz_url = params.get("vmlinuz_url") + check_prompt = params.get("check_prompt") + + vm = env.get_vm(vm_name) + vmxml = vm_xml.VMXML.new_from_inactive_dumpxml(vm_name) + bkxml = vmxml.copy() + + try: + boot_initrd = os.path.join(data_dir.get_data_dir(), "initrd.img") + boot_vmlinuz = os.path.join(data_dir.get_data_dir(), "vmlinuz") + url_download(initrd_url, boot_initrd) + url_download(vmlinuz_url, boot_vmlinuz) + direct_kernel_dict = eval(params.get("direct_kernel_dict") + % (boot_initrd, boot_vmlinuz)) + vmxml = guest_os.prepare_os_xml(vm_name, direct_kernel_dict) + vmxml.set_memory(memory_value) + vmxml.set_current_mem(memory_value) + vmxml.sync() + test.log.debug("The final guest xml is %s", vmxml) + if not vm.is_alive(): + vm.start() + vm.serial_console.read_until_any_line_matches([check_prompt], timeout=360) + finally: + bkxml.sync() + for file_path in [boot_initrd, boot_vmlinuz]: + if os.path.exists(file_path): + os.remove(file_path)