stop converting to old message format
process notifications as is. this should not impact upgrades as this does not change what is outputed by notification agent in any way, just how it does initial processing. note, this *will* change what is stored in Events if raw field is enabled. that said, the raw field is unqueryable from Panko pov and it actually is storing the raw message now. Change-Id: If79f91687c6c1bc27d906045573674b002534ab1
This commit is contained in:
parent
22e8481e70
commit
130a9ed343
|
@ -23,8 +23,6 @@ import oslo_messaging
|
|||
import six
|
||||
from stevedore import extension
|
||||
|
||||
from ceilometer import messaging
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
ExchangeTopics = collections.namedtuple('ExchangeTopics',
|
||||
|
@ -112,8 +110,6 @@ class NotificationBase(PluginBase):
|
|||
def _process_notifications(self, priority, notifications):
|
||||
for notification in notifications:
|
||||
try:
|
||||
notification = messaging.convert_to_old_notification_format(
|
||||
priority, notification)
|
||||
self.to_samples_and_publish(notification)
|
||||
except Exception:
|
||||
LOG.error('Fail to process notification', exc_info=True)
|
||||
|
|
|
@ -315,7 +315,7 @@ metric:
|
|||
plugin: 'timedelta'
|
||||
project_id: $.payload.tenant_id
|
||||
resource_id: $.payload.id
|
||||
user_id: $._context_user
|
||||
user_id: $.ctxt.user
|
||||
metadata:
|
||||
status: $.payload.status
|
||||
pool_id: $.payload.pool_id
|
||||
|
|
|
@ -72,15 +72,15 @@ class EventDefinition(object):
|
|||
|
||||
DEFAULT_TRAITS = dict(
|
||||
service=dict(type='text', fields='publisher_id'),
|
||||
request_id=dict(type='text', fields='_context_request_id'),
|
||||
request_id=dict(type='text', fields='ctxt.request_id'),
|
||||
project_id=dict(type='text', fields=['payload.tenant_id',
|
||||
'_context_tenant']),
|
||||
'ctxt.tenant']),
|
||||
user_id=dict(type='text', fields=['payload.user_id',
|
||||
'_context_user_id']),
|
||||
'ctxt.user_id']),
|
||||
# TODO(dikonoor):tenant_id is old terminology and should
|
||||
# be deprecated
|
||||
tenant_id=dict(type='text', fields=['payload.tenant_id',
|
||||
'_context_tenant']),
|
||||
'ctxt.tenant']),
|
||||
)
|
||||
|
||||
def __init__(self, definition_cfg, trait_plugin_mgr, raw_levels):
|
||||
|
@ -140,18 +140,17 @@ class EventDefinition(object):
|
|||
def is_catchall(self):
|
||||
return '*' in self._included_types and not self._excluded_types
|
||||
|
||||
def to_event(self, notification_body):
|
||||
def to_event(self, priority, notification_body):
|
||||
event_type = notification_body['event_type']
|
||||
message_id = notification_body['message_id']
|
||||
message_id = notification_body['metadata']['message_id']
|
||||
when = timeutils.normalize_time(timeutils.parse_isotime(
|
||||
notification_body['timestamp']))
|
||||
notification_body['metadata']['timestamp']))
|
||||
|
||||
traits = (self.traits[t].to_trait(notification_body)
|
||||
for t in self.traits)
|
||||
# Only accept non-None value traits ...
|
||||
traits = [trait for trait in traits if trait is not None]
|
||||
raw = (notification_body
|
||||
if notification_body.get('priority') in self.raw_levels else {})
|
||||
raw = notification_body if priority in self.raw_levels else {}
|
||||
event = models.Event(message_id, event_type, when, traits, raw)
|
||||
return event
|
||||
|
||||
|
@ -254,9 +253,9 @@ class NotificationEventsConverter(object):
|
|||
trait_plugin_mgr,
|
||||
raw_levels))
|
||||
|
||||
def to_event(self, notification_body):
|
||||
def to_event(self, priority, notification_body):
|
||||
event_type = notification_body['event_type']
|
||||
message_id = notification_body['message_id']
|
||||
message_id = notification_body['metadata']['message_id']
|
||||
edef = None
|
||||
for d in self.definitions:
|
||||
if d.match_type(event_type):
|
||||
|
@ -274,7 +273,7 @@ class NotificationEventsConverter(object):
|
|||
LOG.error(msg)
|
||||
return None
|
||||
|
||||
return edef.to_event(notification_body)
|
||||
return edef.to_event(priority, notification_body)
|
||||
|
||||
|
||||
def setup_events(conf, trait_plugin_mgr):
|
||||
|
|
|
@ -16,8 +16,7 @@ from oslo_log import log
|
|||
import oslo_messaging
|
||||
from stevedore import extension
|
||||
|
||||
from ceilometer.event import converter as event_converter
|
||||
from ceilometer import messaging
|
||||
from ceilometer.event import converter
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
|
@ -26,7 +25,7 @@ class EventsNotificationEndpoint(object):
|
|||
def __init__(self, manager):
|
||||
super(EventsNotificationEndpoint, self).__init__()
|
||||
LOG.debug('Loading event definitions')
|
||||
self.event_converter = event_converter.setup_events(
|
||||
self.event_converter = converter.setup_events(
|
||||
manager.conf,
|
||||
extension.ExtensionManager(
|
||||
namespace='ceilometer.event.trait_plugin'))
|
||||
|
@ -48,14 +47,8 @@ class EventsNotificationEndpoint(object):
|
|||
|
||||
def process_notification(self, priority, notifications):
|
||||
for notification in notifications:
|
||||
# NOTE: the rpc layer currently rips out the notification
|
||||
# delivery_info, which is critical to determining the
|
||||
# source of the notification. This will have to get added back
|
||||
# later.
|
||||
notification = messaging.convert_to_old_notification_format(
|
||||
priority, notification)
|
||||
try:
|
||||
event = self.event_converter.to_event(notification)
|
||||
event = self.event_converter.to_event(priority, notification)
|
||||
if event is not None:
|
||||
with self.manager.publisher() as p:
|
||||
p(event)
|
||||
|
|
|
@ -75,7 +75,7 @@ class TraitPluginBase(object):
|
|||
'payload.thing.*']
|
||||
notification body:
|
||||
{
|
||||
'message_id': '12345',
|
||||
'metadata': {'message_id': '12345'},
|
||||
'publisher': 'someservice.host',
|
||||
'payload': {
|
||||
'foobar': 'test',
|
||||
|
|
|
@ -92,6 +92,9 @@ class SensorNotification(plugin_base.NotificationBase):
|
|||
@staticmethod
|
||||
def _package_payload(message, payload):
|
||||
# NOTE(chdent): How much of the payload should we keep?
|
||||
# FIXME(gordc): ironic adds timestamp and event_type in its payload
|
||||
# which we are using below. we should probably just use oslo.messaging
|
||||
# values instead?
|
||||
payload['node'] = message['payload']['node_uuid']
|
||||
info = {'publisher_id': message['publisher_id'],
|
||||
'timestamp': message['payload']['timestamp'],
|
||||
|
@ -145,7 +148,8 @@ class SensorNotification(plugin_base.NotificationBase):
|
|||
resource_id=resource_id,
|
||||
message=info,
|
||||
user_id=info['user_id'],
|
||||
project_id=info['project_id'])
|
||||
project_id=info['project_id'],
|
||||
timestamp=info['timestamp'])
|
||||
|
||||
except InvalidSensorData as exc:
|
||||
LOG.warning(
|
||||
|
|
|
@ -72,17 +72,3 @@ def get_notifier(transport, publisher_id):
|
|||
"""Return a configured oslo_messaging notifier."""
|
||||
notifier = oslo_messaging.Notifier(transport, serializer=_SERIALIZER)
|
||||
return notifier.prepare(publisher_id=publisher_id)
|
||||
|
||||
|
||||
def convert_to_old_notification_format(priority, notification):
|
||||
# FIXME(sileht): temporary convert notification to old format
|
||||
# to focus on oslo_messaging migration before refactoring the code to
|
||||
# use the new oslo_messaging facilities
|
||||
notification = notification.copy()
|
||||
notification['priority'] = priority
|
||||
notification.update(notification["metadata"])
|
||||
for k in notification['ctxt']:
|
||||
notification['_context_' + k] = notification['ctxt'][k]
|
||||
del notification['ctxt']
|
||||
del notification['metadata']
|
||||
return notification
|
||||
|
|
|
@ -79,9 +79,9 @@ class MeterDefinition(object):
|
|||
_("Invalid type %s specified") % self.cfg['type'], self.cfg)
|
||||
|
||||
self._fallback_user_id = declarative.Definition(
|
||||
'user_id', "_context_user_id|_context_user", plugin_manager)
|
||||
'user_id', "ctxt.user_id|ctxt.user", plugin_manager)
|
||||
self._fallback_project_id = declarative.Definition(
|
||||
'project_id', "_context_tenant_id|_context_tenant", plugin_manager)
|
||||
'project_id', "ctxt.tenant_id|ctxt.tenant", plugin_manager)
|
||||
self._attributes = {}
|
||||
self._metadata_attributes = {}
|
||||
self._user_meta = None
|
||||
|
|
|
@ -171,7 +171,7 @@
|
|||
project_id:
|
||||
fields: payload.tenant_id
|
||||
user_id:
|
||||
fields: ['_context_trustor_user_id', '_context_user_id']
|
||||
fields: ['ctxt.trustor_user_id', 'ctxt.user_id']
|
||||
resource_id:
|
||||
fields: payload.stack_identity
|
||||
- event_type: sahara.cluster.*
|
||||
|
@ -179,7 +179,7 @@
|
|||
project_id:
|
||||
fields: payload.project_id
|
||||
user_id:
|
||||
fields: _context_user_id
|
||||
fields: ctxt.user_id
|
||||
resource_id:
|
||||
fields: payload.cluster_id
|
||||
- event_type: sahara.cluster.health
|
||||
|
@ -293,9 +293,9 @@
|
|||
- event_type: ['network.*', 'subnet.*', 'port.*', 'router.*', 'floatingip.*', 'pool.*', 'vip.*', 'member.*', 'health_monitor.*', 'healthmonitor.*', 'listener.*', 'loadbalancer.*', 'firewall.*', 'firewall_policy.*', 'firewall_rule.*', 'vpnservice.*', 'ipsecpolicy.*', 'ikepolicy.*', 'ipsec_site_connection.*']
|
||||
traits: &network_traits
|
||||
user_id:
|
||||
fields: _context_user_id
|
||||
fields: ctxt.user_id
|
||||
project_id:
|
||||
fields: _context_tenant_id
|
||||
fields: ctxt.tenant_id
|
||||
- event_type: network.*
|
||||
traits:
|
||||
<<: *network_traits
|
||||
|
|
|
@ -125,7 +125,7 @@ class Sample(object):
|
|||
if isinstance(message['payload'], dict) else {})
|
||||
metadata['event_type'] = message['event_type']
|
||||
metadata['host'] = message['publisher_id']
|
||||
ts = timestamp if timestamp else message['timestamp']
|
||||
ts = timestamp if timestamp else message['metadata']['timestamp']
|
||||
return cls(name=name,
|
||||
type=type,
|
||||
volume=volume,
|
||||
|
|
|
@ -1,55 +0,0 @@
|
|||
#
|
||||
# Copyright 2013 eNovance <licensing@enovance.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.
|
||||
|
||||
import mock
|
||||
from oslotest import base
|
||||
|
||||
from ceilometer.agent import plugin_base
|
||||
|
||||
|
||||
class NotificationBaseTestCase(base.BaseTestCase):
|
||||
class FakePlugin(plugin_base.NotificationBase):
|
||||
event_types = ['compute.*']
|
||||
|
||||
def process_notification(self, message):
|
||||
pass
|
||||
|
||||
def get_targets(self, conf):
|
||||
pass
|
||||
|
||||
def test_plugin_info(self):
|
||||
plugin = self.FakePlugin(mock.Mock())
|
||||
plugin.to_samples_and_publish = mock.Mock()
|
||||
message = {
|
||||
'ctxt': {'user_id': 'fake_user_id',
|
||||
'project_id': 'fake_project_id'},
|
||||
'publisher_id': 'fake.publisher_id',
|
||||
'event_type': 'fake.event',
|
||||
'payload': {'foo': 'bar'},
|
||||
'metadata': {'message_id': '3577a84f-29ec-4904-9566-12c52289c2e8',
|
||||
'timestamp': '2015-06-1909:19:35.786893'}
|
||||
}
|
||||
plugin.info([message])
|
||||
notification = {
|
||||
'priority': 'info',
|
||||
'event_type': 'fake.event',
|
||||
'timestamp': '2015-06-1909:19:35.786893',
|
||||
'_context_user_id': 'fake_user_id',
|
||||
'_context_project_id': 'fake_project_id',
|
||||
'publisher_id': 'fake.publisher_id',
|
||||
'payload': {'foo': 'bar'},
|
||||
'message_id': '3577a84f-29ec-4904-9566-12c52289c2e8'
|
||||
}
|
||||
plugin.to_samples_and_publish.assert_called_with(notification)
|
|
@ -30,10 +30,9 @@ class ConverterBase(base.BaseTestCase):
|
|||
@staticmethod
|
||||
def _create_test_notification(event_type, message_id, **kw):
|
||||
return dict(event_type=event_type,
|
||||
message_id=message_id,
|
||||
priority="INFO",
|
||||
metadata=dict(message_id=message_id,
|
||||
timestamp="2013-08-08 21:06:37.803826"),
|
||||
publisher_id="compute.host-1-2-3",
|
||||
timestamp="2013-08-08 21:06:37.803826",
|
||||
payload=kw,
|
||||
)
|
||||
|
||||
|
@ -400,7 +399,7 @@ class TestEventDefinition(ConverterBase):
|
|||
cfg = dict(event_type='test.thing', traits=self.traits_cfg)
|
||||
edef = converter.EventDefinition(cfg, self.fake_plugin_mgr, [])
|
||||
|
||||
e = edef.to_event(self.test_notification1)
|
||||
e = edef.to_event('INFO', self.test_notification1)
|
||||
self.assertEqual('test.thing', e.event_type)
|
||||
self.assertEqual(datetime.datetime(2013, 8, 8, 21, 6, 37, 803826),
|
||||
e.generated)
|
||||
|
@ -416,7 +415,7 @@ class TestEventDefinition(ConverterBase):
|
|||
cfg = dict(event_type='test.thing', traits=self.traits_cfg)
|
||||
edef = converter.EventDefinition(cfg, self.fake_plugin_mgr, [])
|
||||
|
||||
e = edef.to_event(self.test_notification2)
|
||||
e = edef.to_event('INFO', self.test_notification2)
|
||||
|
||||
self.assertHasDefaultTraits(e)
|
||||
self.assertHasTrait(e, 'instance_id',
|
||||
|
@ -429,7 +428,7 @@ class TestEventDefinition(ConverterBase):
|
|||
cfg = dict(event_type='test.thing', traits=self.traits_cfg)
|
||||
edef = converter.EventDefinition(cfg, self.fake_plugin_mgr, [])
|
||||
|
||||
e = edef.to_event(self.test_notification3)
|
||||
e = edef.to_event('INFO', self.test_notification3)
|
||||
|
||||
self.assertHasDefaultTraits(e)
|
||||
self.assertHasTrait(e, 'instance_id',
|
||||
|
@ -613,10 +612,10 @@ class TestNotificationConverter(ConverterBase):
|
|||
c = converter.NotificationEventsConverter(
|
||||
self.CONF, [], self.fake_plugin_mgr)
|
||||
message = {'event_type': "foo",
|
||||
'message_id': "abc",
|
||||
'timestamp': str(now),
|
||||
'metadata': {'message_id': "abc",
|
||||
'timestamp': str(now)},
|
||||
'publisher_id': "1"}
|
||||
e = c.to_event(message)
|
||||
e = c.to_event('INFO', message)
|
||||
self.assertIsValidEvent(e, message)
|
||||
self.assertEqual(1, len(e.traits))
|
||||
self.assertEqual("foo", e.event_type)
|
||||
|
@ -628,14 +627,14 @@ class TestNotificationConverter(ConverterBase):
|
|||
c = converter.NotificationEventsConverter(
|
||||
self.CONF, self.valid_event_def1, self.fake_plugin_mgr)
|
||||
self.assertEqual(2, len(c.definitions))
|
||||
e = c.to_event(self.test_notification1)
|
||||
e = c.to_event('INFO', self.test_notification1)
|
||||
self.assertIsValidEvent(e, self.test_notification1)
|
||||
self.assertEqual(3, len(e.traits))
|
||||
self.assertHasDefaultTraits(e)
|
||||
self.assertHasTrait(e, 'instance_id')
|
||||
self.assertHasTrait(e, 'host')
|
||||
|
||||
e = c.to_event(self.test_notification2)
|
||||
e = c.to_event('INFO', self.test_notification2)
|
||||
self.assertIsValidEvent(e, self.test_notification2)
|
||||
self.assertEqual(1, len(e.traits))
|
||||
self.assertHasDefaultTraits(e)
|
||||
|
@ -648,14 +647,14 @@ class TestNotificationConverter(ConverterBase):
|
|||
c = converter.NotificationEventsConverter(
|
||||
self.CONF, self.valid_event_def1, self.fake_plugin_mgr)
|
||||
self.assertEqual(1, len(c.definitions))
|
||||
e = c.to_event(self.test_notification1)
|
||||
e = c.to_event('INFO', self.test_notification1)
|
||||
self.assertIsValidEvent(e, self.test_notification1)
|
||||
self.assertEqual(3, len(e.traits))
|
||||
self.assertHasDefaultTraits(e)
|
||||
self.assertHasTrait(e, 'instance_id')
|
||||
self.assertHasTrait(e, 'host')
|
||||
|
||||
e = c.to_event(self.test_notification2)
|
||||
e = c.to_event('INFO', self.test_notification2)
|
||||
self.assertIsNotValidEvent(e, self.test_notification2)
|
||||
|
||||
def test_converter_empty_cfg_with_catchall(self):
|
||||
|
@ -664,12 +663,12 @@ class TestNotificationConverter(ConverterBase):
|
|||
c = converter.NotificationEventsConverter(
|
||||
self.CONF, [], self.fake_plugin_mgr)
|
||||
self.assertEqual(1, len(c.definitions))
|
||||
e = c.to_event(self.test_notification1)
|
||||
e = c.to_event('INFO', self.test_notification1)
|
||||
self.assertIsValidEvent(e, self.test_notification1)
|
||||
self.assertEqual(1, len(e.traits))
|
||||
self.assertHasDefaultTraits(e)
|
||||
|
||||
e = c.to_event(self.test_notification2)
|
||||
e = c.to_event('INFO', self.test_notification2)
|
||||
self.assertIsValidEvent(e, self.test_notification2)
|
||||
self.assertEqual(1, len(e.traits))
|
||||
self.assertHasDefaultTraits(e)
|
||||
|
@ -680,18 +679,18 @@ class TestNotificationConverter(ConverterBase):
|
|||
c = converter.NotificationEventsConverter(
|
||||
self.CONF, [], self.fake_plugin_mgr)
|
||||
self.assertEqual(0, len(c.definitions))
|
||||
e = c.to_event(self.test_notification1)
|
||||
e = c.to_event('INFO', self.test_notification1)
|
||||
self.assertIsNotValidEvent(e, self.test_notification1)
|
||||
|
||||
e = c.to_event(self.test_notification2)
|
||||
e = c.to_event('INFO', self.test_notification2)
|
||||
self.assertIsNotValidEvent(e, self.test_notification2)
|
||||
|
||||
@staticmethod
|
||||
def _convert_message(convert, level):
|
||||
message = {'priority': level, 'event_type': "foo",
|
||||
'message_id': "abc", 'publisher_id': "1",
|
||||
'timestamp': "2013-08-08 21:06:37.803826"}
|
||||
return convert.to_event(message)
|
||||
message = {'priority': level, 'event_type': "foo", 'publisher_id': "1",
|
||||
'metadata': {'message_id': "abc",
|
||||
'timestamp': "2013-08-08 21:06:37.803826"}}
|
||||
return convert.to_event(level, message)
|
||||
|
||||
def test_store_raw_all(self):
|
||||
self.CONF.set_override('store_raw', ['info', 'error'],
|
||||
|
|
|
@ -649,7 +649,8 @@ VOLTAGE_DATA = {
|
|||
|
||||
|
||||
SENSOR_DATA = {
|
||||
'message_id': 'f22188ca-c068-47ce-a3e5-0e27ffe234c6',
|
||||
'metadata': {'message_id': 'f22188ca-c068-47ce-a3e5-0e27ffe234c6',
|
||||
'timestamp': '2015-06-1909:19:35.786893'},
|
||||
'publisher_id': 'f23188ca-c068-47ce-a3e5-0e27ffe234c6',
|
||||
'payload': {
|
||||
'instance_uuid': 'f11251ax-c568-25ca-4582-0x27add644c6',
|
||||
|
@ -667,7 +668,8 @@ SENSOR_DATA = {
|
|||
|
||||
|
||||
EMPTY_PAYLOAD = {
|
||||
'message_id': 'f22188ca-c068-47ce-a3e5-0e27ffe234c6',
|
||||
'metadata': {'message_id': 'f22188ca-c068-47ce-a3e5-0e27ffe234c6',
|
||||
'timestamp': '2015-06-1909:19:35.786893'},
|
||||
'publisher_id': 'f23188ca-c068-47ce-a3e5-0e27ffe234c6',
|
||||
'payload': {
|
||||
'instance_uuid': 'f11251ax-c568-25ca-4582-0x27add644c6',
|
||||
|
@ -681,7 +683,8 @@ EMPTY_PAYLOAD = {
|
|||
|
||||
|
||||
MISSING_SENSOR = {
|
||||
'message_id': 'f22188ca-c068-47ce-a3e5-0e27ffe234c6',
|
||||
'metadata': {'message_id': 'f22188ca-c068-47ce-a3e5-0e27ffe234c6',
|
||||
'timestamp': '2015-06-1909:19:35.786893'},
|
||||
'publisher_id': 'f23188ca-c068-47ce-a3e5-0e27ffe234c6',
|
||||
'payload': {
|
||||
'instance_uuid': 'f11251ax-c568-25ca-4582-0x27add644c6',
|
||||
|
@ -719,7 +722,8 @@ MISSING_SENSOR = {
|
|||
|
||||
|
||||
BAD_SENSOR = {
|
||||
'message_id': 'f22188ca-c068-47ce-a3e5-0e27ffe234c6',
|
||||
'metadata': {'message_id': 'f22188ca-c068-47ce-a3e5-0e27ffe234c6',
|
||||
'timestamp': '2015-06-1909:19:35.786893'},
|
||||
'publisher_id': 'f23188ca-c068-47ce-a3e5-0e27ffe234c6',
|
||||
'payload': {
|
||||
'instance_uuid': 'f11251ax-c568-25ca-4582-0x27add644c6',
|
||||
|
@ -758,6 +762,8 @@ BAD_SENSOR = {
|
|||
|
||||
|
||||
NO_SENSOR_ID = {
|
||||
'metadata': {'message_id': 'f22188ca-c068-47ce-a3e5-0e27ffe234c6',
|
||||
'timestamp': '2015-06-1909:19:35.786893'},
|
||||
'message_id': 'f22188ca-c068-47ce-a3e5-0e27ffe234c6',
|
||||
'publisher_id': 'f23188ca-c068-47ce-a3e5-0e27ffe234c6',
|
||||
'payload': {
|
||||
|
@ -777,7 +783,8 @@ NO_SENSOR_ID = {
|
|||
|
||||
|
||||
NO_NODE_ID = {
|
||||
'message_id': 'f22188ca-c068-47ce-a3e5-0e27ffe234c6',
|
||||
'metadata': {'message_id': 'f22188ca-c068-47ce-a3e5-0e27ffe234c6',
|
||||
'timestamp': '2015-06-1909:19:35.786893'},
|
||||
'publisher_id': 'f23188ca-c068-47ce-a3e5-0e27ffe234c6',
|
||||
'payload': {
|
||||
'instance_uuid': 'f11251ax-c568-25ca-4582-0x27add644c6',
|
||||
|
|
|
@ -28,7 +28,8 @@ from ceilometer.tests import base as test
|
|||
|
||||
NOTIFICATION = {
|
||||
'event_type': u'test.create',
|
||||
'timestamp': u'2015-06-1909: 19: 35.786893',
|
||||
'metadata': {'timestamp': u'2015-06-1909: 19: 35.786893',
|
||||
'message_id': u'939823de-c242-45a2-a399-083f4d6a8c3e'},
|
||||
'payload': {u'user_id': u'e1d870e51c7340cb9d555b15cbfcaec2',
|
||||
u'resource_id': u'bea70e51c7340cb9d555b15cbfcaec23',
|
||||
u'timestamp': u'2015-06-19T09:19:35.785330',
|
||||
|
@ -40,16 +41,16 @@ NOTIFICATION = {
|
|||
u'volume': 1.0,
|
||||
u'project_id': u'30be1fc9a03c4e94ab05c403a8a377f2',
|
||||
},
|
||||
u'_context_tenant': u'30be1fc9a03c4e94ab05c403a8a377f2',
|
||||
u'_context_request_id': u'req-da91b4bf-d2b5-43ae-8b66-c7752e72726d',
|
||||
u'_context_user': u'e1d870e51c7340cb9d555b15cbfcaec2',
|
||||
'message_id': u'939823de-c242-45a2-a399-083f4d6a8c3e',
|
||||
'ctxt': {u'tenant': u'30be1fc9a03c4e94ab05c403a8a377f2',
|
||||
u'request_id': u'req-da91b4bf-d2b5-43ae-8b66-c7752e72726d',
|
||||
u'user': u'e1d870e51c7340cb9d555b15cbfcaec2'},
|
||||
'publisher_id': "foo123"
|
||||
}
|
||||
|
||||
USER_META = {
|
||||
'event_type': u'test.create',
|
||||
'timestamp': u'2015-06-1909: 19: 35.786893',
|
||||
'metadata': {'timestamp': u'2015-06-1909: 19: 35.786893',
|
||||
'message_id': u'939823de-c242-45a2-a399-083f4d6a8c3e'},
|
||||
'payload': {u'user_id': u'e1d870e51c7340cb9d555b15cbfcaec2',
|
||||
u'resource_id': u'bea70e51c7340cb9d555b15cbfcaec23',
|
||||
u'timestamp': u'2015-06-19T09:19:35.785330',
|
||||
|
@ -62,36 +63,34 @@ USER_META = {
|
|||
u'project_id': u'30be1fc9a03c4e94ab05c403a8a377f2',
|
||||
u'metadata': {u'metering.xyz': u'abc', u'ignore': u'this'},
|
||||
},
|
||||
u'_context_tenant': u'30be1fc9a03c4e94ab05c403a8a377f2',
|
||||
u'_context_request_id': u'req-da91b4bf-d2b5-43ae-8b66-c7752e72726d',
|
||||
u'_context_user': u'e1d870e51c7340cb9d555b15cbfcaec2',
|
||||
'message_id': u'939823de-c242-45a2-a399-083f4d6a8c3e',
|
||||
'ctxt': {u'tenant': u'30be1fc9a03c4e94ab05c403a8a377f2',
|
||||
u'request_id': u'req-da91b4bf-d2b5-43ae-8b66-c7752e72726d',
|
||||
u'user': u'e1d870e51c7340cb9d555b15cbfcaec2'},
|
||||
'publisher_id': "foo123"
|
||||
}
|
||||
|
||||
MIDDLEWARE_EVENT = {
|
||||
u'_context_request_id': u'req-a8bfa89b-d28b-4b95-9e4b-7d7875275650',
|
||||
u'_context_quota_class': None,
|
||||
u'ctxt': {u'request_id': u'req-a8bfa89b-d28b-4b95-9e4b-7d7875275650',
|
||||
u'quota_class': None,
|
||||
u'service_catalog': [],
|
||||
u'auth_token': None,
|
||||
u'user_id': None,
|
||||
u'is_admin': True,
|
||||
u'user': None,
|
||||
u'remote_address': None,
|
||||
u'roles': [],
|
||||
u'timestamp': u'2013-07-29T06:51:34.348091',
|
||||
u'project_name': None,
|
||||
u'read_deleted': u'no',
|
||||
u'tenant': None,
|
||||
u'instance_lock_checked': False,
|
||||
u'project_id': None,
|
||||
u'user_name': None},
|
||||
u'event_type': u'objectstore.http.request',
|
||||
u'_context_service_catalog': [],
|
||||
u'_context_auth_token': None,
|
||||
u'_context_user_id': None,
|
||||
u'priority': u'INFO',
|
||||
u'_context_is_admin': True,
|
||||
u'_context_user': None,
|
||||
u'publisher_id': u'ceilometermiddleware',
|
||||
u'message_id': u'6eccedba-120e-4db8-9735-2ad5f061e5ee',
|
||||
u'_context_remote_address': None,
|
||||
u'_context_roles': [],
|
||||
u'timestamp': u'2013-07-29 06:51:34.474815',
|
||||
u'_context_timestamp': u'2013-07-29T06:51:34.348091',
|
||||
u'_unique_id': u'0ee26117077648e18d88ac76e28a72e2',
|
||||
u'_context_project_name': None,
|
||||
u'_context_read_deleted': u'no',
|
||||
u'_context_tenant': None,
|
||||
u'_context_instance_lock_checked': False,
|
||||
u'_context_project_id': None,
|
||||
u'_context_user_name': None,
|
||||
u'metadata': {u'message_id': u'6eccedba-120e-4db8-9735-2ad5f061e5ee',
|
||||
u'timestamp': u'2013-07-29 06:51:34.474815',
|
||||
u'_unique_id': u'0ee26117077648e18d88ac76e28a72e2'},
|
||||
u'payload': {
|
||||
'typeURI': 'http: //schemas.dmtf.org/cloud/audit/1.0/event',
|
||||
'eventTime': '2015-01-30T16: 38: 43.233621',
|
||||
|
@ -140,12 +139,7 @@ MIDDLEWARE_EVENT = {
|
|||
}
|
||||
|
||||
FULL_MULTI_MSG = {
|
||||
u'_context_domain': None,
|
||||
u'_context_request_id': u'req-da91b4bf-d2b5-43ae-8b66-c7752e72726d',
|
||||
'event_type': u'full.sample',
|
||||
'timestamp': u'2015-06-1909: 19: 35.786893',
|
||||
u'_context_auth_token': None,
|
||||
u'_context_read_only': False,
|
||||
'payload': [{
|
||||
u'counter_name': u'instance1',
|
||||
u'user_id': u'user1',
|
||||
|
@ -164,26 +158,25 @@ FULL_MULTI_MSG = {
|
|||
u'project_id': u'proj2',
|
||||
u'counter_type': u'delta'
|
||||
}],
|
||||
u'_context_resource_uuid': None,
|
||||
u'_context_user_identity': u'fake_user_identity---',
|
||||
u'_context_show_deleted': False,
|
||||
u'_context_tenant': u'30be1fc9a03c4e94ab05c403a8a377f2',
|
||||
'priority': 'info',
|
||||
u'_context_is_admin': True,
|
||||
u'_context_project_domain': None,
|
||||
u'_context_user': u'e1d870e51c7340cb9d555b15cbfcaec2',
|
||||
u'_context_user_domain': None,
|
||||
u'ctxt': {u'domain': None,
|
||||
u'request_id': u'req-da91b4bf-d2b5-43ae-8b66-c7752e72726d',
|
||||
u'auth_token': None,
|
||||
u'read_only': False,
|
||||
u'resource_uuid': None,
|
||||
u'user_identity': u'fake_user_identity---',
|
||||
u'show_deleted': False,
|
||||
u'tenant': u'30be1fc9a03c4e94ab05c403a8a377f2',
|
||||
u'is_admin': True,
|
||||
u'project_domain': None,
|
||||
u'user': u'e1d870e51c7340cb9d555b15cbfcaec2',
|
||||
u'user_domain': None},
|
||||
'publisher_id': u'ceilometer.api',
|
||||
'message_id': u'939823de-c242-45a2-a399-083f4d6a8c3e'
|
||||
'metadata': {'message_id': u'939823de-c242-45a2-a399-083f4d6a8c3e',
|
||||
'timestamp': u'2015-06-1909: 19: 35.786893'},
|
||||
}
|
||||
|
||||
METRICS_UPDATE = {
|
||||
u'_context_request_id': u'req-a8bfa89b-d28b-4b95-9e4b-7d7875275650',
|
||||
u'_context_quota_class': None,
|
||||
u'event_type': u'compute.metrics.update',
|
||||
u'_context_service_catalog': [],
|
||||
u'_context_auth_token': None,
|
||||
u'_context_user_id': None,
|
||||
u'payload': {
|
||||
u'metrics': [
|
||||
{'timestamp': u'2013-07-29T06:51:34.472416',
|
||||
|
@ -219,22 +212,26 @@ METRICS_UPDATE = {
|
|||
u'nodename': u'tianst.sh.intel.com',
|
||||
u'host': u'tianst',
|
||||
u'host_id': u'10.0.1.1'},
|
||||
u'priority': u'INFO',
|
||||
u'_context_is_admin': True,
|
||||
u'_context_user': None,
|
||||
u'publisher_id': u'compute.tianst.sh.intel.com',
|
||||
u'message_id': u'6eccedba-120e-4db8-9735-2ad5f061e5ee',
|
||||
u'_context_remote_address': None,
|
||||
u'_context_roles': [],
|
||||
u'timestamp': u'2013-07-29 06:51:34.474815',
|
||||
u'_context_timestamp': u'2013-07-29T06:51:34.348091',
|
||||
u'_unique_id': u'0ee26117077648e18d88ac76e28a72e2',
|
||||
u'_context_project_name': None,
|
||||
u'_context_read_deleted': u'no',
|
||||
u'_context_tenant': None,
|
||||
u'_context_instance_lock_checked': False,
|
||||
u'_context_project_id': None,
|
||||
u'_context_user_name': None
|
||||
u'metadata': {u'message_id': u'6eccedba-120e-4db8-9735-2ad5f061e5ee',
|
||||
u'timestamp': u'2013-07-29 06:51:34.474815',
|
||||
u'_unique_id': u'0ee26117077648e18d88ac76e28a72e2'},
|
||||
u'ctxt': {u'request_id': u'req-a8bfa89b-d28b-4b95-9e4b-7d7875275650',
|
||||
u'quota_class': None,
|
||||
u'service_catalog': [],
|
||||
u'auth_token': None,
|
||||
u'user_id': None,
|
||||
u'is_admin': True,
|
||||
u'user': None,
|
||||
u'remote_address': None,
|
||||
u'roles': [],
|
||||
u'timestamp': u'2013-07-29T06:51:34.348091',
|
||||
u'project_name': None,
|
||||
u'read_deleted': u'no',
|
||||
u'tenant': None,
|
||||
u'instance_lock_checked': False,
|
||||
u'project_id': None,
|
||||
u'user_name': None}
|
||||
}
|
||||
|
||||
|
||||
|
@ -413,7 +410,8 @@ class TestMeterProcessing(test.BaseTestCase):
|
|||
c = list(self.handler.process_notification(event))
|
||||
self.assertEqual(1, len(c))
|
||||
s1 = c[0].as_dict()
|
||||
self.assertEqual(MIDDLEWARE_EVENT['timestamp'], s1['timestamp'])
|
||||
self.assertEqual(MIDDLEWARE_EVENT['metadata']['timestamp'],
|
||||
s1['timestamp'])
|
||||
|
||||
def test_custom_timestamp(self):
|
||||
event = copy.deepcopy(MIDDLEWARE_EVENT)
|
||||
|
|
|
@ -20,40 +20,39 @@ from ceilometer.tests import base
|
|||
|
||||
|
||||
HTTP_REQUEST = {
|
||||
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'ctxt': {u'auth_token': u'3d8b13de1b7d499587dfc69b77dc09c2',
|
||||
u'is_admin': True,
|
||||
u'project_id': u'7c150a59fe714e6f9263774af9688f0e',
|
||||
u'quota_class': None,
|
||||
u'read_deleted': u'no',
|
||||
u'remote_address': u'10.0.2.15',
|
||||
u'request_id': u'req-d68b36e0-9233-467f-9afb-d81435d64d66',
|
||||
u'roles': [u'admin'],
|
||||
u'timestamp': u'2012-05-08T20:23:41.425105',
|
||||
u'user_id': u'1e3ce043029547f1a61c1996d1a531a2'},
|
||||
u'event_type': u'http.request',
|
||||
u'message_id': u'dae6f69c-00e0-41c0-b371-41ec3b7f4451',
|
||||
u'payload': {u'request': {'HTTP_X_FOOBAR': 'foobaz',
|
||||
'HTTP_X_USER_ID': 'jd-x32',
|
||||
'HTTP_X_PROJECT_ID': 'project-id',
|
||||
'HTTP_X_SERVICE_NAME': 'nova'}},
|
||||
u'priority': u'INFO',
|
||||
u'publisher_id': u'compute.vagrant-precise',
|
||||
u'timestamp': u'2012-05-08 20:23:48.028195',
|
||||
u'metadata': {u'message_id': u'dae6f69c-00e0-41c0-b371-41ec3b7f4451',
|
||||
u'timestamp': u'2012-05-08 20:23:48.028195'},
|
||||
}
|
||||
|
||||
HTTP_RESPONSE = {
|
||||
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'ctxt': {u'auth_token': u'3d8b13de1b7d499587dfc69b77dc09c2',
|
||||
u'is_admin': True,
|
||||
u'project_id': u'7c150a59fe714e6f9263774af9688f0e',
|
||||
u'quota_class': None,
|
||||
u'read_deleted': u'no',
|
||||
u'remote_address': u'10.0.2.15',
|
||||
u'request_id': u'req-d68b36e0-9233-467f-9afb-d81435d64d66',
|
||||
u'roles': [u'admin'],
|
||||
u'timestamp': u'2012-05-08T20:23:41.425105',
|
||||
u'user_id': u'1e3ce043029547f1a61c1996d1a531a2'},
|
||||
u'event_type': u'http.response',
|
||||
u'message_id': u'dae6f69c-00e0-41c0-b371-41ec3b7f4451',
|
||||
u'payload': {u'request': {'HTTP_X_FOOBAR': 'foobaz',
|
||||
'HTTP_X_USER_ID': 'jd-x32',
|
||||
'HTTP_X_PROJECT_ID': 'project-id',
|
||||
|
@ -61,7 +60,8 @@ HTTP_RESPONSE = {
|
|||
u'response': {'status': '200 OK'}},
|
||||
u'priority': u'INFO',
|
||||
u'publisher_id': u'compute.vagrant-precise',
|
||||
u'timestamp': u'2012-05-08 20:23:48.028195',
|
||||
u'metadata': {u'message_id': u'dae6f69c-00e0-41c0-b371-41ec3b7f4451',
|
||||
u'timestamp': u'2012-05-08 20:23:48.028195'},
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -40,11 +40,12 @@ class TestSample(base.BaseTestCase):
|
|||
def test_sample_from_notifications_list(self):
|
||||
msg = {
|
||||
'event_type': u'sample.create',
|
||||
'timestamp': u'2015-06-1909: 19: 35.786893',
|
||||
'metadata': {
|
||||
'timestamp': u'2015-06-1909: 19: 35.786893',
|
||||
'message_id': u'939823de-c242-45a2-a399-083f4d6a8c3e'},
|
||||
'payload': [{u'counter_name': u'instance100'}],
|
||||
'priority': 'info',
|
||||
'publisher_id': u'ceilometer.api',
|
||||
'message_id': u'939823de-c242-45a2-a399-083f4d6a8c3e'
|
||||
}
|
||||
s = sample.Sample.from_notification(
|
||||
'sample', 'type', 1.0, '%', 'user', 'project', 'res', msg)
|
||||
|
@ -55,11 +56,12 @@ class TestSample(base.BaseTestCase):
|
|||
def test_sample_from_notifications_dict(self):
|
||||
msg = {
|
||||
'event_type': u'sample.create',
|
||||
'timestamp': u'2015-06-1909: 19: 35.786893',
|
||||
'metadata': {
|
||||
'timestamp': u'2015-06-1909: 19: 35.786893',
|
||||
'message_id': u'939823de-c242-45a2-a399-083f4d6a8c3e'},
|
||||
'payload': {u'counter_name': u'instance100'},
|
||||
'priority': 'info',
|
||||
'publisher_id': u'ceilometer.api',
|
||||
'message_id': u'939823de-c242-45a2-a399-083f4d6a8c3e'
|
||||
}
|
||||
s = sample.Sample.from_notification(
|
||||
'sample', 'type', 1.0, '%', 'user', 'project', 'res', msg)
|
||||
|
|
Loading…
Reference in New Issue