-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
guest os booting: add hotplug case with boot order element
This PR mainly implements the hotpluging of disk/usb/filesystem devices with boot order elements. Signed-off-by: Meina Li <[email protected]>
- Loading branch information
Showing
2 changed files
with
130 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
- guest_os_booting.boot_order.hotplug: | ||
type = hotplug | ||
start_vm = no | ||
target_dev = "vda" | ||
boot_order = 1 | ||
order_xpath = [{'element_attrs': ["./devices/disk/boot[@order='2']"]}] | ||
variants device_type: | ||
- disk_device: | ||
bus_type = "virtio" | ||
target_disk = "vdb" | ||
device_dict = {"type_name":"file", "target":{"dev": "${target_disk}", "bus": "${bus_type}"}, 'boot': '2'} | ||
- usb_device: | ||
bus_type = "usb" | ||
target_disk = "sda" | ||
device_dict = {"type_name":"file", "target":{"dev": "${target_disk}", "bus": "${bus_type}"}, 'boot': '2'} | ||
- filesystem_device: | ||
target_dir = "mount_tag" | ||
source_dir = "/tmp" | ||
order_xpath = [{'element_attrs': ["./devices/filesystem/boot[@order='2']"]}] | ||
device_dict = {'target': {'dir': '${target_dir}'}, 'type_name': 'mount', 'source': {'dir': '${source_dir}'}, 'binary': {'path': '/usr/libexec/virtiofsd'}, 'accessmode': 'passthrough', 'boot': '2', 'driver': {'type': 'virtiofs'}} |
110 changes: 110 additions & 0 deletions
110
libvirt/tests/src/guest_os_booting/boot_order/hotplug.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
# Copyright Red Hat | ||
# SPDX-License-Identifier: GPL-2.0 | ||
# Author: Meina Li <[email protected]> | ||
import os | ||
import time | ||
|
||
from virttest import virsh | ||
from virttest.libvirt_xml import vm_xml | ||
from virttest.libvirt_xml.devices.filesystem import Filesystem | ||
from virttest.utils_libvirt import libvirt_vmxml | ||
|
||
from provider.virtual_disk import disk_base | ||
|
||
|
||
def run(test, params, env): | ||
""" | ||
This case is to verify hotplugging device with boot order element. | ||
1) Prepare a running guest. | ||
2) Hotplug the device with boot order element. | ||
3) Check the dumpxml. | ||
4) Hot-unplug the device. | ||
""" | ||
def prepare_device_xml(vm_xml, device_type): | ||
""" | ||
Prepare the hot-plugged device xml. | ||
:params vm_xml: the instance of VMXML class | ||
:params device_type: the device type | ||
:return device_xml: the device xml | ||
:return image_path: the disk path | ||
""" | ||
image_path = '' | ||
# Need to use shared memory for filesystem device | ||
if device_type == "filesystem_device": | ||
vm_xml.VMXML.set_memoryBacking_tag(vm_name, access_mode="shared", | ||
hpgs=False) | ||
if not vm.is_alive(): | ||
virsh.start(vm_name, **virsh_dargs) | ||
vmxml = vm_xml.VMXML.new_from_dumpxml(vm_name) | ||
device_xml = Filesystem() | ||
device_xml.setup_attrs(**device_dict) | ||
else: | ||
device_xml, image_path = disk_obj.prepare_disk_obj("file", device_dict) | ||
return device_xml, image_path | ||
|
||
def check_dumpxml(vmxml, device_type, image_path): | ||
""" | ||
Check if the device is plugged and included the boot order element. | ||
:params vmxml: the current guest xml | ||
:params device_type: the device type | ||
:params image_path: the disk path | ||
""" | ||
if device_type == "filesystem_device": | ||
filesystems = vmxml.devices.by_device_tag('filesystem') | ||
if not filesystems: | ||
test.fail("No filesystem devices in guest xml after hotplug.") | ||
else: | ||
test.log.debug("Get the hotplugged Filesystem device.") | ||
else: | ||
if not vm_xml.VMXML.check_disk_exist(vm_name, image_path): | ||
test.fail(f"No {device_type} in guest xml after hotplug.") | ||
libvirt_vmxml.check_guest_xml_by_xpaths(vmxml, order_xpath, ignore_status=False) | ||
|
||
vm_name = params.get("main_vm") | ||
device_type = params.get("device_type") | ||
target_dev = params.get("target_dev") | ||
boot_order = params.get("boot_order", "1") | ||
device_dict = eval(params.get("device_dict")) | ||
order_xpath = eval(params.get("order_xpath")) | ||
virsh_dargs = {'debug': True, 'ignore_status': False} | ||
|
||
vm = env.get_vm(vm_name) | ||
vmxml = vm_xml.VMXML.new_from_inactive_dumpxml(vm_name) | ||
bkxml = vmxml.copy() | ||
disk_obj = disk_base.DiskBase(test, vm, params) | ||
|
||
try: | ||
test.log.info("STEP1: Prepare a running guest.") | ||
vmxml.remove_all_boots() | ||
vmxml.set_boot_order_by_target_dev(target_dev, order=boot_order) | ||
vmxml.sync() | ||
if not vm.is_alive(): | ||
virsh.start(vm_name, **virsh_dargs) | ||
vm.wait_for_login() | ||
|
||
test.log.info(f"STEP2: Hotplug the {device_type}.") | ||
device_xml, image_path = prepare_device_xml(vm_xml, device_type) | ||
virsh.attach_device(vm_name, device_xml.xml, **virsh_dargs) | ||
|
||
test.log.info("STEP3: Check the dumpxml with boot order.") | ||
vmxml = vm_xml.VMXML.new_from_dumpxml(vm_name) | ||
test.log.debug(f"The current guest xml is: {vmxml}") | ||
check_dumpxml(vmxml, device_type, image_path) | ||
|
||
test.log.info(f"STEP4: Hot-unplug the {device_type}.") | ||
virsh.detach_device(vm_name, device_xml.xml, **virsh_dargs) | ||
time.sleep(10) | ||
vmxml = vm_xml.VMXML.new_from_dumpxml(vm_name) | ||
for xpath_text in order_xpath: | ||
for boot_attrs in xpath_text['element_attrs']: | ||
if vmxml.xmltreefile.findall(boot_attrs): | ||
test.fail("The device hasn't been detached.") | ||
finally: | ||
if vm.is_alive(): | ||
virsh.destroy(vm_name, **virsh_dargs) | ||
if image_path and os.path.exists(image_path): | ||
os.remove(image_path) | ||
bkxml.sync() |