Skip to content

Commit

Permalink
Merge pull request autotest#5547 from meinaLi/snapshot
Browse files Browse the repository at this point in the history
startup_policy: update creating internal snapshot to external snapshot
  • Loading branch information
chunfuwen authored Apr 12, 2024
2 parents e71eb1a + 2340dad commit d73a027
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
6 changes: 5 additions & 1 deletion libvirt/tests/cfg/virtual_disks/startup_policy.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
- disk:
device_type = "disk"
image_size = "100M"
snapshot_options = "--memspec snapshot=external,file=/tmp/mem.%s --diskspec %s,file=/tmp/test.%s --diskspec vda,snapshot=no"
only file dir_pool
variants:
- virtio_bus:
Expand All @@ -89,13 +90,16 @@
update_policy_list = "optional requisite"
start_error = "yes"
restore_error = "yes"
revert_error = "yes"
- optional:
policy = "optional"
update_policy_list = "mandatory requisite"
start_error = "no"
restore_error = "no"
restore_error = "yes"
revert_error = "yes"
- requisite:
policy = "requisite"
update_policy_list = "mandatory optional"
start_error = "yes"
restore_error = "no"
revert_error = "no"
18 changes: 16 additions & 2 deletions libvirt/tests/src/virtual_disks/startup_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ def rename_file(source_file, target_file, revert=False):
# Get start,restore configuration parameters.
start_error = "yes" == params.get("start_error", "no")
restore_error = "yes" == params.get("restore_error", "no")
revert_error = "yes" == params.get("revert_error", "no")
virsh_dargs = {'debug': True, 'ignore_status': True}
attach_option = params.get("attach_option")

Expand Down Expand Up @@ -415,6 +416,9 @@ def rename_file(source_file, target_file, revert=False):
logging.debug("Attach device throws exception:%s", str(attach_device_exception))
os.remove(media_file)
test.error("Attach %s fail" % device_type)
# The guest can restore successfully for optional cdrom disk.
if device_type == "cdrom" and startup_policy == "optional":
restore_error = False
# Check update policy operations.
if disk_type == "file" and update_policy:
vm.start()
Expand Down Expand Up @@ -445,6 +449,10 @@ def rename_file(source_file, target_file, revert=False):

# Step 4. Save the domain normally, then remove the source file
# and restore it back
if startup_policy == "optional":
# Restart the guest with optional disk because the previous optional disk will be lost after the above steps
vm.destroy()
vm.start()
vm.save_to_file(save_file)
rename_file(media_file, media_file_new)
result = virsh.restore(save_file, **virsh_dargs)
Expand Down Expand Up @@ -485,6 +493,10 @@ def rename_file(source_file, target_file, revert=False):
vm.start()

# Step 4 Save the domain normally, then remove the source file,then restore domain.
if startup_policy == "optional":
# Restart the guest with optional disk because the previous optional disk will be lost after the above steps
vm.destroy()
vm.start()
vm.save_to_file(save_file)
rename_file(vol_path, vol_path_new)
cmd_result = virsh.pool_refresh(pool_name)
Expand All @@ -500,10 +512,12 @@ def rename_file(source_file, target_file, revert=False):
if restore_error:
result = virsh.restore(save_file, **virsh_dargs)
libvirt.check_exit_status(result)
ret = virsh.snapshot_create_as(vm_name, snapshot_name, **virsh_dargs)
snapshot_options = params.get("snapshot_options", "") % (snapshot_name, target_dev, snapshot_name)
ret = virsh.snapshot_create_as(vm_name, "%s %s" % (snapshot_name, snapshot_options), **virsh_dargs)
libvirt.check_exit_status(ret)
rename_file(vol_path, vol_path_new)
ret = virsh.snapshot_revert(vm_name, snapshot_name, **virsh_dargs)
result = virsh.snapshot_revert(vm_name, snapshot_name, **virsh_dargs)
libvirt.check_exit_status(result, expect_error=revert_error)
# Clean up snapshot.
libvirt.clean_up_snapshots(vm_name, domxml=vmxml_backup)
finally:
Expand Down

0 comments on commit d73a027

Please sign in to comment.