Skip to content

Commit

Permalink
Merge pull request #5922 from rh-jugraham/boot_order_timeout
Browse files Browse the repository at this point in the history
boot_order: waiting for the boot.iso file to download
  • Loading branch information
Yingshun authored Oct 10, 2024
2 parents 6fd65ed + 4bc7bdc commit 235bde7
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import os
import platform

from avocado.utils import download
from avocado.utils import process

from virttest import data_dir
from virttest import remote
from virttest import utils_misc
from virttest.libvirt_xml import vm_xml
from virttest.libvirt_xml.devices import disk

from provider.guest_os_booting import guest_os_booting_base
from provider.guest_os_booting import guest_os_booting_base as guest_os


def parse_cdroms_attrs(params):
def parse_cdroms_attrs(test, params):
"""
Parse cdrom devices' attrs
:param test: test object
:param params: Dictionary with the test parameters
:return: (boot image path, list of cdrom devices' attrs)
"""
Expand All @@ -35,7 +36,8 @@ def parse_cdroms_attrs(params):
boot_img_url = os.path.join(repo_url, 'images', 'boot.iso')
if os.path.exists(boot_img_path):
os.remove(boot_img_path)
download.get_file(boot_img_url, boot_img_path)
if not utils_misc.wait_for(lambda: guest_os.test_file_download(boot_img_url, boot_img_path), 60):
test.fail('Unable to download boot image')
return boot_img_path, cdrom_attrs_list


Expand Down Expand Up @@ -82,7 +84,7 @@ def run(test, params, env):
Boot VM from cdrom devices
This case covers per-device(cdrom) boot elements and os/boot elements.
"""
vm_name = guest_os_booting_base.get_vm(params)
vm_name = guest_os.get_vm(params)
status_error = "yes" == params.get("status_error", "no")
check_bootable_iso = "yes" == params.get("check_bootable_iso", "no")
bootable_patterns = eval(params.get('bootable_patterns', '[]'))
Expand All @@ -93,7 +95,7 @@ def run(test, params, env):
boot_img_path = None

try:
boot_img_path, cdrom_attrs_list = parse_cdroms_attrs(params)
boot_img_path, cdrom_attrs_list = parse_cdroms_attrs(test, params)
update_vm_xml(vm, params, cdrom_attrs_list)
test.log.debug(vm_xml.VMXML.new_from_dumpxml(vm.name))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

import os

from avocado.utils import download
from avocado.utils import process

from virttest import data_dir
from virttest import utils_misc
from virttest.libvirt_xml import vm_xml
from virttest.utils_libvirt import libvirt_vmxml
from virttest.utils_test import libvirt
Expand All @@ -30,10 +30,11 @@ def get_vmxml_with_multiple_boot(params, vm_name):
return vmxml


def prepare_device(params, vm_name, bootable_device):
def prepare_device(test, params, vm_name, bootable_device):
"""
Prepare the device xml based on different test matrix.
:params test: test object
:params params: wrapped dict with all parameters
:params vm_name: the guest name
:params bootable_device: the device expected to boot from
Expand All @@ -50,7 +51,8 @@ def prepare_device(params, vm_name, bootable_device):
cmd = "dnf repolist -v enabled |awk '/Repo-baseurl.*composes.*BaseOS.*os/ {res=$NF} END{print res}'"
repo_url = process.run(cmd, shell=True).stdout_text.strip()
boot_img_url = os.path.join(repo_url, 'images', 'boot.iso')
download.get_file(boot_img_url, cdrom_path)
if not utils_misc.wait_for(lambda: guest_os.test_file_download(boot_img_url, cdrom_path), 60):
test.fail('Unable to download boot image')
else:
cdrom_path = os.path.join(data_dir.get_data_dir(), 'images', 'test.iso')
libvirt.create_local_disk("file", path=cdrom_path, size="500M", disk_format="raw")
Expand Down Expand Up @@ -79,7 +81,7 @@ def run(test, params, env):

try:
test.log.info("TEST_SETUP: prepare a guest with necessary attributes.")
vmxml, disk_image, cdrom_path = prepare_device(params, vm_name, bootable_device)
vmxml, disk_image, cdrom_path = prepare_device(test, params, vm_name, bootable_device)
test.log.info("TEST_STEP1: start the guest.")
if not vm.is_alive():
vm.start()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

import os

from avocado.utils import download
from avocado.utils import process

from virttest import data_dir
from virttest import utils_misc
from virttest.libvirt_xml import vm_xml
from virttest.utils_libvirt import libvirt_vmxml
from virttest.utils_test import libvirt
Expand All @@ -18,10 +18,11 @@
file_list = []


def prepare_device_attrs(params, vm_name, bootable_device):
def prepare_device_attrs(test, params, vm_name, bootable_device):
"""
Prepare the device xml based on different test matrix.
:params test: test object
:params params: wrapped dict with all parameters
:params vm_name: the guest name
:params bootable_device: the bootable device
Expand All @@ -45,7 +46,8 @@ def prepare_device_attrs(params, vm_name, bootable_device):
cmd = "dnf repolist -v enabled |awk '/Repo-baseurl.*composes.*BaseOS.*os/ {res=$NF} END{print res}'"
repo_url = process.run(cmd, shell=True).stdout_text.strip()
boot_img_url = os.path.join(repo_url, 'images', 'boot.iso')
download.get_file(boot_img_url, cdrom_path)
if not utils_misc.wait_for(lambda: guest_os.test_file_download(boot_img_url, cdrom_path), 60):
test.fail('Unable to download boot image')
else:
cdrom_path = os.path.join(data_dir.get_data_dir(), 'images', 'test.iso')
libvirt.create_local_disk("file", path=cdrom_path, size="500M", disk_format="raw")
Expand Down Expand Up @@ -79,7 +81,7 @@ def run(test, params, env):

try:
test.log.info("TEST_SETUP: prepare a guest with necessary attributes.")
prepare_device_attrs(params, vm_name, bootable_device)
prepare_device_attrs(test, params, vm_name, bootable_device)
test.log.info("TEST_STEP1: start the guest.")
if not vm.is_alive():
vm.start()
Expand Down
13 changes: 13 additions & 0 deletions provider/guest_os_booting/guest_os_booting_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

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

from virttest import virsh
from virttest.libvirt_xml import vm_xml
Expand Down Expand Up @@ -102,3 +104,14 @@ 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 test_file_download(url, path):
"""
Returns true if the file could be successfully downloaded
:param url: source URL
:param path: destination path
"""
download.get_file(url, path)
return process.run('ls -d ' + path, ignore_status="yes").exit_status == 0

0 comments on commit 235bde7

Please sign in to comment.