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#5113 from Yingshun/os_boot_org_neg
guest_os_booting: Add negative test about boot order settings
- Loading branch information
Showing
2 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
libvirt/tests/cfg/guest_os_booting/boot_order/boot_order_setting_negative.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,19 @@ | ||
- guest_os_booting.boot_order.setting.negative: | ||
type = boot_order_setting_negative | ||
start_vm = no | ||
err_msg = "Invalid value for attribute 'order' in element 'boot'" | ||
variants: | ||
- duplicate: | ||
boot_index = '1' | ||
iface_dict = {'boot': ${boot_index}} | ||
err_msg = "used for more than one device" | ||
- with_os_boots: | ||
os_attrs_boots = ['hd'] | ||
boot_index = '1' | ||
err_msg = "per-device boot elements cannot be used together with os/boot elements" | ||
- minus: | ||
boot_index = '-1' | ||
- zero: | ||
boot_index = '0' | ||
- string: | ||
boot_index = 'invalid' |
49 changes: 49 additions & 0 deletions
49
libvirt/tests/src/guest_os_booting/boot_order/boot_order_setting_negative.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,49 @@ | ||
from virttest.libvirt_xml import vm_xml | ||
from virttest.libvirt_xml import xcepts | ||
|
||
from provider.guest_os_booting import guest_os_booting_base | ||
|
||
|
||
def run(test, params, env): | ||
""" | ||
Test boot order settings - negative | ||
""" | ||
vm_name = guest_os_booting_base.get_vm(params) | ||
iface_dict = eval(params.get("iface_dict", "{}")) | ||
err_msg = params.get('err_msg', "Invalid value") | ||
|
||
vm = env.get_vm(vm_name) | ||
vmxml = vm_xml.VMXML.new_from_inactive_dumpxml(vm.name) | ||
bkxml = vmxml.copy() | ||
|
||
try: | ||
os_attrs_boots = eval(params.get('os_attrs_boots', '[]')) | ||
if os_attrs_boots: | ||
os_attrs = {'boots': os_attrs_boots} | ||
vmxml.setup_attrs(os=os_attrs) | ||
else: | ||
vm_os = vmxml.os | ||
vm_os.del_boots() | ||
vmxml.os = vm_os | ||
|
||
xml_devices = vmxml.devices | ||
if iface_dict: | ||
iface_obj = xml_devices.by_device_tag('interface')[0] | ||
iface_obj.setup_attrs(**iface_dict) | ||
vmxml.devices = xml_devices | ||
disk_attrs = xml_devices.by_device_tag('disk')[0].fetch_attrs() | ||
vmxml.set_boot_order_by_target_dev( | ||
disk_attrs['target']['dev'], params.get('boot_index')) | ||
vmxml.xmltreefile.write() | ||
test.log.debug(f"vmxml after updating: {vmxml}") | ||
try: | ||
vmxml.sync() | ||
except xcepts.LibvirtXMLError as xml_error: | ||
test.log.debug("Failed define vm as expected: %s.", str(xml_error)) | ||
if err_msg not in str(xml_error): | ||
test.fail("Unable to get expected error: %s!" % xml_error) | ||
else: | ||
test.fail("It should Fail") | ||
|
||
finally: | ||
bkxml.sync() |