fix perf when libvirt is >=2.0.0 and <2.3.0

Closes-bug: #1632207
Change-Id: I311e612035a86981ad315872eade0e107ad87e07
(cherry picked from commit f86dbd8804)
This commit is contained in:
Mehdi Abaakouk 2016-10-11 07:34:43 +02:00 committed by Mehdi Abaakouk (sileht)
parent a417a8754c
commit 5e0f3e144b
2 changed files with 18 additions and 1 deletions

View File

@ -291,7 +291,10 @@ class LibvirtInspector(virt_inspector.Inspector):
instructions=perf["perf.instructions"],
cache_references=perf["perf.cache_references"],
cache_misses=perf["perf.cache_misses"])
except AttributeError as e:
# NOTE(sileht): KeyError if for libvirt >=2.0.0,<2.3.0, the perf
# subsystem ws existing but not these attributes
# https://github.com/libvirt/libvirt/commit/bae660869de0612bee2a740083fb494c27e3f80c
except (AttributeError, KeyError) as e:
msg = _LE('Perf is not supported by current version of libvirt, '
'and failed to inspect perf events of '
'%(instance_uuid)s, can not get info from libvirt: '

View File

@ -404,6 +404,20 @@ class TestLibvirtInspection(base.BaseTestCase):
self.assertEqual(74184, pe.cache_references)
self.assertEqual(16737, pe.cache_misses)
def test_inspect_perf_events_libvirt_less_than_2_3_0(self):
fake_stats = [({}, {})]
connection = self.inspector.connection
with mock.patch.object(connection, 'lookupByUUIDString',
return_value=self.domain):
with mock.patch.object(self.domain, 'info',
return_value=(0, 0, 51200,
2, 999999)):
with mock.patch.object(connection, 'domainListGetStats',
return_value=fake_stats):
self.assertRaises(virt_inspector.NoDataException,
self.inspector.inspect_perf_events,
self.instance)
class TestLibvirtInspectionWithError(base.BaseTestCase):