libvirt: Handle unsupported host capabilities
Neither libvirt-xen nor libvirt-lxc support
VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES so check for the proper error
code that is returned by libvirt.
The existing code was performing this check improperly by trying to
catch an enum value; instead, we need to catch the `libvirtError`
exception and then check its return code.
Co-Authored-By: Rick Harris <rconradharris@gmail.com>
Co-Authored-By: Andrew Melton <andrew.melton@rackspace.com>
Closes-Bug: 1297962
Change-Id: Ie8bf5c9d1f2a27c387f8b2f54a9bb729fa2f0985
(cherry picked from commit 5fc157e0f5
)
This commit is contained in:
parent
df9ead9af4
commit
8141e7aecd
|
@ -887,6 +887,42 @@ class LibvirtConnTestCase(test.TestCase):
|
|||
caps = conn.get_host_capabilities()
|
||||
self.assertIn('aes', [x.name for x in caps.host.cpu.features])
|
||||
|
||||
def test_baseline_cpu_not_supported(self):
|
||||
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)
|
||||
|
||||
# `mock` has trouble stubbing attributes that don't exist yet, so
|
||||
# fallback to plain-Python attribute setting/deleting
|
||||
cap_str = 'VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES'
|
||||
if not hasattr(libvirt_driver.libvirt, cap_str):
|
||||
setattr(libvirt_driver.libvirt, cap_str, True)
|
||||
self.addCleanup(delattr, libvirt_driver.libvirt, cap_str)
|
||||
|
||||
# Handle just the NO_SUPPORT error
|
||||
not_supported_exc = fakelibvirt.make_libvirtError(
|
||||
libvirt.libvirtError,
|
||||
'this function is not supported by the connection driver:'
|
||||
' virConnectBaselineCPU',
|
||||
error_code=libvirt.VIR_ERR_NO_SUPPORT)
|
||||
|
||||
with mock.patch.object(conn._conn, 'baselineCPU',
|
||||
side_effect=not_supported_exc):
|
||||
caps = conn.get_host_capabilities()
|
||||
self.assertEqual(vconfig.LibvirtConfigCaps, type(caps))
|
||||
self.assertNotIn('aes', [x.name for x in caps.host.cpu.features])
|
||||
|
||||
# Clear cached result so we can test again...
|
||||
conn._caps = None
|
||||
|
||||
# Other errors should not be caught
|
||||
other_exc = fakelibvirt.make_libvirtError(
|
||||
libvirt.libvirtError,
|
||||
'other exc',
|
||||
error_code=libvirt.VIR_ERR_NO_DOMAIN)
|
||||
|
||||
with mock.patch.object(conn._conn, 'baselineCPU',
|
||||
side_effect=other_exc):
|
||||
self.assertRaises(libvirt.libvirtError, conn.get_host_capabilities)
|
||||
|
||||
def test_lxc_get_host_capabilities_failed(self):
|
||||
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)
|
||||
|
||||
|
|
|
@ -77,6 +77,7 @@ from nova.objects import service as service_obj
|
|||
from nova.openstack.common import excutils
|
||||
from nova.openstack.common import fileutils
|
||||
from nova.openstack.common.gettextutils import _
|
||||
from nova.openstack.common.gettextutils import _LW
|
||||
from nova.openstack.common import importutils
|
||||
from nova.openstack.common import jsonutils
|
||||
from nova.openstack.common import log as logging
|
||||
|
@ -2888,9 +2889,14 @@ class LibvirtDriver(driver.ComputeDriver):
|
|||
# this -1 checking should be removed later.
|
||||
if features and features != -1:
|
||||
self._caps.host.cpu.parse_str(features)
|
||||
except libvirt.VIR_ERR_NO_SUPPORT:
|
||||
# Note(yjiang5): ignore if libvirt has no support
|
||||
pass
|
||||
except libvirt.libvirtError as ex:
|
||||
error_code = ex.get_error_code()
|
||||
if error_code == libvirt.VIR_ERR_NO_SUPPORT:
|
||||
LOG.warn(_LW("URI %(uri)s does not support full set"
|
||||
" of host capabilities: " "%(error)s"),
|
||||
{'uri': self.uri(), 'error': ex})
|
||||
else:
|
||||
raise
|
||||
return self._caps
|
||||
|
||||
def get_host_uuid(self):
|
||||
|
|
Loading…
Reference in New Issue