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:
Jay Lau 2013-08-02 16:24:49 +08:00
parent b999458a43
commit a34bcb76d2
24 changed files with 150 additions and 151 deletions

View File

@ -35,17 +35,17 @@ class PollingTask(agent.PollingTask):
def poll_and_publish(self): def poll_and_publish(self):
"""Tasks to be run at a periodic interval.""" """Tasks to be run at a periodic interval."""
with self.publish_context as publisher: 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 # polling all counters one by one
cache = {} cache = {}
for pollster in self.pollsters: for pollster in self.pollsters:
try: try:
LOG.info("Polling pollster %s", pollster.name) LOG.info("Polling pollster %s", pollster.name)
counters = list(pollster.obj.get_counters( samples = list(pollster.obj.get_samples(
self.manager, self.manager,
cache, cache,
)) ))
publisher(counters) publisher(samples)
except Exception as err: except Exception as err:
LOG.warning('Continue after error from %s: %s', LOG.warning('Continue after error from %s: %s',
pollster.name, err) pollster.name, err)

View File

@ -40,12 +40,12 @@ class PollingTask(agent.PollingTask):
for pollster in self.pollsters: for pollster in self.pollsters:
try: try:
LOG.info("Polling pollster %s", pollster.name) LOG.info("Polling pollster %s", pollster.name)
counters = list(pollster.obj.get_counters( samples = list(pollster.obj.get_samples(
self.manager, self.manager,
cache, cache,
instance, instance,
)) ))
publisher(counters) publisher(samples)
except Exception as err: except Exception as err:
LOG.warning('Continue after error from %s: %s', LOG.warning('Continue after error from %s: %s',
pollster.name, err) pollster.name, err)

View File

@ -55,21 +55,20 @@ class DeletedInstanceStatsGatherer(object):
self.mgr = extensions self.mgr = extensions
self.inspector = inspector.get_hypervisor_inspector() 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.""" """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): def __call__(self, instance):
cache = {} cache = {}
counters = self.mgr.map(self._get_counters_from_plugin, samples = self.mgr.map(self._get_samples_from_plugin,
cache=cache, cache=cache,
instance=instance, instance=instance)
)
# counters is a list of lists, so flatten it before returning # counters is a list of lists, so flatten it before returning
# the results # the results
results = [] results = []
for clist in counters: for slist in samples:
results.extend(clist) results.extend(slist)
return results return results

View File

@ -30,7 +30,7 @@ class ComputePollster(plugin.PollsterBase):
__metaclass__ = abc.ABCMeta __metaclass__ = abc.ABCMeta
@abc.abstractmethod @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. """Return a sequence of Counter instances from polling the resources.
:param manager: The service manager invoking the plugin :param manager: The service manager invoking the plugin

View File

@ -28,7 +28,7 @@ LOG = log.getLogger(__name__)
class CPUPollster(plugin.ComputePollster): 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) LOG.info('checking instance %s', instance.id)
instance_name = util.instance_name(instance) instance_name = util.instance_name(instance)
try: try:

View File

@ -76,7 +76,7 @@ class _Base(plugin.ComputePollster):
def _get_counter(instance, c_data): def _get_counter(instance, c_data):
"""Return one Counter.""" """Return one Counter."""
def get_counters(self, manager, cache, instance): def get_samples(self, manager, cache, instance):
instance_name = util.instance_name(instance) instance_name = util.instance_name(instance)
c_data = self._populate_cache( c_data = self._populate_cache(
manager.inspector, manager.inspector,

View File

@ -26,7 +26,7 @@ from ceilometer.compute.pollsters import util
class InstancePollster(plugin.ComputePollster): class InstancePollster(plugin.ComputePollster):
@staticmethod @staticmethod
def get_counters(manager, cache, instance): def get_samples(manager, cache, instance):
yield util.make_counter_from_instance( yield util.make_counter_from_instance(
instance, instance,
name='instance', name='instance',
@ -39,7 +39,7 @@ class InstancePollster(plugin.ComputePollster):
class InstanceFlavorPollster(plugin.ComputePollster): class InstanceFlavorPollster(plugin.ComputePollster):
@staticmethod @staticmethod
def get_counters(manager, cache, instance): def get_samples(manager, cache, instance):
yield util.make_counter_from_instance( yield util.make_counter_from_instance(
instance, instance,
# Use the "meter name + variable" syntax # Use the "meter name + variable" syntax

View File

@ -70,7 +70,7 @@ class _Base(plugin.ComputePollster):
) )
return i_cache[instance_name] 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) instance_name = util.instance_name(instance)
LOG.info('checking instance %s', instance.id) LOG.info('checking instance %s', instance.id)
try: try:

View File

@ -82,7 +82,7 @@ class _Base(plugin.CentralPollster):
class EnergyPollster(_Base): class EnergyPollster(_Base):
"""Measures energy consumption.""" """Measures energy consumption."""
def get_counters(self, manager, cache): def get_samples(self, manager, cache):
"""Returns all counters.""" """Returns all counters."""
for probe in self._iter_probes(manager.keystone, cache): for probe in self._iter_probes(manager.keystone, cache):
yield sample.Sample( yield sample.Sample(
@ -102,7 +102,7 @@ class EnergyPollster(_Base):
class PowerPollster(_Base): class PowerPollster(_Base):
"""Measures power consumption.""" """Measures power consumption."""
def get_counters(self, manager, cache): def get_samples(self, manager, cache):
"""Returns all counters.""" """Returns all counters."""
for probe in self._iter_probes(manager.keystone, cache): for probe in self._iter_probes(manager.keystone, cache):
yield sample.Sample( yield sample.Sample(

View File

@ -101,7 +101,7 @@ class _Base(plugin.PollsterBase):
class ImagePollster(_Base): class ImagePollster(_Base):
def get_counters(self, manager, cache): def get_samples(self, manager, cache):
for image in self._iter_images(manager.keystone, cache): for image in self._iter_images(manager.keystone, cache):
yield sample.Sample( yield sample.Sample(
name='image', name='image',
@ -118,7 +118,7 @@ class ImagePollster(_Base):
class ImageSizePollster(_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): for image in self._iter_images(manager.keystone, cache):
yield sample.Sample( yield sample.Sample(
name='image.size', name='image.size',

View File

@ -40,7 +40,7 @@ class FloatingIPPollster(plugin.CentralPollster):
cache['floating_ips'] = list(self._get_floating_ips()) cache['floating_ips'] = list(self._get_floating_ips())
return iter(cache['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): for ip in self._iter_floating_ips(cache):
self.LOG.info("FLOATING IP USAGE: %s" % ip.ip) self.LOG.info("FLOATING IP USAGE: %s" % ip.ip)
# FIXME (flwang) Now Nova API /os-floating-ips can't provide those # FIXME (flwang) Now Nova API /os-floating-ips can't provide those

View File

@ -82,7 +82,7 @@ class ObjectsPollster(_Base):
"""Iterate over all accounts, using keystone. """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): for tenant, account in self._iter_accounts(manager.keystone, cache):
yield sample.Sample( yield sample.Sample(
name='storage.objects', name='storage.objects',
@ -101,7 +101,7 @@ class ObjectsSizePollster(_Base):
"""Iterate over all accounts, using keystone. """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): for tenant, account in self._iter_accounts(manager.keystone, cache):
yield sample.Sample( yield sample.Sample(
name='storage.objects.size', name='storage.objects.size',
@ -120,7 +120,7 @@ class ObjectsContainersPollster(_Base):
"""Iterate over all accounts, using keystone. """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): for tenant, account in self._iter_accounts(manager.keystone, cache):
yield sample.Sample( yield sample.Sample(
name='storage.objects.containers', name='storage.objects.containers',

View File

@ -76,7 +76,7 @@ class PollsterBase(PluginBase):
__metaclass__ = abc.ABCMeta __metaclass__ = abc.ABCMeta
@abc.abstractmethod @abc.abstractmethod
def get_counters(self, manager, cache): def get_samples(self, manager, cache):
"""Return a sequence of Counter instances from polling the resources. """Return a sequence of Counter instances from polling the resources.
:param manager: The service manager class invoking the plugin. :param manager: The service manager class invoking the plugin.

View File

@ -33,12 +33,12 @@ information follows.
The compute agent is implemented in ``ceilometer/compute/manager.py``. As The compute agent is implemented in ``ceilometer/compute/manager.py``. As
you will see in the manager, the computeagent loads all plugins defined in you will see in the manager, the computeagent loads all plugins defined in
the namespace ``ceilometer.poll.compute``, then periodically calls their 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 polls other types of resources from a management server.
The central agent is defined in ``ceilometer/central/manager.py``. It loads The central agent is defined in ``ceilometer/central/manager.py``. It loads
plugins from the ``ceilometer.poll.central`` namespace and polls them by plugins from the ``ceilometer.poll.central`` namespace and polls them by
calling their :func:`get_counters` method. calling their :func:`get_samples` method.
Plugins Plugins
======= =======
@ -64,11 +64,11 @@ Pollster
Compute plugins are defined as subclasses of the Compute plugins are defined as subclasses of the
:class:`ceilometer.compute.plugin.ComputePollster` class as defined in :class:`ceilometer.compute.plugin.ComputePollster` class as defined in
the ``ceilometer/compute/plugin.py`` file. Pollsters must implement one 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 sequence of ``Counter`` objects as defined in the
``ceilometer/counter.py`` file. ``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 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 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 "cpu", is of type "cumulative", meaning that between two polls, its value is

View File

@ -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)) self.instances.append((manager, instance))
return [self.test_data] return [self.test_data]

View File

@ -48,17 +48,17 @@ default_test_data = sample.Sample(
class TestPollster: class TestPollster:
test_data = default_test_data 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)) self.counters.append((manager, instance))
return [self.test_data] return [self.test_data]
class TestPollsterException(TestPollster): 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 # Put an instance parameter here so that it can be used
# by both central manager and compute manager # by both central manager and compute manager
# In future, we possibly don't need such hack if we # 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)) self.counters.append((manager, instance))
raise Exception() raise Exception()

View File

@ -35,7 +35,7 @@ class TestCPUPollster(base.TestPollsterBase):
super(TestCPUPollster, self).setUp() super(TestCPUPollster, self).setUp()
@mock.patch('ceilometer.pipeline.setup_pipeline', mock.MagicMock()) @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( self.inspector.inspect_cpus(self.instance.name).AndReturn(
virt_inspector.CPUStats(time=1 * (10 ** 6), number=2)) virt_inspector.CPUStats(time=1 * (10 ** 6), number=2))
self.inspector.inspect_cpus(self.instance.name).AndReturn( self.inspector.inspect_cpus(self.instance.name).AndReturn(
@ -50,12 +50,12 @@ class TestCPUPollster(base.TestPollsterBase):
def _verify_cpu_metering(expected_time): def _verify_cpu_metering(expected_time):
cache = {} cache = {}
counters = list(pollster.get_counters(mgr, cache, self.instance)) samples = list(pollster.get_samples(mgr, cache, self.instance))
self.assertEquals(len(counters), 1) self.assertEquals(len(samples), 1)
self.assertEqual(set([c.name for c in counters]), self.assertEqual(set([s.name for s in samples]),
set(['cpu'])) set(['cpu']))
assert counters[0].volume == expected_time assert samples[0].volume == expected_time
self.assertEquals(counters[0].resource_metadata.get('cpu_number'), self.assertEquals(samples[0].resource_metadata.get('cpu_number'),
2) 2)
# ensure elapsed time between polling cycles is non-zero # ensure elapsed time between polling cycles is non-zero
time.sleep(0.001) time.sleep(0.001)
@ -65,7 +65,7 @@ class TestCPUPollster(base.TestPollsterBase):
_verify_cpu_metering(2 * (10 ** 6)) _verify_cpu_metering(2 * (10 ** 6))
@mock.patch('ceilometer.pipeline.setup_pipeline', mock.MagicMock()) @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( self.inspector.inspect_cpus(self.instance.name).AndReturn(
virt_inspector.CPUStats(time=1 * (10 ** 6), number=2)) virt_inspector.CPUStats(time=1 * (10 ** 6), number=2))
self.mox.ReplayAll() self.mox.ReplayAll()
@ -74,7 +74,7 @@ class TestCPUPollster(base.TestPollsterBase):
pollster = cpu.CPUPollster() pollster = cpu.CPUPollster()
cache = {} cache = {}
counters = list(pollster.get_counters(mgr, cache, self.instance)) samples = list(pollster.get_samples(mgr, cache, self.instance))
self.assertEquals(len(counters), 1) self.assertEquals(len(samples), 1)
self.assertEquals(counters[0].volume, 10 ** 6) self.assertEquals(samples[0].volume, 10 ** 6)
self.assertEquals(len(cache), 0) self.assertEquals(len(cache), 0)

View File

@ -42,36 +42,36 @@ class TestDiskPollsters(base.TestPollsterBase):
self.mox.ReplayAll() self.mox.ReplayAll()
@mock.patch('ceilometer.pipeline.setup_pipeline', mock.MagicMock()) @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() pollster = factory()
mgr = manager.AgentManager() mgr = manager.AgentManager()
cache = {} cache = {}
counters = list(pollster.get_counters(mgr, cache, self.instance)) samples = list(pollster.get_samples(mgr, cache, self.instance))
assert counters assert samples
assert pollster.CACHE_KEY_DISK in cache assert pollster.CACHE_KEY_DISK in cache
assert self.instance.name in cache[pollster.CACHE_KEY_DISK] 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])) 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(len(match), 1, 'missing counter %s' % name)
self.assertEquals(match[0].volume, expected_volume) self.assertEquals(match[0].volume, expected_volume)
self.assertEquals(match[0].type, 'cumulative') self.assertEquals(match[0].type, 'cumulative')
def test_disk_read_requests(self): def test_disk_read_requests(self):
self._check_get_counters(disk.ReadRequestsPollster, self._check_get_samples(disk.ReadRequestsPollster,
'disk.read.requests', 2L) 'disk.read.requests', 2L)
def test_disk_read_bytes(self): def test_disk_read_bytes(self):
self._check_get_counters(disk.ReadBytesPollster, self._check_get_samples(disk.ReadBytesPollster,
'disk.read.bytes', 1L) 'disk.read.bytes', 1L)
def test_disk_write_requests(self): def test_disk_write_requests(self):
self._check_get_counters(disk.WriteRequestsPollster, self._check_get_samples(disk.WriteRequestsPollster,
'disk.write.requests', 4L) 'disk.write.requests', 4L)
def test_disk_write_bytes(self): def test_disk_write_bytes(self):
self._check_get_counters(disk.WriteBytesPollster, self._check_get_samples(disk.WriteBytesPollster,
'disk.write.bytes', 3L) 'disk.write.bytes', 3L)

View File

@ -32,21 +32,21 @@ class TestInstancePollster(base.TestPollsterBase):
super(TestInstancePollster, self).setUp() super(TestInstancePollster, self).setUp()
@mock.patch('ceilometer.pipeline.setup_pipeline', mock.MagicMock()) @mock.patch('ceilometer.pipeline.setup_pipeline', mock.MagicMock())
def test_get_counters_instance(self): def test_get_samples_instance(self):
self.mox.ReplayAll() self.mox.ReplayAll()
mgr = manager.AgentManager() mgr = manager.AgentManager()
pollster = pollsters_instance.InstancePollster() pollster = pollsters_instance.InstancePollster()
counters = list(pollster.get_counters(mgr, {}, self.instance)) samples = list(pollster.get_samples(mgr, {}, self.instance))
self.assertEquals(len(counters), 1) self.assertEquals(len(samples), 1)
self.assertEqual(counters[0].name, 'instance') self.assertEqual(samples[0].name, 'instance')
@mock.patch('ceilometer.pipeline.setup_pipeline', mock.MagicMock()) @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() self.mox.ReplayAll()
mgr = manager.AgentManager() mgr = manager.AgentManager()
pollster = pollsters_instance.InstanceFlavorPollster() pollster = pollsters_instance.InstanceFlavorPollster()
counters = list(pollster.get_counters(mgr, {}, self.instance)) samples = list(pollster.get_samples(mgr, {}, self.instance))
self.assertEquals(len(counters), 1) self.assertEquals(len(samples), 1)
self.assertEqual(counters[0].name, 'instance:m1.small') self.assertEqual(samples[0].name, 'instance:m1.small')

View File

@ -71,17 +71,17 @@ class TestNetPollster(base.TestPollsterBase):
self.mox.ReplayAll() self.mox.ReplayAll()
@mock.patch('ceilometer.pipeline.setup_pipeline', mock.MagicMock()) @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() mgr = manager.AgentManager()
pollster = factory() pollster = factory()
counters = list(pollster.get_counters(mgr, {}, self.instance)) samples = list(pollster.get_samples(mgr, {}, self.instance))
self.assertEqual(len(counters), 3) # one for each nic self.assertEqual(len(samples), 3) # one for each nic
self.assertEqual(set([c.name for c in counters]), self.assertEqual(set([s.name for s in samples]),
set([counters[0].name])) set([samples[0].name]))
def _verify_vnic_metering(ip, expected_volume, expected_rid): def _verify_vnic_metering(ip, expected_volume, expected_rid):
match = [c for c in counters match = [s for s in samples
if c.resource_metadata['parameters']['ip'] == ip if s.resource_metadata['parameters']['ip'] == ip
] ]
self.assertEquals(len(match), 1, 'missing ip %s' % ip) self.assertEquals(len(match), 1, 'missing ip %s' % ip)
self.assertEquals(match[0].volume, expected_volume) self.assertEquals(match[0].volume, expected_volume)
@ -93,7 +93,7 @@ class TestNetPollster(base.TestPollsterBase):
def test_incoming_bytes(self): def test_incoming_bytes(self):
instance_name_id = "%s-%s" % (self.instance.name, self.instance.id) instance_name_id = "%s-%s" % (self.instance.name, self.instance.id)
self._check_get_counters( self._check_get_samples(
net.IncomingBytesPollster, net.IncomingBytesPollster,
[('10.0.0.2', 1L, self.vnic0.fref), [('10.0.0.2', 1L, self.vnic0.fref),
('192.168.0.3', 5L, self.vnic1.fref), ('192.168.0.3', 5L, self.vnic1.fref),
@ -104,7 +104,7 @@ class TestNetPollster(base.TestPollsterBase):
def test_outgoing_bytes(self): def test_outgoing_bytes(self):
instance_name_id = "%s-%s" % (self.instance.name, self.instance.id) instance_name_id = "%s-%s" % (self.instance.name, self.instance.id)
self._check_get_counters( self._check_get_samples(
net.OutgoingBytesPollster, net.OutgoingBytesPollster,
[('10.0.0.2', 3L, self.vnic0.fref), [('10.0.0.2', 3L, self.vnic0.fref),
('192.168.0.3', 7L, self.vnic1.fref), ('192.168.0.3', 7L, self.vnic1.fref),
@ -115,7 +115,7 @@ class TestNetPollster(base.TestPollsterBase):
def test_incoming_packets(self): def test_incoming_packets(self):
instance_name_id = "%s-%s" % (self.instance.name, self.instance.id) instance_name_id = "%s-%s" % (self.instance.name, self.instance.id)
self._check_get_counters( self._check_get_samples(
net.IncomingPacketsPollster, net.IncomingPacketsPollster,
[('10.0.0.2', 2L, self.vnic0.fref), [('10.0.0.2', 2L, self.vnic0.fref),
('192.168.0.3', 6L, self.vnic1.fref), ('192.168.0.3', 6L, self.vnic1.fref),
@ -126,7 +126,7 @@ class TestNetPollster(base.TestPollsterBase):
def test_outgoing_packets(self): def test_outgoing_packets(self):
instance_name_id = "%s-%s" % (self.instance.name, self.instance.id) instance_name_id = "%s-%s" % (self.instance.name, self.instance.id)
self._check_get_counters( self._check_get_samples(
net.OutgoingPacketsPollster, net.OutgoingPacketsPollster,
[('10.0.0.2', 4L, self.vnic0.fref), [('10.0.0.2', 4L, self.vnic0.fref),
('192.168.0.3', 8L, self.vnic1.fref), ('192.168.0.3', 8L, self.vnic1.fref),
@ -143,7 +143,7 @@ class TestNetPollsterCache(base.TestPollsterBase):
self.mox.ReplayAll() self.mox.ReplayAll()
@mock.patch('ceilometer.pipeline.setup_pipeline', mock.MagicMock()) @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( vnic0 = virt_inspector.Interface(
name='vnet0', name='vnet0',
fref='fa163e71ec6e', fref='fa163e71ec6e',
@ -163,17 +163,17 @@ class TestNetPollsterCache(base.TestPollsterBase):
self.instance.name: vnics, self.instance.name: vnics,
}, },
} }
counters = list(pollster.get_counters(mgr, cache, self.instance)) samples = list(pollster.get_samples(mgr, cache, self.instance))
self.assertEqual(len(counters), 1) self.assertEqual(len(samples), 1)
def test_incoming_bytes(self): def test_incoming_bytes(self):
self._check_get_counters_cache(net.IncomingBytesPollster) self._check_get_samples_cache(net.IncomingBytesPollster)
def test_outgoing_bytes(self): def test_outgoing_bytes(self):
self._check_get_counters_cache(net.OutgoingBytesPollster) self._check_get_samples_cache(net.OutgoingBytesPollster)
def test_incoming_packets(self): def test_incoming_packets(self):
self._check_get_counters_cache(net.IncomingPacketsPollster) self._check_get_samples_cache(net.IncomingPacketsPollster)
def test_outgoing_packets(self): def test_outgoing_packets(self):
self._check_get_counters_cache(net.OutgoingPacketsPollster) self._check_get_samples_cache(net.OutgoingPacketsPollster)

View File

@ -68,8 +68,8 @@ class TestKwapi(base.TestCase):
self.stubs.Set(kwapi._Base, 'get_kwapi_client', self.stubs.Set(kwapi._Base, 'get_kwapi_client',
self.fake_get_kwapi_client) self.fake_get_kwapi_client)
counters = list(kwapi.EnergyPollster().get_counters(self.manager, {})) samples = list(kwapi.EnergyPollster().get_samples(self.manager, {}))
self.assertEqual(len(counters), 0) self.assertEqual(len(samples), 0)
class TestEnergyPollster(base.TestCase): class TestEnergyPollster(base.TestCase):
@ -90,24 +90,24 @@ class TestEnergyPollster(base.TestCase):
probe_dict['id'] = key probe_dict['id'] = key
yield probe_dict yield probe_dict
def test_counter(self): def test_sample(self):
cache = {} cache = {}
counters = list(kwapi.EnergyPollster().get_counters( samples = list(kwapi.EnergyPollster().get_samples(
self.manager, self.manager,
cache, cache,
)) ))
self.assertEqual(len(counters), 3) self.assertEqual(len(samples), 3)
counters_by_name = dict((c.resource_id, c) for c in counters) samples_by_name = dict((s.resource_id, s) for s in samples)
for name, probe in PROBE_DICT['probes'].items(): for name, probe in PROBE_DICT['probes'].items():
counter = counters_by_name[name] sample = samples_by_name[name]
expected = datetime.datetime.fromtimestamp( expected = datetime.datetime.fromtimestamp(
probe['timestamp'] probe['timestamp']
).isoformat() ).isoformat()
self.assertEqual(counter.timestamp, expected) self.assertEqual(sample.timestamp, expected)
self.assertEqual(counter.volume, probe['kwh']) self.assertEqual(sample.volume, probe['kwh'])
# self.assert_( # self.assert_(
# any(map(lambda counter: counter.volume == probe['w'], # any(map(lambda sample: sample.volume == probe['w'],
# power_counters))) # power_samples)))
class TestEnergyPollsterCache(base.TestCase): class TestEnergyPollsterCache(base.TestCase):
@ -118,7 +118,7 @@ class TestEnergyPollsterCache(base.TestCase):
self.context = context.get_admin_context() self.context = context.get_admin_context()
self.manager = TestManager() self.manager = TestManager()
def test_get_counters_cached(self): def test_get_samples_cached(self):
probe = {'id': 'A'} probe = {'id': 'A'}
probe.update(PROBE_DICT['probes']['A']) probe.update(PROBE_DICT['probes']['A'])
cache = { cache = {
@ -128,8 +128,8 @@ class TestEnergyPollsterCache(base.TestCase):
pollster = kwapi.EnergyPollster() pollster = kwapi.EnergyPollster()
with mock.patch.object(pollster, '_get_probes') as do_not_call: with mock.patch.object(pollster, '_get_probes') as do_not_call:
do_not_call.side_effect = AssertionError('should not be called') do_not_call.side_effect = AssertionError('should not be called')
counters = list(pollster.get_counters(self.manager, cache)) samples = list(pollster.get_samples(self.manager, cache))
self.assertEqual(len(counters), 1) self.assertEqual(len(samples), 1)
class TestPowerPollster(base.TestCase): class TestPowerPollster(base.TestCase):
@ -150,21 +150,21 @@ class TestPowerPollster(base.TestCase):
probe_dict['id'] = key probe_dict['id'] = key
yield probe_dict yield probe_dict
def test_counter(self): def test_sample(self):
cache = {} cache = {}
counters = list(kwapi.PowerPollster().get_counters( samples = list(kwapi.PowerPollster().get_samples(
self.manager, self.manager,
cache, cache,
)) ))
self.assertEqual(len(counters), 3) self.assertEqual(len(samples), 3)
counters_by_name = dict((c.resource_id, c) for c in counters) samples_by_name = dict((s.resource_id, s) for s in samples)
for name, probe in PROBE_DICT['probes'].items(): for name, probe in PROBE_DICT['probes'].items():
counter = counters_by_name[name] sample = samples_by_name[name]
expected = datetime.datetime.fromtimestamp( expected = datetime.datetime.fromtimestamp(
probe['timestamp'] probe['timestamp']
).isoformat() ).isoformat()
self.assertEqual(counter.timestamp, expected) self.assertEqual(sample.timestamp, expected)
self.assertEqual(counter.volume, probe['w']) self.assertEqual(sample.volume, probe['w'])
class TestPowerPollsterCache(base.TestCase): class TestPowerPollsterCache(base.TestCase):
@ -175,7 +175,7 @@ class TestPowerPollsterCache(base.TestCase):
self.context = context.get_admin_context() self.context = context.get_admin_context()
self.manager = TestManager() self.manager = TestManager()
def test_get_counters_cached(self): def test_get_samples_cached(self):
probe = {'id': 'A'} probe = {'id': 'A'}
probe.update(PROBE_DICT['probes']['A']) probe.update(PROBE_DICT['probes']['A'])
cache = { cache = {
@ -185,5 +185,5 @@ class TestPowerPollsterCache(base.TestCase):
pollster = kwapi.PowerPollster() pollster = kwapi.PowerPollster()
with mock.patch.object(pollster, '_get_probes') as do_not_call: with mock.patch.object(pollster, '_get_probes') as do_not_call:
do_not_call.side_effect = AssertionError('should not be called') do_not_call.side_effect = AssertionError('should not be called')
counters = list(pollster.get_counters(self.manager, cache)) samples = list(pollster.get_samples(self.manager, cache))
self.assertEqual(len(counters), 1) self.assertEqual(len(samples), 1)

View File

@ -149,27 +149,27 @@ class TestImagePollster(base.TestCase):
self.assertEqual(images, []) self.assertEqual(images, [])
def test_image(self): def test_image(self):
counters = list(glance.ImagePollster().get_counters(self.manager, {})) samples = list(glance.ImagePollster().get_samples(self.manager, {}))
self.assertEqual(len(counters), 3) self.assertEqual(len(samples), 3)
for counter in counters: for sample in samples:
self.assertEqual(counter.volume, 1) self.assertEqual(sample.volume, 1)
def test_image_size(self): def test_image_size(self):
counters = list(glance.ImageSizePollster().get_counters(self.manager, samples = list(glance.ImageSizePollster().get_samples(self.manager,
{})) {}))
self.assertEqual(len(counters), 3) self.assertEqual(len(samples), 3)
for image in IMAGE_LIST: for image in IMAGE_LIST:
self.assert_( self.assert_(
any(map(lambda counter: counter.volume == image.size, any(map(lambda sample: sample.volume == image.size,
counters))) samples)))
def test_image_get_counter_names(self): def test_image_get_sample_names(self):
counters = list(glance.ImagePollster().get_counters(self.manager, {})) samples = list(glance.ImagePollster().get_samples(self.manager, {}))
self.assertEqual(set([c.name for c in counters]), self.assertEqual(set([s.name for s in samples]),
set(['image'])) set(['image']))
def test_image_size_get_counter_names(self): def test_image_size_get_sample_names(self):
counters = list(glance.ImageSizePollster().get_counters(self.manager, samples = list(glance.ImageSizePollster().get_samples(self.manager,
{})) {}))
self.assertEqual(set([c.name for c in counters]), self.assertEqual(set([s.name for s in samples]),
set(['image.size'])) set(['image.size']))

View File

@ -54,9 +54,9 @@ class TestFloatingIPPollster(base.TestCase):
# FIXME(dhellmann): Is there a useful way to define this # FIXME(dhellmann): Is there a useful way to define this
# test without a database? # test without a database?
# #
# def test_get_counters_none_defined(self): # def test_get_samples_none_defined(self):
# try: # try:
# list(self.pollster.get_counters(self.manager, # list(self.pollster.get_samples(self.manager,
# self.context) # self.context)
# ) # )
# except exception.NoFloatingIpsDefined: # except exception.NoFloatingIpsDefined:
@ -64,30 +64,30 @@ class TestFloatingIPPollster(base.TestCase):
# else: # else:
# assert False, 'Should have seen an error' # assert False, 'Should have seen an error'
def test_get_counters_not_empty(self): def test_get_samples_not_empty(self):
counters = list(self.pollster.get_counters(self.manager, {})) samples = list(self.pollster.get_samples(self.manager, {}))
self.assertEqual(len(counters), 3) self.assertEqual(len(samples), 3)
# It's necessary to verify all the attributes extracted by Nova # It's necessary to verify all the attributes extracted by Nova
# API /os-floating-ips to make sure they're available and correct. # API /os-floating-ips to make sure they're available and correct.
self.assertEqual(counters[0].resource_id, 1) self.assertEqual(samples[0].resource_id, 1)
self.assertEqual(counters[0].resource_metadata["address"], "1.1.1.1") self.assertEqual(samples[0].resource_metadata["address"], "1.1.1.1")
self.assertEqual(counters[0].resource_metadata["pool"], "public") self.assertEqual(samples[0].resource_metadata["pool"], "public")
self.assertEqual(counters[1].resource_id, 2) self.assertEqual(samples[1].resource_id, 2)
self.assertEqual(counters[1].resource_metadata["address"], "1.1.1.2") self.assertEqual(samples[1].resource_metadata["address"], "1.1.1.2")
self.assertEqual(counters[1].resource_metadata["pool"], "public") self.assertEqual(samples[1].resource_metadata["pool"], "public")
self.assertEqual(counters[2].resource_id, 3) self.assertEqual(samples[2].resource_id, 3)
self.assertEqual(counters[2].resource_metadata["address"], "1.1.1.3") self.assertEqual(samples[2].resource_metadata["address"], "1.1.1.3")
self.assertEqual(counters[2].resource_metadata["pool"], "public") self.assertEqual(samples[2].resource_metadata["pool"], "public")
def test_get_counter_names(self): def test_get_counter_names(self):
counters = list(self.pollster.get_counters(self.manager, {})) samples = list(self.pollster.get_samples(self.manager, {}))
self.assertEqual(set([c.name for c in counters]), self.assertEqual(set([s.name for s in samples]),
set(['ip.floating'])) set(['ip.floating']))
def test_get_counters_cached(self): def test_get_samples_cached(self):
cache = {} cache = {}
cache['floating_ips'] = self.faux_get_ips(None)[:2] cache['floating_ips'] = self.faux_get_ips(None)[:2]
counters = list(self.pollster.get_counters(self.manager, cache)) samples = list(self.pollster.get_samples(self.manager, cache))
self.assertEqual(len(counters), 2) self.assertEqual(len(samples), 2)

View File

@ -127,18 +127,18 @@ class TestSwiftPollster(base.TestCase):
def test_metering(self): def test_metering(self):
self.stubs.Set(self.factory, '_iter_accounts', self.stubs.Set(self.factory, '_iter_accounts',
self.fake_iter_accounts) self.fake_iter_accounts)
counters = list(self.pollster.get_counters(self.manager, {})) samples = list(self.pollster.get_samples(self.manager, {}))
self.assertEqual(len(counters), 2) self.assertEqual(len(samples), 2)
def test_get_counter_names(self): def test_get_counter_names(self):
self.stubs.Set(self.factory, '_iter_accounts', self.stubs.Set(self.factory, '_iter_accounts',
self.fake_iter_accounts) self.fake_iter_accounts)
counters = list(self.pollster.get_counters(self.manager, {})) samples = list(self.pollster.get_samples(self.manager, {}))
self.assertEqual(set([c.name for c in counters]), self.assertEqual(set([s.name for s in samples]),
set([counters[0].name])) set([samples[0].name]))
def test_endpoint_notfound(self): def test_endpoint_notfound(self):
self.stubs.Set(self.manager.keystone.service_catalog, 'url_for', self.stubs.Set(self.manager.keystone.service_catalog, 'url_for',
self.fake_ks_service_catalog_url_for) self.fake_ks_service_catalog_url_for)
counters = list(self.pollster.get_counters(self.manager, {})) samples = list(self.pollster.get_samples(self.manager, {}))
self.assertEqual(len(counters), 0) self.assertEqual(len(samples), 0)