Handle missing libvirt vnic targets!

Updates the libvirt inspector so that our vnic inspection
can handle cases where the interface/target is missing.
This can occur in some (usually transient) cases where
Nova is pausing/migrating/etc an instance.

Previously Ceilometer would functionally work fine but
a rather long stack trace would get logged to the log file.

Fixes LP Bug #1221784

Change-Id: I7113c6e4bb4af622d517915d13147f5912bad126
This commit is contained in:
Dan Prince 2013-09-06 11:15:30 -04:00
parent a9f147c62a
commit d6ab6d10a8
2 changed files with 13 additions and 1 deletions

View File

@ -111,7 +111,11 @@ class LibvirtInspector(virt_inspector.Inspector):
domain = self._lookup_by_name(instance_name)
tree = etree.fromstring(domain.XMLDesc(0))
for iface in tree.findall('devices/interface'):
name = iface.find('target').get('dev')
target = iface.find('target')
if target is not None:
name = target.get('dev')
else:
continue
mac = iface.find('mac').get('address')
fref = iface.find('filterref')
if fref is not None:

View File

@ -47,6 +47,14 @@ class TestLibvirtInspection(test_base.TestCase):
dom_xml = """
<domain type='kvm'>
<devices>
<!-- NOTE(dprince): interface with no target -->
<interface type='bridge'>
<mac address='fa:16:3e:93:31:5a'/>
<source bridge='br100'/>
<model type='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' \
slot='0x03' function='0x0'/>
</interface>
<interface type='bridge'>
<mac address='fa:16:3e:71:ec:6d'/>
<source bridge='br100'/>