Rename get_counters to get_samples
Now counter has been renamed to sample, so it is better that we update the function get_counters to get_samples. Implements part of blueprint remove-counter Change-Id: I908ea347f8d0fd4b5ef4b76eee6de98da5d2e0ca
This commit is contained in:
parent
b999458a43
commit
a34bcb76d2
@ -35,17 +35,17 @@ class PollingTask(agent.PollingTask):
|
||||
def poll_and_publish(self):
|
||||
"""Tasks to be run at a periodic interval."""
|
||||
with self.publish_context as publisher:
|
||||
# TODO(yjiang5) passing counters into get_counters to avoid
|
||||
# TODO(yjiang5) passing samples into get_samples to avoid
|
||||
# polling all counters one by one
|
||||
cache = {}
|
||||
for pollster in self.pollsters:
|
||||
try:
|
||||
LOG.info("Polling pollster %s", pollster.name)
|
||||
counters = list(pollster.obj.get_counters(
|
||||
samples = list(pollster.obj.get_samples(
|
||||
self.manager,
|
||||
cache,
|
||||
))
|
||||
publisher(counters)
|
||||
publisher(samples)
|
||||
except Exception as err:
|
||||
LOG.warning('Continue after error from %s: %s',
|
||||
pollster.name, err)
|
||||
|
@ -40,12 +40,12 @@ class PollingTask(agent.PollingTask):
|
||||
for pollster in self.pollsters:
|
||||
try:
|
||||
LOG.info("Polling pollster %s", pollster.name)
|
||||
counters = list(pollster.obj.get_counters(
|
||||
samples = list(pollster.obj.get_samples(
|
||||
self.manager,
|
||||
cache,
|
||||
instance,
|
||||
))
|
||||
publisher(counters)
|
||||
publisher(samples)
|
||||
except Exception as err:
|
||||
LOG.warning('Continue after error from %s: %s',
|
||||
pollster.name, err)
|
||||
|
@ -55,21 +55,20 @@ class DeletedInstanceStatsGatherer(object):
|
||||
self.mgr = extensions
|
||||
self.inspector = inspector.get_hypervisor_inspector()
|
||||
|
||||
def _get_counters_from_plugin(self, ext, cache, instance, *args, **kwds):
|
||||
def _get_samples_from_plugin(self, ext, cache, instance, *args, **kwds):
|
||||
"""Used with the extenaion manager map() method."""
|
||||
return ext.obj.get_counters(self, cache, instance)
|
||||
return ext.obj.get_samples(self, cache, instance)
|
||||
|
||||
def __call__(self, instance):
|
||||
cache = {}
|
||||
counters = self.mgr.map(self._get_counters_from_plugin,
|
||||
cache=cache,
|
||||
instance=instance,
|
||||
)
|
||||
samples = self.mgr.map(self._get_samples_from_plugin,
|
||||
cache=cache,
|
||||
instance=instance)
|
||||
# counters is a list of lists, so flatten it before returning
|
||||
# the results
|
||||
results = []
|
||||
for clist in counters:
|
||||
results.extend(clist)
|
||||
for slist in samples:
|
||||
results.extend(slist)
|
||||
return results
|
||||
|
||||
|
||||
|
@ -30,7 +30,7 @@ class ComputePollster(plugin.PollsterBase):
|
||||
__metaclass__ = abc.ABCMeta
|
||||
|
||||
@abc.abstractmethod
|
||||
def get_counters(self, manager, cache, instance):
|
||||
def get_samples(self, manager, cache, instance):
|
||||
"""Return a sequence of Counter instances from polling the resources.
|
||||
|
||||
:param manager: The service manager invoking the plugin
|
||||
|
@ -28,7 +28,7 @@ LOG = log.getLogger(__name__)
|
||||
|
||||
class CPUPollster(plugin.ComputePollster):
|
||||
|
||||
def get_counters(self, manager, cache, instance):
|
||||
def get_samples(self, manager, cache, instance):
|
||||
LOG.info('checking instance %s', instance.id)
|
||||
instance_name = util.instance_name(instance)
|
||||
try:
|
||||
|
@ -76,7 +76,7 @@ class _Base(plugin.ComputePollster):
|
||||
def _get_counter(instance, c_data):
|
||||
"""Return one Counter."""
|
||||
|
||||
def get_counters(self, manager, cache, instance):
|
||||
def get_samples(self, manager, cache, instance):
|
||||
instance_name = util.instance_name(instance)
|
||||
c_data = self._populate_cache(
|
||||
manager.inspector,
|
||||
|
@ -26,7 +26,7 @@ from ceilometer.compute.pollsters import util
|
||||
class InstancePollster(plugin.ComputePollster):
|
||||
|
||||
@staticmethod
|
||||
def get_counters(manager, cache, instance):
|
||||
def get_samples(manager, cache, instance):
|
||||
yield util.make_counter_from_instance(
|
||||
instance,
|
||||
name='instance',
|
||||
@ -39,7 +39,7 @@ class InstancePollster(plugin.ComputePollster):
|
||||
class InstanceFlavorPollster(plugin.ComputePollster):
|
||||
|
||||
@staticmethod
|
||||
def get_counters(manager, cache, instance):
|
||||
def get_samples(manager, cache, instance):
|
||||
yield util.make_counter_from_instance(
|
||||
instance,
|
||||
# Use the "meter name + variable" syntax
|
||||
|
@ -70,7 +70,7 @@ class _Base(plugin.ComputePollster):
|
||||
)
|
||||
return i_cache[instance_name]
|
||||
|
||||
def get_counters(self, manager, cache, instance):
|
||||
def get_samples(self, manager, cache, instance):
|
||||
instance_name = util.instance_name(instance)
|
||||
LOG.info('checking instance %s', instance.id)
|
||||
try:
|
||||
|
@ -82,7 +82,7 @@ class _Base(plugin.CentralPollster):
|
||||
class EnergyPollster(_Base):
|
||||
"""Measures energy consumption."""
|
||||
|
||||
def get_counters(self, manager, cache):
|
||||
def get_samples(self, manager, cache):
|
||||
"""Returns all counters."""
|
||||
for probe in self._iter_probes(manager.keystone, cache):
|
||||
yield sample.Sample(
|
||||
@ -102,7 +102,7 @@ class EnergyPollster(_Base):
|
||||
class PowerPollster(_Base):
|
||||
"""Measures power consumption."""
|
||||
|
||||
def get_counters(self, manager, cache):
|
||||
def get_samples(self, manager, cache):
|
||||
"""Returns all counters."""
|
||||
for probe in self._iter_probes(manager.keystone, cache):
|
||||
yield sample.Sample(
|
||||
|
@ -101,7 +101,7 @@ class _Base(plugin.PollsterBase):
|
||||
|
||||
class ImagePollster(_Base):
|
||||
|
||||
def get_counters(self, manager, cache):
|
||||
def get_samples(self, manager, cache):
|
||||
for image in self._iter_images(manager.keystone, cache):
|
||||
yield sample.Sample(
|
||||
name='image',
|
||||
@ -118,7 +118,7 @@ class ImagePollster(_Base):
|
||||
|
||||
class ImageSizePollster(_Base):
|
||||
|
||||
def get_counters(self, manager, cache):
|
||||
def get_samples(self, manager, cache):
|
||||
for image in self._iter_images(manager.keystone, cache):
|
||||
yield sample.Sample(
|
||||
name='image.size',
|
||||
|
@ -40,7 +40,7 @@ class FloatingIPPollster(plugin.CentralPollster):
|
||||
cache['floating_ips'] = list(self._get_floating_ips())
|
||||
return iter(cache['floating_ips'])
|
||||
|
||||
def get_counters(self, manager, cache):
|
||||
def get_samples(self, manager, cache):
|
||||
for ip in self._iter_floating_ips(cache):
|
||||
self.LOG.info("FLOATING IP USAGE: %s" % ip.ip)
|
||||
# FIXME (flwang) Now Nova API /os-floating-ips can't provide those
|
||||
|
@ -82,7 +82,7 @@ class ObjectsPollster(_Base):
|
||||
"""Iterate over all accounts, using keystone.
|
||||
"""
|
||||
|
||||
def get_counters(self, manager, cache):
|
||||
def get_samples(self, manager, cache):
|
||||
for tenant, account in self._iter_accounts(manager.keystone, cache):
|
||||
yield sample.Sample(
|
||||
name='storage.objects',
|
||||
@ -101,7 +101,7 @@ class ObjectsSizePollster(_Base):
|
||||
"""Iterate over all accounts, using keystone.
|
||||
"""
|
||||
|
||||
def get_counters(self, manager, cache):
|
||||
def get_samples(self, manager, cache):
|
||||
for tenant, account in self._iter_accounts(manager.keystone, cache):
|
||||
yield sample.Sample(
|
||||
name='storage.objects.size',
|
||||
@ -120,7 +120,7 @@ class ObjectsContainersPollster(_Base):
|
||||
"""Iterate over all accounts, using keystone.
|
||||
"""
|
||||
|
||||
def get_counters(self, manager, cache):
|
||||
def get_samples(self, manager, cache):
|
||||
for tenant, account in self._iter_accounts(manager.keystone, cache):
|
||||
yield sample.Sample(
|
||||
name='storage.objects.containers',
|
||||
|
@ -76,7 +76,7 @@ class PollsterBase(PluginBase):
|
||||
__metaclass__ = abc.ABCMeta
|
||||
|
||||
@abc.abstractmethod
|
||||
def get_counters(self, manager, cache):
|
||||
def get_samples(self, manager, cache):
|
||||
"""Return a sequence of Counter instances from polling the resources.
|
||||
|
||||
:param manager: The service manager class invoking the plugin.
|
||||
|
@ -33,12 +33,12 @@ information follows.
|
||||
The compute agent is implemented in ``ceilometer/compute/manager.py``. As
|
||||
you will see in the manager, the computeagent loads all plugins defined in
|
||||
the namespace ``ceilometer.poll.compute``, then periodically calls their
|
||||
:func:`get_counters` method.
|
||||
:func:`get_samples` method.
|
||||
|
||||
The central agent polls other types of resources from a management server.
|
||||
The central agent is defined in ``ceilometer/central/manager.py``. It loads
|
||||
plugins from the ``ceilometer.poll.central`` namespace and polls them by
|
||||
calling their :func:`get_counters` method.
|
||||
calling their :func:`get_samples` method.
|
||||
|
||||
Plugins
|
||||
=======
|
||||
@ -64,11 +64,11 @@ Pollster
|
||||
Compute plugins are defined as subclasses of the
|
||||
:class:`ceilometer.compute.plugin.ComputePollster` class as defined in
|
||||
the ``ceilometer/compute/plugin.py`` file. Pollsters must implement one
|
||||
method: ``get_counters(self, manager, context)``, which returns a
|
||||
method: ``get_samples(self, manager, context)``, which returns a
|
||||
sequence of ``Counter`` objects as defined in the
|
||||
``ceilometer/counter.py`` file.
|
||||
|
||||
In the ``CPUPollster`` plugin, the ``get_counters`` method is implemented as a loop
|
||||
In the ``CPUPollster`` plugin, the ``get_samples`` method is implemented as a loop
|
||||
which, for each instances running on the local host, retrieves the cpu_time
|
||||
from the hypervisor and sends back two ``Counter`` objects. The first one, named
|
||||
"cpu", is of type "cumulative", meaning that between two polls, its value is
|
||||
|
@ -77,7 +77,7 @@ class TestNovaNotifier(base.TestCase):
|
||||
},
|
||||
)
|
||||
|
||||
def get_counters(self, manager, cache, instance):
|
||||
def get_samples(self, manager, cache, instance):
|
||||
self.instances.append((manager, instance))
|
||||
return [self.test_data]
|
||||
|
||||
|
@ -48,17 +48,17 @@ default_test_data = sample.Sample(
|
||||
class TestPollster:
|
||||
test_data = default_test_data
|
||||
|
||||
def get_counters(self, manager, cache, instance=None):
|
||||
def get_samples(self, manager, cache, instance=None):
|
||||
self.counters.append((manager, instance))
|
||||
return [self.test_data]
|
||||
|
||||
|
||||
class TestPollsterException(TestPollster):
|
||||
def get_counters(self, manager, cache, instance=None):
|
||||
def get_samples(self, manager, cache, instance=None):
|
||||
# Put an instance parameter here so that it can be used
|
||||
# by both central manager and compute manager
|
||||
# In future, we possibly don't need such hack if we
|
||||
# combine the get_counters() function again
|
||||
# combine the get_samples() function again
|
||||
self.counters.append((manager, instance))
|
||||
raise Exception()
|
||||
|
||||
|
@ -35,7 +35,7 @@ class TestCPUPollster(base.TestPollsterBase):
|
||||
super(TestCPUPollster, self).setUp()
|
||||
|
||||
@mock.patch('ceilometer.pipeline.setup_pipeline', mock.MagicMock())
|
||||
def test_get_counters(self):
|
||||
def test_get_samples(self):
|
||||
self.inspector.inspect_cpus(self.instance.name).AndReturn(
|
||||
virt_inspector.CPUStats(time=1 * (10 ** 6), number=2))
|
||||
self.inspector.inspect_cpus(self.instance.name).AndReturn(
|
||||
@ -50,12 +50,12 @@ class TestCPUPollster(base.TestPollsterBase):
|
||||
|
||||
def _verify_cpu_metering(expected_time):
|
||||
cache = {}
|
||||
counters = list(pollster.get_counters(mgr, cache, self.instance))
|
||||
self.assertEquals(len(counters), 1)
|
||||
self.assertEqual(set([c.name for c in counters]),
|
||||
samples = list(pollster.get_samples(mgr, cache, self.instance))
|
||||
self.assertEquals(len(samples), 1)
|
||||
self.assertEqual(set([s.name for s in samples]),
|
||||
set(['cpu']))
|
||||
assert counters[0].volume == expected_time
|
||||
self.assertEquals(counters[0].resource_metadata.get('cpu_number'),
|
||||
assert samples[0].volume == expected_time
|
||||
self.assertEquals(samples[0].resource_metadata.get('cpu_number'),
|
||||
2)
|
||||
# ensure elapsed time between polling cycles is non-zero
|
||||
time.sleep(0.001)
|
||||
@ -65,7 +65,7 @@ class TestCPUPollster(base.TestPollsterBase):
|
||||
_verify_cpu_metering(2 * (10 ** 6))
|
||||
|
||||
@mock.patch('ceilometer.pipeline.setup_pipeline', mock.MagicMock())
|
||||
def test_get_counters_no_caching(self):
|
||||
def test_get_samples_no_caching(self):
|
||||
self.inspector.inspect_cpus(self.instance.name).AndReturn(
|
||||
virt_inspector.CPUStats(time=1 * (10 ** 6), number=2))
|
||||
self.mox.ReplayAll()
|
||||
@ -74,7 +74,7 @@ class TestCPUPollster(base.TestPollsterBase):
|
||||
pollster = cpu.CPUPollster()
|
||||
|
||||
cache = {}
|
||||
counters = list(pollster.get_counters(mgr, cache, self.instance))
|
||||
self.assertEquals(len(counters), 1)
|
||||
self.assertEquals(counters[0].volume, 10 ** 6)
|
||||
samples = list(pollster.get_samples(mgr, cache, self.instance))
|
||||
self.assertEquals(len(samples), 1)
|
||||
self.assertEquals(samples[0].volume, 10 ** 6)
|
||||
self.assertEquals(len(cache), 0)
|
||||
|
@ -42,36 +42,36 @@ class TestDiskPollsters(base.TestPollsterBase):
|
||||
self.mox.ReplayAll()
|
||||
|
||||
@mock.patch('ceilometer.pipeline.setup_pipeline', mock.MagicMock())
|
||||
def _check_get_counters(self, factory, name, expected_volume):
|
||||
def _check_get_samples(self, factory, name, expected_volume):
|
||||
pollster = factory()
|
||||
|
||||
mgr = manager.AgentManager()
|
||||
cache = {}
|
||||
counters = list(pollster.get_counters(mgr, cache, self.instance))
|
||||
assert counters
|
||||
samples = list(pollster.get_samples(mgr, cache, self.instance))
|
||||
assert samples
|
||||
assert pollster.CACHE_KEY_DISK in cache
|
||||
assert self.instance.name in cache[pollster.CACHE_KEY_DISK]
|
||||
|
||||
self.assertEqual(set([c.name for c in counters]),
|
||||
self.assertEqual(set([s.name for s in samples]),
|
||||
set([name]))
|
||||
|
||||
match = [c for c in counters if c.name == name]
|
||||
match = [s for s in samples if s.name == name]
|
||||
self.assertEquals(len(match), 1, 'missing counter %s' % name)
|
||||
self.assertEquals(match[0].volume, expected_volume)
|
||||
self.assertEquals(match[0].type, 'cumulative')
|
||||
|
||||
def test_disk_read_requests(self):
|
||||
self._check_get_counters(disk.ReadRequestsPollster,
|
||||
'disk.read.requests', 2L)
|
||||
self._check_get_samples(disk.ReadRequestsPollster,
|
||||
'disk.read.requests', 2L)
|
||||
|
||||
def test_disk_read_bytes(self):
|
||||
self._check_get_counters(disk.ReadBytesPollster,
|
||||
'disk.read.bytes', 1L)
|
||||
self._check_get_samples(disk.ReadBytesPollster,
|
||||
'disk.read.bytes', 1L)
|
||||
|
||||
def test_disk_write_requests(self):
|
||||
self._check_get_counters(disk.WriteRequestsPollster,
|
||||
'disk.write.requests', 4L)
|
||||
self._check_get_samples(disk.WriteRequestsPollster,
|
||||
'disk.write.requests', 4L)
|
||||
|
||||
def test_disk_write_bytes(self):
|
||||
self._check_get_counters(disk.WriteBytesPollster,
|
||||
'disk.write.bytes', 3L)
|
||||
self._check_get_samples(disk.WriteBytesPollster,
|
||||
'disk.write.bytes', 3L)
|
||||
|
@ -32,21 +32,21 @@ class TestInstancePollster(base.TestPollsterBase):
|
||||
super(TestInstancePollster, self).setUp()
|
||||
|
||||
@mock.patch('ceilometer.pipeline.setup_pipeline', mock.MagicMock())
|
||||
def test_get_counters_instance(self):
|
||||
def test_get_samples_instance(self):
|
||||
self.mox.ReplayAll()
|
||||
|
||||
mgr = manager.AgentManager()
|
||||
pollster = pollsters_instance.InstancePollster()
|
||||
counters = list(pollster.get_counters(mgr, {}, self.instance))
|
||||
self.assertEquals(len(counters), 1)
|
||||
self.assertEqual(counters[0].name, 'instance')
|
||||
samples = list(pollster.get_samples(mgr, {}, self.instance))
|
||||
self.assertEquals(len(samples), 1)
|
||||
self.assertEqual(samples[0].name, 'instance')
|
||||
|
||||
@mock.patch('ceilometer.pipeline.setup_pipeline', mock.MagicMock())
|
||||
def test_get_counters_instance_flavor(self):
|
||||
def test_get_samples_instance_flavor(self):
|
||||
self.mox.ReplayAll()
|
||||
|
||||
mgr = manager.AgentManager()
|
||||
pollster = pollsters_instance.InstanceFlavorPollster()
|
||||
counters = list(pollster.get_counters(mgr, {}, self.instance))
|
||||
self.assertEquals(len(counters), 1)
|
||||
self.assertEqual(counters[0].name, 'instance:m1.small')
|
||||
samples = list(pollster.get_samples(mgr, {}, self.instance))
|
||||
self.assertEquals(len(samples), 1)
|
||||
self.assertEqual(samples[0].name, 'instance:m1.small')
|
||||
|
@ -71,17 +71,17 @@ class TestNetPollster(base.TestPollsterBase):
|
||||
self.mox.ReplayAll()
|
||||
|
||||
@mock.patch('ceilometer.pipeline.setup_pipeline', mock.MagicMock())
|
||||
def _check_get_counters(self, factory, expected):
|
||||
def _check_get_samples(self, factory, expected):
|
||||
mgr = manager.AgentManager()
|
||||
pollster = factory()
|
||||
counters = list(pollster.get_counters(mgr, {}, self.instance))
|
||||
self.assertEqual(len(counters), 3) # one for each nic
|
||||
self.assertEqual(set([c.name for c in counters]),
|
||||
set([counters[0].name]))
|
||||
samples = list(pollster.get_samples(mgr, {}, self.instance))
|
||||
self.assertEqual(len(samples), 3) # one for each nic
|
||||
self.assertEqual(set([s.name for s in samples]),
|
||||
set([samples[0].name]))
|
||||
|
||||
def _verify_vnic_metering(ip, expected_volume, expected_rid):
|
||||
match = [c for c in counters
|
||||
if c.resource_metadata['parameters']['ip'] == ip
|
||||
match = [s for s in samples
|
||||
if s.resource_metadata['parameters']['ip'] == ip
|
||||
]
|
||||
self.assertEquals(len(match), 1, 'missing ip %s' % ip)
|
||||
self.assertEquals(match[0].volume, expected_volume)
|
||||
@ -93,7 +93,7 @@ class TestNetPollster(base.TestPollsterBase):
|
||||
|
||||
def test_incoming_bytes(self):
|
||||
instance_name_id = "%s-%s" % (self.instance.name, self.instance.id)
|
||||
self._check_get_counters(
|
||||
self._check_get_samples(
|
||||
net.IncomingBytesPollster,
|
||||
[('10.0.0.2', 1L, self.vnic0.fref),
|
||||
('192.168.0.3', 5L, self.vnic1.fref),
|
||||
@ -104,7 +104,7 @@ class TestNetPollster(base.TestPollsterBase):
|
||||
|
||||
def test_outgoing_bytes(self):
|
||||
instance_name_id = "%s-%s" % (self.instance.name, self.instance.id)
|
||||
self._check_get_counters(
|
||||
self._check_get_samples(
|
||||
net.OutgoingBytesPollster,
|
||||
[('10.0.0.2', 3L, self.vnic0.fref),
|
||||
('192.168.0.3', 7L, self.vnic1.fref),
|
||||
@ -115,7 +115,7 @@ class TestNetPollster(base.TestPollsterBase):
|
||||
|
||||
def test_incoming_packets(self):
|
||||
instance_name_id = "%s-%s" % (self.instance.name, self.instance.id)
|
||||
self._check_get_counters(
|
||||
self._check_get_samples(
|
||||
net.IncomingPacketsPollster,
|
||||
[('10.0.0.2', 2L, self.vnic0.fref),
|
||||
('192.168.0.3', 6L, self.vnic1.fref),
|
||||
@ -126,7 +126,7 @@ class TestNetPollster(base.TestPollsterBase):
|
||||
|
||||
def test_outgoing_packets(self):
|
||||
instance_name_id = "%s-%s" % (self.instance.name, self.instance.id)
|
||||
self._check_get_counters(
|
||||
self._check_get_samples(
|
||||
net.OutgoingPacketsPollster,
|
||||
[('10.0.0.2', 4L, self.vnic0.fref),
|
||||
('192.168.0.3', 8L, self.vnic1.fref),
|
||||
@ -143,7 +143,7 @@ class TestNetPollsterCache(base.TestPollsterBase):
|
||||
self.mox.ReplayAll()
|
||||
|
||||
@mock.patch('ceilometer.pipeline.setup_pipeline', mock.MagicMock())
|
||||
def _check_get_counters_cache(self, factory):
|
||||
def _check_get_samples_cache(self, factory):
|
||||
vnic0 = virt_inspector.Interface(
|
||||
name='vnet0',
|
||||
fref='fa163e71ec6e',
|
||||
@ -163,17 +163,17 @@ class TestNetPollsterCache(base.TestPollsterBase):
|
||||
self.instance.name: vnics,
|
||||
},
|
||||
}
|
||||
counters = list(pollster.get_counters(mgr, cache, self.instance))
|
||||
self.assertEqual(len(counters), 1)
|
||||
samples = list(pollster.get_samples(mgr, cache, self.instance))
|
||||
self.assertEqual(len(samples), 1)
|
||||
|
||||
def test_incoming_bytes(self):
|
||||
self._check_get_counters_cache(net.IncomingBytesPollster)
|
||||
self._check_get_samples_cache(net.IncomingBytesPollster)
|
||||
|
||||
def test_outgoing_bytes(self):
|
||||
self._check_get_counters_cache(net.OutgoingBytesPollster)
|
||||
self._check_get_samples_cache(net.OutgoingBytesPollster)
|
||||
|
||||
def test_incoming_packets(self):
|
||||
self._check_get_counters_cache(net.IncomingPacketsPollster)
|
||||
self._check_get_samples_cache(net.IncomingPacketsPollster)
|
||||
|
||||
def test_outgoing_packets(self):
|
||||
self._check_get_counters_cache(net.OutgoingPacketsPollster)
|
||||
self._check_get_samples_cache(net.OutgoingPacketsPollster)
|
||||
|
@ -68,8 +68,8 @@ class TestKwapi(base.TestCase):
|
||||
self.stubs.Set(kwapi._Base, 'get_kwapi_client',
|
||||
self.fake_get_kwapi_client)
|
||||
|
||||
counters = list(kwapi.EnergyPollster().get_counters(self.manager, {}))
|
||||
self.assertEqual(len(counters), 0)
|
||||
samples = list(kwapi.EnergyPollster().get_samples(self.manager, {}))
|
||||
self.assertEqual(len(samples), 0)
|
||||
|
||||
|
||||
class TestEnergyPollster(base.TestCase):
|
||||
@ -90,24 +90,24 @@ class TestEnergyPollster(base.TestCase):
|
||||
probe_dict['id'] = key
|
||||
yield probe_dict
|
||||
|
||||
def test_counter(self):
|
||||
def test_sample(self):
|
||||
cache = {}
|
||||
counters = list(kwapi.EnergyPollster().get_counters(
|
||||
samples = list(kwapi.EnergyPollster().get_samples(
|
||||
self.manager,
|
||||
cache,
|
||||
))
|
||||
self.assertEqual(len(counters), 3)
|
||||
counters_by_name = dict((c.resource_id, c) for c in counters)
|
||||
self.assertEqual(len(samples), 3)
|
||||
samples_by_name = dict((s.resource_id, s) for s in samples)
|
||||
for name, probe in PROBE_DICT['probes'].items():
|
||||
counter = counters_by_name[name]
|
||||
sample = samples_by_name[name]
|
||||
expected = datetime.datetime.fromtimestamp(
|
||||
probe['timestamp']
|
||||
).isoformat()
|
||||
self.assertEqual(counter.timestamp, expected)
|
||||
self.assertEqual(counter.volume, probe['kwh'])
|
||||
self.assertEqual(sample.timestamp, expected)
|
||||
self.assertEqual(sample.volume, probe['kwh'])
|
||||
# self.assert_(
|
||||
# any(map(lambda counter: counter.volume == probe['w'],
|
||||
# power_counters)))
|
||||
# any(map(lambda sample: sample.volume == probe['w'],
|
||||
# power_samples)))
|
||||
|
||||
|
||||
class TestEnergyPollsterCache(base.TestCase):
|
||||
@ -118,7 +118,7 @@ class TestEnergyPollsterCache(base.TestCase):
|
||||
self.context = context.get_admin_context()
|
||||
self.manager = TestManager()
|
||||
|
||||
def test_get_counters_cached(self):
|
||||
def test_get_samples_cached(self):
|
||||
probe = {'id': 'A'}
|
||||
probe.update(PROBE_DICT['probes']['A'])
|
||||
cache = {
|
||||
@ -128,8 +128,8 @@ class TestEnergyPollsterCache(base.TestCase):
|
||||
pollster = kwapi.EnergyPollster()
|
||||
with mock.patch.object(pollster, '_get_probes') as do_not_call:
|
||||
do_not_call.side_effect = AssertionError('should not be called')
|
||||
counters = list(pollster.get_counters(self.manager, cache))
|
||||
self.assertEqual(len(counters), 1)
|
||||
samples = list(pollster.get_samples(self.manager, cache))
|
||||
self.assertEqual(len(samples), 1)
|
||||
|
||||
|
||||
class TestPowerPollster(base.TestCase):
|
||||
@ -150,21 +150,21 @@ class TestPowerPollster(base.TestCase):
|
||||
probe_dict['id'] = key
|
||||
yield probe_dict
|
||||
|
||||
def test_counter(self):
|
||||
def test_sample(self):
|
||||
cache = {}
|
||||
counters = list(kwapi.PowerPollster().get_counters(
|
||||
samples = list(kwapi.PowerPollster().get_samples(
|
||||
self.manager,
|
||||
cache,
|
||||
))
|
||||
self.assertEqual(len(counters), 3)
|
||||
counters_by_name = dict((c.resource_id, c) for c in counters)
|
||||
self.assertEqual(len(samples), 3)
|
||||
samples_by_name = dict((s.resource_id, s) for s in samples)
|
||||
for name, probe in PROBE_DICT['probes'].items():
|
||||
counter = counters_by_name[name]
|
||||
sample = samples_by_name[name]
|
||||
expected = datetime.datetime.fromtimestamp(
|
||||
probe['timestamp']
|
||||
).isoformat()
|
||||
self.assertEqual(counter.timestamp, expected)
|
||||
self.assertEqual(counter.volume, probe['w'])
|
||||
self.assertEqual(sample.timestamp, expected)
|
||||
self.assertEqual(sample.volume, probe['w'])
|
||||
|
||||
|
||||
class TestPowerPollsterCache(base.TestCase):
|
||||
@ -175,7 +175,7 @@ class TestPowerPollsterCache(base.TestCase):
|
||||
self.context = context.get_admin_context()
|
||||
self.manager = TestManager()
|
||||
|
||||
def test_get_counters_cached(self):
|
||||
def test_get_samples_cached(self):
|
||||
probe = {'id': 'A'}
|
||||
probe.update(PROBE_DICT['probes']['A'])
|
||||
cache = {
|
||||
@ -185,5 +185,5 @@ class TestPowerPollsterCache(base.TestCase):
|
||||
pollster = kwapi.PowerPollster()
|
||||
with mock.patch.object(pollster, '_get_probes') as do_not_call:
|
||||
do_not_call.side_effect = AssertionError('should not be called')
|
||||
counters = list(pollster.get_counters(self.manager, cache))
|
||||
self.assertEqual(len(counters), 1)
|
||||
samples = list(pollster.get_samples(self.manager, cache))
|
||||
self.assertEqual(len(samples), 1)
|
||||
|
@ -149,27 +149,27 @@ class TestImagePollster(base.TestCase):
|
||||
self.assertEqual(images, [])
|
||||
|
||||
def test_image(self):
|
||||
counters = list(glance.ImagePollster().get_counters(self.manager, {}))
|
||||
self.assertEqual(len(counters), 3)
|
||||
for counter in counters:
|
||||
self.assertEqual(counter.volume, 1)
|
||||
samples = list(glance.ImagePollster().get_samples(self.manager, {}))
|
||||
self.assertEqual(len(samples), 3)
|
||||
for sample in samples:
|
||||
self.assertEqual(sample.volume, 1)
|
||||
|
||||
def test_image_size(self):
|
||||
counters = list(glance.ImageSizePollster().get_counters(self.manager,
|
||||
{}))
|
||||
self.assertEqual(len(counters), 3)
|
||||
samples = list(glance.ImageSizePollster().get_samples(self.manager,
|
||||
{}))
|
||||
self.assertEqual(len(samples), 3)
|
||||
for image in IMAGE_LIST:
|
||||
self.assert_(
|
||||
any(map(lambda counter: counter.volume == image.size,
|
||||
counters)))
|
||||
any(map(lambda sample: sample.volume == image.size,
|
||||
samples)))
|
||||
|
||||
def test_image_get_counter_names(self):
|
||||
counters = list(glance.ImagePollster().get_counters(self.manager, {}))
|
||||
self.assertEqual(set([c.name for c in counters]),
|
||||
def test_image_get_sample_names(self):
|
||||
samples = list(glance.ImagePollster().get_samples(self.manager, {}))
|
||||
self.assertEqual(set([s.name for s in samples]),
|
||||
set(['image']))
|
||||
|
||||
def test_image_size_get_counter_names(self):
|
||||
counters = list(glance.ImageSizePollster().get_counters(self.manager,
|
||||
{}))
|
||||
self.assertEqual(set([c.name for c in counters]),
|
||||
def test_image_size_get_sample_names(self):
|
||||
samples = list(glance.ImageSizePollster().get_samples(self.manager,
|
||||
{}))
|
||||
self.assertEqual(set([s.name for s in samples]),
|
||||
set(['image.size']))
|
||||
|
@ -54,9 +54,9 @@ class TestFloatingIPPollster(base.TestCase):
|
||||
# FIXME(dhellmann): Is there a useful way to define this
|
||||
# test without a database?
|
||||
#
|
||||
# def test_get_counters_none_defined(self):
|
||||
# def test_get_samples_none_defined(self):
|
||||
# try:
|
||||
# list(self.pollster.get_counters(self.manager,
|
||||
# list(self.pollster.get_samples(self.manager,
|
||||
# self.context)
|
||||
# )
|
||||
# except exception.NoFloatingIpsDefined:
|
||||
@ -64,30 +64,30 @@ class TestFloatingIPPollster(base.TestCase):
|
||||
# else:
|
||||
# assert False, 'Should have seen an error'
|
||||
|
||||
def test_get_counters_not_empty(self):
|
||||
counters = list(self.pollster.get_counters(self.manager, {}))
|
||||
self.assertEqual(len(counters), 3)
|
||||
def test_get_samples_not_empty(self):
|
||||
samples = list(self.pollster.get_samples(self.manager, {}))
|
||||
self.assertEqual(len(samples), 3)
|
||||
# It's necessary to verify all the attributes extracted by Nova
|
||||
# API /os-floating-ips to make sure they're available and correct.
|
||||
self.assertEqual(counters[0].resource_id, 1)
|
||||
self.assertEqual(counters[0].resource_metadata["address"], "1.1.1.1")
|
||||
self.assertEqual(counters[0].resource_metadata["pool"], "public")
|
||||
self.assertEqual(samples[0].resource_id, 1)
|
||||
self.assertEqual(samples[0].resource_metadata["address"], "1.1.1.1")
|
||||
self.assertEqual(samples[0].resource_metadata["pool"], "public")
|
||||
|
||||
self.assertEqual(counters[1].resource_id, 2)
|
||||
self.assertEqual(counters[1].resource_metadata["address"], "1.1.1.2")
|
||||
self.assertEqual(counters[1].resource_metadata["pool"], "public")
|
||||
self.assertEqual(samples[1].resource_id, 2)
|
||||
self.assertEqual(samples[1].resource_metadata["address"], "1.1.1.2")
|
||||
self.assertEqual(samples[1].resource_metadata["pool"], "public")
|
||||
|
||||
self.assertEqual(counters[2].resource_id, 3)
|
||||
self.assertEqual(counters[2].resource_metadata["address"], "1.1.1.3")
|
||||
self.assertEqual(counters[2].resource_metadata["pool"], "public")
|
||||
self.assertEqual(samples[2].resource_id, 3)
|
||||
self.assertEqual(samples[2].resource_metadata["address"], "1.1.1.3")
|
||||
self.assertEqual(samples[2].resource_metadata["pool"], "public")
|
||||
|
||||
def test_get_counter_names(self):
|
||||
counters = list(self.pollster.get_counters(self.manager, {}))
|
||||
self.assertEqual(set([c.name for c in counters]),
|
||||
samples = list(self.pollster.get_samples(self.manager, {}))
|
||||
self.assertEqual(set([s.name for s in samples]),
|
||||
set(['ip.floating']))
|
||||
|
||||
def test_get_counters_cached(self):
|
||||
def test_get_samples_cached(self):
|
||||
cache = {}
|
||||
cache['floating_ips'] = self.faux_get_ips(None)[:2]
|
||||
counters = list(self.pollster.get_counters(self.manager, cache))
|
||||
self.assertEqual(len(counters), 2)
|
||||
samples = list(self.pollster.get_samples(self.manager, cache))
|
||||
self.assertEqual(len(samples), 2)
|
||||
|
@ -127,18 +127,18 @@ class TestSwiftPollster(base.TestCase):
|
||||
def test_metering(self):
|
||||
self.stubs.Set(self.factory, '_iter_accounts',
|
||||
self.fake_iter_accounts)
|
||||
counters = list(self.pollster.get_counters(self.manager, {}))
|
||||
self.assertEqual(len(counters), 2)
|
||||
samples = list(self.pollster.get_samples(self.manager, {}))
|
||||
self.assertEqual(len(samples), 2)
|
||||
|
||||
def test_get_counter_names(self):
|
||||
self.stubs.Set(self.factory, '_iter_accounts',
|
||||
self.fake_iter_accounts)
|
||||
counters = list(self.pollster.get_counters(self.manager, {}))
|
||||
self.assertEqual(set([c.name for c in counters]),
|
||||
set([counters[0].name]))
|
||||
samples = list(self.pollster.get_samples(self.manager, {}))
|
||||
self.assertEqual(set([s.name for s in samples]),
|
||||
set([samples[0].name]))
|
||||
|
||||
def test_endpoint_notfound(self):
|
||||
self.stubs.Set(self.manager.keystone.service_catalog, 'url_for',
|
||||
self.fake_ks_service_catalog_url_for)
|
||||
counters = list(self.pollster.get_counters(self.manager, {}))
|
||||
self.assertEqual(len(counters), 0)
|
||||
samples = list(self.pollster.get_samples(self.manager, {}))
|
||||
self.assertEqual(len(samples), 0)
|
||||
|
Loading…
Reference in New Issue
Block a user