diff options
author | Jenkins <jenkins@review.openstack.org> | 2016-03-24 21:54:31 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2016-03-24 21:54:32 +0000 |
commit | ae2cd311344aae4c230f7e6465c0f2cfe8be3082 (patch) | |
tree | a88cf7212830a512edee1d0d4b5a858870867b50 /nova | |
parent | 3f217a441af6595cb2a240ab72133aff133504b6 (diff) | |
parent | 1a0e8fce204fa99290de4d6f886371c80ecd2b48 (diff) | |
download | nova-ae2cd311344aae4c230f7e6465c0f2cfe8be3082.tar.gz |
Merge "libvirt: don't attempt to get baseline cpu features if host cpu model is None" into stable/liberty
Diffstat (limited to 'nova')
-rw-r--r-- | nova/tests/unit/virt/libvirt/test_host.py | 21 | ||||
-rw-r--r-- | nova/virt/libvirt/host.py | 5 |
2 files changed, 25 insertions, 1 deletions
diff --git a/nova/tests/unit/virt/libvirt/test_host.py b/nova/tests/unit/virt/libvirt/test_host.py index 8186f7cf53..2998cd304e 100644 --- a/nova/tests/unit/virt/libvirt/test_host.py +++ b/nova/tests/unit/virt/libvirt/test_host.py @@ -679,6 +679,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" diff --git a/nova/virt/libvirt/host.py b/nova/virt/libvirt/host.py index 77ae3eb92d..d2ca79119e 100644 --- a/nova/virt/libvirt/host.py +++ b/nova/virt/libvirt/host.py @@ -766,7 +766,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()], |