libvirt: don't attempt to get baseline cpu features if host cpu model is None
In certain cases, libvirt can't determine the host's CPU model. This is fine when you're setting virt_type=qemu and cpu_mode=none, for example (like with nested virtualization). If we can't determine the host's cpu model, don't attempt to get cpu features on startup of the compute service (since it will crash the service). Change-Id: I81ae5a04c7b4eb84e976902a575d890d4e850151 Closes-Bug: #1447342
This commit is contained in:
parent
3087672083
commit
04bbf658e7
|
@ -691,6 +691,27 @@ class HostTestCase(test.NoDBTestCase):
|
|||
self.assertEqual(vconfig.LibvirtConfigCaps, type(caps))
|
||||
self.assertNotIn('aes', [x.name for x in caps.host.cpu.features])
|
||||
|
||||
def test_get_capabilities_no_host_cpu_model(self):
|
||||
"""Tests that cpu features are not retrieved when the host cpu model
|
||||
is not in the capabilities.
|
||||
"""
|
||||
fake_caps_xml = '''
|
||||
<capabilities>
|
||||
<host>
|
||||
<uuid>cef19ce0-0ca2-11df-855d-b19fbce37686</uuid>
|
||||
<cpu>
|
||||
<arch>x86_64</arch>
|
||||
<vendor>Intel</vendor>
|
||||
</cpu>
|
||||
</host>
|
||||
</capabilities>'''
|
||||
with mock.patch.object(fakelibvirt.virConnect, 'getCapabilities',
|
||||
return_value=fake_caps_xml):
|
||||
caps = self.host.get_capabilities()
|
||||
self.assertEqual(vconfig.LibvirtConfigCaps, type(caps))
|
||||
self.assertIsNone(caps.host.cpu.model)
|
||||
self.assertEqual(0, len(caps.host.cpu.features))
|
||||
|
||||
@mock.patch.object(fakelibvirt.virConnect, "getHostname")
|
||||
def test_get_hostname_caching(self, mock_hostname):
|
||||
mock_hostname.return_value = "foo"
|
||||
|
|
|
@ -780,7 +780,10 @@ class Host(object):
|
|||
LOG.info(_LI("Libvirt host capabilities %s"), xmlstr)
|
||||
self._caps = vconfig.LibvirtConfigCaps()
|
||||
self._caps.parse_str(xmlstr)
|
||||
if hasattr(libvirt, 'VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES'):
|
||||
# NOTE(mriedem): Don't attempt to get baseline CPU features
|
||||
# if libvirt can't determine the host cpu model.
|
||||
if (hasattr(libvirt, 'VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES')
|
||||
and self._caps.host.cpu.model is not None):
|
||||
try:
|
||||
features = self.get_connection().baselineCPU(
|
||||
[self._caps.host.cpu.to_xml()],
|
||||
|
|
Loading…
Reference in New Issue