diff --git a/ceilometer/publisher/rpc.py b/ceilometer/publisher/rpc.py index 8df2d52e2..c6baebec4 100644 --- a/ceilometer/publisher/rpc.py +++ b/ceilometer/publisher/rpc.py @@ -85,13 +85,13 @@ def verify_signature(message, secret): return new_sig == old_sig -def meter_message_from_counter(counter, secret, source): +def meter_message_from_counter(counter, secret): """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': source, + msg = {'source': counter.source, 'counter_name': counter.name, 'counter_type': counter.type, 'counter_unit': counter.unit, @@ -148,8 +148,7 @@ class RPCPublisher(publisher.PublisherBase): meters = [ meter_message_from_counter( counter, - cfg.CONF.publisher_rpc.metering_secret, - counter.source) + cfg.CONF.publisher_rpc.metering_secret) for counter in counters ] diff --git a/tests/api/v1/test_list_events_scenarios.py b/tests/api/v1/test_list_events_scenarios.py index 6505cd423..3133160d7 100644 --- a/tests/api/v1/test_list_events_scenarios.py +++ b/tests/api/v1/test_list_events_scenarios.py @@ -49,7 +49,8 @@ class TestListEvents(tests_api.TestBase, 'resource-id', timestamp=datetime.datetime(2012, 7, 2, 10, 40), resource_metadata={'display_name': 'test-server', - 'tag': 'self.counter'} + 'tag': 'self.counter'}, + source='source1', ), sample.Sample( 'instance', @@ -61,7 +62,8 @@ class TestListEvents(tests_api.TestBase, 'resource-id', timestamp=datetime.datetime(2012, 7, 2, 10, 41), resource_metadata={'display_name': 'test-server', - 'tag': 'self.counter'} + 'tag': 'self.counter'}, + source='source1', ), sample.Sample( 'instance', @@ -73,13 +75,13 @@ class TestListEvents(tests_api.TestBase, 'resource-id-alternate', timestamp=datetime.datetime(2012, 7, 2, 10, 42), resource_metadata={'display_name': 'test-server', - 'tag': 'self.counter2'} + 'tag': 'self.counter2'}, + source='source1', ), ]: msg = rpc.meter_message_from_counter( cnt, - cfg.CONF.publisher_rpc.metering_secret, - 'source1') + cfg.CONF.publisher_rpc.metering_secret) self.conn.record_metering_data(msg) def test_empty_project(self): diff --git a/tests/api/v1/test_list_meters_scenarios.py b/tests/api/v1/test_list_meters_scenarios.py index 7d9531851..672d49019 100644 --- a/tests/api/v1/test_list_meters_scenarios.py +++ b/tests/api/v1/test_list_meters_scenarios.py @@ -61,7 +61,8 @@ class TestListMeters(tests_api.TestBase, 'resource-id', timestamp=datetime.datetime(2012, 7, 2, 10, 40), resource_metadata={'display_name': 'test-server', - 'tag': 'self.counter'}), + 'tag': 'self.counter'}, + source='test_list_resources'), sample.Sample( 'meter.test', 'cumulative', @@ -72,7 +73,8 @@ class TestListMeters(tests_api.TestBase, 'resource-id', timestamp=datetime.datetime(2012, 7, 2, 11, 40), resource_metadata={'display_name': 'test-server', - 'tag': 'self.counter'}), + 'tag': 'self.counter'}, + source='test_list_resources'), sample.Sample( 'meter.mine', 'gauge', @@ -83,7 +85,8 @@ class TestListMeters(tests_api.TestBase, 'resource-id2', timestamp=datetime.datetime(2012, 7, 2, 10, 41), resource_metadata={'display_name': 'test-server', - 'tag': 'two.counter'}), + 'tag': 'two.counter'}, + source='test_list_resources'), sample.Sample( 'meter.test', 'cumulative', @@ -94,7 +97,8 @@ class TestListMeters(tests_api.TestBase, 'resource-id3', timestamp=datetime.datetime(2012, 7, 2, 10, 42), resource_metadata={'display_name': 'test-server', - 'tag': 'three.counter'}), + 'tag': 'three.counter'}, + source='test_list_resources'), sample.Sample( 'meter.mine', 'gauge', @@ -105,11 +109,11 @@ class TestListMeters(tests_api.TestBase, 'resource-id4', timestamp=datetime.datetime(2012, 7, 2, 10, 43), resource_metadata={'display_name': 'test-server', - 'tag': 'four.counter'})]: + 'tag': 'four.counter'}, + source='test_list_resources')]: msg = rpc.meter_message_from_counter( cnt, - cfg.CONF.publisher_rpc.metering_secret, - 'test_list_resources') + cfg.CONF.publisher_rpc.metering_secret) self.conn.record_metering_data(msg) def test_list_meters(self): diff --git a/tests/api/v1/test_list_projects_scenarios.py b/tests/api/v1/test_list_projects_scenarios.py index 949f58973..9445a001f 100644 --- a/tests/api/v1/test_list_projects_scenarios.py +++ b/tests/api/v1/test_list_projects_scenarios.py @@ -59,12 +59,12 @@ class TestListProjects(tests_api.TestBase, 'resource-id', timestamp=datetime.datetime(2012, 7, 2, 10, 40), resource_metadata={'display_name': 'test-server', - 'tag': 'self.counter'} + 'tag': 'self.counter'}, + source='test_list_projects', ) msg = rpc.meter_message_from_counter( counter1, cfg.CONF.publisher_rpc.metering_secret, - 'test_list_projects', ) self.conn.record_metering_data(msg) @@ -78,12 +78,12 @@ class TestListProjects(tests_api.TestBase, 'resource-id-alternate', timestamp=datetime.datetime(2012, 7, 2, 10, 41), resource_metadata={'display_name': 'test-server', - 'tag': 'self.counter2'} + 'tag': 'self.counter2'}, + source='test_list_users', ) msg2 = rpc.meter_message_from_counter( counter2, cfg.CONF.publisher_rpc.metering_secret, - 'test_list_users', ) self.conn.record_metering_data(msg2) diff --git a/tests/api/v1/test_list_resources_scenarios.py b/tests/api/v1/test_list_resources_scenarios.py index 074164598..6bd1e7b1b 100644 --- a/tests/api/v1/test_list_resources_scenarios.py +++ b/tests/api/v1/test_list_resources_scenarios.py @@ -62,6 +62,7 @@ class TestListResourcesBase(tests_api.TestBase, timestamp=datetime.datetime(2012, 7, 2, 10, 40), resource_metadata={'display_name': 'test-server', 'tag': 'self.counter'}, + source='test_list_resources', ), sample.Sample( 'instance', @@ -74,6 +75,7 @@ class TestListResourcesBase(tests_api.TestBase, timestamp=datetime.datetime(2012, 7, 2, 10, 41), resource_metadata={'display_name': 'test-server', 'tag': 'self.counter2'}, + source='test_list_resources', ), sample.Sample( 'instance', @@ -86,6 +88,7 @@ class TestListResourcesBase(tests_api.TestBase, timestamp=datetime.datetime(2012, 7, 2, 10, 42), resource_metadata={'display_name': 'test-server', 'tag': 'self.counter3'}, + source='test_list_resources', ), sample.Sample( 'instance', @@ -97,12 +100,12 @@ class TestListResourcesBase(tests_api.TestBase, 'resource-id', timestamp=datetime.datetime(2012, 7, 2, 10, 43), resource_metadata={'display_name': 'test-server', - 'tag': 'self.counter4'} + 'tag': 'self.counter4'}, + source='test_list_resources', )]: msg = rpc.meter_message_from_counter( cnt, - cfg.CONF.publisher_rpc.metering_secret, - 'test_list_resources') + cfg.CONF.publisher_rpc.metering_secret) self.conn.record_metering_data(msg) diff --git a/tests/api/v1/test_list_users_scenarios.py b/tests/api/v1/test_list_users_scenarios.py index 37b775a04..b76507b93 100644 --- a/tests/api/v1/test_list_users_scenarios.py +++ b/tests/api/v1/test_list_users_scenarios.py @@ -61,12 +61,12 @@ class TestListUsers(tests_api.TestBase, timestamp=datetime.datetime(2012, 7, 2, 10, 40), resource_metadata={'display_name': 'test-server', 'tag': 'self.counter', - } + }, + source='test_list_users', ) msg = rpc.meter_message_from_counter( counter1, cfg.CONF.publisher_rpc.metering_secret, - 'test_list_users', ) self.conn.record_metering_data(msg) @@ -81,12 +81,12 @@ class TestListUsers(tests_api.TestBase, timestamp=datetime.datetime(2012, 7, 2, 10, 41), resource_metadata={'display_name': 'test-server', 'tag': 'self.counter2', - } + }, + source='not-test', ) msg2 = rpc.meter_message_from_counter( counter2, cfg.CONF.publisher_rpc.metering_secret, - 'not-test', ) self.conn.record_metering_data(msg2) diff --git a/tests/api/v1/test_max_project_volume_scenarios.py b/tests/api/v1/test_max_project_volume_scenarios.py index ffe8e3af2..5a2fc48f1 100644 --- a/tests/api/v1/test_max_project_volume_scenarios.py +++ b/tests/api/v1/test_max_project_volume_scenarios.py @@ -52,13 +52,13 @@ class TestMaxProjectVolume(tests_api.TestBase, timestamp=datetime.datetime(2012, 9, 25, 10 + i, 30 + i), resource_metadata={'display_name': 'test-volume', 'tag': 'self.counter', - } + }, + source='source1', ) self.counters.append(c) msg = rpc.meter_message_from_counter( c, cfg.CONF.publisher_rpc.metering_secret, - 'source1', ) self.conn.record_metering_data(msg) diff --git a/tests/api/v1/test_max_resource_volume_scenarios.py b/tests/api/v1/test_max_resource_volume_scenarios.py index 16baf00b4..855c26211 100644 --- a/tests/api/v1/test_max_resource_volume_scenarios.py +++ b/tests/api/v1/test_max_resource_volume_scenarios.py @@ -51,13 +51,13 @@ class TestMaxResourceVolume(tests_api.TestBase, timestamp=datetime.datetime(2012, 9, 25, 10 + i, 30 + i), resource_metadata={'display_name': 'test-volume', 'tag': 'self.counter', - } + }, + source='source1', ) self.counters.append(c) msg = rpc.meter_message_from_counter( c, cfg.CONF.publisher_rpc.metering_secret, - 'source1', ) self.conn.record_metering_data(msg) diff --git a/tests/api/v1/test_sum_project_volume_scenarios.py b/tests/api/v1/test_sum_project_volume_scenarios.py index c734cc460..2bf7d899b 100644 --- a/tests/api/v1/test_sum_project_volume_scenarios.py +++ b/tests/api/v1/test_sum_project_volume_scenarios.py @@ -52,13 +52,13 @@ class TestSumProjectVolume(tests_api.TestBase, timestamp=datetime.datetime(2012, 9, 25, 10 + i, 30 + i), resource_metadata={'display_name': 'test-volume', 'tag': 'self.counter', - } + }, + source='source1', ) self.counters.append(c) msg = rpc.meter_message_from_counter( c, cfg.CONF.publisher_rpc.metering_secret, - 'source1', ) self.conn.record_metering_data(msg) diff --git a/tests/api/v1/test_sum_resource_volume_scenarios.py b/tests/api/v1/test_sum_resource_volume_scenarios.py index 9d1e162a0..5f5910834 100644 --- a/tests/api/v1/test_sum_resource_volume_scenarios.py +++ b/tests/api/v1/test_sum_resource_volume_scenarios.py @@ -52,13 +52,13 @@ class TestSumResourceVolume(tests_api.TestBase, timestamp=datetime.datetime(2012, 9, 25, 10 + i, 30 + i), resource_metadata={'display_name': 'test-volume', 'tag': 'self.counter', - } + }, + source='source1', ) self.counters.append(c) msg = rpc.meter_message_from_counter( c, cfg.CONF.publisher_rpc.metering_secret, - 'source1', ) self.conn.record_metering_data(msg) diff --git a/tests/api/v2/test_acl_scenarios.py b/tests/api/v2/test_acl_scenarios.py index b0bb2a044..85764c60c 100644 --- a/tests/api/v2/test_acl_scenarios.py +++ b/tests/api/v2/test_acl_scenarios.py @@ -93,7 +93,8 @@ class TestAPIACL(FunctionalTest, 'resource-good', timestamp=datetime.datetime(2012, 7, 2, 10, 40), resource_metadata={'display_name': 'test-server', - 'tag': 'self.counter'}), + 'tag': 'self.counter'}, + source='test_source'), sample.Sample( 'meter.mine', 'gauge', @@ -104,11 +105,11 @@ class TestAPIACL(FunctionalTest, 'resource-56', timestamp=datetime.datetime(2012, 7, 2, 10, 43), resource_metadata={'display_name': 'test-server', - 'tag': 'self.counter4'})]: + 'tag': 'self.counter4'}, + source='test_source')]: msg = rpc.meter_message_from_counter( cnt, - cfg.CONF.publisher_rpc.metering_secret, - 'test_source') + cfg.CONF.publisher_rpc.metering_secret) self.conn.record_metering_data(msg) def get_json(self, path, expect_errors=False, headers=None, diff --git a/tests/api/v2/test_list_events_scenarios.py b/tests/api/v2/test_list_events_scenarios.py index d7291a0b8..50215a97b 100644 --- a/tests/api/v2/test_list_events_scenarios.py +++ b/tests/api/v2/test_list_events_scenarios.py @@ -54,12 +54,12 @@ class TestListEvents(FunctionalTest, 'tag': 'self.counter', 'ignored_dict': {'key': 'value'}, 'ignored_list': ['not-returned'], - } + }, + source='test_source', ) msg = rpc.meter_message_from_counter( self.counter1, cfg.CONF.publisher_rpc.metering_secret, - 'test_source', ) self.conn.record_metering_data(msg) @@ -74,12 +74,12 @@ class TestListEvents(FunctionalTest, timestamp=datetime.datetime(2012, 7, 2, 10, 41), resource_metadata={'display_name': 'test-server', 'tag': 'self.counter2', - } + }, + source='source2', ) msg2 = rpc.meter_message_from_counter( self.counter2, cfg.CONF.publisher_rpc.metering_secret, - 'source2', ) self.conn.record_metering_data(msg2) diff --git a/tests/api/v2/test_list_meters_scenarios.py b/tests/api/v2/test_list_meters_scenarios.py index 2f77e52e6..e39192298 100644 --- a/tests/api/v2/test_list_meters_scenarios.py +++ b/tests/api/v2/test_list_meters_scenarios.py @@ -60,7 +60,8 @@ class TestListMeters(FunctionalTest, 'resource-id', timestamp=datetime.datetime(2012, 7, 2, 10, 40), resource_metadata={'display_name': 'test-server', - 'tag': 'self.counter'}), + 'tag': 'self.counter'}, + source='test_source'), sample.Sample( 'meter.test', 'cumulative', @@ -71,7 +72,8 @@ class TestListMeters(FunctionalTest, 'resource-id', timestamp=datetime.datetime(2012, 7, 2, 11, 40), resource_metadata={'display_name': 'test-server', - 'tag': 'self.counter1'}), + 'tag': 'self.counter1'}, + source='test_source'), sample.Sample( 'meter.mine', 'gauge', @@ -82,7 +84,8 @@ class TestListMeters(FunctionalTest, 'resource-id2', timestamp=datetime.datetime(2012, 7, 2, 10, 41), resource_metadata={'display_name': 'test-server', - 'tag': 'self.counter2'}), + 'tag': 'self.counter2'}, + source='test_source'), sample.Sample( 'meter.test', 'cumulative', @@ -93,7 +96,8 @@ class TestListMeters(FunctionalTest, 'resource-id3', timestamp=datetime.datetime(2012, 7, 2, 10, 42), resource_metadata={'display_name': 'test-server', - 'tag': 'self.counter3'}), + 'tag': 'self.counter3'}, + source='test_source'), sample.Sample( 'meter.mine', 'gauge', @@ -104,11 +108,11 @@ class TestListMeters(FunctionalTest, 'resource-id4', timestamp=datetime.datetime(2012, 7, 2, 10, 43), resource_metadata={'display_name': 'test-server', - 'tag': 'self.counter4'})]: + 'tag': 'self.counter4'}, + source='test_source')]: msg = rpc.meter_message_from_counter( cnt, - cfg.CONF.publisher_rpc.metering_secret, - 'test_source') + cfg.CONF.publisher_rpc.metering_secret) self.conn.record_metering_data(msg) def test_list_meters(self): diff --git a/tests/api/v2/test_list_resources_scenarios.py b/tests/api/v2/test_list_resources_scenarios.py index eaa4ecbca..cbbe6de03 100644 --- a/tests/api/v2/test_list_resources_scenarios.py +++ b/tests/api/v2/test_list_resources_scenarios.py @@ -54,12 +54,12 @@ class TestListResources(FunctionalTest, 'project-id', 'resource-id', timestamp=datetime.datetime(2012, 7, 2, 10, 40), - resource_metadata=None + resource_metadata=None, + source='test', ) msg = rpc.meter_message_from_counter( counter1, cfg.CONF.publisher_rpc.metering_secret, - 'test', ) self.conn.record_metering_data(msg) @@ -78,12 +78,12 @@ class TestListResources(FunctionalTest, timestamp=datetime.datetime(2012, 7, 2, 10, 40), resource_metadata={'display_name': 'test-server', 'tag': 'self.counter', - } + }, + source='test', ) msg = rpc.meter_message_from_counter( counter1, cfg.CONF.publisher_rpc.metering_secret, - 'test', ) self.conn.record_metering_data(msg) @@ -98,12 +98,12 @@ class TestListResources(FunctionalTest, timestamp=datetime.datetime(2012, 7, 2, 10, 41), resource_metadata={'display_name': 'test-server', 'tag': 'self.counter2', - } + }, + source='test', ) msg2 = rpc.meter_message_from_counter( counter2, cfg.CONF.publisher_rpc.metering_secret, - 'test', ) self.conn.record_metering_data(msg2) @@ -122,12 +122,12 @@ class TestListResources(FunctionalTest, timestamp=datetime.datetime(2012, 7, 2, 10, 40), resource_metadata={'display_name': 'test-server', 'tag': 'self.counter', - } + }, + source='test', ) msg = rpc.meter_message_from_counter( counter1, cfg.CONF.publisher_rpc.metering_secret, - 'test', ) self.conn.record_metering_data(msg) @@ -142,12 +142,12 @@ class TestListResources(FunctionalTest, timestamp=datetime.datetime(2012, 7, 2, 10, 41), resource_metadata={'display_name': 'test-server', 'tag': 'self.counter2', - } + }, + source='test', ) msg2 = rpc.meter_message_from_counter( counter2, cfg.CONF.publisher_rpc.metering_secret, - 'test', ) self.conn.record_metering_data(msg2) @@ -166,12 +166,12 @@ class TestListResources(FunctionalTest, timestamp=datetime.datetime(2012, 7, 2, 10, 40), resource_metadata={'display_name': 'test-server', 'tag': 'self.counter', - } + }, + source='test_list_resources', ) msg = rpc.meter_message_from_counter( counter1, cfg.CONF.publisher_rpc.metering_secret, - 'test_list_resources', ) self.conn.record_metering_data(msg) @@ -186,12 +186,12 @@ class TestListResources(FunctionalTest, timestamp=datetime.datetime(2012, 7, 2, 10, 41), resource_metadata={'display_name': 'test-server', 'tag': 'self.counter2', - } + }, + source='not-test', ) msg2 = rpc.meter_message_from_counter( counter2, cfg.CONF.publisher_rpc.metering_secret, - 'not-test', ) self.conn.record_metering_data(msg2) @@ -213,12 +213,12 @@ class TestListResources(FunctionalTest, timestamp=datetime.datetime(2012, 7, 2, 10, 40), resource_metadata={'display_name': 'test-server', 'tag': 'self.counter', - } + }, + source='test_list_resources', ) msg = rpc.meter_message_from_counter( counter1, cfg.CONF.publisher_rpc.metering_secret, - 'test_list_resources', ) self.conn.record_metering_data(msg) @@ -233,12 +233,12 @@ class TestListResources(FunctionalTest, timestamp=datetime.datetime(2012, 7, 2, 10, 41), resource_metadata={'display_name': 'test-server', 'tag': 'self.counter2', - } + }, + source='test_list_resources', ) msg2 = rpc.meter_message_from_counter( counter2, cfg.CONF.publisher_rpc.metering_secret, - 'test_list_resources', ) self.conn.record_metering_data(msg2) @@ -263,12 +263,12 @@ class TestListResources(FunctionalTest, timestamp=datetime.datetime(2012, 7, 2, 10, 40), resource_metadata={'display_name': 'test-server', 'tag': 'self.counter', - } + }, + source='test_list_resources', ) msg = rpc.meter_message_from_counter( counter1, cfg.CONF.publisher_rpc.metering_secret, - 'test_list_resources', ) self.conn.record_metering_data(msg) @@ -283,12 +283,12 @@ class TestListResources(FunctionalTest, timestamp=datetime.datetime(2012, 7, 2, 10, 41), resource_metadata={'display_name': 'test-server', 'tag': 'self.counter2', - } + }, + source='not-test', ) msg2 = rpc.meter_message_from_counter( counter2, cfg.CONF.publisher_rpc.metering_secret, - 'not-test', ) self.conn.record_metering_data(msg2) @@ -310,12 +310,12 @@ class TestListResources(FunctionalTest, timestamp=datetime.datetime(2012, 7, 2, 10, 40), resource_metadata={'display_name': 'test-server', 'tag': 'self.counter', - } + }, + source='test_list_resources', ) msg = rpc.meter_message_from_counter( counter1, cfg.CONF.publisher_rpc.metering_secret, - 'test_list_resources', ) self.conn.record_metering_data(msg) @@ -330,12 +330,12 @@ class TestListResources(FunctionalTest, timestamp=datetime.datetime(2012, 7, 2, 10, 41), resource_metadata={'display_name': 'test-server', 'tag': 'self.counter2', - } + }, + source='not-test', ) msg2 = rpc.meter_message_from_counter( counter2, cfg.CONF.publisher_rpc.metering_secret, - 'not-test', ) self.conn.record_metering_data(msg2) @@ -357,12 +357,12 @@ class TestListResources(FunctionalTest, timestamp=datetime.datetime(2012, 7, 2, 10, 41), resource_metadata={'display_name': 'test-server', 'tag': 'self.counter1', - } + }, + source='not-test', ) msg2 = rpc.meter_message_from_counter( counter1, cfg.CONF.publisher_rpc.metering_secret, - 'not-test', ) self.conn.record_metering_data(msg2) @@ -384,12 +384,12 @@ class TestListResources(FunctionalTest, timestamp=datetime.datetime(2012, 7, 2, 10, 41), resource_metadata={'display_name': 'test-server', 'tag': 'self.counter1', - } + }, + source='not-test', ) msg2 = rpc.meter_message_from_counter( counter1, cfg.CONF.publisher_rpc.metering_secret, - 'not-test', ) self.conn.record_metering_data(msg2) @@ -413,12 +413,12 @@ class TestListResources(FunctionalTest, 'tag': 'self.counter', 'ignored_dict': {'key': 'value'}, 'ignored_list': ['not-returned'], - } + }, + source='test', ) msg = rpc.meter_message_from_counter( counter1, cfg.CONF.publisher_rpc.metering_secret, - 'test', ) self.conn.record_metering_data(msg) @@ -442,12 +442,12 @@ class TestListResources(FunctionalTest, timestamp=datetime.datetime(2012, 7, 2, 10, 40), resource_metadata={'display_name': 'test-server', 'tag': 'self.counter', - } + }, + source='test_list_resources', ) msg = rpc.meter_message_from_counter( counter1, cfg.CONF.publisher_rpc.metering_secret, - 'test_list_resources', ) self.conn.record_metering_data(msg) diff --git a/tests/api/v2/test_statistics_scenarios.py b/tests/api/v2/test_statistics_scenarios.py index 1c5d8f761..23712db3c 100644 --- a/tests/api/v2/test_statistics_scenarios.py +++ b/tests/api/v2/test_statistics_scenarios.py @@ -51,13 +51,13 @@ class TestMaxProjectVolume(base.FunctionalTest, timestamp=datetime.datetime(2012, 9, 25, 10 + i, 30 + i), resource_metadata={'display_name': 'test-volume', 'tag': 'self.counter', - } + }, + source='source1', ) self.counters.append(c) msg = rpc.meter_message_from_counter( c, cfg.CONF.publisher_rpc.metering_secret, - 'source1', ) self.conn.record_metering_data(msg) @@ -152,13 +152,13 @@ class TestMaxResourceVolume(base.FunctionalTest, timestamp=datetime.datetime(2012, 9, 25, 10 + i, 30 + i), resource_metadata={'display_name': 'test-volume', 'tag': 'self.counter', - } + }, + source='source1', ) self.counters.append(c) msg = rpc.meter_message_from_counter( c, cfg.CONF.publisher_rpc.metering_secret, - 'source1', ) self.conn.record_metering_data(msg) @@ -269,13 +269,13 @@ class TestSumProjectVolume(base.FunctionalTest, timestamp=datetime.datetime(2012, 9, 25, 10 + i, 30 + i), resource_metadata={'display_name': 'test-volume', 'tag': 'self.counter', - } + }, + source='source1', ) self.counters.append(c) msg = rpc.meter_message_from_counter( c, cfg.CONF.publisher_rpc.metering_secret, - 'source1', ) self.conn.record_metering_data(msg) @@ -372,13 +372,13 @@ class TestSumResourceVolume(base.FunctionalTest, timestamp=datetime.datetime(2012, 9, 25, 10 + i, 30 + i), resource_metadata={'display_name': 'test-volume', 'tag': 'self.counter', - } + }, + source='source1', ) self.counters.append(c) msg = rpc.meter_message_from_counter( c, cfg.CONF.publisher_rpc.metering_secret, - 'source1', ) self.conn.record_metering_data(msg) diff --git a/tests/publisher/test_rpc_publisher.py b/tests/publisher/test_rpc_publisher.py index 602a0088c..0eff7540a 100644 --- a/tests/publisher/test_rpc_publisher.py +++ b/tests/publisher/test_rpc_publisher.py @@ -119,20 +119,19 @@ class TestCounter(base.TestCase): project_id='project', resource_id=2, timestamp='today', - resource_metadata={'key': 'value'}) + resource_metadata={'key': 'value'}, + source='rpc') def test_meter_message_from_counter_signed(self): msg = rpc.meter_message_from_counter(self.TEST_COUNTER, - 'not-so-secret', - 'src') + 'not-so-secret') self.assertIn('message_signature', msg) def test_meter_message_from_counter_field(self): def compare(f, c, msg_f, msg): self.assertEqual(msg, c) msg = rpc.meter_message_from_counter(self.TEST_COUNTER, - 'not-so-secret', - 'src') + 'not-so-secret') name_map = {'name': 'counter_name', 'type': 'counter_type', 'unit': 'counter_unit', diff --git a/tests/storage/base.py b/tests/storage/base.py index 56718a731..03c6d37d7 100644 --- a/tests/storage/base.py +++ b/tests/storage/base.py @@ -69,12 +69,12 @@ class DBTestBase(test_db.TestBase): timestamp=datetime.datetime(*timestamp_list[0]), resource_metadata={'display_name': 'test-server', 'tag': 'self.counter', - } + }, + source='test-1', ) self.msg1 = rpc.meter_message_from_counter( self.counter, cfg.CONF.publisher_rpc.metering_secret, - 'test-1', ) self.conn.record_metering_data(self.msg1) self.msgs.append(self.msg1) @@ -90,12 +90,12 @@ class DBTestBase(test_db.TestBase): timestamp=datetime.datetime(*timestamp_list[1]), resource_metadata={'display_name': 'test-server', 'tag': 'self.counter2', - } + }, + source='test-2', ) self.msg2 = rpc.meter_message_from_counter( self.counter2, cfg.CONF.publisher_rpc.metering_secret, - 'test-2', ) self.conn.record_metering_data(self.msg2) self.msgs.append(self.msg2) @@ -111,12 +111,12 @@ class DBTestBase(test_db.TestBase): timestamp=datetime.datetime(*timestamp_list[2]), resource_metadata={'display_name': 'test-server', 'tag': 'self.counter3', - } + }, + source='test-3', ) self.msg3 = rpc.meter_message_from_counter( self.counter3, cfg.CONF.publisher_rpc.metering_secret, - 'test-3', ) self.conn.record_metering_data(self.msg3) self.msgs.append(self.msg3) @@ -137,11 +137,11 @@ class DBTestBase(test_db.TestBase): timestamp=datetime.datetime(*ts), resource_metadata={'display_name': 'test-server', 'tag': 'counter-%s' % i}, + source='test', ) msg = rpc.meter_message_from_counter( c, cfg.CONF.publisher_rpc.metering_secret, - 'test', ) self.conn.record_metering_data(msg) self.msgs.append(msg) @@ -558,13 +558,13 @@ class StatisticsTest(DBTestBase): timestamp=datetime.datetime(2012, 9, 25, 10 + i, 30 + i), resource_metadata={'display_name': 'test-volume', 'tag': 'self.counter', - } + }, + source='test', ) self.counters.append(c) msg = rpc.meter_message_from_counter( c, secret='not-so-secret', - source='test', ) self.conn.record_metering_data(msg) for i in range(3): @@ -579,13 +579,13 @@ class StatisticsTest(DBTestBase): timestamp=datetime.datetime(2012, 9, 25, 10 + i, 30 + i), resource_metadata={'display_name': 'test-volume', 'tag': 'self.counter', - } + }, + source='test', ) self.counters.append(c) msg = rpc.meter_message_from_counter( c, secret='not-so-secret', - source='test', ) self.conn.record_metering_data(msg) @@ -763,12 +763,12 @@ class CounterDataTypeTest(DBTestBase): project_id='project-id', resource_id='resource-id', timestamp=datetime.datetime(2012, 7, 2, 10, 40), - resource_metadata={} + resource_metadata={}, + source='test-1', ) msg = rpc.meter_message_from_counter( c, cfg.CONF.publisher_rpc.metering_secret, - 'test-1', ) self.conn.record_metering_data(msg) @@ -782,12 +782,12 @@ class CounterDataTypeTest(DBTestBase): project_id='project-id', resource_id='resource-id', timestamp=datetime.datetime(2012, 7, 2, 10, 40), - resource_metadata={} + resource_metadata={}, + source='test-1', ) msg = rpc.meter_message_from_counter( c, cfg.CONF.publisher_rpc.metering_secret, - 'test-1', ) self.conn.record_metering_data(msg) @@ -800,12 +800,12 @@ class CounterDataTypeTest(DBTestBase): project_id='project-id', resource_id='resource-id', timestamp=datetime.datetime(2012, 7, 2, 10, 40), - resource_metadata={} + resource_metadata={}, + source='test-1', ) msg = rpc.meter_message_from_counter( c, cfg.CONF.publisher_rpc.metering_secret, - 'test-1', ) self.conn.record_metering_data(msg) diff --git a/tests/storage/test_impl_mongodb.py b/tests/storage/test_impl_mongodb.py index eb39c43e9..b8949275a 100644 --- a/tests/storage/test_impl_mongodb.py +++ b/tests/storage/test_impl_mongodb.py @@ -234,13 +234,13 @@ class CompatibilityTest(MongoDBEngineTestBase): timestamp=datetime.datetime(2012, 9, 25, 10, 30), resource_metadata={'display_name': 'test-volume', 'tag': 'self.counter', - } + }, + source='test', ) self.counters.append(c) msg = rpc.meter_message_from_counter( c, - secret='not-so-secret', - source='test') + secret='not-so-secret') self.conn.record_metering_data(self.conn, msg) def test_counter_unit(self): diff --git a/tools/make_test_data.py b/tools/make_test_data.py index 5068ef7d6..34176b51c 100755 --- a/tools/make_test_data.py +++ b/tools/make_test_data.py @@ -128,11 +128,11 @@ def main(): resource_id=args.resource, timestamp=timestamp, resource_metadata={}, + source='artificial', ) data = rpc.meter_message_from_counter( c, - cfg.CONF.publisher_rpc.metering_secret, - 'artificial') + cfg.CONF.publisher_rpc.metering_secret) conn.record_metering_data(data) n += 1 timestamp = timestamp + increment