From 44d18793a0c8d4416fb71ca58d1222b1b75c8e5e Mon Sep 17 00:00:00 2001 From: Yingshun Cui Date: Thu, 17 Aug 2023 10:11:29 +0800 Subject: [PATCH] guest_os_booting: Add negative test about boot order settings This PR adds: VIRT-297200: [Negative] Define vm with invalid boot order Signed-off-by: Yingshun Cui --- .../boot_order_setting_negative.cfg | 19 +++++++ .../boot_order/boot_order_setting_negative.py | 49 +++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 libvirt/tests/cfg/guest_os_booting/boot_order/boot_order_setting_negative.cfg create mode 100644 libvirt/tests/src/guest_os_booting/boot_order/boot_order_setting_negative.py diff --git a/libvirt/tests/cfg/guest_os_booting/boot_order/boot_order_setting_negative.cfg b/libvirt/tests/cfg/guest_os_booting/boot_order/boot_order_setting_negative.cfg new file mode 100644 index 0000000000..8684065105 --- /dev/null +++ b/libvirt/tests/cfg/guest_os_booting/boot_order/boot_order_setting_negative.cfg @@ -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' diff --git a/libvirt/tests/src/guest_os_booting/boot_order/boot_order_setting_negative.py b/libvirt/tests/src/guest_os_booting/boot_order/boot_order_setting_negative.py new file mode 100644 index 0000000000..96acdb22a8 --- /dev/null +++ b/libvirt/tests/src/guest_os_booting/boot_order/boot_order_setting_negative.py @@ -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()