From 464370212221631ae03a5aac2a1bf2321a8fb7ed Mon Sep 17 00:00:00 2001 From: Dan Prince Date: Fri, 6 Sep 2013 11:25:08 -0400 Subject: [PATCH] Improve libvirt vnic parsing with missing mac! Improve the libvirt inspector vnic parsing so that it handles a missing mac address gracefully. Previously a missing MAC address (if possible) could cause an ugly AttributeError to get logged to the Ceilometer log file. Related to LP Bug #1221784. Change-Id: Ia897b493c9a9493a3ed3d9c3cf54ca29ff944892 --- ceilometer/compute/virt/libvirt/inspector.py | 8 ++++++-- tests/compute/virt/libvirt/test_inspector.py | 8 ++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/ceilometer/compute/virt/libvirt/inspector.py b/ceilometer/compute/virt/libvirt/inspector.py index 565c2230e..fd6b34496 100644 --- a/ceilometer/compute/virt/libvirt/inspector.py +++ b/ceilometer/compute/virt/libvirt/inspector.py @@ -116,14 +116,18 @@ class LibvirtInspector(virt_inspector.Inspector): name = target.get('dev') else: continue - mac = iface.find('mac').get('address') + mac = iface.find('mac') + if mac is not None: + mac_address = mac.get('address') + else: + continue fref = iface.find('filterref') if fref is not None: fref = fref.get('filter') params = dict((p.get('name').lower(), p.get('value')) for p in iface.findall('filterref/parameter')) - interface = virt_inspector.Interface(name=name, mac=mac, + interface = virt_inspector.Interface(name=name, mac=mac_address, fref=fref, parameters=params) rx_bytes, rx_packets, _, _, \ tx_bytes, tx_packets, _, _ = domain.interfaceStats(name) diff --git a/tests/compute/virt/libvirt/test_inspector.py b/tests/compute/virt/libvirt/test_inspector.py index eaa7627f2..b0ab671ac 100644 --- a/tests/compute/virt/libvirt/test_inspector.py +++ b/tests/compute/virt/libvirt/test_inspector.py @@ -55,6 +55,14 @@ class TestLibvirtInspection(test_base.TestCase):
+ + + + + +
+