Merge "Ignoring cpu measurement when instance's state is SHUTOFF."
This commit is contained in:
commit
9fab213ba8
@ -20,7 +20,7 @@ import ceilometer
|
||||
from ceilometer.compute import pollsters
|
||||
from ceilometer.compute.pollsters import util
|
||||
from ceilometer.compute.virt import inspector as virt_inspector
|
||||
from ceilometer.i18n import _
|
||||
from ceilometer.i18n import _, _LW
|
||||
from ceilometer import sample
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
@ -48,6 +48,11 @@ class CPUPollster(pollsters.BaseComputePollster):
|
||||
except virt_inspector.InstanceNotFoundException as err:
|
||||
# Instance was deleted while getting samples. Ignore it.
|
||||
LOG.debug('Exception while getting samples %s', err)
|
||||
except virt_inspector.InstanceShutOffException as e:
|
||||
LOG.warning(_LW('Instance %(instance_id)s was shut off while '
|
||||
'getting samples of %(pollster)s: %(exc)s'),
|
||||
{'instance_id': instance.id,
|
||||
'pollster': self.__class__.__name__, 'exc': e})
|
||||
except ceilometer.NotImplementedError:
|
||||
# Selected inspector does not implement this pollster.
|
||||
LOG.debug('Obtaining CPU time is not implemented for %s',
|
||||
|
@ -110,7 +110,7 @@ class LibvirtInspector(virt_inspector.Inspector):
|
||||
raise virt_inspector.InstanceNotFoundException(msg)
|
||||
|
||||
def inspect_cpus(self, instance):
|
||||
domain = self._lookup_by_uuid(instance)
|
||||
domain = self._get_domain_not_shut_off_or_raise(instance)
|
||||
dom_info = domain.info()
|
||||
return virt_inspector.CPUStats(number=dom_info[3], time=dom_info[4])
|
||||
|
||||
|
@ -60,6 +60,17 @@ class TestLibvirtInspection(base.BaseTestCase):
|
||||
self.assertEqual(2, cpu_info.number)
|
||||
self.assertEqual(999999, cpu_info.time)
|
||||
|
||||
def test_inspect_cpus_with_domain_shutoff(self):
|
||||
connection = self.inspector.connection
|
||||
with mock.patch.object(connection, 'lookupByUUIDString',
|
||||
return_value=self.domain):
|
||||
with mock.patch.object(self.domain, 'info',
|
||||
return_value=(5, 0, 0,
|
||||
2, 999999)):
|
||||
self.assertRaises(virt_inspector.InstanceShutOffException,
|
||||
self.inspector.inspect_cpus,
|
||||
self.instance)
|
||||
|
||||
def test_inspect_vnics(self):
|
||||
dom_xml = """
|
||||
<domain type='kvm'>
|
||||
|
Loading…
Reference in New Issue
Block a user