Change in vdsm[ovirt-3.5]: caps: workaround for libvirt's canonical name in machine types

fromani at redhat.com fromani at redhat.com
Thu Aug 20 15:53:19 UTC 2015


Hello Dan Kenigsberg, Martin Polednik,

I'd like you to do a code review.  Please visit

    https://gerrit.ovirt.org/45155

to review the following change.

Change subject: caps: workaround for libvirt's canonical name in machine types
......................................................................

caps: workaround for libvirt's canonical name in machine types

Libvirt is supposed to return the machine type as 'text' attribute of the
XML. For the default machine type there is an alias in the "canonical"
attribute. Still each machine type is a separate <machine> tag.
In EL7 there is a regression in libvirt that the proper machine type's
name is not reported, only the "canonical" alias is - as part of the
default machine type entry.

This patch is workaround so we don't miss the latest machine type
and can be dropped once libvirt is fixed (bug 1229666).

Change-Id: Ic0bade940d7d548be18eb779cde324e37231ce73
Bug-Url: https://bugzilla.redhat.com/1239258
Bug-Url: https://bugzilla.redhat.com/1229396
Signed-off-by: Martin Polednik <mpolednik at redhat.com>
Reviewed-on: https://gerrit.ovirt.org/42082
Reviewed-by: Francesco Romani <fromani at redhat.com>
Reviewed-by: Dan Kenigsberg <danken at redhat.com>
Continuous-Integration: Dan Kenigsberg <danken at redhat.com>
---
M debian/vdsm-tests.install
M tests/Makefile.am
M tests/capsTests.py
A tests/caps_libvirt_intel_E5606.out
M vdsm.spec.in
M vdsm/caps.py
6 files changed, 188 insertions(+), 8 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/55/45155/1

diff --git a/debian/vdsm-tests.install b/debian/vdsm-tests.install
index 20d447d..bc68996 100644
--- a/debian/vdsm-tests.install
+++ b/debian/vdsm-tests.install
@@ -2,6 +2,7 @@
 usr/share/vdsm/tests/*.py
 usr/share/vdsm/tests/caps_libvirt_amd_6274.out
 usr/share/vdsm/tests/caps_libvirt_intel_E31220.out
+usr/share/vdsm/tests/caps_libvirt_intel_E5606.out
 usr/share/vdsm/tests/caps_libvirt_intel_E5649.out
 usr/share/vdsm/tests/caps_libvirt_intel_i73770.out
 usr/share/vdsm/tests/caps_libvirt_intel_i73770_nosnap.out
diff --git a/tests/Makefile.am b/tests/Makefile.am
index ec9ab0b..0876d1d 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -108,6 +108,7 @@
 	caps_libvirt_intel_E5649.out \
 	caps_libvirt_amd_6274.out \
 	caps_libvirt_intel_E31220.out \
+	caps_libvirt_intel_E5606.out \
 	caps_libvirt_intel_i73770.out \
 	caps_libvirt_intel_i73770_nosnap.out \
 	caps_lscpu_ppc64_1_4_4.out \
diff --git a/tests/capsTests.py b/tests/capsTests.py
index e3f7d6a..0b88e09 100644
--- a/tests/capsTests.py
+++ b/tests/capsTests.py
@@ -119,9 +119,8 @@
         capsData = self._readCaps("caps_libvirt_amd_6274.out")
         machines = caps._getEmulatedMachines(caps.Architecture.X86_64,
                                              capsData)
-        expectedMachines = ['pc-0.15', 'pc', 'pc-1.0', 'pc-0.14',
-                            'pc-0.13', 'pc-0.12', 'pc-0.11',
-                            'pc-0.10', 'isapc']
+        expectedMachines = ['pc-1.0', 'pc', 'isapc', 'pc-0.12', 'pc-0.13',
+                            'pc-0.10', 'pc-0.11', 'pc-0.14', 'pc-0.15']
         self.assertEqual(machines, expectedMachines)
 
     def test_parseKeyVal(self):
@@ -190,3 +189,29 @@
         support = caps._getLiveSnapshotSupport(caps.Architecture.X86_64,
                                                capsData)
         self.assertEqual(support, False)
+
+    def test_getEmulatedMachines(self):
+        capsData = self._readCaps("caps_libvirt_intel_i73770_nosnap.out")
+        result = caps._getEmulatedMachines('x86_64', capsData)
+        expected = ['rhel6.3.0', 'rhel6.1.0', 'rhel6.2.0', 'pc', 'rhel5.4.0',
+                    'rhel5.4.4', 'rhel6.4.0', 'rhel6.0.0', 'rhel6.5.0',
+                    'rhel5.5.0']
+        self.assertEqual(expected, result)
+
+    def test_getEmulatedMachinesCanonical(self):
+        capsData = self._readCaps("caps_libvirt_intel_E5606.out")
+        result = caps._getEmulatedMachines('x86_64', capsData)
+        expected = ['pc-i440fx-rhel7.1.0',
+                    'rhel6.3.0',
+                    'pc-q35-rhel7.0.0',
+                    'rhel6.1.0',
+                    'rhel6.6.0',
+                    'rhel6.2.0',
+                    'pc',
+                    'pc-q35-rhel7.1.0',
+                    'q35',
+                    'rhel6.4.0',
+                    'rhel6.0.0',
+                    'rhel6.5.0',
+                    'pc-i440fx-rhel7.0.0']
+        self.assertEqual(expected, result)
diff --git a/tests/caps_libvirt_intel_E5606.out b/tests/caps_libvirt_intel_E5606.out
new file mode 100644
index 0000000..5aa670b
--- /dev/null
+++ b/tests/caps_libvirt_intel_E5606.out
@@ -0,0 +1,143 @@
+<capabilities>
+
+  <host>
+    <uuid>f71ae682-f6ab-4cc0-a67f-41ef0ae39ece</uuid>
+    <cpu>
+      <arch>x86_64</arch>
+      <model>Westmere</model>
+      <vendor>Intel</vendor>
+      <topology sockets='1' cores='4' threads='1'/>
+      <feature name='invtsc'/>
+      <feature name='rdtscp'/>
+      <feature name='pdpe1gb'/>
+      <feature name='dca'/>
+      <feature name='pcid'/>
+      <feature name='pdcm'/>
+      <feature name='xtpr'/>
+      <feature name='tm2'/>
+      <feature name='est'/>
+      <feature name='smx'/>
+      <feature name='vmx'/>
+      <feature name='ds_cpl'/>
+      <feature name='monitor'/>
+      <feature name='dtes64'/>
+      <feature name='pclmuldq'/>
+      <feature name='pbe'/>
+      <feature name='tm'/>
+      <feature name='ht'/>
+      <feature name='ss'/>
+      <feature name='acpi'/>
+      <feature name='ds'/>
+      <feature name='vme'/>
+      <pages unit='KiB' size='4'/>
+      <pages unit='KiB' size='2048'/>
+    </cpu>
+    <power_management>
+      <suspend_mem/>
+      <suspend_disk/>
+      <suspend_hybrid/>
+    </power_management>
+    <migration_features>
+      <live/>
+      <uri_transports>
+        <uri_transport>tcp</uri_transport>
+        <uri_transport>rdma</uri_transport>
+      </uri_transports>
+    </migration_features>
+    <topology>
+      <cells num='1'>
+        <cell id='0'>
+          <memory unit='KiB'>12573660</memory>
+          <pages unit='KiB' size='4'>3143415</pages>
+          <pages unit='KiB' size='2048'>0</pages>
+          <distances>
+            <sibling id='0' value='10'/>
+          </distances>
+          <cpus num='4'>
+            <cpu id='0' socket_id='1' core_id='0' siblings='0'/>
+            <cpu id='1' socket_id='1' core_id='1' siblings='1'/>
+            <cpu id='2' socket_id='1' core_id='9' siblings='2'/>
+            <cpu id='3' socket_id='1' core_id='10' siblings='3'/>
+          </cpus>
+        </cell>
+      </cells>
+    </topology>
+    <secmodel>
+      <model>selinux</model>
+      <doi>0</doi>
+      <baselabel type='kvm'>system_u:system_r:svirt_t:s0</baselabel>
+      <baselabel type='qemu'>system_u:system_r:svirt_tcg_t:s0</baselabel>
+    </secmodel>
+    <secmodel>
+      <model>dac</model>
+      <doi>0</doi>
+      <baselabel type='kvm'>+107:+107</baselabel>
+      <baselabel type='qemu'>+107:+107</baselabel>
+    </secmodel>
+  </host>
+
+  <guest>
+    <os_type>hvm</os_type>
+    <arch name='i686'>
+      <wordsize>32</wordsize>
+      <emulator>/usr/libexec/qemu-kvm</emulator>
+      <machine canonical='pc-i440fx-rhel7.1.0' maxCpus='240'>pc</machine>
+      <machine maxCpus='240'>rhel6.6.0</machine>
+      <machine maxCpus='240'>pc-q35-rhel7.0.0</machine>
+      <machine maxCpus='240'>rhel6.4.0</machine>
+      <machine canonical='pc-q35-rhel7.1.0' maxCpus='240'>q35</machine>
+      <machine maxCpus='240'>pc-i440fx-rhel7.0.0</machine>
+      <machine maxCpus='240'>rhel6.2.0</machine>
+      <machine maxCpus='240'>rhel6.1.0</machine>
+      <machine maxCpus='240'>rhel6.5.0</machine>
+      <machine maxCpus='240'>rhel6.0.0</machine>
+      <machine maxCpus='240'>rhel6.3.0</machine>
+      <domain type='qemu'>
+      </domain>
+      <domain type='kvm'>
+        <emulator>/usr/libexec/qemu-kvm</emulator>
+      </domain>
+    </arch>
+    <features>
+      <cpuselection/>
+      <deviceboot/>
+      <disksnapshot default='on' toggle='no'/>
+      <acpi default='on' toggle='yes'/>
+      <apic default='on' toggle='no'/>
+      <pae/>
+      <nonpae/>
+    </features>
+  </guest>
+
+  <guest>
+    <os_type>hvm</os_type>
+    <arch name='x86_64'>
+      <wordsize>64</wordsize>
+      <emulator>/usr/libexec/qemu-kvm</emulator>
+      <machine canonical='pc-i440fx-rhel7.1.0' maxCpus='240'>pc</machine>
+      <machine maxCpus='240'>rhel6.6.0</machine>
+      <machine maxCpus='240'>pc-q35-rhel7.0.0</machine>
+      <machine maxCpus='240'>rhel6.4.0</machine>
+      <machine canonical='pc-q35-rhel7.1.0' maxCpus='240'>q35</machine>
+      <machine maxCpus='240'>pc-i440fx-rhel7.0.0</machine>
+      <machine maxCpus='240'>rhel6.2.0</machine>
+      <machine maxCpus='240'>rhel6.1.0</machine>
+      <machine maxCpus='240'>rhel6.5.0</machine>
+      <machine maxCpus='240'>rhel6.0.0</machine>
+      <machine maxCpus='240'>rhel6.3.0</machine>
+      <domain type='qemu'>
+      </domain>
+      <domain type='kvm'>
+        <emulator>/usr/libexec/qemu-kvm</emulator>
+      </domain>
+    </arch>
+    <features>
+      <cpuselection/>
+      <deviceboot/>
+      <disksnapshot default='on' toggle='no'/>
+      <acpi default='on' toggle='yes'/>
+      <apic default='on' toggle='no'/>
+    </features>
+  </guest>
+
+</capabilities>
diff --git a/vdsm.spec.in b/vdsm.spec.in
index 9d68e9b..4547b86 100644
--- a/vdsm.spec.in
+++ b/vdsm.spec.in
@@ -1305,6 +1305,7 @@
 %{_datadir}/%{vdsm_name}/tests/caps_libvirt_intel_E5649.out
 %{_datadir}/%{vdsm_name}/tests/caps_libvirt_amd_6274.out
 %{_datadir}/%{vdsm_name}/tests/caps_libvirt_intel_E31220.out
+%{_datadir}/%{vdsm_name}/tests/caps_libvirt_intel_E5606.out
 %{_datadir}/%{vdsm_name}/tests/caps_libvirt_intel_i73770.out
 %{_datadir}/%{vdsm_name}/tests/caps_libvirt_intel_i73770_nosnap.out
 %{_datadir}/%{vdsm_name}/tests/caps_lscpu_ppc64_1_4_4.out
diff --git a/vdsm/caps.py b/vdsm/caps.py
index 7f1242d..b66dcd6 100644
--- a/vdsm/caps.py
+++ b/vdsm/caps.py
@@ -29,6 +29,7 @@
 import linecache
 import glob
 import re
+import xml.etree.ElementTree as ET
 from distutils.version import LooseVersion
 
 import libvirt
@@ -363,12 +364,20 @@
 def _getEmulatedMachines(arch, capabilities=None):
     if capabilities is None:
         capabilities = _getCapsXMLStr()
-    caps = minidom.parseString(capabilities)
+    caps = ET.fromstring(capabilities)
 
-    for archTag in caps.getElementsByTagName('arch'):
-        if archTag.getAttribute('name') == arch:
-            return [m.firstChild.data for m in archTag.childNodes
-                    if m.nodeName == 'machine']
+    for archTag in caps.iter(tag='arch'):
+        if archTag.get('name') == arch:
+            # We have to make sure to inspect 'canonical' attribute where
+            # libvirt puts the real machine name. Relevant bug:
+            # https://bugzilla.redhat.com/show_bug.cgi?id=1229666
+            return list(set((itertools.chain.from_iterable(
+                (
+                    (m.text, m.get('canonical')) if
+                    m.get('canonical') else (m.text,)
+                )
+                for m in archTag.iterfind('machine')))))
+
     return []
 
 


-- 
To view, visit https://gerrit.ovirt.org/45155
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic0bade940d7d548be18eb779cde324e37231ce73
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: ovirt-3.5
Gerrit-Owner: Francesco Romani <fromani at redhat.com>
Gerrit-Reviewer: Dan Kenigsberg <danken at redhat.com>
Gerrit-Reviewer: Martin Polednik <mpolednik at redhat.com>


More information about the vdsm-patches mailing list