issue an error log when cannot import libvirt
the ceilometer-compute-agent doesn't issue an error log even if libvirt couldn't be imported. This patch fixes this problem. Change-Id: I91bd80a694983da3eab93866a649a61b09d133c7 Closes-Bug: #1232961
This commit is contained in:
parent
d280925aa0
commit
440bdacec1
@ -81,7 +81,9 @@ class LibvirtInspector(virt_inspector.Inspector):
|
||||
try:
|
||||
return self._get_connection().lookupByName(instance_name)
|
||||
except Exception as ex:
|
||||
error_code = ex.get_error_code() if libvirt else 'unknown'
|
||||
if not libvirt or not isinstance(ex, libvirt.libvirtError):
|
||||
raise virt_inspector.InspectorException(unicode(ex))
|
||||
error_code = ex.get_error_code()
|
||||
msg = ("Error from libvirt while looking up %(instance_name)s: "
|
||||
"[Error Code %(error_code)s] "
|
||||
"%(ex)s" % {'instance_name': instance_name,
|
||||
|
@ -19,8 +19,10 @@
|
||||
"""Tests for libvirt inspector.
|
||||
"""
|
||||
|
||||
from ceilometer.compute.virt import inspector as virt_inspector
|
||||
from ceilometer.compute.virt.libvirt import inspector as libvirt_inspector
|
||||
from ceilometer.tests import base as test_base
|
||||
import fixtures
|
||||
|
||||
|
||||
class TestLibvirtInspection(test_base.TestCase):
|
||||
@ -181,3 +183,22 @@ class TestLibvirtInspection(test_base.TestCase):
|
||||
self.assertEqual(info0.read_bytes, 2L)
|
||||
self.assertEqual(info0.write_requests, 3L)
|
||||
self.assertEqual(info0.write_bytes, 4L)
|
||||
|
||||
|
||||
class TestLibvirtInspectionWithError(test_base.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestLibvirtInspectionWithError, self).setUp()
|
||||
self.inspector = libvirt_inspector.LibvirtInspector()
|
||||
self.useFixture(fixtures.MonkeyPatch(
|
||||
'ceilometer.compute.virt.libvirt.inspector.'
|
||||
'LibvirtInspector._get_connection',
|
||||
self._dummy_get_connection))
|
||||
|
||||
def _dummy_get_connection(*args, **kwargs):
|
||||
raise Exception('dummy')
|
||||
|
||||
def test_inspect_unknown_error(self):
|
||||
|
||||
self.assertRaises(virt_inspector.InspectorException,
|
||||
self.inspector.inspect_cpus, 'foo')
|
||||
|
Loading…
Reference in New Issue
Block a user