def config_feature_pv_eoi(test, vmxml, **kwargs): """ Config libvirt VM XML to enable/disable PV EOI feature. :param vmxml: VMXML instance :param kwargs: Function keywords :return: Corresponding feature flag in qem cmdline """ # This attribute supported since 0.10.2 (QEMU only) if not libvirt_version.version_compare(0, 10, 2): test.cancel("PV eoi is not supported in current" " libvirt version") qemu_flags = [] eoi_enable = kwargs.get('eoi_enable', 'on') get_hostos_version = astring.to_text( process.run("cat /etc/redhat-release", shell=True).stdout) if re.search(r'(\d+(\.\d+)?)', get_hostos_version) is not None: hostos_version = float( re.search(r'(\d+(\.\d+)?)', get_hostos_version).group(0)) if hostos_version < float(8.1): if eoi_enable == 'on': qemu_flags.append('+kvm_pv_eoi') elif eoi_enable == 'off': qemu_flags.append('-kvm_pv_eoi') else: logging.error( "Invaild value %s, eoi_enable must be 'on' or 'off'", eoi_enable) elif hostos_version > float(8.0): if eoi_enable == 'on': qemu_flags.append('kvm-pv-eoi=on') elif eoi_enable == 'off': qemu_flags.append('kvm-pv-eoi=off') else: logging.error( "Invaild value %s, eoi_enable must be 'on' or 'off'", eoi_enable) else: test.fail( "Can not decide the expected qemu cmd line because of no expected hostos version" ) # Create features tag if not existed if not vmxml.xmltreefile.find('features'): vmxml.features = vm_xml.VMFeaturesXML() vmxml_feature = vmxml.features if vmxml_feature.has_feature('apic'): vmxml_feature.remove_feature('apic') vmxml_feature.add_feature('apic', 'eoi', eoi_enable) vmxml.features = vmxml_feature logging.debug("Update VM XML:\n%s", vmxml) expect_fail = False if 'expect_define_vm_fail' not in kwargs \ else kwargs['expect_define_vm_fail'] result = virsh.define(vmxml.xml, debug=True) libvirt.check_exit_status(result, expect_fail) if expect_fail: libvirt.check_result(result, kwargs.get('expected_msg')) return return qemu_flags
def set_hpt(resizing, vmxml, sync=True): """ Set resizing value to vm xml """ features_xml = vm_xml.VMFeaturesXML() features_xml.hpt_resizing = resizing vmxml.features = features_xml if sync: vmxml.sync()
def set_hpt(resizing, vmxml): """ Set the hpt feature for PPC :param resizing: The value needed :param vmxml: guest xml """ features_xml = vm_xml.VMFeaturesXML() features_xml.hpt_resizing = resizing vmxml.features = features_xml vmxml.sync()
def set_feature(vmxml, feature, value): """ Set guest features for PPC :param state: the htm status :param vmxml: guest xml """ features_xml = vm_xml.VMFeaturesXML() if feature == 'hpt': features_xml.hpt_resizing = value elif feature == 'htm': features_xml.htm = value vmxml.features = features_xml vmxml.sync()
def set_hpt(vmxml, sync, **attrs): """ Set resizing value to vm xml :param vmxml: xml of vm to be manipulated :param sync: whether to sync vmxml after :param attrs: attrs to set to hpt xml """ if vmxml.xmltreefile.find('/features'): features_xml = vmxml.features else: features_xml = vm_xml.VMFeaturesXML() hpt_xml = vm_xml.VMFeaturesHptXML() for attr in attrs: setattr(hpt_xml, attr, attrs[attr]) features_xml.hpt = hpt_xml vmxml.features = features_xml logging.debug(vmxml) if sync: vmxml.sync()
def run(test, params, env): """ Test extended TSEG on Q35 machine types <smm state='on'> <tseg unit='MiB'>48</tseg> </smm> Steps: 1) Edit VM xml for smm or tseg sub element 2) Verify if Guest can boot as expected 3) On i440 machine types, the property does not support. On Q35 machine types, both Seabios and OVMF Guest can bootup """ vm_name = params.get("main_vm", "") vm = env.get_vm(vm_name) smm_state = params.get("smm_state", "off") unit = params.get("tseg_unit") size = params.get("tseg_size") boot_type = params.get("boot_type", "") loader_type = params.get("loader_type") loader = params.get("loader") err_msg = params.get("error_msg", "") vm_arch_name = params.get("vm_arch_name", "x86_64") status_error = ("yes" == params.get("status_error", "no")) if not libvirt_version.version_compare(4, 5, 0): test.cancel("TSEG does not support in " "current libvirt version") if (boot_type == "seabios" and not utils_package.package_install('seabios-bin')): test.cancel("Failed to install Seabios") if (boot_type == 'ovmf' and not utils_package.package_install('OVMF')): test.cancel("Failed to install OVMF") # Back VM XML v_xml_backup = vm_xml.VMXML.new_from_dumpxml(vm_name) v_xml = vm_xml.VMXML.new_from_dumpxml(vm_name) try: # Specify boot loader for OVMF if boot_type == 'ovmf': os_xml = v_xml.os os_xml.loader_type = loader_type os_xml.loader = loader os_xml.loader_readonly = "yes" v_xml.os = os_xml try: features_xml = v_xml.features except xcepts.LibvirtXMLNotFoundError: if vm_arch_name == 'x86_64': # ACPI is required for UEFI on x86_64 v_xml.xmltreefile.create_by_xpath("/features/acpi") features_xml = v_xml.features else: features_xml = vm_xml.VMFeaturesXML() features_xml.smm = smm_state if unit and size: features_xml.smm_tseg_unit = unit features_xml.smm_tseg = size v_xml.features = features_xml logging.debug("New VM XML is:\n%s", v_xml) ret = virsh.define(v_xml.xml) utlv.check_result(ret, expected_fails=err_msg) # Check result if not status_error: vm.start() if unit and size: # If tseg unit is KiB, convert it to MiB # as vm dumpxml convert it automatically if unit == 'KiB': unit, size = unify_to_MiB(unit, size) expect_line = "<tseg unit=\"%s\">%s</tseg>" % (unit, size) utlv.check_dumpxml(vm, expect_line) # Qemu cmdline use mbytes unit, tseg_mbytes = unify_to_MiB(unit, size) expect_line = '-global mch.extended-tseg-mbytes=%s' % size utlv.check_qemu_cmd_line(expect_line) finally: logging.debug("Restore the VM XML") if vm.is_alive(): vm.destroy() # OVMF enable nvram by default v_xml_backup.sync(options="--nvram")