diff options
author | Cole Robinson <crobinso@redhat.com> | 2018-10-13 17:47:31 -0400 |
---|---|---|
committer | Cole Robinson <crobinso@redhat.com> | 2018-10-13 17:48:25 -0400 |
commit | b051b6c95d8adca7f7ec6a8d582e62d6427d28e3 (patch) | |
tree | 0a5f6afadc7a7afdd86151e9185af0affdf008bc | |
parent | 535e34481d28910c524b50d6da82892858e231db (diff) | |
download | virt-manager-b051b6c95d8adca7f7ec6a8d582e62d6427d28e3.tar.gz |
cpu: Have host-copy use domcaps if qemu is new enough (bz 1637767)
capabilities is known problematic. Use domcaps if libvirt+qemu
reports working host-model
https://bugzilla.redhat.com/show_bug.cgi?id=1637767
-rw-r--r-- | tests/cli-test-xml/compare/virt-install-kvm-hostcopy-fallback.xml | 161 | ||||
-rw-r--r-- | tests/cli-test-xml/compare/virt-install-singleton-config-1.xml | 16 | ||||
-rw-r--r-- | tests/clitest.py | 4 | ||||
-rw-r--r-- | tests/xmlparse.py | 2 | ||||
-rw-r--r-- | virtinst/domain/cpu.py | 30 | ||||
-rw-r--r-- | virtinst/domcapabilities.py | 12 |
6 files changed, 212 insertions, 13 deletions
diff --git a/tests/cli-test-xml/compare/virt-install-kvm-hostcopy-fallback.xml b/tests/cli-test-xml/compare/virt-install-kvm-hostcopy-fallback.xml new file mode 100644 index 00000000..fb745060 --- /dev/null +++ b/tests/cli-test-xml/compare/virt-install-kvm-hostcopy-fallback.xml @@ -0,0 +1,161 @@ +<domain type="kvm"> + <name>foobar</name> + <uuid>00000000-1111-2222-3333-444444444444</uuid> + <memory>65536</memory> + <currentMemory>65536</currentMemory> + <vcpu>1</vcpu> + <os> + <type arch="x86_64" machine="pc">hvm</type> + <boot dev="network"/> + </os> + <features> + <acpi/> + <apic/> + <vmport state="off"/> + </features> + <cpu mode="custom" match="exact"> + <model>Opteron_G4</model> + <vendor>AMD</vendor> + <feature name="invtsc"/> + <feature name="perfctr_nb"/> + <feature name="perfctr_core"/> + <feature name="topoext"/> + <feature name="nodeid_msr"/> + <feature name="lwp"/> + <feature name="wdt"/> + <feature name="skinit"/> + <feature name="ibs"/> + <feature name="osvw"/> + <feature name="cr8legacy"/> + <feature name="extapic"/> + <feature name="cmp_legacy"/> + <feature name="fxsr_opt"/> + <feature name="mmxext"/> + <feature name="osxsave"/> + <feature name="monitor"/> + <feature name="ht"/> + <feature name="vme"/> + </cpu> + <clock offset="utc"> + <timer name="rtc" tickpolicy="catchup"/> + <timer name="pit" tickpolicy="delay"/> + <timer name="hpet" present="no"/> + </clock> + <on_reboot>destroy</on_reboot> + <pm> + <suspend-to-mem enabled="no"/> + <suspend-to-disk enabled="no"/> + </pm> + <devices> + <emulator>/usr/bin/qemu-kvm</emulator> + <controller type="usb" index="0" model="ich9-ehci1"/> + <controller type="usb" index="0" model="ich9-uhci1"> + <master startport="0"/> + </controller> + <controller type="usb" index="0" model="ich9-uhci2"> + <master startport="2"/> + </controller> + <controller type="usb" index="0" model="ich9-uhci3"> + <master startport="4"/> + </controller> + <interface type="bridge"> + <source bridge="eth0"/> + <mac address="00:11:22:33:44:55"/> + <model type="e1000"/> + </interface> + <console type="pty"/> + <channel type="spicevmc"> + <target type="virtio" name="com.redhat.spice.0"/> + </channel> + <input type="tablet" bus="usb"/> + <graphics type="spice" port="-1" tlsPort="-1" autoport="yes"> + <image compression="off"/> + </graphics> + <sound model="ich6"/> + <video> + <model type="qxl"/> + </video> + <redirdev bus="usb" type="spicevmc"/> + <redirdev bus="usb" type="spicevmc"/> + </devices> +</domain> +<domain type="kvm"> + <name>foobar</name> + <uuid>00000000-1111-2222-3333-444444444444</uuid> + <memory>65536</memory> + <currentMemory>65536</currentMemory> + <vcpu>1</vcpu> + <os> + <type arch="x86_64" machine="pc">hvm</type> + <boot dev="network"/> + </os> + <features> + <acpi/> + <apic/> + <vmport state="off"/> + </features> + <cpu mode="custom" match="exact"> + <model>Opteron_G4</model> + <vendor>AMD</vendor> + <feature name="invtsc"/> + <feature name="perfctr_nb"/> + <feature name="perfctr_core"/> + <feature name="topoext"/> + <feature name="nodeid_msr"/> + <feature name="lwp"/> + <feature name="wdt"/> + <feature name="skinit"/> + <feature name="ibs"/> + <feature name="osvw"/> + <feature name="cr8legacy"/> + <feature name="extapic"/> + <feature name="cmp_legacy"/> + <feature name="fxsr_opt"/> + <feature name="mmxext"/> + <feature name="osxsave"/> + <feature name="monitor"/> + <feature name="ht"/> + <feature name="vme"/> + </cpu> + <clock offset="utc"> + <timer name="rtc" tickpolicy="catchup"/> + <timer name="pit" tickpolicy="delay"/> + <timer name="hpet" present="no"/> + </clock> + <pm> + <suspend-to-mem enabled="no"/> + <suspend-to-disk enabled="no"/> + </pm> + <devices> + <emulator>/usr/bin/qemu-kvm</emulator> + <controller type="usb" index="0" model="ich9-ehci1"/> + <controller type="usb" index="0" model="ich9-uhci1"> + <master startport="0"/> + </controller> + <controller type="usb" index="0" model="ich9-uhci2"> + <master startport="2"/> + </controller> + <controller type="usb" index="0" model="ich9-uhci3"> + <master startport="4"/> + </controller> + <interface type="bridge"> + <source bridge="eth0"/> + <mac address="00:11:22:33:44:55"/> + <model type="e1000"/> + </interface> + <console type="pty"/> + <channel type="spicevmc"> + <target type="virtio" name="com.redhat.spice.0"/> + </channel> + <input type="tablet" bus="usb"/> + <graphics type="spice" port="-1" tlsPort="-1" autoport="yes"> + <image compression="off"/> + </graphics> + <sound model="ich6"/> + <video> + <model type="qxl"/> + </video> + <redirdev bus="usb" type="spicevmc"/> + <redirdev bus="usb" type="spicevmc"/> + </devices> +</domain> diff --git a/tests/cli-test-xml/compare/virt-install-singleton-config-1.xml b/tests/cli-test-xml/compare/virt-install-singleton-config-1.xml index 009d3e29..0e25af9f 100644 --- a/tests/cli-test-xml/compare/virt-install-singleton-config-1.xml +++ b/tests/cli-test-xml/compare/virt-install-singleton-config-1.xml @@ -29,7 +29,21 @@ <acpi/> <vmport state="off"/> </features> - <cpu mode="host-model"/> + <cpu mode="custom" match="exact"> + <model fallback="forbid">Broadwell</model> + <vendor>Intel</vendor> + <feature policy="require" name="vme"/> + <feature policy="require" name="ss"/> + <feature policy="require" name="f16c"/> + <feature policy="require" name="rdrand"/> + <feature policy="require" name="hypervisor"/> + <feature policy="require" name="arat"/> + <feature policy="require" name="tsc_adjust"/> + <feature policy="require" name="xsaveopt"/> + <feature policy="require" name="pdpe1gb"/> + <feature policy="require" name="abm"/> + <feature policy="require" name="invtsc"/> + </cpu> <clock offset="localtime"> <timer name="rtc" tickpolicy="catchup"/> <timer name="pit" tickpolicy="delay"/> diff --git a/tests/clitest.py b/tests/clitest.py index e6488cd6..144eac7a 100644 --- a/tests/clitest.py +++ b/tests/clitest.py @@ -357,7 +357,7 @@ c = vinst.add_category("xml-comparsion", "--connect %(URI-KVM)s --noautoconsole c.add_compare(""" \ --memory 1024 \ --vcpus 4 --cpuset=1,3-5 \ ---cpu host \ +--cpu host-copy \ --description \"foobar & baz\" \ --boot uefi,smbios_mode=emulate \ --security type=dynamic \ @@ -732,6 +732,8 @@ c.add_compare("--disk %(EXISTIMG1)s --pxe --os-variant rhel5.4", "kvm-rhel5") # c.add_compare("--disk %(EXISTIMG1)s --pxe --os-variant rhel6.4", "kvm-rhel6") # RHEL6 defaults c.add_compare("--disk %(EXISTIMG1)s --pxe --os-variant rhel7.0", "kvm-rhel7", skip_check=OLD_OSINFO) # RHEL7 defaults c.add_compare("--connect " + utils.URIs.kvm_nodomcaps + " --disk %(EXISTIMG1)s --pxe --os-variant rhel7.0", "kvm-cpu-default-fallback", skip_check=OLD_OSINFO) # No domcaps, so mode=host-model isn't safe, so we fallback to host-model-only +c.add_compare("--connect " + utils.URIs.kvm_nodomcaps + " --cpu host-copy --disk none --pxe", "kvm-hostcopy-fallback") # No domcaps so need to use capabilities for CPU host-copy +c.add_compare("--disk %(EXISTIMG1)s --pxe --os-variant centos7.0", "kvm-centos7", skip_check=OLD_OSINFO) # Centos 7 defaults c.add_compare("--disk %(EXISTIMG1)s --pxe --os-variant centos7.0", "kvm-centos7", skip_check=OLD_OSINFO) # Centos 7 defaults c.add_compare("--disk %(EXISTIMG1)s --cdrom %(EXISTIMG2)s --os-variant win10", "kvm-win10", skip_check=OLD_OSINFO) # win10 defaults c.add_compare("--os-variant win7 --cdrom %(EXISTIMG2)s --boot loader_type=pflash,loader=CODE.fd,nvram_template=VARS.fd --disk %(EXISTIMG1)s", "win7-uefi", skip_check=OLD_OSINFO) # no HYPER-V with UEFI diff --git a/tests/xmlparse.py b/tests/xmlparse.py index da2487f0..709bc48f 100644 --- a/tests/xmlparse.py +++ b/tests/xmlparse.py @@ -1426,7 +1426,7 @@ class XMLParseTest(unittest.TestCase): outfile = "tests/xmlparse-xml/%s-out.xml" % basename guest = virtinst.Guest(self.kvmconn, parsexml=open(infile).read()) - guest.cpu.copy_host_cpu() + guest.cpu.copy_host_cpu(guest) guest.cpu.clear() utils.diff_compare(guest.get_xml(), outfile) diff --git a/virtinst/domain/cpu.py b/virtinst/domain/cpu.py index 7912838a..d66704c1 100644 --- a/virtinst/domain/cpu.py +++ b/virtinst/domain/cpu.py @@ -96,7 +96,7 @@ class DomainCpu(XMLBuilder): self.remove_child(f) self.mode = val elif val == self.SPECIAL_MODE_HOST_COPY: - self.copy_host_cpu() + self.copy_host_cpu(guest) elif (val == self.SPECIAL_MODE_HV_DEFAULT or val == self.SPECIAL_MODE_CLEAR): self.clear() @@ -119,24 +119,36 @@ class DomainCpu(XMLBuilder): cells = XMLChildProperty(_CPUCell, relative_xpath="./numa") cache = XMLChildProperty(_CPUCache) - def copy_host_cpu(self): + def copy_host_cpu(self, guest): """ - Enact the equivalent of qemu -cpu host, pulling all info - from capabilities about the host CPU + Try to manually mimic host-model, copying all the info + preferably out of domcapabilities, but capabilities as fallback. """ - cpu = self.conn.caps.host.cpu - if not cpu.model: - raise ValueError(_("No host CPU reported in capabilities")) + domcaps = guest.lookup_domcaps() + if domcaps.supports_safe_host_model(): + logging.debug("Using domcaps for host-copy") + cpu = domcaps.cpu.get_mode("host-model") + model = cpu.models[0].model + fallback = cpu.models[0].fallback + else: + cpu = self.conn.caps.host.cpu + model = cpu.model + fallback = None + if not model: + raise ValueError(_("No host CPU reported in capabilities")) self.mode = "custom" self.match = "exact" - self.model = cpu.model + self.model = model + if fallback: + self.model_fallback = fallback self.vendor = cpu.vendor for feature in self.features: self.remove_child(feature) for feature in cpu.features: - self.add_feature(feature.name) + policy = getattr(feature, "policy", "require") + self.add_feature(feature.name, policy) def vcpus_from_topology(self): """ diff --git a/virtinst/domcapabilities.py b/virtinst/domcapabilities.py index b49e1498..4cbb7f20 100644 --- a/virtinst/domcapabilities.py +++ b/virtinst/domcapabilities.py @@ -95,19 +95,29 @@ class _CPUModel(XMLBuilder): XML_NAME = "model" model = XMLProperty(".") usable = XMLProperty("./@usable", is_yesno=True) + fallback = XMLProperty("./@fallback") + + +class _CPUFeature(XMLBuilder): + XML_NAME = "feature" + name = XMLProperty("./@name") + policy = XMLProperty("./@policy") class _CPUMode(XMLBuilder): XML_NAME = "mode" name = XMLProperty("./@name") supported = XMLProperty("./@supported", is_yesno=True) - models = XMLChildProperty(_CPUModel) + vendor = XMLProperty("./vendor") + models = XMLChildProperty(_CPUModel) def get_model(self, name): for model in self.models: if model.model == name: return model + features = XMLChildProperty(_CPUFeature) + class _CPU(XMLBuilder): XML_NAME = "cpu" |