rpc: remove source argument from message conversion
Change-Id: Ic727b7f61e7b2e38a36f5c2757271668ec143d77
This commit is contained in:
parent
4f87a14c7e
commit
6a07abf288
@ -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
|
||||
]
|
||||
|
||||
|
@ -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):
|
||||
|
@ -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):
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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):
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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',
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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):
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user