From f6868e5e4827e96754f832a0eae4c4210ea41df7 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Thu, 25 Oct 2012 18:38:52 +0200 Subject: [PATCH] Set source at publish time We stop putting the source in the Counter, but we set it via the configuration file and use it as a source. Change-Id: I82c00ac5e55e09ab38de9364cda3194beb35e3c4 Signed-off-by: Julien Danjou --- ceilometer/collector/manager.py | 5 +++-- ceilometer/compute/libvirt.py | 2 -- ceilometer/compute/notifications.py | 16 +++++----------- ceilometer/counter.py | 23 +++++++++++------------ ceilometer/image/glance.py | 2 -- ceilometer/image/notifications.py | 5 ----- ceilometer/meter.py | 8 ++++++-- ceilometer/network/floatingip.py | 1 - ceilometer/network/notifications.py | 6 ++---- ceilometer/publish.py | 7 +++++-- ceilometer/volume/notifications.py | 6 ++---- doc/source/configuration.rst | 1 + tests/api/v1/test_list_events.py | 4 ++-- tests/api/v1/test_list_projects.py | 8 ++++---- tests/api/v1/test_list_resources.py | 16 ++++++++-------- tests/api/v1/test_list_users.py | 8 ++++---- tests/compute/test_manager.py | 1 - tests/compute/test_nova_notifier.py | 1 - tests/storage/test_impl_mongodb.py | 15 +++++++-------- tests/storage/test_impl_sqlalchemy.py | 14 +++++++------- tests/test_meter.py | 9 +++++---- tests/test_publish.py | 2 +- tools/make_test_data.py | 7 ++++--- 23 files changed, 77 insertions(+), 90 deletions(-) diff --git a/ceilometer/collector/manager.py b/ceilometer/collector/manager.py index 0df7a19a..2c74b9a0 100644 --- a/ceilometer/collector/manager.py +++ b/ceilometer/collector/manager.py @@ -125,8 +125,9 @@ class CollectorManager(manager.Manager): """Create a metering message for the counter and publish it.""" ctxt = context.get_admin_context() publish.publish_counter(ctxt, counter, - cfg.CONF.metering_topic, cfg.CONF.metering_secret, - ) + cfg.CONF.metering_topic, + cfg.CONF.metering_secret, + cfg.CONF.counter_source) def record_metering_data(self, context, data): """This method is triggered when metering data is diff --git a/ceilometer/compute/libvirt.py b/ceilometer/compute/libvirt.py index 37b7c0cc..73e4c849 100644 --- a/ceilometer/compute/libvirt.py +++ b/ceilometer/compute/libvirt.py @@ -47,7 +47,6 @@ def get_libvirt_connection(): def make_counter_from_instance(instance, name, type, volume): return counter.Counter( - source='?', name=name, type=type, volume=volume, @@ -195,7 +194,6 @@ class NetPollster(plugin.ComputePollster): resource_metadata['instance_id'] = instance.uuid return counter.Counter( - source='?', name=name, type=type, volume=volume, diff --git a/ceilometer/compute/notifications.py b/ceilometer/compute/notifications.py index 187e3223..94b9cad7 100644 --- a/ceilometer/compute/notifications.py +++ b/ceilometer/compute/notifications.py @@ -67,8 +67,7 @@ class Instance(_Base): def process_notification(self, message): return [ - counter.Counter(source='?', - name='instance', + counter.Counter(name='instance', type=counter.TYPE_GAUGE, volume=1, user_id=message['payload']['user_id'], @@ -85,8 +84,7 @@ class Memory(_Base): def process_notification(self, message): return [ - counter.Counter(source='?', - name='memory', + counter.Counter(name='memory', type=counter.TYPE_GAUGE, volume=message['payload']['memory_mb'], user_id=message['payload']['user_id'], @@ -103,8 +101,7 @@ class VCpus(_Base): def process_notification(self, message): return [ - counter.Counter(source='?', - name='vcpus', + counter.Counter(name='vcpus', type=counter.TYPE_GAUGE, volume=message['payload']['vcpus'], user_id=message['payload']['user_id'], @@ -121,8 +118,7 @@ class RootDiskSize(_Base): def process_notification(self, message): return [ - counter.Counter(source='?', - name='disk.root.size', + counter.Counter(name='disk.root.size', type=counter.TYPE_GAUGE, volume=message['payload']['root_gb'], user_id=message['payload']['user_id'], @@ -139,8 +135,7 @@ class EphemeralDiskSize(_Base): def process_notification(self, message): return [ - counter.Counter(source='?', - name='disk.ephemeral.size', + counter.Counter(name='disk.ephemeral.size', type=counter.TYPE_GAUGE, volume=message['payload']['ephemeral_gb'], user_id=message['payload']['user_id'], @@ -161,7 +156,6 @@ class InstanceFlavor(_Base): if instance_type: counters.append( counter.Counter( - source='?', name='instance:%s' % instance_type, type=counter.TYPE_GAUGE, volume=1, diff --git a/ceilometer/counter.py b/ceilometer/counter.py index d9e539b5..96a8a06c 100644 --- a/ceilometer/counter.py +++ b/ceilometer/counter.py @@ -26,7 +26,6 @@ import collections # Fields explanation: # -# Source: # Name: the name of the counter, must be unique # Type: the type of the counter, must be either: # - cumulative: the value is incremented and never reset to 0 @@ -39,17 +38,17 @@ import collections # Timestamp: when the counter has been read # Resource metadata: various metadata Counter = collections.namedtuple('Counter', - ' '.join(['source', - 'name', - 'type', - 'volume', - 'user_id', - 'project_id', - 'resource_id', - 'timestamp', - 'resource_metadata', - ]) - ) + ' '.join([ + 'name', + 'type', + 'volume', + 'user_id', + 'project_id', + 'resource_id', + 'timestamp', + 'resource_metadata', + ])) + TYPE_GAUGE = 'gauge' TYPE_DELTA = 'delta' diff --git a/ceilometer/image/glance.py b/ceilometer/image/glance.py index b943b666..34a93471 100644 --- a/ceilometer/image/glance.py +++ b/ceilometer/image/glance.py @@ -86,7 +86,6 @@ class ImagePollster(_Base): def get_counters(self, manager, context): for image in self.iter_images(): yield counter.Counter( - source='?', name='image', type=counter.TYPE_GAUGE, volume=1, @@ -103,7 +102,6 @@ class ImageSizePollster(_Base): def get_counters(self, manager, context): for image in self.iter_images(): yield counter.Counter( - source='?', name='image.size', type=counter.TYPE_GAUGE, volume=image.size, diff --git a/ceilometer/image/notifications.py b/ceilometer/image/notifications.py index c165d87f..82d35cb6 100644 --- a/ceilometer/image/notifications.py +++ b/ceilometer/image/notifications.py @@ -88,7 +88,6 @@ class ImageCRUD(ImageCRUDBase): metadata = self.notification_to_metadata(message) return [ counter.Counter( - source='?', name=message['event_type'], type=counter.TYPE_DELTA, volume=1, @@ -107,7 +106,6 @@ class Image(ImageCRUDBase): metadata = self.notification_to_metadata(message) return [ counter.Counter( - source='?', name='image', type=counter.TYPE_GAUGE, volume=1, @@ -126,7 +124,6 @@ class ImageSize(ImageCRUDBase): metadata = self.notification_to_metadata(message) return [ counter.Counter( - source='?', name='image.size', type=counter.TYPE_GAUGE, volume=message['payload']['size'], @@ -154,7 +151,6 @@ class ImageDownload(ImageBase): metadata = self.notification_to_metadata(message) return [ counter.Counter( - source='?', name='image.download', type=counter.TYPE_DELTA, volume=message['payload']['bytes_sent'], @@ -183,7 +179,6 @@ class ImageServe(ImageBase): metadata = self.notification_to_metadata(message) return [ counter.Counter( - source='?', name='image.serve', type=counter.TYPE_DELTA, volume=message['payload']['bytes_sent'], diff --git a/ceilometer/meter.py b/ceilometer/meter.py index 90d82998..e622ffc5 100644 --- a/ceilometer/meter.py +++ b/ceilometer/meter.py @@ -29,6 +29,10 @@ METER_OPTS = [ default='change this or be hacked', help='Secret value for signing metering messages', ), + cfg.StrOpt('counter_source', + default='openstack', + help='Source for counters emited on this instance', + ), ] @@ -75,13 +79,13 @@ def verify_signature(message, secret): return new_sig == old_sig -def meter_message_from_counter(counter, secret): +def meter_message_from_counter(counter, secret, source): """Make a metering message ready to be published or stored. Returns a dictionary containing a metering message for a notification message and a Counter instance. """ - msg = {'source': counter.source, + msg = {'source': source, 'counter_name': counter.name, 'counter_type': counter.type, 'counter_volume': counter.volume, diff --git a/ceilometer/network/floatingip.py b/ceilometer/network/floatingip.py index 693049eb..a8ae6069 100644 --- a/ceilometer/network/floatingip.py +++ b/ceilometer/network/floatingip.py @@ -38,7 +38,6 @@ class FloatingIPPollster(plugin.CentralPollster): for ip in ips: self.LOG.info("FLOATING IP USAGE: %s" % ip.address) yield counter.Counter( - source='?', name='ip.floating', type=counter.TYPE_GAUGE, volume=1, diff --git a/ceilometer/network/notifications.py b/ceilometer/network/notifications.py index 5ad72810..c39d5de9 100644 --- a/ceilometer/network/notifications.py +++ b/ceilometer/network/notifications.py @@ -71,8 +71,7 @@ class NetworkNotificationBase(plugin.NotificationBase): LOG.info('network notification %r', message) message['payload'] = message['payload'][self.resource_name] metadata = self.notification_to_metadata(message) - yield counter.Counter(source='?', - name=self.resource_name, + yield counter.Counter(name=self.resource_name, type=counter.TYPE_GAUGE, volume=1, user_id=message['_context_user_id'], @@ -84,8 +83,7 @@ class NetworkNotificationBase(plugin.NotificationBase): network_counter_name = message['event_type'].rpartition('.')[0] if network_counter_name != self.resource_name: - yield counter.Counter(source='?', - name=network_counter_name, + yield counter.Counter(name=network_counter_name, type=counter.TYPE_DELTA, volume=1, user_id=message['_context_user_id'], diff --git a/ceilometer/publish.py b/ceilometer/publish.py index d2063cb1..2f35ff1e 100644 --- a/ceilometer/publish.py +++ b/ceilometer/publish.py @@ -45,16 +45,19 @@ def register_opts(config): register_opts(cfg.CONF) -def publish_counter(context, counter, topic, secret): +def publish_counter(context, counter, topic, secret, source): """Send a metering message for the data represented by the counter. :param context: Execution context from the service or RPC call :param counter: ceilometer.counter.Counter instance + :param source: counter source """ msg = { 'method': 'record_metering_data', 'version': '1.0', - 'args': {'data': meter.meter_message_from_counter(counter, secret), + 'args': {'data': meter.meter_message_from_counter(counter, + secret, + source), }, } LOG.debug('PUBLISH: %s', str(msg)) diff --git a/ceilometer/volume/notifications.py b/ceilometer/volume/notifications.py index 3695f8fe..b3742a87 100644 --- a/ceilometer/volume/notifications.py +++ b/ceilometer/volume/notifications.py @@ -69,8 +69,7 @@ class Volume(_Base): def process_notification(self, message): return [ - counter.Counter(source='?', - name='volume', + counter.Counter(name='volume', type=counter.TYPE_GAUGE, volume=1, user_id=message['payload']['user_id'], @@ -87,8 +86,7 @@ class VolumeSize(_Base): def process_notification(self, message): return [ - counter.Counter(source='?', - name='volume.size', + counter.Counter(name='volume.size', type=counter.TYPE_GAUGE, volume=message['payload']['size'], user_id=message['payload']['user_id'], diff --git a/doc/source/configuration.rst b/doc/source/configuration.rst index 19ba5709..103a699a 100644 --- a/doc/source/configuration.rst +++ b/doc/source/configuration.rst @@ -36,6 +36,7 @@ cinder_control_exchange cinder Exchange name quantum_control_exchange quantum Exchange name for Quantum notifications metering_secret change this or be hacked Secret value for signing metering messages metering_topic metering the topic ceilometer uses for metering messages +counter_source openstack The source name of emited counters control_exchange ceilometer AMQP exchange to connect to if using RabbitMQ or Qpid periodic_interval 600 seconds between running periodic tasks os-username glance Username to use for openstack service access diff --git a/tests/api/v1/test_list_events.py b/tests/api/v1/test_list_events.py index befa6361..a3b9f435 100644 --- a/tests/api/v1/test_list_events.py +++ b/tests/api/v1/test_list_events.py @@ -35,7 +35,6 @@ class TestListEvents(tests_api.TestBase): def setUp(self): super(TestListEvents, self).setUp() self.counter1 = counter.Counter( - 'source1', 'instance', 'cumulative', 1, @@ -49,11 +48,11 @@ class TestListEvents(tests_api.TestBase): ) msg = meter.meter_message_from_counter(self.counter1, cfg.CONF.metering_secret, + 'source1', ) self.conn.record_metering_data(msg) self.counter2 = counter.Counter( - 'source2', 'instance', 'cumulative', 1, @@ -67,6 +66,7 @@ class TestListEvents(tests_api.TestBase): ) msg2 = meter.meter_message_from_counter(self.counter2, cfg.CONF.metering_secret, + 'source2', ) self.conn.record_metering_data(msg2) diff --git a/tests/api/v1/test_list_projects.py b/tests/api/v1/test_list_projects.py index af58fd3a..9256e866 100644 --- a/tests/api/v1/test_list_projects.py +++ b/tests/api/v1/test_list_projects.py @@ -38,7 +38,6 @@ class TestListProjects(tests_api.TestBase): def test_projects(self): counter1 = counter.Counter( - 'test_list_projects', 'instance', 'cumulative', 1, @@ -52,11 +51,11 @@ class TestListProjects(tests_api.TestBase): ) msg = meter.meter_message_from_counter(counter1, cfg.CONF.metering_secret, + 'test_list_projects', ) self.conn.record_metering_data(msg) counter2 = counter.Counter( - 'test_list_users', 'instance', 'cumulative', 1, @@ -70,6 +69,7 @@ class TestListProjects(tests_api.TestBase): ) msg2 = meter.meter_message_from_counter(counter2, cfg.CONF.metering_secret, + 'test_list_users', ) self.conn.record_metering_data(msg2) @@ -78,7 +78,6 @@ class TestListProjects(tests_api.TestBase): def test_with_source(self): counter1 = counter.Counter( - 'test_list_users', 'instance', 'cumulative', 1, @@ -92,11 +91,11 @@ class TestListProjects(tests_api.TestBase): ) msg = meter.meter_message_from_counter(counter1, cfg.CONF.metering_secret, + 'test_list_users', ) self.conn.record_metering_data(msg) counter2 = counter.Counter( - 'not-test', 'instance', 'cumulative', 1, @@ -110,6 +109,7 @@ class TestListProjects(tests_api.TestBase): ) msg2 = meter.meter_message_from_counter(counter2, cfg.CONF.metering_secret, + 'not-test', ) self.conn.record_metering_data(msg2) diff --git a/tests/api/v1/test_list_resources.py b/tests/api/v1/test_list_resources.py index 70561a3e..e497cfa6 100644 --- a/tests/api/v1/test_list_resources.py +++ b/tests/api/v1/test_list_resources.py @@ -38,7 +38,6 @@ class TestListResources(tests_api.TestBase): def test_instances(self): counter1 = counter.Counter( - 'test', 'instance', 'cumulative', 1, @@ -52,11 +51,11 @@ class TestListResources(tests_api.TestBase): ) msg = meter.meter_message_from_counter(counter1, cfg.CONF.metering_secret, + 'test', ) self.conn.record_metering_data(msg) counter2 = counter.Counter( - 'test', 'instance', 'cumulative', 1, @@ -70,6 +69,7 @@ class TestListResources(tests_api.TestBase): ) msg2 = meter.meter_message_from_counter(counter2, cfg.CONF.metering_secret, + 'test', ) self.conn.record_metering_data(msg2) @@ -78,7 +78,6 @@ class TestListResources(tests_api.TestBase): def test_with_source(self): counter1 = counter.Counter( - 'test_list_resources', 'instance', 'cumulative', 1, @@ -92,11 +91,11 @@ class TestListResources(tests_api.TestBase): ) msg = meter.meter_message_from_counter(counter1, cfg.CONF.metering_secret, + 'test_list_resources', ) self.conn.record_metering_data(msg) counter2 = counter.Counter( - 'not-test', 'instance', 'cumulative', 1, @@ -110,6 +109,7 @@ class TestListResources(tests_api.TestBase): ) msg2 = meter.meter_message_from_counter(counter2, cfg.CONF.metering_secret, + 'not-test', ) self.conn.record_metering_data(msg2) @@ -119,7 +119,6 @@ class TestListResources(tests_api.TestBase): def test_with_user(self): counter1 = counter.Counter( - 'test_list_resources', 'instance', 'cumulative', 1, @@ -133,11 +132,11 @@ class TestListResources(tests_api.TestBase): ) msg = meter.meter_message_from_counter(counter1, cfg.CONF.metering_secret, + 'test_list_resources', ) self.conn.record_metering_data(msg) counter2 = counter.Counter( - 'not-test', 'instance', 'cumulative', 1, @@ -151,6 +150,7 @@ class TestListResources(tests_api.TestBase): ) msg2 = meter.meter_message_from_counter(counter2, cfg.CONF.metering_secret, + 'not-test', ) self.conn.record_metering_data(msg2) @@ -160,7 +160,6 @@ class TestListResources(tests_api.TestBase): def test_with_project(self): counter1 = counter.Counter( - 'test_list_resources', 'instance', 'cumulative', 1, @@ -174,11 +173,11 @@ class TestListResources(tests_api.TestBase): ) msg = meter.meter_message_from_counter(counter1, cfg.CONF.metering_secret, + 'test_list_resources', ) self.conn.record_metering_data(msg) counter2 = counter.Counter( - 'not-test', 'instance', 'cumulative', 1, @@ -192,6 +191,7 @@ class TestListResources(tests_api.TestBase): ) msg2 = meter.meter_message_from_counter(counter2, cfg.CONF.metering_secret, + 'not-test', ) self.conn.record_metering_data(msg2) diff --git a/tests/api/v1/test_list_users.py b/tests/api/v1/test_list_users.py index 4f79f574..c688d07b 100644 --- a/tests/api/v1/test_list_users.py +++ b/tests/api/v1/test_list_users.py @@ -38,7 +38,6 @@ class TestListUsers(tests_api.TestBase): def test_users(self): counter1 = counter.Counter( - 'test_list_users', 'instance', 'cumulative', 1, @@ -52,11 +51,11 @@ class TestListUsers(tests_api.TestBase): ) msg = meter.meter_message_from_counter(counter1, cfg.CONF.metering_secret, + 'test_list_users', ) self.conn.record_metering_data(msg) counter2 = counter.Counter( - 'test_list_users', 'instance', 'cumulative', 1, @@ -70,6 +69,7 @@ class TestListUsers(tests_api.TestBase): ) msg2 = meter.meter_message_from_counter(counter2, cfg.CONF.metering_secret, + 'test_list_users', ) self.conn.record_metering_data(msg2) @@ -78,7 +78,6 @@ class TestListUsers(tests_api.TestBase): def test_with_source(self): counter1 = counter.Counter( - 'test_list_users', 'instance', 'cumulative', 1, @@ -92,11 +91,11 @@ class TestListUsers(tests_api.TestBase): ) msg = meter.meter_message_from_counter(counter1, cfg.CONF.metering_secret, + 'test_list_users', ) self.conn.record_metering_data(msg) counter2 = counter.Counter( - 'not-test', 'instance', 'cumulative', 1, @@ -110,6 +109,7 @@ class TestListUsers(tests_api.TestBase): ) msg2 = meter.meter_message_from_counter(counter2, cfg.CONF.metering_secret, + 'not-test', ) self.conn.record_metering_data(msg2) diff --git a/tests/compute/test_manager.py b/tests/compute/test_manager.py index a18549cb..d4a64708 100644 --- a/tests/compute/test_manager.py +++ b/tests/compute/test_manager.py @@ -40,7 +40,6 @@ class TestRunTasks(base.TestCase): class Pollster: counters = [] test_data = counter.Counter( - source='test', name='test', type=counter.TYPE_CUMULATIVE, volume=1, diff --git a/tests/compute/test_nova_notifier.py b/tests/compute/test_nova_notifier.py index 636d4ec9..2d1dcace 100644 --- a/tests/compute/test_nova_notifier.py +++ b/tests/compute/test_nova_notifier.py @@ -47,7 +47,6 @@ class TestNovaNotifier(base.TestCase): class Pollster(object): counters = [] test_data = counter.Counter( - source='test', name='test', type=counter.TYPE_CUMULATIVE, volume=1, diff --git a/tests/storage/test_impl_mongodb.py b/tests/storage/test_impl_mongodb.py index d3d5a0f6..728c43b0 100644 --- a/tests/storage/test_impl_mongodb.py +++ b/tests/storage/test_impl_mongodb.py @@ -71,7 +71,6 @@ class MongoDBEngineTestBase(unittest.TestCase): self.db = self.conn.conn[self.DBNAME] self.counter = counter.Counter( - 'test-1', 'instance', counter.TYPE_CUMULATIVE, 1, @@ -84,11 +83,11 @@ class MongoDBEngineTestBase(unittest.TestCase): } ) self.msg = meter.meter_message_from_counter(self.counter, - 'not-so-secret') + 'not-so-secret', + 'test-1') self.conn.record_metering_data(self.msg) self.counter2 = counter.Counter( - 'test-2', 'instance', counter.TYPE_CUMULATIVE, 1, @@ -101,11 +100,11 @@ class MongoDBEngineTestBase(unittest.TestCase): } ) self.msg2 = meter.meter_message_from_counter(self.counter2, - 'not-so-secret') + 'not-so-secret', + 'test-2') self.conn.record_metering_data(self.msg2) self.counter3 = counter.Counter( - 'test-3', 'instance', counter.TYPE_CUMULATIVE, 1, @@ -118,12 +117,12 @@ class MongoDBEngineTestBase(unittest.TestCase): } ) self.msg3 = meter.meter_message_from_counter(self.counter3, - 'not-so-secret') + 'not-so-secret', + 'test-3') self.conn.record_metering_data(self.msg3) for i in range(2, 4): c = counter.Counter( - 'test', 'instance', counter.TYPE_CUMULATIVE, 1, @@ -135,7 +134,7 @@ class MongoDBEngineTestBase(unittest.TestCase): 'tag': 'counter-%s' % i, } ) - msg = meter.meter_message_from_counter(c, 'not-so-secret') + msg = meter.meter_message_from_counter(c, 'not-so-secret', 'test') self.conn.record_metering_data(msg) def tearDown(self): diff --git a/tests/storage/test_impl_sqlalchemy.py b/tests/storage/test_impl_sqlalchemy.py index fcddf06a..f58e4b07 100644 --- a/tests/storage/test_impl_sqlalchemy.py +++ b/tests/storage/test_impl_sqlalchemy.py @@ -79,7 +79,6 @@ class SQLAlchemyEngineTestBase(unittest.TestCase): migration.db_sync() self.counter = counter.Counter( - 'test-1', 'instance', counter.TYPE_CUMULATIVE, volume=1, @@ -93,11 +92,11 @@ class SQLAlchemyEngineTestBase(unittest.TestCase): ) self.msg1 = meter.meter_message_from_counter(self.counter, cfg.CONF.metering_secret, + 'test-1', ) self.conn.record_metering_data(self.msg1) self.counter2 = counter.Counter( - 'test-2', 'instance', counter.TYPE_CUMULATIVE, volume=1, @@ -111,11 +110,11 @@ class SQLAlchemyEngineTestBase(unittest.TestCase): ) self.msg2 = meter.meter_message_from_counter(self.counter2, cfg.CONF.metering_secret, + 'test-2', ) self.conn.record_metering_data(self.msg2) self.counter3 = counter.Counter( - 'test-3', 'instance', counter.TYPE_CUMULATIVE, volume=1, @@ -129,12 +128,12 @@ class SQLAlchemyEngineTestBase(unittest.TestCase): ) self.msg3 = meter.meter_message_from_counter(self.counter3, cfg.CONF.metering_secret, + 'test-3', ) self.conn.record_metering_data(self.msg3) for i in range(2, 4): c = counter.Counter( - 'test', 'instance', counter.TYPE_CUMULATIVE, 1, @@ -146,7 +145,8 @@ class SQLAlchemyEngineTestBase(unittest.TestCase): 'tag': 'counter-%s' % i, } ) - msg = meter.meter_message_from_counter(c, cfg.CONF.metering_secret) + msg = meter.meter_message_from_counter(c, cfg.CONF.metering_secret, + 'test') self.conn.record_metering_data(msg) @@ -396,7 +396,6 @@ class TestGetEventInterval(SQLAlchemyEngineTestBase): def _make_events(self, *timestamps): for t in timestamps: c = counter.Counter( - 'test', 'instance', counter.TYPE_CUMULATIVE, 1, @@ -407,7 +406,8 @@ class TestGetEventInterval(SQLAlchemyEngineTestBase): resource_metadata={'display_name': 'test-server', } ) - msg = meter.meter_message_from_counter(c, cfg.CONF.metering_secret) + msg = meter.meter_message_from_counter(c, cfg.CONF.metering_secret, + 'test') self.conn.record_metering_data(msg) def test_before_range(self): diff --git a/tests/test_meter.py b/tests/test_meter.py index 64fae5eb..cabf2df7 100644 --- a/tests/test_meter.py +++ b/tests/test_meter.py @@ -99,8 +99,7 @@ def test_verify_signature_nested(): assert meter.verify_signature(data, 'not-so-secret') -TEST_COUNTER = counter.Counter(source='src', - name='name', +TEST_COUNTER = counter.Counter(name='name', type='typ', volume=1, user_id='user', @@ -149,14 +148,16 @@ TEST_NOTICE = { def test_meter_message_from_counter_signed(): - msg = meter.meter_message_from_counter(TEST_COUNTER, 'not-so-secret') + msg = meter.meter_message_from_counter(TEST_COUNTER, 'not-so-secret', + 'src') assert 'message_signature' in msg def test_meter_message_from_counter_field(): def compare(f, c, msg_f, msg): assert msg == c - msg = meter.meter_message_from_counter(TEST_COUNTER, 'not-so-secret') + msg = meter.meter_message_from_counter(TEST_COUNTER, 'not-so-secret', + 'src') name_map = {'name': 'counter_name', 'type': 'counter_type', 'volume': 'counter_volume', diff --git a/tests/test_publish.py b/tests/test_publish.py index b02d1093..90309581 100644 --- a/tests/test_publish.py +++ b/tests/test_publish.py @@ -30,7 +30,6 @@ from ceilometer import publish class TestPublish(base.TestCase): test_data = counter.Counter( - source='test', name='test', type=counter.TYPE_CUMULATIVE, volume=1, @@ -53,6 +52,7 @@ class TestPublish(base.TestCase): self.test_data, 'metering', 'not-so-secret', + 'test', ) def test_notify(self): diff --git a/tools/make_test_data.py b/tools/make_test_data.py index 5e20a3c9..bfcfb57c 100755 --- a/tools/make_test_data.py +++ b/tools/make_test_data.py @@ -113,8 +113,7 @@ def main(): # Generate events n = 0 while timestamp <= end: - c = counter.Counter(source='artificial', - name=args.counter, + c = counter.Counter(name=args.counter, type=args.type, volume=args.volume, user_id=args.user, @@ -123,7 +122,9 @@ def main(): timestamp=timestamp, resource_metadata={}, ) - data = meter.meter_message_from_counter(c, cfg.CONF.metering_secret) + data = meter.meter_message_from_counter(c, + cfg.CONF.metering_secret, + 'artificial') conn.record_metering_data(data) n += 1 timestamp = timestamp + increment