Removed unused param for get_counters().

This patch removed the unused param 'context' for get_counters() in
central pollsters.

Also added a test case for the central manager.

Fixed bug #1111233.

Change-Id: Ibfa3d5af8516cc432327e1d0da2af800effd9973
This commit is contained in:
Lianhao Lu 2013-01-31 16:45:28 +08:00
parent b13701f7c4
commit baee82420e
11 changed files with 107 additions and 16 deletions

View File

@ -72,7 +72,7 @@ class _Base(plugin.CentralPollster):
class KwapiPollster(_Base):
"""Kwapi pollster derived from the base class."""
def get_counters(self, manager, context):
def get_counters(self, manager):
"""Returns all counters."""
for probe in self.iter_probes():
yield counter.Counter(

View File

@ -83,7 +83,7 @@ class _Base(plugin.PollsterBase):
class ImagePollster(_Base):
def get_counters(self, manager, context):
def get_counters(self, manager):
for image in self.iter_images():
yield counter.Counter(
name='image',

View File

@ -28,7 +28,7 @@ class FloatingIPPollster(plugin.CentralPollster):
LOG = log.getLogger(__name__ + '.floatingip')
def get_counters(self, manager, context):
def get_counters(self, manager):
nv = nova_client.Client()
for ip in nv.floating_ip_get_all():
self.LOG.info("FLOATING IP USAGE: %s" % ip.address)

View File

@ -52,7 +52,7 @@ class _Base(plugin.PollsterBase):
def iter_accounts():
"""Iterate over all accounts, yielding (tenant_id, stats) tuples."""
def get_counters(self, manager, context):
def get_counters(self, manager):
for tenant, account in self.iter_accounts():
yield counter.Counter(
name='storage.objects',

View File

View File

@ -0,0 +1,92 @@
# -*- encoding: utf-8 -*-
#
# Copyright © 2013 Intel Corp.
#
# Author: Lianhao Lu <lianhao.lu@intel.com>
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""Tests for ceilometer/central/manager.py
"""
import datetime
from stevedore import extension
from ceilometer.central import manager
from ceilometer import counter
from ceilometer import publish
from ceilometer.tests import base
from ceilometer.openstack.common import cfg
def test_load_plugins():
mgr = manager.AgentManager()
assert list(mgr.ext_manager), 'Failed to load any plugins'
return
class TestRunTasks(base.TestCase):
class Pollster:
counters = []
test_data = counter.Counter(
name='test',
type=counter.TYPE_CUMULATIVE,
unit='',
volume=1,
user_id='test',
project_id='test',
resource_id='test_run_tasks',
timestamp=datetime.datetime.utcnow().isoformat(),
resource_metadata={'name': 'Pollster'},
)
def get_counters(self, manager):
self.counters.append((manager, self.test_data))
return [self.test_data]
def faux_notify(self, context, msg, topic, secret, source):
self.notifications.append((msg, topic, secret, source))
def setUp(self):
super(TestRunTasks, self).setUp()
self.notifications = []
self.stubs.Set(publish, 'publish_counter', self.faux_notify)
self.mgr = manager.AgentManager()
self.mgr.ext_manager = extension.ExtensionManager('fake',
invoke_on_load=False,
)
self.mgr.ext_manager.extensions = [extension.Extension('test',
None,
None,
self.Pollster(),
),
]
# Invoke the periodic tasks to call the pollsters.
self.mgr.periodic_tasks(None)
def tearDown(self):
self.Pollster.counters = []
super(TestRunTasks, self).tearDown()
def test_message(self):
self.assertEqual(len(self.Pollster.counters), 1)
self.assertTrue(self.Pollster.counters[0][1] is
self.Pollster.test_data)
def test_notifications(self):
actual = self.notifications
self.assertEqual(list(actual[0]), [self.Pollster.test_data,
cfg.CONF.metering_topic,
cfg.CONF.metering_secret,
cfg.CONF.counter_source])

View File

@ -19,7 +19,6 @@
"""
import datetime
import mock
from stevedore import extension
@ -94,11 +93,11 @@ class TestRunTasks(base.TestCase):
def test_message(self):
self.assertEqual(len(self.Pollster.counters), 2)
assert self.Pollster.counters[0][1] is self.instance
self.assertTrue(self.Pollster.counters[0][1] is self.instance)
def test_notifications(self):
actual = self.notifications
assert list(actual[0]) == [self.Pollster.test_data,
self.assertEqual(list(actual[0]), [self.Pollster.test_data,
cfg.CONF.metering_topic,
cfg.CONF.metering_secret,
cfg.CONF.counter_source]
cfg.CONF.counter_source])

View File

@ -60,8 +60,7 @@ class TestKwapiPollster(base.TestCase):
self.stubs.Set(kwapi._Base, 'iter_probes', self.fake_kwapi_iter_probes)
def test_kwapi_counter(self):
counters = list(kwapi.KwapiPollster().get_counters(self.manager,
self.context))
counters = list(kwapi.KwapiPollster().get_counters(self.manager))
self.assertEqual(len(counters), 6)
energy_counters = [counter for counter in counters
if counter.name == "energy"]

View File

@ -97,8 +97,7 @@ class TestImagePollster(base.TestCase):
self.fake_glance_iter_images)
def test_glance_image_counter(self):
counters = list(glance.ImagePollster().get_counters(self.manager,
self.context))
counters = list(glance.ImagePollster().get_counters(self.manager))
self.assertEqual(len(counters), 6)
for counter in [c for c in counters if c.name == 'image']:
self.assertEqual(counter.volume, 1)

View File

@ -58,7 +58,7 @@ class TestFloatingIPPollster(base.TestCase):
# assert False, 'Should have seen an error'
def test_get_counters_not_empty(self):
counters = list(self.pollster.get_counters(self.manager, self.context))
counters = list(self.pollster.get_counters(self.manager))
self.assertEqual(len(counters), 3)
addresses = [c.resource_metadata['address']
for c in counters

View File

@ -17,6 +17,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from ceilometer.central import manager
from ceilometer.objectstore import swift
from ceilometer.tests import base
@ -40,9 +41,10 @@ class TestSwiftPollster(base.TestCase):
def setUp(self):
super(TestSwiftPollster, self).setUp()
self.pollster = swift.SwiftPollster()
self.manager = manager.AgentManager()
self.stubs.Set(swift.SwiftPollster, 'iter_accounts',
self.fake_iter_accounts)
def test_objectstore_metering(self):
counters = list(self.pollster.get_counters(None, None))
counters = list(self.pollster.get_counters(self.manager))
self.assertEqual(len(counters), 6)