From 7f1c7a80c98be2880055d4f84c0d38d7fb012329 Mon Sep 17 00:00:00 2001 From: Pavel Hrdina Date: Fri, 10 Jul 2015 12:06:48 +0200 Subject: [PATCH 4/6] refactor detection of guest type capabilities Each guest type can have its own capabilities and we should always ask only for those capabilities. The old approach was to get capabilities from libvirt and then for example cycle trough all guests and return True, if any guest type supports kvm or pae, etc. Now we check those capabilities only for the correct guest type according to defaults and input from user. Signed-off-by: Pavel Hrdina (cherry picked from commit 3ff35898a463f7e352009dd3b8c40104fec3debc) Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1215692 Signed-off-by: Pavel Hrdina --- tests/capabilities.py | 5 +- .../compare/virt-convert-ovf-compare.xml | 1 - .../compare/virt-convert-vmx-compare.xml | 1 - .../compare/virt-install-aarch64-cdrom.xml | 2 - .../compare/virt-install-aarch64-machdefault.xml | 1 - .../compare/virt-install-aarch64-machvirt.xml | 1 - .../compare/virt-install-arm-defaultmach-f20.xml | 1 - .../compare/virt-install-arm-vexpress-f19.xml | 1 - .../compare/virt-install-arm-vexpress-plain.xml | 1 - .../compare/virt-install-arm-virt-f20.xml | 1 - .../compare/virt-install-f21-kvm-remote.xml | 1 - .../compare/virt-install-kvm-centos7.xml | 2 - .../compare/virt-install-kvm-f14-url.xml | 2 - .../compare/virt-install-kvm-rhel6.xml | 2 - .../compare/virt-install-kvm-rhel7.xml | 2 - .../compare/virt-install-kvm-win2k3-cdrom.xml | 3 - .../compare/virt-install-location-iso.xml | 2 - .../compare/virt-install-many-devices.xml | 1 - .../compare/virt-install-ppc64-machdefault-f20.xml | 1 - .../compare/virt-install-ppc64-pseries-f20.xml | 1 - .../compare/virt-install-q35-defaults.xml | 2 - .../compare/virt-install-qemu-plain.xml | 1 - .../compare/virt-install-singleton-config-1.xml | 1 - .../compare/virt-install-singleton-config-2.xml | 2 - .../compare/virt-install-win7-uefi.xml | 3 - .../cli-test-xml/compare/virt-install-xen-hvm.xml | 1 - .../ovf2libvirt_ovf_directory.libvirt | 1 - .../libvirt_output/ovf2libvirt_test1.libvirt | 1 - .../ovf2libvirt_test1.libvirt.disk_qcow2 | 1 - .../libvirt_output/ovf2libvirt_test2.libvirt | 1 - .../vmx2libvirt_test-nodisks.libvirt | 1 - .../vmx2libvirt_test-vmx-zip.libvirt | 1 - .../libvirt_output/vmx2libvirt_test1.libvirt | 1 - .../vmx2libvirt_test1.libvirt.disk_raw | 1 - .../libvirt_output/vmx2libvirt_vmx-dir.libvirt | 1 - tests/xmlconfig.py | 2 +- virtManager/create.py | 9 ++- virtinst/capabilities.py | 82 +++++++++------------- virtinst/guest.py | 5 +- 39 files changed, 47 insertions(+), 102 deletions(-) diff --git a/tests/capabilities.py b/tests/capabilities.py index 6c71fca..b727e80 100644 --- a/tests/capabilities.py +++ b/tests/capabilities.py @@ -70,8 +70,9 @@ class TestCapabilities(unittest.TestCase): caps_empty = self._buildCaps("test-old-vmx.xml") def test_utils(caps, has_guests, is_kvm): - self.assertEquals(caps.has_install_options(), has_guests) - self.assertEquals(caps.is_kvm_available(), is_kvm) + if caps.guests: + self.assertEquals(caps.guests[0].has_install_options(), has_guests) + self.assertEquals(caps.guests[0].is_kvm_available(), is_kvm) test_utils(caps_empty, False, False) test_utils(caps_with_kvm, True, True) diff --git a/tests/cli-test-xml/compare/virt-convert-ovf-compare.xml b/tests/cli-test-xml/compare/virt-convert-ovf-compare.xml index 0d8556d..eb8e131 100644 --- a/tests/cli-test-xml/compare/virt-convert-ovf-compare.xml +++ b/tests/cli-test-xml/compare/virt-convert-ovf-compare.xml @@ -12,7 +12,6 @@ - diff --git a/tests/cli-test-xml/compare/virt-convert-vmx-compare.xml b/tests/cli-test-xml/compare/virt-convert-vmx-compare.xml index d5a0714..202542b 100644 --- a/tests/cli-test-xml/compare/virt-convert-vmx-compare.xml +++ b/tests/cli-test-xml/compare/virt-convert-vmx-compare.xml @@ -11,7 +11,6 @@ - diff --git a/tests/cli-test-xml/compare/virt-install-aarch64-cdrom.xml b/tests/cli-test-xml/compare/virt-install-aarch64-cdrom.xml index 1b4264b..80e5c32 100644 --- a/tests/cli-test-xml/compare/virt-install-aarch64-cdrom.xml +++ b/tests/cli-test-xml/compare/virt-install-aarch64-cdrom.xml @@ -14,7 +14,6 @@ - restart @@ -57,7 +56,6 @@ - restart diff --git a/tests/cli-test-xml/compare/virt-install-aarch64-machdefault.xml b/tests/cli-test-xml/compare/virt-install-aarch64-machdefault.xml index 5e526a8..8ad033b 100644 --- a/tests/cli-test-xml/compare/virt-install-aarch64-machdefault.xml +++ b/tests/cli-test-xml/compare/virt-install-aarch64-machdefault.xml @@ -13,7 +13,6 @@ - cortex-a57 diff --git a/tests/cli-test-xml/compare/virt-install-aarch64-machvirt.xml b/tests/cli-test-xml/compare/virt-install-aarch64-machvirt.xml index 5e526a8..8ad033b 100644 --- a/tests/cli-test-xml/compare/virt-install-aarch64-machvirt.xml +++ b/tests/cli-test-xml/compare/virt-install-aarch64-machvirt.xml @@ -13,7 +13,6 @@ - cortex-a57 diff --git a/tests/cli-test-xml/compare/virt-install-arm-defaultmach-f20.xml b/tests/cli-test-xml/compare/virt-install-arm-defaultmach-f20.xml index ba23454..d10d85f 100644 --- a/tests/cli-test-xml/compare/virt-install-arm-defaultmach-f20.xml +++ b/tests/cli-test-xml/compare/virt-install-arm-defaultmach-f20.xml @@ -13,7 +13,6 @@ - destroy diff --git a/tests/cli-test-xml/compare/virt-install-arm-vexpress-f19.xml b/tests/cli-test-xml/compare/virt-install-arm-vexpress-f19.xml index 493de63..cdcb7c0 100644 --- a/tests/cli-test-xml/compare/virt-install-arm-vexpress-f19.xml +++ b/tests/cli-test-xml/compare/virt-install-arm-vexpress-f19.xml @@ -14,7 +14,6 @@ - destroy diff --git a/tests/cli-test-xml/compare/virt-install-arm-vexpress-plain.xml b/tests/cli-test-xml/compare/virt-install-arm-vexpress-plain.xml index a92ab4f..3defad4 100644 --- a/tests/cli-test-xml/compare/virt-install-arm-vexpress-plain.xml +++ b/tests/cli-test-xml/compare/virt-install-arm-vexpress-plain.xml @@ -14,7 +14,6 @@ - destroy diff --git a/tests/cli-test-xml/compare/virt-install-arm-virt-f20.xml b/tests/cli-test-xml/compare/virt-install-arm-virt-f20.xml index ba23454..d10d85f 100644 --- a/tests/cli-test-xml/compare/virt-install-arm-virt-f20.xml +++ b/tests/cli-test-xml/compare/virt-install-arm-virt-f20.xml @@ -13,7 +13,6 @@ - destroy diff --git a/tests/cli-test-xml/compare/virt-install-f21-kvm-remote.xml b/tests/cli-test-xml/compare/virt-install-f21-kvm-remote.xml index 735181c..f8eafbf 100644 --- a/tests/cli-test-xml/compare/virt-install-f21-kvm-remote.xml +++ b/tests/cli-test-xml/compare/virt-install-f21-kvm-remote.xml @@ -11,7 +11,6 @@ - diff --git a/tests/cli-test-xml/compare/virt-install-kvm-centos7.xml b/tests/cli-test-xml/compare/virt-install-kvm-centos7.xml index 92105c1..e05fadb 100644 --- a/tests/cli-test-xml/compare/virt-install-kvm-centos7.xml +++ b/tests/cli-test-xml/compare/virt-install-kvm-centos7.xml @@ -12,7 +12,6 @@ - @@ -85,7 +84,6 @@ - diff --git a/tests/cli-test-xml/compare/virt-install-kvm-f14-url.xml b/tests/cli-test-xml/compare/virt-install-kvm-f14-url.xml index d70b4fa..4a43c3b 100644 --- a/tests/cli-test-xml/compare/virt-install-kvm-f14-url.xml +++ b/tests/cli-test-xml/compare/virt-install-kvm-f14-url.xml @@ -13,7 +13,6 @@ - @@ -73,7 +72,6 @@ - diff --git a/tests/cli-test-xml/compare/virt-install-kvm-rhel6.xml b/tests/cli-test-xml/compare/virt-install-kvm-rhel6.xml index 92105c1..e05fadb 100644 --- a/tests/cli-test-xml/compare/virt-install-kvm-rhel6.xml +++ b/tests/cli-test-xml/compare/virt-install-kvm-rhel6.xml @@ -12,7 +12,6 @@ - @@ -85,7 +84,6 @@ - diff --git a/tests/cli-test-xml/compare/virt-install-kvm-rhel7.xml b/tests/cli-test-xml/compare/virt-install-kvm-rhel7.xml index 92105c1..e05fadb 100644 --- a/tests/cli-test-xml/compare/virt-install-kvm-rhel7.xml +++ b/tests/cli-test-xml/compare/virt-install-kvm-rhel7.xml @@ -12,7 +12,6 @@ - @@ -85,7 +84,6 @@ - diff --git a/tests/cli-test-xml/compare/virt-install-kvm-win2k3-cdrom.xml b/tests/cli-test-xml/compare/virt-install-kvm-win2k3-cdrom.xml index 0a0ef95..8423178 100644 --- a/tests/cli-test-xml/compare/virt-install-kvm-win2k3-cdrom.xml +++ b/tests/cli-test-xml/compare/virt-install-kvm-win2k3-cdrom.xml @@ -12,7 +12,6 @@ - @@ -83,7 +82,6 @@ - @@ -154,7 +152,6 @@ - diff --git a/tests/cli-test-xml/compare/virt-install-location-iso.xml b/tests/cli-test-xml/compare/virt-install-location-iso.xml index ec40d9c..b990055 100644 --- a/tests/cli-test-xml/compare/virt-install-location-iso.xml +++ b/tests/cli-test-xml/compare/virt-install-location-iso.xml @@ -12,7 +12,6 @@ - @@ -77,7 +76,6 @@ - diff --git a/tests/cli-test-xml/compare/virt-install-many-devices.xml b/tests/cli-test-xml/compare/virt-install-many-devices.xml index 7c8b39a..80535b4 100644 --- a/tests/cli-test-xml/compare/virt-install-many-devices.xml +++ b/tests/cli-test-xml/compare/virt-install-many-devices.xml @@ -10,7 +10,6 @@ - diff --git a/tests/cli-test-xml/compare/virt-install-ppc64-machdefault-f20.xml b/tests/cli-test-xml/compare/virt-install-ppc64-machdefault-f20.xml index 6c7e573..a24c0d5 100644 --- a/tests/cli-test-xml/compare/virt-install-ppc64-machdefault-f20.xml +++ b/tests/cli-test-xml/compare/virt-install-ppc64-machdefault-f20.xml @@ -11,7 +11,6 @@ - diff --git a/tests/cli-test-xml/compare/virt-install-ppc64-pseries-f20.xml b/tests/cli-test-xml/compare/virt-install-ppc64-pseries-f20.xml index 6c7e573..a24c0d5 100644 --- a/tests/cli-test-xml/compare/virt-install-ppc64-pseries-f20.xml +++ b/tests/cli-test-xml/compare/virt-install-ppc64-pseries-f20.xml @@ -11,7 +11,6 @@ - diff --git a/tests/cli-test-xml/compare/virt-install-q35-defaults.xml b/tests/cli-test-xml/compare/virt-install-q35-defaults.xml index 0f28abf..9c6bce0 100644 --- a/tests/cli-test-xml/compare/virt-install-q35-defaults.xml +++ b/tests/cli-test-xml/compare/virt-install-q35-defaults.xml @@ -12,7 +12,6 @@ - @@ -86,7 +85,6 @@ - diff --git a/tests/cli-test-xml/compare/virt-install-qemu-plain.xml b/tests/cli-test-xml/compare/virt-install-qemu-plain.xml index 5f82d26..5978184 100644 --- a/tests/cli-test-xml/compare/virt-install-qemu-plain.xml +++ b/tests/cli-test-xml/compare/virt-install-qemu-plain.xml @@ -11,7 +11,6 @@ - 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 8f98aa3..9b9bafd 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 @@ -18,7 +18,6 @@ - diff --git a/tests/cli-test-xml/compare/virt-install-singleton-config-2.xml b/tests/cli-test-xml/compare/virt-install-singleton-config-2.xml index a03a7c0..9d35eaf 100644 --- a/tests/cli-test-xml/compare/virt-install-singleton-config-2.xml +++ b/tests/cli-test-xml/compare/virt-install-singleton-config-2.xml @@ -44,7 +44,6 @@ - @@ -165,7 +164,6 @@ - diff --git a/tests/cli-test-xml/compare/virt-install-win7-uefi.xml b/tests/cli-test-xml/compare/virt-install-win7-uefi.xml index 19bab1a..4c3b9b6 100644 --- a/tests/cli-test-xml/compare/virt-install-win7-uefi.xml +++ b/tests/cli-test-xml/compare/virt-install-win7-uefi.xml @@ -14,7 +14,6 @@ - @@ -90,7 +89,6 @@ - @@ -166,7 +164,6 @@ - diff --git a/tests/cli-test-xml/compare/virt-install-xen-hvm.xml b/tests/cli-test-xml/compare/virt-install-xen-hvm.xml index 3af66b9..0fe3064 100644 --- a/tests/cli-test-xml/compare/virt-install-xen-hvm.xml +++ b/tests/cli-test-xml/compare/virt-install-xen-hvm.xml @@ -13,7 +13,6 @@ - destroy diff --git a/tests/virtconv-files/libvirt_output/ovf2libvirt_ovf_directory.libvirt b/tests/virtconv-files/libvirt_output/ovf2libvirt_ovf_directory.libvirt index 4bdcac3..ec4e165 100644 --- a/tests/virtconv-files/libvirt_output/ovf2libvirt_ovf_directory.libvirt +++ b/tests/virtconv-files/libvirt_output/ovf2libvirt_ovf_directory.libvirt @@ -11,7 +11,6 @@ - diff --git a/tests/virtconv-files/libvirt_output/ovf2libvirt_test1.libvirt b/tests/virtconv-files/libvirt_output/ovf2libvirt_test1.libvirt index a6d8651..b527bfa 100644 --- a/tests/virtconv-files/libvirt_output/ovf2libvirt_test1.libvirt +++ b/tests/virtconv-files/libvirt_output/ovf2libvirt_test1.libvirt @@ -12,7 +12,6 @@ - diff --git a/tests/virtconv-files/libvirt_output/ovf2libvirt_test1.libvirt.disk_qcow2 b/tests/virtconv-files/libvirt_output/ovf2libvirt_test1.libvirt.disk_qcow2 index 9dbcb05..9d09a99 100644 --- a/tests/virtconv-files/libvirt_output/ovf2libvirt_test1.libvirt.disk_qcow2 +++ b/tests/virtconv-files/libvirt_output/ovf2libvirt_test1.libvirt.disk_qcow2 @@ -12,7 +12,6 @@ - diff --git a/tests/virtconv-files/libvirt_output/ovf2libvirt_test2.libvirt b/tests/virtconv-files/libvirt_output/ovf2libvirt_test2.libvirt index d2570bc..8376dff 100644 --- a/tests/virtconv-files/libvirt_output/ovf2libvirt_test2.libvirt +++ b/tests/virtconv-files/libvirt_output/ovf2libvirt_test2.libvirt @@ -12,7 +12,6 @@ - diff --git a/tests/virtconv-files/libvirt_output/vmx2libvirt_test-nodisks.libvirt b/tests/virtconv-files/libvirt_output/vmx2libvirt_test-nodisks.libvirt index 85712dd..3e7f079 100644 --- a/tests/virtconv-files/libvirt_output/vmx2libvirt_test-nodisks.libvirt +++ b/tests/virtconv-files/libvirt_output/vmx2libvirt_test-nodisks.libvirt @@ -11,7 +11,6 @@ - diff --git a/tests/virtconv-files/libvirt_output/vmx2libvirt_test-vmx-zip.libvirt b/tests/virtconv-files/libvirt_output/vmx2libvirt_test-vmx-zip.libvirt index 688ccfb..a3dcb85 100644 --- a/tests/virtconv-files/libvirt_output/vmx2libvirt_test-vmx-zip.libvirt +++ b/tests/virtconv-files/libvirt_output/vmx2libvirt_test-vmx-zip.libvirt @@ -12,7 +12,6 @@ - diff --git a/tests/virtconv-files/libvirt_output/vmx2libvirt_test1.libvirt b/tests/virtconv-files/libvirt_output/vmx2libvirt_test1.libvirt index 57282f0..687e705 100644 --- a/tests/virtconv-files/libvirt_output/vmx2libvirt_test1.libvirt +++ b/tests/virtconv-files/libvirt_output/vmx2libvirt_test1.libvirt @@ -11,7 +11,6 @@ - diff --git a/tests/virtconv-files/libvirt_output/vmx2libvirt_test1.libvirt.disk_raw b/tests/virtconv-files/libvirt_output/vmx2libvirt_test1.libvirt.disk_raw index 7d9b13c..1270809 100644 --- a/tests/virtconv-files/libvirt_output/vmx2libvirt_test1.libvirt.disk_raw +++ b/tests/virtconv-files/libvirt_output/vmx2libvirt_test1.libvirt.disk_raw @@ -11,7 +11,6 @@ - diff --git a/tests/virtconv-files/libvirt_output/vmx2libvirt_vmx-dir.libvirt b/tests/virtconv-files/libvirt_output/vmx2libvirt_vmx-dir.libvirt index 23d6c4c..4692fbf 100644 --- a/tests/virtconv-files/libvirt_output/vmx2libvirt_vmx-dir.libvirt +++ b/tests/virtconv-files/libvirt_output/vmx2libvirt_vmx-dir.libvirt @@ -12,7 +12,6 @@ - diff --git a/tests/xmlconfig.py b/tests/xmlconfig.py index 048675d..8665086 100644 --- a/tests/xmlconfig.py +++ b/tests/xmlconfig.py @@ -32,7 +32,7 @@ def _make_guest(installer=None, conn=None): if conn is None: conn = _default_conn - g = virtinst.Guest(conn) + g = conn.caps.lookup_virtinst_guest() g.type = "kvm" g.name = "TestGuest" g.memory = int(200 * 1024) diff --git a/virtManager/create.py b/virtManager/create.py index 8401a7a..81b0064 100644 --- a/virtManager/create.py +++ b/virtManager/create.py @@ -504,7 +504,7 @@ class vmmCreate(vmmGObjectUI): self.widget("startup-error-box").hide() self.widget("create-forward").set_sensitive(True) - if not self.conn.caps.has_install_options(): + if not self.capsinfo.guest.has_install_options(): error = _("No hypervisor options were found for this " "connection.") @@ -539,7 +539,7 @@ class vmmCreate(vmmGObjectUI): self.startup_warning(error) elif self.conn.is_qemu(): - if not self.conn.caps.is_kvm_available(): + if not self.capsinfo.guest.is_kvm_available(): error = _("KVM is not available. This may mean the KVM " "package is not installed, or the KVM kernel modules " "are not loaded. Your virtual machines may perform poorly.") @@ -875,11 +875,10 @@ class vmmCreate(vmmGObjectUI): break capsinfo = self.conn.caps.guest_lookup(os_type=gtype, arch=arch) - newg, newdom = capsinfo.get_caps_objects() if self.capsinfo: - oldg, olddom = self.capsinfo.get_caps_objects() - if oldg == newg and olddom and newdom: + if (self.capsinfo.guest == capsinfo.guest and + self.capsinfo.domain == capsinfo.domain): return self.capsinfo = capsinfo diff --git a/virtinst/capabilities.py b/virtinst/capabilities.py index bed8596..17af632 100644 --- a/virtinst/capabilities.py +++ b/virtinst/capabilities.py @@ -268,6 +268,31 @@ class _CapsGuest(XMLBuilder): # Fallback, just return last item in list return domains[-1] + def has_install_options(self): + """ + Return True if there are any install options available + """ + return bool(len(self.domains) > 0) + + def is_kvm_available(self): + """ + Return True if kvm guests can be installed + """ + if self.os_type != "hvm": + return False + + for d in self.domains: + if d.hypervisor_type == "kvm": + return True + + return False + + def supports_pae(self): + """ + Return True if capabilities report support for PAE + """ + return bool(self.features.pae) + ############################ # Main capabilities object # @@ -280,23 +305,17 @@ class _CapsInfo(object): """ def __init__(self, conn, guest, domain, requested_machine): self.conn = conn - self._guest = guest - self._domain = domain + self.guest = guest + self.domain = domain self._requested_machine = requested_machine - self.hypervisor_type = self._domain.hypervisor_type - self.os_type = self._guest.os_type - self.arch = self._guest.arch - self.loader = self._guest.loader + self.hypervisor_type = self.domain.hypervisor_type + self.os_type = self.guest.os_type + self.arch = self.guest.arch + self.loader = self.guest.loader - self.emulator = self._domain.emulator - self.machines = self._domain.machines[:] - - def get_caps_objects(self): - """ - Return the raw backing caps objects - """ - return self._guest, self._domain + self.emulator = self.domain.emulator + self.machines = self.domain.machines[:] def get_recommended_machine(self): """ @@ -360,39 +379,6 @@ class Capabilities(XMLBuilder): # Public API # ############## - def has_install_options(self): - """ - Return True if there are any install options available - """ - for g in self.guests: - if len(g.domains) > 0: - return True - - return False - - def is_kvm_available(self): - """ - Return True if kvm guests can be installed - """ - for g in self.guests: - if g.os_type != "hvm": - continue - - for d in g.domains: - if d.hypervisor_type == "kvm": - return True - - return False - - def supports_pae(self): - """ - Return True if capabilities report support for PAE - """ - for g in self.guests: - if g.features.pae: - return True - return False - def get_cpu_values(self, arch): if not arch: return [] @@ -498,6 +484,8 @@ class Capabilities(XMLBuilder): gobj.os.machine = capsinfo.get_recommended_machine() + gobj.capsinfo = capsinfo + return gobj def lookup_virtinst_guest(self, *args, **kwargs): diff --git a/virtinst/guest.py b/virtinst/guest.py index bf4b70b..26fadf8 100644 --- a/virtinst/guest.py +++ b/virtinst/guest.py @@ -131,6 +131,9 @@ class Guest(XMLBuilder): # The libvirt virDomain object we 'Create' self.domain = None + # This is set via Capabilities.build_virtinst_guest + self.capsinfo = None + self.installer = DistroInstaller(self.conn) @@ -844,7 +847,7 @@ class Guest(XMLBuilder): if self.features.apic == "default": self.features.apic = self._os_object.supports_apic(default) if self.features.pae == "default": - self.features.pae = self.conn.caps.supports_pae() + self.features.pae = self.capsinfo.guest.supports_pae() if (self.features.vmport == "default" and self.has_spice() and -- 2.4.5