diff --git a/libvirt/tests/cfg/storage/virsh_pool_autostart.cfg b/libvirt/tests/cfg/storage/virsh_pool_autostart.cfg index 3e39f26482..05b4048926 100644 --- a/libvirt/tests/cfg/storage/virsh_pool_autostart.cfg +++ b/libvirt/tests/cfg/storage/virsh_pool_autostart.cfg @@ -1,7 +1,5 @@ - virsh.pool_autostart: type = virsh_pool_autostart - vms = '' - main_vm = '' pool_name = "virsh_pool_test" pool_type = "dir" start_vm = "no" @@ -74,6 +72,11 @@ ip_protocal = "ipv4" - ipv6_target: ip_protocal = "ipv6" + - destroy_pool_used_by_guest: + destroy_pool_used_by_guest = "yes" + new_dev = 'sdc' + source_attr = "'source':{'attrs': {'pool': '%s', 'volume':'%s'}}" + disk_dict = {"type_name":"volume",'device':'disk',${source_attr},"target":{"dev": "${new_dev}", "bus": "virtio"}, "driver": {"name": "qemu", "type":"raw"}} - pool_type_scsi: pool_type = "scsi" pool_target = "/dev/disk/by-path" diff --git a/libvirt/tests/src/storage/virsh_pool_autostart.py b/libvirt/tests/src/storage/virsh_pool_autostart.py index 3076a4b887..c267347e80 100755 --- a/libvirt/tests/src/storage/virsh_pool_autostart.py +++ b/libvirt/tests/src/storage/virsh_pool_autostart.py @@ -1,15 +1,18 @@ import os +import re import logging as log from avocado.utils import process from avocado.core import exceptions -from virttest import utils_libvirtd from virttest import libvirt_storage - +from virttest import utils_libvirtd from virttest import virsh -from virttest.utils_test import libvirt as utlv from virttest.libvirt_xml import pool_xml +from virttest.libvirt_xml import vm_xml +from virttest.utils_libvirt import libvirt_vmxml +from virttest.utils_test import libvirt as utlv +from virttest.utils_libvirt import libvirt_disk from virttest.staging import lv_utils from virttest import libvirt_version @@ -52,6 +55,12 @@ def run(test, params, env): lv_name = params.get("lv_name", "") update_policy = params.get("update_policy") libvirt_version.is_libvirt_feature_supported(params) + destroy_pool_used_by_guest = params.get("destroy_pool_used_by_guest") + disk_dict = params.get("disk_dict") + vm_name = params.get("main_vm", "avocado-vt-vm1") + vm = env.get_vm(vm_name) + vmxml = vm_xml.VMXML.new_from_inactive_dumpxml(vm_name) + bkxml = vmxml.copy() # Readonly mode ro_flag = False @@ -148,6 +157,17 @@ def change_source_path(new_path, update_policy="set"): # Get pool uuid: if pool_ref == "uuid" and not pool_uuid: pool = pool_ins.get_pool_uuid(pool_name) + if destroy_pool_used_by_guest: + virsh.pool_start(pool_name, debug=True, ignore_status=False) + res = virsh.vol_list(pool_name, debug=True, + ignore_status=False).stdout_text + vol = re.findall(r"(\S+)\ +(\S+)", str(res.strip()))[1][0] + + libvirt_vmxml.modify_vm_device( + vmxml, 'disk', eval(disk_dict % (pool_name, vol)), index=1) + virsh.start(vm_name) + vmxml = vm_xml.VMXML.new_from_dumpxml(vm_name) + test.log.debug("Get guest xml is:\n%s", vmxml) # Setup logical block device # Change pool source path @@ -202,6 +222,15 @@ def change_source_path(new_path, update_policy="set"): if not result.exit_status: check_pool(pool_name, pool_type, checkpoint='Autostart', expect_value="yes", expect_error=status_error) + if destroy_pool_used_by_guest: + session = vm.wait_for_login() + disk_name, _ = libvirt_disk.get_non_root_disk_name(session) + test.log.debug("Get new disk name is:%s", disk_name) + session.close() + + virsh.pool_destroy(pool_name, debug=True, ignore_status=False) + utils_libvirtd.Libvirtd().restart() + libvirt_disk.check_virtual_disk_io(vm, disk_name) # Step(3) # Restart libvirtd and check pool status @@ -240,6 +269,8 @@ def change_source_path(new_path, update_policy="set"): # Clean up logging.debug("Try to clean up env") try: + if destroy_pool_used_by_guest: + bkxml.sync() if clean_mount is True: for src in source_list: process.system("umount %s" % pool_target)