Skip to content

Commit

Permalink
Merge pull request autotest#5395 from nanli1/add_case_for_destroying_…
Browse files Browse the repository at this point in the history
…storage_pool_with_running_vm

add case for destroying storage pool with running vm and then restart…
  • Loading branch information
dzhengfy authored Feb 6, 2024
2 parents 7076732 + c54992a commit 6dc1a9e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
7 changes: 5 additions & 2 deletions libvirt/tests/cfg/storage/virsh_pool_autostart.cfg
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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"
Expand Down
37 changes: 34 additions & 3 deletions libvirt/tests/src/storage/virsh_pool_autostart.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 6dc1a9e

Please sign in to comment.