Avoid crashing while getting libvirt capabilities with unknown arch names

In _get_instance_capabilities() we get a list of host capabilities and then
build a list of arches supported by the virt type of an instance to arrive
at the list of possibilities for the instance. We check each of those
against our enum, but fail to gracefully skip unsupported values should we
encounter one.

This patch makes that graceful, and also introduces an unsupported arch to
the test stub to make sure we always skip it. Note that we do not warn
because this happens once per instance in a periodic task, and since the
situation is caused by a (somewhat permanent) mismatch of libvirt and
nova version support, isn't something that needs to be remedied by an
operator.

Closes-Bug: #1820125
Change-Id: I5d95bd50279a6bf903a5793ad5f3ae9d06f085f4
(cherry picked from commit 71df650d0a)
This commit is contained in:
Dan Smith 2019-03-14 14:07:31 -07:00 committed by Matt Riedemann
parent 9c6d900486
commit 2b86a9cacc
2 changed files with 19 additions and 5 deletions

View File

@ -16157,6 +16157,14 @@ class LibvirtConnTestCase(test.NoDBTestCase,
guest.domtype = ['kvm']
caps.guests.append(guest)
# Include one that is not known to nova to make sure it
# does not trip us up.
guest = vconfig.LibvirtConfigGuest()
guest.ostype = 'hvm'
guest.arch = 'itanic'
guest.domtype = ['kvm']
caps.guests.append(guest)
return caps
self.stubs.Set(host.Host, "get_capabilities",

View File

@ -5861,11 +5861,17 @@ class LibvirtDriver(driver.ComputeDriver):
for dt in g.domtype:
if dt != CONF.libvirt.virt_type:
continue
instance_cap = (
fields.Architecture.canonicalize(g.arch),
fields.HVType.canonicalize(dt),
fields.VMMode.canonicalize(g.ostype))
instance_caps.append(instance_cap)
try:
instance_cap = (
fields.Architecture.canonicalize(g.arch),
fields.HVType.canonicalize(dt),
fields.VMMode.canonicalize(g.ostype))
instance_caps.append(instance_cap)
except exception.InvalidArchitectureName:
# NOTE(danms): Libvirt is exposing a guest arch that nova
# does not even know about. Avoid aborting here and
# continue to process the rest.
pass
return instance_caps