Move meter signature computing into meter_publish
Blueprint: oslo-multi-publisher Change-Id: I7e758dfb56604fb5a92690ac9719b129837159cf Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
1667ded277
commit
43d728c631
@ -1,6 +1,6 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
#
|
||||
# Copyright © 2012 eNovance <licensing@enovance.com>
|
||||
# Copyright © 2012-2013 eNovance <licensing@enovance.com>
|
||||
#
|
||||
# Author: Julien Danjou <julien@danjou.info>
|
||||
#
|
||||
@ -18,7 +18,7 @@
|
||||
|
||||
from oslo.config import cfg
|
||||
|
||||
from ceilometer.collector import meter as meter_api
|
||||
from ceilometer.publisher import meter as publisher_meter
|
||||
from ceilometer import extension_manager
|
||||
from ceilometer.openstack.common import context
|
||||
from ceilometer.openstack.common import log
|
||||
@ -87,9 +87,9 @@ class CollectorService(service.PeriodicService):
|
||||
# Set ourselves up as a separate worker for the metering data,
|
||||
# since the default for service is to use create_consumer().
|
||||
self.conn.create_worker(
|
||||
cfg.CONF.metering_topic,
|
||||
cfg.CONF.publisher_meter.metering_topic,
|
||||
rpc_dispatcher.RpcDispatcher([self]),
|
||||
'ceilometer.collector.' + cfg.CONF.metering_topic,
|
||||
'ceilometer.collector.' + cfg.CONF.publisher_meter.metering_topic,
|
||||
)
|
||||
|
||||
def _setup_subscription(self, ext, *args, **kwds):
|
||||
@ -139,7 +139,9 @@ class CollectorService(service.PeriodicService):
|
||||
meter['resource_id'],
|
||||
meter.get('timestamp', 'NO TIMESTAMP'),
|
||||
meter['counter_volume'])
|
||||
if meter_api.verify_signature(meter, cfg.CONF.metering_secret):
|
||||
if publisher_meter.verify_signature(
|
||||
meter,
|
||||
cfg.CONF.publisher_meter.metering_secret):
|
||||
try:
|
||||
# Convert the timestamp to a datetime instance.
|
||||
# Storage engines are responsible for converting
|
||||
|
@ -15,27 +15,41 @@
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
"""Compute the signature of a metering message.
|
||||
"""Publish a counter using the preferred RPC mechanism.
|
||||
"""
|
||||
|
||||
import hashlib
|
||||
import hmac
|
||||
import itertools
|
||||
import uuid
|
||||
|
||||
from oslo.config import cfg
|
||||
|
||||
METER_OPTS = [
|
||||
from ceilometer.openstack.common import log
|
||||
from ceilometer.openstack.common import rpc
|
||||
from ceilometer import publisher
|
||||
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
METER_PUBLISH_OPTS = [
|
||||
cfg.StrOpt('metering_topic',
|
||||
default='metering',
|
||||
help='the topic ceilometer uses for metering messages',
|
||||
deprecated_group="DEFAULT",
|
||||
),
|
||||
cfg.StrOpt('metering_secret',
|
||||
default='change this or be hacked',
|
||||
help='Secret value for signing metering messages',
|
||||
deprecated_group="DEFAULT",
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
def register_opts(config):
|
||||
"""Register the options for signing metering messages.
|
||||
"""Register the options for publishing metering messages.
|
||||
"""
|
||||
config.register_opts(METER_OPTS)
|
||||
config.register_opts(METER_PUBLISH_OPTS, group="publisher_meter")
|
||||
|
||||
|
||||
register_opts(cfg.CONF)
|
||||
@ -101,3 +115,40 @@ def meter_message_from_counter(counter, secret, source):
|
||||
}
|
||||
msg['message_signature'] = compute_signature(msg, secret)
|
||||
return msg
|
||||
|
||||
|
||||
class MeterPublisher(publisher.PublisherBase):
|
||||
def publish_counters(self, context, counters, source):
|
||||
"""Send a metering message for publishing
|
||||
|
||||
:param context: Execution context from the service or RPC call
|
||||
:param counter: Counter from pipeline after transformation
|
||||
:param source: counter source
|
||||
"""
|
||||
|
||||
meters = [
|
||||
meter_message_from_counter(
|
||||
counter,
|
||||
cfg.CONF.publisher_meter.metering_secret,
|
||||
source)
|
||||
for counter in counters
|
||||
]
|
||||
|
||||
topic = cfg.CONF.publisher_meter.metering_topic
|
||||
msg = {
|
||||
'method': 'record_metering_data',
|
||||
'version': '1.0',
|
||||
'args': {'data': meters},
|
||||
}
|
||||
LOG.debug('PUBLISH: %s', str(msg))
|
||||
rpc.cast(context, topic, msg)
|
||||
|
||||
for meter_name, meter_list in itertools.groupby(
|
||||
sorted(meters, key=lambda m: m['counter_name']),
|
||||
lambda m: m['counter_name']):
|
||||
msg = {
|
||||
'method': 'record_metering_data',
|
||||
'version': '1.0',
|
||||
'args': {'data': list(meter_list)},
|
||||
}
|
||||
rpc.cast(context, topic + '.' + meter_name, msg)
|
@ -1,83 +0,0 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
#
|
||||
# Copyright © 2012 New Dream Network, LLC (DreamHost)
|
||||
#
|
||||
# Author: Doug Hellmann <doug.hellmann@dreamhost.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.
|
||||
"""Publish a counter using the preferred RPC mechanism.
|
||||
"""
|
||||
|
||||
import itertools
|
||||
|
||||
from oslo.config import cfg
|
||||
|
||||
from ceilometer.collector import meter as meter_api
|
||||
from ceilometer.openstack.common import log
|
||||
from ceilometer.openstack.common import rpc
|
||||
from ceilometer import publisher
|
||||
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
PUBLISH_OPTS = [
|
||||
cfg.StrOpt('metering_topic',
|
||||
default='metering',
|
||||
help='the topic ceilometer uses for metering messages',
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
def register_opts(config):
|
||||
"""Register the options for publishing metering messages.
|
||||
"""
|
||||
config.register_opts(PUBLISH_OPTS)
|
||||
|
||||
|
||||
register_opts(cfg.CONF)
|
||||
|
||||
|
||||
class MeterPublisher(publisher.PublisherBase):
|
||||
def publish_counters(self, context, counters, source):
|
||||
"""Send a metering message for publishing
|
||||
|
||||
:param context: Execution context from the service or RPC call
|
||||
:param counter: Counter from pipeline after transformation
|
||||
:param source: counter source
|
||||
"""
|
||||
|
||||
meters = [
|
||||
meter_api.meter_message_from_counter(counter,
|
||||
cfg.CONF.metering_secret,
|
||||
source)
|
||||
for counter in counters
|
||||
]
|
||||
|
||||
topic = cfg.CONF.metering_topic
|
||||
msg = {
|
||||
'method': 'record_metering_data',
|
||||
'version': '1.0',
|
||||
'args': {'data': meters},
|
||||
}
|
||||
LOG.debug('PUBLISH: %s', str(msg))
|
||||
rpc.cast(context, topic, msg)
|
||||
|
||||
for meter_name, meter_list in itertools.groupby(
|
||||
sorted(meters, key=lambda m: m['counter_name']),
|
||||
lambda m: m['counter_name']):
|
||||
msg = {
|
||||
'method': 'record_metering_data',
|
||||
'version': '1.0',
|
||||
'args': {'data': list(meter_list)},
|
||||
}
|
||||
rpc.cast(context, topic + '.' + meter_name, msg)
|
@ -404,7 +404,7 @@
|
||||
#matchmaker_heartbeat_ttl=600
|
||||
|
||||
|
||||
######## defined in ceilometer.publisher.meter_publish ########
|
||||
######## defined in ceilometer.publisher.meter ########
|
||||
|
||||
# the topic ceilometer uses for metering messages (string
|
||||
# value)
|
||||
|
@ -6,4 +6,4 @@
|
||||
- "*"
|
||||
transformers:
|
||||
publishers:
|
||||
- meter_publisher
|
||||
- meter
|
||||
|
3
setup.py
3
setup.py
@ -140,7 +140,8 @@ setuptools.setup(
|
||||
accumulator = ceilometer.transformer.accumulator:TransformerAccumulator
|
||||
|
||||
[ceilometer.publisher]
|
||||
meter_publisher = ceilometer.publisher.meter_publish:MeterPublisher
|
||||
meter_publisher = ceilometer.publisher.meter:MeterPublisher
|
||||
meter = ceilometer.publisher.meter:MeterPublisher
|
||||
|
||||
[paste.filter_factory]
|
||||
swift=ceilometer.objectstore.swift_middleware:filter_factory
|
||||
|
@ -23,7 +23,7 @@ import datetime
|
||||
|
||||
from oslo.config import cfg
|
||||
|
||||
from ceilometer.collector import meter
|
||||
from ceilometer.publisher import meter
|
||||
from ceilometer import counter
|
||||
|
||||
from ceilometer.tests import api as tests_api
|
||||
@ -71,9 +71,10 @@ class TestListEvents(tests_api.TestBase):
|
||||
'tag': 'self.counter2'}
|
||||
),
|
||||
]:
|
||||
msg = meter.meter_message_from_counter(cnt,
|
||||
cfg.CONF.metering_secret,
|
||||
'source1')
|
||||
msg = meter.meter_message_from_counter(
|
||||
cnt,
|
||||
cfg.CONF.publisher_meter.metering_secret,
|
||||
'source1')
|
||||
self.conn.record_metering_data(msg)
|
||||
|
||||
def test_empty_project(self):
|
||||
|
@ -24,7 +24,7 @@ import logging
|
||||
|
||||
from oslo.config import cfg
|
||||
|
||||
from ceilometer.collector import meter
|
||||
from ceilometer.publisher import meter
|
||||
from ceilometer import counter
|
||||
|
||||
from ceilometer.tests import api as tests_api
|
||||
@ -100,9 +100,10 @@ class TestListMeters(tests_api.TestBase):
|
||||
timestamp=datetime.datetime(2012, 7, 2, 10, 43),
|
||||
resource_metadata={'display_name': 'test-server',
|
||||
'tag': 'four.counter'})]:
|
||||
msg = meter.meter_message_from_counter(cnt,
|
||||
cfg.CONF.metering_secret,
|
||||
'test_list_resources')
|
||||
msg = meter.meter_message_from_counter(
|
||||
cnt,
|
||||
cfg.CONF.publisher_meter.metering_secret,
|
||||
'test_list_resources')
|
||||
self.conn.record_metering_data(msg)
|
||||
|
||||
def test_list_meters(self):
|
||||
|
@ -24,7 +24,7 @@ import logging
|
||||
|
||||
from oslo.config import cfg
|
||||
|
||||
from ceilometer.collector import meter
|
||||
from ceilometer.publisher import meter
|
||||
from ceilometer import counter
|
||||
|
||||
from ceilometer.tests import api as tests_api
|
||||
@ -55,10 +55,11 @@ class TestListProjects(tests_api.TestBase):
|
||||
resource_metadata={'display_name': 'test-server',
|
||||
'tag': 'self.counter'}
|
||||
)
|
||||
msg = meter.meter_message_from_counter(counter1,
|
||||
cfg.CONF.metering_secret,
|
||||
'test_list_projects',
|
||||
)
|
||||
msg = meter.meter_message_from_counter(
|
||||
counter1,
|
||||
cfg.CONF.publisher_meter.metering_secret,
|
||||
'test_list_projects',
|
||||
)
|
||||
self.conn.record_metering_data(msg)
|
||||
|
||||
counter2 = counter.Counter(
|
||||
@ -73,10 +74,11 @@ class TestListProjects(tests_api.TestBase):
|
||||
resource_metadata={'display_name': 'test-server',
|
||||
'tag': 'self.counter2'}
|
||||
)
|
||||
msg2 = meter.meter_message_from_counter(counter2,
|
||||
cfg.CONF.metering_secret,
|
||||
'test_list_users',
|
||||
)
|
||||
msg2 = meter.meter_message_from_counter(
|
||||
counter2,
|
||||
cfg.CONF.publisher_meter.metering_secret,
|
||||
'test_list_users',
|
||||
)
|
||||
self.conn.record_metering_data(msg2)
|
||||
|
||||
def test_projects(self):
|
||||
|
@ -24,7 +24,7 @@ import logging
|
||||
|
||||
from oslo.config import cfg
|
||||
|
||||
from ceilometer.collector import meter
|
||||
from ceilometer.publisher import meter
|
||||
from ceilometer import counter
|
||||
|
||||
from ceilometer.tests import api as tests_api
|
||||
@ -93,9 +93,10 @@ class TestListResourcesBase(tests_api.TestBase):
|
||||
resource_metadata={'display_name': 'test-server',
|
||||
'tag': 'self.counter4'}
|
||||
)]:
|
||||
msg = meter.meter_message_from_counter(cnt,
|
||||
cfg.CONF.metering_secret,
|
||||
'test_list_resources')
|
||||
msg = meter.meter_message_from_counter(
|
||||
cnt,
|
||||
cfg.CONF.publisher_meter.metering_secret,
|
||||
'test_list_resources')
|
||||
self.conn.record_metering_data(msg)
|
||||
|
||||
|
||||
|
@ -24,7 +24,7 @@ import logging
|
||||
|
||||
from oslo.config import cfg
|
||||
|
||||
from ceilometer.collector import meter
|
||||
from ceilometer.publisher import meter
|
||||
from ceilometer import counter
|
||||
|
||||
from ceilometer.tests import api as tests_api
|
||||
@ -57,10 +57,11 @@ class TestListUsers(tests_api.TestBase):
|
||||
'tag': 'self.counter',
|
||||
}
|
||||
)
|
||||
msg = meter.meter_message_from_counter(counter1,
|
||||
cfg.CONF.metering_secret,
|
||||
'test_list_users',
|
||||
)
|
||||
msg = meter.meter_message_from_counter(
|
||||
counter1,
|
||||
cfg.CONF.publisher_meter.metering_secret,
|
||||
'test_list_users',
|
||||
)
|
||||
self.conn.record_metering_data(msg)
|
||||
|
||||
counter2 = counter.Counter(
|
||||
@ -76,10 +77,11 @@ class TestListUsers(tests_api.TestBase):
|
||||
'tag': 'self.counter2',
|
||||
}
|
||||
)
|
||||
msg2 = meter.meter_message_from_counter(counter2,
|
||||
cfg.CONF.metering_secret,
|
||||
'not-test',
|
||||
)
|
||||
msg2 = meter.meter_message_from_counter(
|
||||
counter2,
|
||||
cfg.CONF.publisher_meter.metering_secret,
|
||||
'not-test',
|
||||
)
|
||||
self.conn.record_metering_data(msg2)
|
||||
|
||||
def test_users(self):
|
||||
|
@ -23,7 +23,7 @@ import datetime
|
||||
|
||||
from oslo.config import cfg
|
||||
|
||||
from ceilometer.collector import meter
|
||||
from ceilometer.publisher import meter
|
||||
from ceilometer import counter
|
||||
|
||||
from ceilometer.tests import api as tests_api
|
||||
@ -52,10 +52,11 @@ class TestMaxProjectVolume(tests_api.TestBase):
|
||||
}
|
||||
)
|
||||
self.counters.append(c)
|
||||
msg = meter.meter_message_from_counter(c,
|
||||
cfg.CONF.metering_secret,
|
||||
'source1',
|
||||
)
|
||||
msg = meter.meter_message_from_counter(
|
||||
c,
|
||||
cfg.CONF.publisher_meter.metering_secret,
|
||||
'source1',
|
||||
)
|
||||
self.conn.record_metering_data(msg)
|
||||
|
||||
def test_no_time_bounds(self):
|
||||
|
@ -22,7 +22,7 @@ import datetime
|
||||
|
||||
from oslo.config import cfg
|
||||
|
||||
from ceilometer.collector import meter
|
||||
from ceilometer.publisher import meter
|
||||
from ceilometer import counter
|
||||
|
||||
from ceilometer.tests import api as tests_api
|
||||
@ -51,10 +51,11 @@ class TestMaxResourceVolume(tests_api.TestBase):
|
||||
}
|
||||
)
|
||||
self.counters.append(c)
|
||||
msg = meter.meter_message_from_counter(c,
|
||||
cfg.CONF.metering_secret,
|
||||
'source1',
|
||||
)
|
||||
msg = meter.meter_message_from_counter(
|
||||
c,
|
||||
cfg.CONF.publisher_meter.metering_secret,
|
||||
'source1',
|
||||
)
|
||||
self.conn.record_metering_data(msg)
|
||||
|
||||
def test_no_time_bounds(self):
|
||||
|
@ -23,7 +23,7 @@ import datetime
|
||||
|
||||
from oslo.config import cfg
|
||||
|
||||
from ceilometer.collector import meter
|
||||
from ceilometer.publisher import meter
|
||||
from ceilometer import counter
|
||||
|
||||
from ceilometer.tests import api as tests_api
|
||||
@ -52,10 +52,11 @@ class TestSumProjectVolume(tests_api.TestBase):
|
||||
}
|
||||
)
|
||||
self.counters.append(c)
|
||||
msg = meter.meter_message_from_counter(c,
|
||||
cfg.CONF.metering_secret,
|
||||
'source1',
|
||||
)
|
||||
msg = meter.meter_message_from_counter(
|
||||
c,
|
||||
cfg.CONF.publisher_meter.metering_secret,
|
||||
'source1',
|
||||
)
|
||||
self.conn.record_metering_data(msg)
|
||||
|
||||
def test_no_time_bounds(self):
|
||||
|
@ -23,7 +23,7 @@ import datetime
|
||||
|
||||
from oslo.config import cfg
|
||||
|
||||
from ceilometer.collector import meter
|
||||
from ceilometer.publisher import meter
|
||||
from ceilometer import counter
|
||||
|
||||
from ceilometer.tests import api as tests_api
|
||||
@ -52,10 +52,11 @@ class TestSumResourceVolume(tests_api.TestBase):
|
||||
}
|
||||
)
|
||||
self.counters.append(c)
|
||||
msg = meter.meter_message_from_counter(c,
|
||||
cfg.CONF.metering_secret,
|
||||
'source1',
|
||||
)
|
||||
msg = meter.meter_message_from_counter(
|
||||
c,
|
||||
cfg.CONF.publisher_meter.metering_secret,
|
||||
'source1',
|
||||
)
|
||||
self.conn.record_metering_data(msg)
|
||||
|
||||
def test_no_time_bounds(self):
|
||||
|
@ -23,7 +23,7 @@ import logging
|
||||
|
||||
from oslo.config import cfg
|
||||
|
||||
from ceilometer.collector import meter
|
||||
from ceilometer.publisher import meter
|
||||
from ceilometer import counter
|
||||
|
||||
from .base import FunctionalTest
|
||||
@ -50,10 +50,11 @@ class TestListEvents(FunctionalTest):
|
||||
'ignored_list': ['not-returned'],
|
||||
}
|
||||
)
|
||||
msg = meter.meter_message_from_counter(self.counter1,
|
||||
cfg.CONF.metering_secret,
|
||||
'test_source',
|
||||
)
|
||||
msg = meter.meter_message_from_counter(
|
||||
self.counter1,
|
||||
cfg.CONF.publisher_meter.metering_secret,
|
||||
'test_source',
|
||||
)
|
||||
self.conn.record_metering_data(msg)
|
||||
|
||||
self.counter2 = counter.Counter(
|
||||
@ -69,10 +70,11 @@ class TestListEvents(FunctionalTest):
|
||||
'tag': 'self.counter2',
|
||||
}
|
||||
)
|
||||
msg2 = meter.meter_message_from_counter(self.counter2,
|
||||
cfg.CONF.metering_secret,
|
||||
'source2',
|
||||
)
|
||||
msg2 = meter.meter_message_from_counter(
|
||||
self.counter2,
|
||||
cfg.CONF.publisher_meter.metering_secret,
|
||||
'source2',
|
||||
)
|
||||
self.conn.record_metering_data(msg2)
|
||||
|
||||
def test_all(self):
|
||||
|
@ -23,7 +23,7 @@ import logging
|
||||
|
||||
from oslo.config import cfg
|
||||
|
||||
from ceilometer.collector import meter
|
||||
from ceilometer.publisher import meter
|
||||
from ceilometer import counter
|
||||
|
||||
from .base import FunctionalTest
|
||||
@ -99,9 +99,10 @@ class TestListMeters(FunctionalTest):
|
||||
timestamp=datetime.datetime(2012, 7, 2, 10, 43),
|
||||
resource_metadata={'display_name': 'test-server',
|
||||
'tag': 'self.counter4'})]:
|
||||
msg = meter.meter_message_from_counter(cnt,
|
||||
cfg.CONF.metering_secret,
|
||||
'test_source')
|
||||
msg = meter.meter_message_from_counter(
|
||||
cnt,
|
||||
cfg.CONF.publisher_meter.metering_secret,
|
||||
'test_source')
|
||||
self.conn.record_metering_data(msg)
|
||||
|
||||
def test_list_meters(self):
|
||||
|
@ -23,7 +23,7 @@ import logging
|
||||
|
||||
from oslo.config import cfg
|
||||
|
||||
from ceilometer.collector import meter
|
||||
from ceilometer.publisher import meter
|
||||
from ceilometer import counter
|
||||
|
||||
from .base import FunctionalTest
|
||||
@ -51,10 +51,11 @@ class TestListResources(FunctionalTest):
|
||||
timestamp=datetime.datetime(2012, 7, 2, 10, 40),
|
||||
resource_metadata=None
|
||||
)
|
||||
msg = meter.meter_message_from_counter(counter1,
|
||||
cfg.CONF.metering_secret,
|
||||
'test',
|
||||
)
|
||||
msg = meter.meter_message_from_counter(
|
||||
counter1,
|
||||
cfg.CONF.publisher_meter.metering_secret,
|
||||
'test',
|
||||
)
|
||||
self.conn.record_metering_data(msg)
|
||||
|
||||
data = self.get_json('/resources')
|
||||
@ -74,10 +75,11 @@ class TestListResources(FunctionalTest):
|
||||
'tag': 'self.counter',
|
||||
}
|
||||
)
|
||||
msg = meter.meter_message_from_counter(counter1,
|
||||
cfg.CONF.metering_secret,
|
||||
'test',
|
||||
)
|
||||
msg = meter.meter_message_from_counter(
|
||||
counter1,
|
||||
cfg.CONF.publisher_meter.metering_secret,
|
||||
'test',
|
||||
)
|
||||
self.conn.record_metering_data(msg)
|
||||
|
||||
counter2 = counter.Counter(
|
||||
@ -93,10 +95,11 @@ class TestListResources(FunctionalTest):
|
||||
'tag': 'self.counter2',
|
||||
}
|
||||
)
|
||||
msg2 = meter.meter_message_from_counter(counter2,
|
||||
cfg.CONF.metering_secret,
|
||||
'test',
|
||||
)
|
||||
msg2 = meter.meter_message_from_counter(
|
||||
counter2,
|
||||
cfg.CONF.publisher_meter.metering_secret,
|
||||
'test',
|
||||
)
|
||||
self.conn.record_metering_data(msg2)
|
||||
|
||||
data = self.get_json('/resources')
|
||||
@ -116,10 +119,11 @@ class TestListResources(FunctionalTest):
|
||||
'tag': 'self.counter',
|
||||
}
|
||||
)
|
||||
msg = meter.meter_message_from_counter(counter1,
|
||||
cfg.CONF.metering_secret,
|
||||
'test',
|
||||
)
|
||||
msg = meter.meter_message_from_counter(
|
||||
counter1,
|
||||
cfg.CONF.publisher_meter.metering_secret,
|
||||
'test',
|
||||
)
|
||||
self.conn.record_metering_data(msg)
|
||||
|
||||
counter2 = counter.Counter(
|
||||
@ -135,10 +139,11 @@ class TestListResources(FunctionalTest):
|
||||
'tag': 'self.counter2',
|
||||
}
|
||||
)
|
||||
msg2 = meter.meter_message_from_counter(counter2,
|
||||
cfg.CONF.metering_secret,
|
||||
'test',
|
||||
)
|
||||
msg2 = meter.meter_message_from_counter(
|
||||
counter2,
|
||||
cfg.CONF.publisher_meter.metering_secret,
|
||||
'test',
|
||||
)
|
||||
self.conn.record_metering_data(msg2)
|
||||
|
||||
data = self.get_json('/resources/resource-id')
|
||||
@ -158,10 +163,11 @@ class TestListResources(FunctionalTest):
|
||||
'tag': 'self.counter',
|
||||
}
|
||||
)
|
||||
msg = meter.meter_message_from_counter(counter1,
|
||||
cfg.CONF.metering_secret,
|
||||
'test_list_resources',
|
||||
)
|
||||
msg = meter.meter_message_from_counter(
|
||||
counter1,
|
||||
cfg.CONF.publisher_meter.metering_secret,
|
||||
'test_list_resources',
|
||||
)
|
||||
self.conn.record_metering_data(msg)
|
||||
|
||||
counter2 = counter.Counter(
|
||||
@ -177,10 +183,11 @@ class TestListResources(FunctionalTest):
|
||||
'tag': 'self.counter2',
|
||||
}
|
||||
)
|
||||
msg2 = meter.meter_message_from_counter(counter2,
|
||||
cfg.CONF.metering_secret,
|
||||
'not-test',
|
||||
)
|
||||
msg2 = meter.meter_message_from_counter(
|
||||
counter2,
|
||||
cfg.CONF.publisher_meter.metering_secret,
|
||||
'not-test',
|
||||
)
|
||||
self.conn.record_metering_data(msg2)
|
||||
|
||||
data = self.get_json('/resources', q=[{'field': 'source',
|
||||
@ -203,10 +210,11 @@ class TestListResources(FunctionalTest):
|
||||
'tag': 'self.counter',
|
||||
}
|
||||
)
|
||||
msg = meter.meter_message_from_counter(counter1,
|
||||
cfg.CONF.metering_secret,
|
||||
'test_list_resources',
|
||||
)
|
||||
msg = meter.meter_message_from_counter(
|
||||
counter1,
|
||||
cfg.CONF.publisher_meter.metering_secret,
|
||||
'test_list_resources',
|
||||
)
|
||||
self.conn.record_metering_data(msg)
|
||||
|
||||
counter2 = counter.Counter(
|
||||
@ -222,10 +230,11 @@ class TestListResources(FunctionalTest):
|
||||
'tag': 'self.counter2',
|
||||
}
|
||||
)
|
||||
msg2 = meter.meter_message_from_counter(counter2,
|
||||
cfg.CONF.metering_secret,
|
||||
'not-test',
|
||||
)
|
||||
msg2 = meter.meter_message_from_counter(
|
||||
counter2,
|
||||
cfg.CONF.publisher_meter.metering_secret,
|
||||
'not-test',
|
||||
)
|
||||
self.conn.record_metering_data(msg2)
|
||||
|
||||
data = self.get_json('/resources', q=[{'field': 'user_id',
|
||||
@ -248,10 +257,11 @@ class TestListResources(FunctionalTest):
|
||||
'tag': 'self.counter',
|
||||
}
|
||||
)
|
||||
msg = meter.meter_message_from_counter(counter1,
|
||||
cfg.CONF.metering_secret,
|
||||
'test_list_resources',
|
||||
)
|
||||
msg = meter.meter_message_from_counter(
|
||||
counter1,
|
||||
cfg.CONF.publisher_meter.metering_secret,
|
||||
'test_list_resources',
|
||||
)
|
||||
self.conn.record_metering_data(msg)
|
||||
|
||||
counter2 = counter.Counter(
|
||||
@ -267,10 +277,11 @@ class TestListResources(FunctionalTest):
|
||||
'tag': 'self.counter2',
|
||||
}
|
||||
)
|
||||
msg2 = meter.meter_message_from_counter(counter2,
|
||||
cfg.CONF.metering_secret,
|
||||
'not-test',
|
||||
)
|
||||
msg2 = meter.meter_message_from_counter(
|
||||
counter2,
|
||||
cfg.CONF.publisher_meter.metering_secret,
|
||||
'not-test',
|
||||
)
|
||||
self.conn.record_metering_data(msg2)
|
||||
|
||||
data = self.get_json('/resources', q=[{'field': 'project_id',
|
||||
@ -295,10 +306,11 @@ class TestListResources(FunctionalTest):
|
||||
'ignored_list': ['not-returned'],
|
||||
}
|
||||
)
|
||||
msg = meter.meter_message_from_counter(counter1,
|
||||
cfg.CONF.metering_secret,
|
||||
'test',
|
||||
)
|
||||
msg = meter.meter_message_from_counter(
|
||||
counter1,
|
||||
cfg.CONF.publisher_meter.metering_secret,
|
||||
'test',
|
||||
)
|
||||
self.conn.record_metering_data(msg)
|
||||
|
||||
data = self.get_json('/resources')
|
||||
@ -323,10 +335,11 @@ class TestListResources(FunctionalTest):
|
||||
'tag': 'self.counter',
|
||||
}
|
||||
)
|
||||
msg = meter.meter_message_from_counter(counter1,
|
||||
cfg.CONF.metering_secret,
|
||||
'test_list_resources',
|
||||
)
|
||||
msg = meter.meter_message_from_counter(
|
||||
counter1,
|
||||
cfg.CONF.publisher_meter.metering_secret,
|
||||
'test_list_resources',
|
||||
)
|
||||
self.conn.record_metering_data(msg)
|
||||
|
||||
data = self.get_json('/resources')
|
||||
|
@ -22,7 +22,7 @@ import datetime
|
||||
|
||||
from oslo.config import cfg
|
||||
|
||||
from ceilometer.collector import meter
|
||||
from ceilometer.publisher import meter
|
||||
from ceilometer import counter
|
||||
|
||||
from ceilometer.storage.impl_mongodb import require_map_reduce
|
||||
@ -54,10 +54,11 @@ class TestMaxProjectVolume(FunctionalTest):
|
||||
}
|
||||
)
|
||||
self.counters.append(c)
|
||||
msg = meter.meter_message_from_counter(c,
|
||||
cfg.CONF.metering_secret,
|
||||
'source1',
|
||||
)
|
||||
msg = meter.meter_message_from_counter(
|
||||
c,
|
||||
cfg.CONF.publisher_meter.metering_secret,
|
||||
'source1',
|
||||
)
|
||||
self.conn.record_metering_data(msg)
|
||||
|
||||
def test_no_time_bounds(self):
|
||||
|
@ -22,7 +22,7 @@ import datetime
|
||||
|
||||
from oslo.config import cfg
|
||||
|
||||
from ceilometer.collector import meter
|
||||
from ceilometer.publisher import meter
|
||||
from ceilometer import counter
|
||||
|
||||
from .base import FunctionalTest
|
||||
@ -53,10 +53,11 @@ class TestMaxResourceVolume(FunctionalTest):
|
||||
}
|
||||
)
|
||||
self.counters.append(c)
|
||||
msg = meter.meter_message_from_counter(c,
|
||||
cfg.CONF.metering_secret,
|
||||
'source1',
|
||||
)
|
||||
msg = meter.meter_message_from_counter(
|
||||
c,
|
||||
cfg.CONF.publisher_meter.metering_secret,
|
||||
'source1',
|
||||
)
|
||||
self.conn.record_metering_data(msg)
|
||||
|
||||
def test_no_time_bounds(self):
|
||||
|
@ -22,7 +22,7 @@ import datetime
|
||||
|
||||
from oslo.config import cfg
|
||||
|
||||
from ceilometer.collector import meter
|
||||
from ceilometer.publisher import meter
|
||||
from ceilometer import counter
|
||||
|
||||
from .base import FunctionalTest
|
||||
@ -53,10 +53,11 @@ class TestSumProjectVolume(FunctionalTest):
|
||||
}
|
||||
)
|
||||
self.counters.append(c)
|
||||
msg = meter.meter_message_from_counter(c,
|
||||
cfg.CONF.metering_secret,
|
||||
'source1',
|
||||
)
|
||||
msg = meter.meter_message_from_counter(
|
||||
c,
|
||||
cfg.CONF.publisher_meter.metering_secret,
|
||||
'source1',
|
||||
)
|
||||
self.conn.record_metering_data(msg)
|
||||
|
||||
def test_no_time_bounds(self):
|
||||
|
@ -22,7 +22,7 @@ import datetime
|
||||
|
||||
from oslo.config import cfg
|
||||
|
||||
from ceilometer.collector import meter
|
||||
from ceilometer.publisher import meter
|
||||
from ceilometer import counter
|
||||
|
||||
from .base import FunctionalTest
|
||||
@ -53,10 +53,11 @@ class TestSumResourceVolume(FunctionalTest):
|
||||
}
|
||||
)
|
||||
self.counters.append(c)
|
||||
msg = meter.meter_message_from_counter(c,
|
||||
cfg.CONF.metering_secret,
|
||||
'source1',
|
||||
)
|
||||
msg = meter.meter_message_from_counter(
|
||||
c,
|
||||
cfg.CONF.publisher_meter.metering_secret,
|
||||
'source1',
|
||||
)
|
||||
self.conn.record_metering_data(msg)
|
||||
|
||||
def test_no_time_bounds(self):
|
||||
|
@ -26,7 +26,7 @@ from oslo.config import cfg
|
||||
from stevedore import extension
|
||||
from stevedore.tests import manager as test_manager
|
||||
|
||||
from ceilometer.collector import meter
|
||||
from ceilometer.publisher import meter
|
||||
from ceilometer.collector import service
|
||||
from ceilometer.storage import base
|
||||
from ceilometer.tests import base as tests_base
|
||||
@ -89,7 +89,7 @@ class TestCollectorService(tests_base.TestCase):
|
||||
super(TestCollectorService, self).setUp()
|
||||
self.srv = service.CollectorService('the-host', 'the-topic')
|
||||
self.ctx = None
|
||||
#cfg.CONF.metering_secret = 'not-so-secret'
|
||||
#cfg.CONF.publisher_meter.metering_secret = 'not-so-secret'
|
||||
|
||||
@patch('ceilometer.pipeline.setup_pipeline', MagicMock())
|
||||
def test_init_host(self):
|
||||
@ -107,7 +107,7 @@ class TestCollectorService(tests_base.TestCase):
|
||||
}
|
||||
msg['message_signature'] = meter.compute_signature(
|
||||
msg,
|
||||
cfg.CONF.metering_secret,
|
||||
cfg.CONF.publisher_meter.metering_secret,
|
||||
)
|
||||
|
||||
self.srv.storage_conn = self.mox.CreateMock(base.Connection)
|
||||
@ -146,7 +146,7 @@ class TestCollectorService(tests_base.TestCase):
|
||||
}
|
||||
msg['message_signature'] = meter.compute_signature(
|
||||
msg,
|
||||
cfg.CONF.metering_secret,
|
||||
cfg.CONF.publisher_meter.metering_secret,
|
||||
)
|
||||
|
||||
expected = {}
|
||||
@ -168,7 +168,7 @@ class TestCollectorService(tests_base.TestCase):
|
||||
}
|
||||
msg['message_signature'] = meter.compute_signature(
|
||||
msg,
|
||||
cfg.CONF.metering_secret,
|
||||
cfg.CONF.publisher_meter.metering_secret,
|
||||
)
|
||||
|
||||
expected = {}
|
||||
|
@ -1,184 +0,0 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
#
|
||||
# Copyright © 2012 New Dream Network, LLC (DreamHost)
|
||||
#
|
||||
# Author: Doug Hellmann <doug.hellmann@dreamhost.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.meter
|
||||
"""
|
||||
|
||||
from ceilometer.collector import meter
|
||||
from ceilometer import counter
|
||||
from ceilometer.openstack.common import jsonutils
|
||||
|
||||
|
||||
def test_compute_signature_change_key():
|
||||
sig1 = meter.compute_signature({'a': 'A', 'b': 'B'}, 'not-so-secret')
|
||||
sig2 = meter.compute_signature({'A': 'A', 'b': 'B'}, 'not-so-secret')
|
||||
assert sig1 != sig2
|
||||
|
||||
|
||||
def test_compute_signature_change_value():
|
||||
sig1 = meter.compute_signature({'a': 'A', 'b': 'B'}, 'not-so-secret')
|
||||
sig2 = meter.compute_signature({'a': 'a', 'b': 'B'}, 'not-so-secret')
|
||||
assert sig1 != sig2
|
||||
|
||||
|
||||
def test_compute_signature_same():
|
||||
sig1 = meter.compute_signature({'a': 'A', 'b': 'B'}, 'not-so-secret')
|
||||
sig2 = meter.compute_signature({'a': 'A', 'b': 'B'}, 'not-so-secret')
|
||||
assert sig1 == sig2
|
||||
|
||||
|
||||
def test_compute_signature_signed():
|
||||
data = {'a': 'A', 'b': 'B'}
|
||||
sig1 = meter.compute_signature(data, 'not-so-secret')
|
||||
data['message_signature'] = sig1
|
||||
sig2 = meter.compute_signature(data, 'not-so-secret')
|
||||
assert sig1 == sig2
|
||||
|
||||
|
||||
def test_compute_signature_use_configured_secret():
|
||||
data = {'a': 'A', 'b': 'B'}
|
||||
sig1 = meter.compute_signature(data, 'not-so-secret')
|
||||
sig2 = meter.compute_signature(data, 'different-value')
|
||||
assert sig1 != sig2
|
||||
|
||||
|
||||
def test_verify_signature_signed():
|
||||
data = {'a': 'A', 'b': 'B'}
|
||||
sig1 = meter.compute_signature(data, 'not-so-secret')
|
||||
data['message_signature'] = sig1
|
||||
assert meter.verify_signature(data, 'not-so-secret')
|
||||
|
||||
|
||||
def test_verify_signature_unsigned():
|
||||
data = {'a': 'A', 'b': 'B'}
|
||||
assert not meter.verify_signature(data, 'not-so-secret')
|
||||
|
||||
|
||||
def test_verify_signature_incorrect():
|
||||
data = {'a': 'A', 'b': 'B',
|
||||
'message_signature': 'Not the same'}
|
||||
assert not meter.verify_signature(data, 'not-so-secret')
|
||||
|
||||
|
||||
def test_recursive_keypairs():
|
||||
data = {'a': 'A',
|
||||
'b': 'B',
|
||||
'nested': {'a': 'A',
|
||||
'b': 'B',
|
||||
},
|
||||
}
|
||||
pairs = list(meter.recursive_keypairs(data))
|
||||
assert pairs == [('a', 'A'),
|
||||
('b', 'B'),
|
||||
('nested:a', 'A'),
|
||||
('nested:b', 'B'),
|
||||
]
|
||||
|
||||
|
||||
def test_verify_signature_nested():
|
||||
data = {'a': 'A',
|
||||
'b': 'B',
|
||||
'nested': {'a': 'A',
|
||||
'b': 'B',
|
||||
},
|
||||
}
|
||||
data['message_signature'] = meter.compute_signature(data, 'not-so-secret')
|
||||
assert meter.verify_signature(data, 'not-so-secret')
|
||||
|
||||
|
||||
def test_verify_signature_nested_json():
|
||||
data = {'a': 'A',
|
||||
'b': 'B',
|
||||
'nested': {'a': 'A',
|
||||
'b': 'B',
|
||||
'c': ('c',),
|
||||
'd': ['d']
|
||||
},
|
||||
}
|
||||
data['message_signature'] = meter.compute_signature(data, 'not-so-secret')
|
||||
jsondata = jsonutils.loads(jsonutils.dumps(data))
|
||||
assert meter.verify_signature(jsondata, 'not-so-secret')
|
||||
|
||||
|
||||
TEST_COUNTER = counter.Counter(name='name',
|
||||
type='typ',
|
||||
unit='',
|
||||
volume=1,
|
||||
user_id='user',
|
||||
project_id='project',
|
||||
resource_id=2,
|
||||
timestamp='today',
|
||||
resource_metadata={'key': 'value'},
|
||||
)
|
||||
|
||||
TEST_NOTICE = {
|
||||
u'_context_auth_token': u'3d8b13de1b7d499587dfc69b77dc09c2',
|
||||
u'_context_is_admin': True,
|
||||
u'_context_project_id': u'7c150a59fe714e6f9263774af9688f0e',
|
||||
u'_context_quota_class': None,
|
||||
u'_context_read_deleted': u'no',
|
||||
u'_context_remote_address': u'10.0.2.15',
|
||||
u'_context_request_id': u'req-d68b36e0-9233-467f-9afb-d81435d64d66',
|
||||
u'_context_roles': [u'admin'],
|
||||
u'_context_timestamp': u'2012-05-08T20:23:41.425105',
|
||||
u'_context_user_id': u'1e3ce043029547f1a61c1996d1a531a2',
|
||||
u'event_type': u'compute.instance.create.end',
|
||||
u'message_id': u'dae6f69c-00e0-41c0-b371-41ec3b7f4451',
|
||||
u'payload': {u'created_at': u'2012-05-08 20:23:41',
|
||||
u'deleted_at': u'',
|
||||
u'disk_gb': 0,
|
||||
u'display_name': u'testme',
|
||||
u'fixed_ips': [{u'address': u'10.0.0.2',
|
||||
u'floating_ips': [],
|
||||
u'meta': {},
|
||||
u'type': u'fixed',
|
||||
u'version': 4}],
|
||||
u'image_ref_url': u'http://10.0.2.15:9292/images/UUID',
|
||||
u'instance_id': u'9f9d01b9-4a58-4271-9e27-398b21ab20d1',
|
||||
u'instance_type': u'm1.tiny',
|
||||
u'instance_type_id': 2,
|
||||
u'launched_at': u'2012-05-08 20:23:47.985999',
|
||||
u'memory_mb': 512,
|
||||
u'state': u'active',
|
||||
u'state_description': u'',
|
||||
u'tenant_id': u'7c150a59fe714e6f9263774af9688f0e',
|
||||
u'user_id': u'1e3ce043029547f1a61c1996d1a531a2'},
|
||||
u'priority': u'INFO',
|
||||
u'publisher_id': u'compute.vagrant-precise',
|
||||
u'timestamp': u'2012-05-08 20:23:48.028195',
|
||||
}
|
||||
|
||||
|
||||
def test_meter_message_from_counter_signed():
|
||||
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',
|
||||
'src')
|
||||
name_map = {'name': 'counter_name',
|
||||
'type': 'counter_type',
|
||||
'unit': 'counter_unit',
|
||||
'volume': 'counter_volume',
|
||||
}
|
||||
for f in TEST_COUNTER._fields:
|
||||
msg_f = name_map.get(f, f)
|
||||
yield compare, f, getattr(TEST_COUNTER, f), msg_f, msg[msg_f]
|
@ -22,11 +22,185 @@ import datetime
|
||||
|
||||
from oslo.config import cfg
|
||||
|
||||
from ceilometer import counter
|
||||
from ceilometer.openstack.common import jsonutils
|
||||
from ceilometer.openstack.common import rpc
|
||||
from ceilometer.publisher import meter
|
||||
from ceilometer.tests import base
|
||||
|
||||
from ceilometer import counter
|
||||
from ceilometer.publisher import meter_publish
|
||||
|
||||
def test_compute_signature_change_key():
|
||||
sig1 = meter.compute_signature({'a': 'A', 'b': 'B'},
|
||||
'not-so-secret')
|
||||
sig2 = meter.compute_signature({'A': 'A', 'b': 'B'},
|
||||
'not-so-secret')
|
||||
assert sig1 != sig2
|
||||
|
||||
|
||||
def test_compute_signature_change_value():
|
||||
sig1 = meter.compute_signature({'a': 'A', 'b': 'B'},
|
||||
'not-so-secret')
|
||||
sig2 = meter.compute_signature({'a': 'a', 'b': 'B'},
|
||||
'not-so-secret')
|
||||
assert sig1 != sig2
|
||||
|
||||
|
||||
def test_compute_signature_same():
|
||||
sig1 = meter.compute_signature({'a': 'A', 'b': 'B'},
|
||||
'not-so-secret')
|
||||
sig2 = meter.compute_signature({'a': 'A', 'b': 'B'},
|
||||
'not-so-secret')
|
||||
assert sig1 == sig2
|
||||
|
||||
|
||||
def test_compute_signature_signed():
|
||||
data = {'a': 'A', 'b': 'B'}
|
||||
sig1 = meter.compute_signature(data, 'not-so-secret')
|
||||
data['message_signature'] = sig1
|
||||
sig2 = meter.compute_signature(data, 'not-so-secret')
|
||||
assert sig1 == sig2
|
||||
|
||||
|
||||
def test_compute_signature_use_configured_secret():
|
||||
data = {'a': 'A', 'b': 'B'}
|
||||
sig1 = meter.compute_signature(data, 'not-so-secret')
|
||||
sig2 = meter.compute_signature(data, 'different-value')
|
||||
assert sig1 != sig2
|
||||
|
||||
|
||||
def test_verify_signature_signed():
|
||||
data = {'a': 'A', 'b': 'B'}
|
||||
sig1 = meter.compute_signature(data, 'not-so-secret')
|
||||
data['message_signature'] = sig1
|
||||
assert meter.verify_signature(data, 'not-so-secret')
|
||||
|
||||
|
||||
def test_verify_signature_unsigned():
|
||||
data = {'a': 'A', 'b': 'B'}
|
||||
assert not meter.verify_signature(data, 'not-so-secret')
|
||||
|
||||
|
||||
def test_verify_signature_incorrect():
|
||||
data = {'a': 'A', 'b': 'B',
|
||||
'message_signature': 'Not the same'}
|
||||
assert not meter.verify_signature(data, 'not-so-secret')
|
||||
|
||||
|
||||
def test_recursive_keypairs():
|
||||
data = {'a': 'A',
|
||||
'b': 'B',
|
||||
'nested': {'a': 'A',
|
||||
'b': 'B',
|
||||
},
|
||||
}
|
||||
pairs = list(meter.recursive_keypairs(data))
|
||||
assert pairs == [('a', 'A'),
|
||||
('b', 'B'),
|
||||
('nested:a', 'A'),
|
||||
('nested:b', 'B'),
|
||||
]
|
||||
|
||||
|
||||
def test_verify_signature_nested():
|
||||
data = {'a': 'A',
|
||||
'b': 'B',
|
||||
'nested': {'a': 'A',
|
||||
'b': 'B',
|
||||
},
|
||||
}
|
||||
data['message_signature'] = meter.compute_signature(
|
||||
data,
|
||||
'not-so-secret')
|
||||
assert meter.verify_signature(data, 'not-so-secret')
|
||||
|
||||
|
||||
def test_verify_signature_nested_json():
|
||||
data = {'a': 'A',
|
||||
'b': 'B',
|
||||
'nested': {'a': 'A',
|
||||
'b': 'B',
|
||||
'c': ('c',),
|
||||
'd': ['d']
|
||||
},
|
||||
}
|
||||
data['message_signature'] = meter.compute_signature(
|
||||
data,
|
||||
'not-so-secret')
|
||||
jsondata = jsonutils.loads(jsonutils.dumps(data))
|
||||
assert meter.verify_signature(jsondata, 'not-so-secret')
|
||||
|
||||
|
||||
TEST_COUNTER = counter.Counter(name='name',
|
||||
type='typ',
|
||||
unit='',
|
||||
volume=1,
|
||||
user_id='user',
|
||||
project_id='project',
|
||||
resource_id=2,
|
||||
timestamp='today',
|
||||
resource_metadata={'key': 'value'},
|
||||
)
|
||||
|
||||
TEST_NOTICE = {
|
||||
u'_context_auth_token': u'3d8b13de1b7d499587dfc69b77dc09c2',
|
||||
u'_context_is_admin': True,
|
||||
u'_context_project_id': u'7c150a59fe714e6f9263774af9688f0e',
|
||||
u'_context_quota_class': None,
|
||||
u'_context_read_deleted': u'no',
|
||||
u'_context_remote_address': u'10.0.2.15',
|
||||
u'_context_request_id': u'req-d68b36e0-9233-467f-9afb-d81435d64d66',
|
||||
u'_context_roles': [u'admin'],
|
||||
u'_context_timestamp': u'2012-05-08T20:23:41.425105',
|
||||
u'_context_user_id': u'1e3ce043029547f1a61c1996d1a531a2',
|
||||
u'event_type': u'compute.instance.create.end',
|
||||
u'message_id': u'dae6f69c-00e0-41c0-b371-41ec3b7f4451',
|
||||
u'payload': {u'created_at': u'2012-05-08 20:23:41',
|
||||
u'deleted_at': u'',
|
||||
u'disk_gb': 0,
|
||||
u'display_name': u'testme',
|
||||
u'fixed_ips': [{u'address': u'10.0.0.2',
|
||||
u'floating_ips': [],
|
||||
u'meta': {},
|
||||
u'type': u'fixed',
|
||||
u'version': 4}],
|
||||
u'image_ref_url': u'http://10.0.2.15:9292/images/UUID',
|
||||
u'instance_id': u'9f9d01b9-4a58-4271-9e27-398b21ab20d1',
|
||||
u'instance_type': u'm1.tiny',
|
||||
u'instance_type_id': 2,
|
||||
u'launched_at': u'2012-05-08 20:23:47.985999',
|
||||
u'memory_mb': 512,
|
||||
u'state': u'active',
|
||||
u'state_description': u'',
|
||||
u'tenant_id': u'7c150a59fe714e6f9263774af9688f0e',
|
||||
u'user_id': u'1e3ce043029547f1a61c1996d1a531a2'},
|
||||
u'priority': u'INFO',
|
||||
u'publisher_id': u'compute.vagrant-precise',
|
||||
u'timestamp': u'2012-05-08 20:23:48.028195',
|
||||
}
|
||||
|
||||
|
||||
def test_meter_message_from_counter_signed():
|
||||
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',
|
||||
'src')
|
||||
name_map = {'name': 'counter_name',
|
||||
'type': 'counter_type',
|
||||
'unit': 'counter_unit',
|
||||
'volume': 'counter_volume',
|
||||
}
|
||||
for f in TEST_COUNTER._fields:
|
||||
msg_f = name_map.get(f, f)
|
||||
yield compare, f, getattr(TEST_COUNTER, f), msg_f, msg[msg_f]
|
||||
|
||||
|
||||
class TestPublish(base.TestCase):
|
||||
@ -96,7 +270,7 @@ class TestPublish(base.TestCase):
|
||||
super(TestPublish, self).setUp()
|
||||
self.published = []
|
||||
self.stubs.Set(rpc, 'cast', self.faux_cast)
|
||||
publisher = meter_publish.MeterPublisher()
|
||||
publisher = meter.MeterPublisher()
|
||||
publisher.publish_counters(None,
|
||||
self.test_data,
|
||||
'test')
|
||||
@ -106,7 +280,7 @@ class TestPublish(base.TestCase):
|
||||
for topic, rpc_call in self.published:
|
||||
meters = rpc_call['args']['data']
|
||||
self.assertIsInstance(meters, list)
|
||||
if topic != cfg.CONF.metering_topic:
|
||||
if topic != cfg.CONF.publisher_meter.metering_topic:
|
||||
self.assertEqual(len(set(meter['counter_name']
|
||||
for meter in meters)),
|
||||
1,
|
||||
@ -114,7 +288,10 @@ class TestPublish(base.TestCase):
|
||||
|
||||
def test_published_topics(self):
|
||||
topics = [topic for topic, meter in self.published]
|
||||
self.assertIn(cfg.CONF.metering_topic, topics)
|
||||
self.assertIn(cfg.CONF.metering_topic + '.' + 'test', topics)
|
||||
self.assertIn(cfg.CONF.metering_topic + '.' + 'test2', topics)
|
||||
self.assertIn(cfg.CONF.metering_topic + '.' + 'test3', topics)
|
||||
self.assertIn(cfg.CONF.publisher_meter.metering_topic, topics)
|
||||
self.assertIn(
|
||||
cfg.CONF.publisher_meter.metering_topic + '.' + 'test', topics)
|
||||
self.assertIn(
|
||||
cfg.CONF.publisher_meter.metering_topic + '.' + 'test2', topics)
|
||||
self.assertIn(
|
||||
cfg.CONF.publisher_meter.metering_topic + '.' + 'test3', topics)
|
||||
|
@ -25,7 +25,7 @@ import datetime
|
||||
|
||||
from oslo.config import cfg
|
||||
|
||||
from ceilometer.collector import meter
|
||||
from ceilometer.publisher import meter
|
||||
from ceilometer import counter
|
||||
from ceilometer import storage
|
||||
from ceilometer.tests import db as test_db
|
||||
@ -54,10 +54,11 @@ class DBTestBase(test_db.TestBase):
|
||||
'tag': 'self.counter',
|
||||
}
|
||||
)
|
||||
self.msg1 = meter.meter_message_from_counter(self.counter,
|
||||
cfg.CONF.metering_secret,
|
||||
'test-1',
|
||||
)
|
||||
self.msg1 = meter.meter_message_from_counter(
|
||||
self.counter,
|
||||
cfg.CONF.publisher_meter.metering_secret,
|
||||
'test-1',
|
||||
)
|
||||
self.conn.record_metering_data(self.msg1)
|
||||
self.msgs.append(self.msg1)
|
||||
|
||||
@ -74,10 +75,11 @@ class DBTestBase(test_db.TestBase):
|
||||
'tag': 'self.counter2',
|
||||
}
|
||||
)
|
||||
self.msg2 = meter.meter_message_from_counter(self.counter2,
|
||||
cfg.CONF.metering_secret,
|
||||
'test-2',
|
||||
)
|
||||
self.msg2 = meter.meter_message_from_counter(
|
||||
self.counter2,
|
||||
cfg.CONF.publisher_meter.metering_secret,
|
||||
'test-2',
|
||||
)
|
||||
self.conn.record_metering_data(self.msg2)
|
||||
self.msgs.append(self.msg2)
|
||||
|
||||
@ -94,10 +96,11 @@ class DBTestBase(test_db.TestBase):
|
||||
'tag': 'self.counter3',
|
||||
}
|
||||
)
|
||||
self.msg3 = meter.meter_message_from_counter(self.counter3,
|
||||
cfg.CONF.metering_secret,
|
||||
'test-3',
|
||||
)
|
||||
self.msg3 = meter.meter_message_from_counter(
|
||||
self.counter3,
|
||||
cfg.CONF.publisher_meter.metering_secret,
|
||||
'test-3',
|
||||
)
|
||||
self.conn.record_metering_data(self.msg3)
|
||||
self.msgs.append(self.msg3)
|
||||
|
||||
@ -114,8 +117,11 @@ class DBTestBase(test_db.TestBase):
|
||||
resource_metadata={'display_name': 'test-server',
|
||||
'tag': 'counter-%s' % i},
|
||||
)
|
||||
msg = meter.meter_message_from_counter(c, cfg.CONF.metering_secret,
|
||||
'test')
|
||||
msg = meter.meter_message_from_counter(
|
||||
c,
|
||||
cfg.CONF.publisher_meter.metering_secret,
|
||||
'test',
|
||||
)
|
||||
self.conn.record_metering_data(msg)
|
||||
self.msgs.append(msg)
|
||||
|
||||
@ -359,10 +365,11 @@ class StatisticsTest(DBTestBase):
|
||||
}
|
||||
)
|
||||
self.counters.append(c)
|
||||
msg = meter.meter_message_from_counter(c,
|
||||
secret='not-so-secret',
|
||||
source='test',
|
||||
)
|
||||
msg = meter.meter_message_from_counter(
|
||||
c,
|
||||
secret='not-so-secret',
|
||||
source='test',
|
||||
)
|
||||
self.conn.record_metering_data(msg)
|
||||
for i in range(3):
|
||||
c = counter.Counter(
|
||||
@ -379,10 +386,11 @@ class StatisticsTest(DBTestBase):
|
||||
}
|
||||
)
|
||||
self.counters.append(c)
|
||||
msg = meter.meter_message_from_counter(c,
|
||||
secret='not-so-secret',
|
||||
source='test',
|
||||
)
|
||||
msg = meter.meter_message_from_counter(
|
||||
c,
|
||||
secret='not-so-secret',
|
||||
source='test',
|
||||
)
|
||||
self.conn.record_metering_data(msg)
|
||||
|
||||
def test_by_user(self):
|
||||
@ -522,7 +530,7 @@ class CounterDataTypeTest(DBTestBase):
|
||||
)
|
||||
msg = meter.meter_message_from_counter(
|
||||
c,
|
||||
cfg.CONF.metering_secret,
|
||||
cfg.CONF.publisher_meter.metering_secret,
|
||||
'test-1',
|
||||
)
|
||||
|
||||
@ -541,7 +549,7 @@ class CounterDataTypeTest(DBTestBase):
|
||||
)
|
||||
msg = meter.meter_message_from_counter(
|
||||
c,
|
||||
cfg.CONF.metering_secret,
|
||||
cfg.CONF.publisher_meter.metering_secret,
|
||||
'test-1',
|
||||
)
|
||||
self.conn.record_metering_data(msg)
|
||||
@ -559,7 +567,7 @@ class CounterDataTypeTest(DBTestBase):
|
||||
)
|
||||
msg = meter.meter_message_from_counter(
|
||||
c,
|
||||
cfg.CONF.metering_secret,
|
||||
cfg.CONF.publisher_meter.metering_secret,
|
||||
'test-1',
|
||||
)
|
||||
self.conn.record_metering_data(msg)
|
||||
|
@ -51,7 +51,7 @@ import datetime
|
||||
|
||||
from tests.storage import base
|
||||
|
||||
from ceilometer.collector import meter
|
||||
from ceilometer.publisher import meter
|
||||
from ceilometer import counter
|
||||
from ceilometer.storage.impl_mongodb import require_map_reduce
|
||||
|
||||
@ -158,9 +158,10 @@ class CompatibilityTest(MongoDBEngineTestBase):
|
||||
}
|
||||
)
|
||||
self.counters.append(c)
|
||||
msg = meter.meter_message_from_counter(c,
|
||||
secret='not-so-secret',
|
||||
source='test')
|
||||
msg = meter.meter_message_from_counter(
|
||||
c,
|
||||
secret='not-so-secret',
|
||||
source='test')
|
||||
self.conn.record_metering_data(self.conn, msg)
|
||||
|
||||
def test_counter_unit(self):
|
||||
|
@ -27,7 +27,7 @@ import sys
|
||||
|
||||
from oslo.config import cfg
|
||||
|
||||
from ceilometer.collector import meter
|
||||
from ceilometer.publisher import meter
|
||||
from ceilometer import counter
|
||||
from ceilometer import storage
|
||||
from ceilometer.openstack.common import timeutils
|
||||
@ -129,9 +129,10 @@ def main():
|
||||
timestamp=timestamp,
|
||||
resource_metadata={},
|
||||
)
|
||||
data = meter.meter_message_from_counter(c,
|
||||
cfg.CONF.metering_secret,
|
||||
'artificial')
|
||||
data = meter.meter_message_from_counter(
|
||||
c,
|
||||
cfg.CONF.publisher_meter.metering_secret,
|
||||
'artificial')
|
||||
conn.record_metering_data(data)
|
||||
n += 1
|
||||
timestamp = timestamp + increment
|
||||
|
Loading…
x
Reference in New Issue
Block a user