Skip to content

Commit

Permalink
Merge pull request autotest#5113 from Yingshun/os_boot_org_neg
Browse files Browse the repository at this point in the history
guest_os_booting: Add negative test about boot order settings
  • Loading branch information
chloerh authored Aug 29, 2023
2 parents a3717a0 + 44d1879 commit 9b15f0c
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
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'
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()

0 comments on commit 9b15f0c

Please sign in to comment.