Skip to content

Commit

Permalink
guest os booting: add new modular case for direct kernel boot
Browse files Browse the repository at this point in the history
This PR mainly automate the function of direct kernel boot feature in os
element.

Signed-off-by: Meina Li <[email protected]>
  • Loading branch information
meinaLi committed Aug 11, 2023
1 parent 69841a0 commit 74fd151
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
- guest_os_booting.direct_kernel_boot:
type = direct_kernel_boot
start_vm = no
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"
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Copyright Red Hat
#
# SPDX-License-Identifier: GPL-2.0

# Author: Meina Li <[email protected]>
#
import os

from avocado.utils import process

from virttest import data_dir
from virttest import utils_package
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")
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")
guest_os.download_file(initrd_url, boot_initrd, test)
guest_os.download_file(vmlinuz_url, boot_vmlinuz, test)
direct_kernel_dict = eval(params.get("direct_kernel_dict", "{}")
% (boot_initrd, boot_vmlinuz))
guest_os.prepare_os_xml(vm_name, direct_kernel_dict)
if not vm.is_alive():
vm.start()
vm.serial_console.read_until_any_line_matches([check_prompt], timeout=120)
finally:
bkxml.sync()
for file_path in [boot_initrd, boot_vmlinuz]:
if os.path.exists(file_path):
os.remove(file_path)
21 changes: 21 additions & 0 deletions provider/guest_os_booting/guest_os_booting_base.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import logging
import os

from avocado.core import exceptions
from avocado.utils import distro
from avocado.utils import process

from virttest import virsh
from virttest import utils_package
from virttest.libvirt_xml import vm_xml
from virttest.utils_libvirt import libvirt_bios
from virttest.utils_test import libvirt
Expand Down Expand Up @@ -95,3 +98,21 @@ def check_vm_startup(vm, vm_name, error_msg=None):
vm.wait_for_login().close()
LOG.debug("Succeed to boot %s", vm_name)
return vmxml


def download_file(url, dest_file, test):
"""
Perform file download via wget
:param url: The source url
:param dest_file: The dest file path
:param test: Avocado test object
"""
if utils_package.package_install("wget"):
if url.count("URL"):
test.cancel("Please provide the url %s" % url)
download_cmd = "wget %s -O %s" % (url, dest_file)
if not os.path.exists(dest_file):
if process.system(download_cmd, verbose=False, shell=True):
test.error("Failed to download boot iso file")
else:
test.error("wget install failed")

0 comments on commit 74fd151

Please sign in to comment.