forked from autotest/tp-libvirt
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request autotest#4979 from chloerh/restore-unqualified
Add case of restoring vm from unqualified file
- Loading branch information
Showing
2 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
libvirt/tests/cfg/save_and_restore/restore_from_unqualified_file.cfg
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,14 @@ | ||
- save_and_restore.restore_from_unqualified_file: | ||
type = restore_from_unqualified_file | ||
status_error = yes | ||
variants scenario: | ||
- non_exist: | ||
error_msg = No such file or directory | ||
- invalid: | ||
error_msg = failed to read qemu header | ||
- to_running_vm: | ||
error_msg = domain .* is already active | ||
- image_running_by_another_vm: | ||
vm_2nd = vm2 | ||
vms += ' ${vm_2nd}' | ||
error_msg = Setting different SELinux label on .* which is already in use |
67 changes: 67 additions & 0 deletions
67
libvirt/tests/src/save_and_restore/restore_from_unqualified_file.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,67 @@ | ||
import logging | ||
import os | ||
|
||
from avocado.utils import process | ||
from virttest import utils_misc | ||
from virttest import virsh | ||
from virttest.libvirt_xml import vm_xml | ||
from virttest.utils_test import libvirt | ||
|
||
LOG = logging.getLogger('avocado.test.' + __name__) | ||
VIRSH_ARGS = {'debug': True, 'ignore_status': False} | ||
|
||
|
||
def modify_save_image_disk_source(save_path, vm_disk_source): | ||
""" | ||
Modify disk source of saved file | ||
:param save_path: path of saved file | ||
:param vm_disk_source: new disk source file to be set | ||
""" | ||
save_xml = vm_xml.VMXML() | ||
save_xml.xml = virsh.save_image_dumpxml( | ||
save_path, **VIRSH_ARGS).stdout_text | ||
disk_attrs = {'source': {'attrs': {'file': vm_disk_source}}} | ||
disk_xml, xml_devices = libvirt.get_vm_device(save_xml, 'disk') | ||
disk_xml.setup_attrs(**disk_attrs) | ||
save_xml.devices = xml_devices | ||
virsh.save_image_define(save_path, save_xml.xml, **VIRSH_ARGS) | ||
|
||
|
||
def run(test, params, env): | ||
""" | ||
Test restoring vm from unqualified file | ||
""" | ||
vm_name = params.get('main_vm') | ||
vm_2nd = params.get('vm_2nd') | ||
vm = env.get_vm(vm_name) | ||
|
||
scenario = params.get('scenario', '') | ||
status_error = "yes" == params.get('status_error', 'no') | ||
error_msg = params.get('error_msg', '') | ||
rand_id = utils_misc.generate_random_string(3) | ||
save_path = f'/var/tmp/{vm_name}_{rand_id}.save' | ||
|
||
vmxml = vm_xml.VMXML.new_from_inactive_dumpxml(vm_name) | ||
bkxml = vmxml.copy() | ||
try: | ||
if scenario == 'invalid': | ||
process.run(f'echo > {save_path}', shell=True) | ||
|
||
if scenario == 'to_running_vm': | ||
virsh.save(vm_name, save_path, **VIRSH_ARGS) | ||
virsh.start(vm_name, **VIRSH_ARGS) | ||
|
||
if scenario == 'image_running_by_another_vm': | ||
vm_disk_source = vmxml.get_devices('disk')[0].source.attrs['file'] | ||
virsh.save(vm_2nd, save_path, **VIRSH_ARGS) | ||
modify_save_image_disk_source(save_path, vm_disk_source) | ||
|
||
restore_result = virsh.restore(save_path, debug=True) | ||
libvirt.check_exit_status(restore_result, status_error) | ||
libvirt.check_result(restore_result, error_msg) | ||
|
||
finally: | ||
bkxml.sync() | ||
if os.path.exists(save_path): | ||
os.remove(save_path) |