2
# Licensed under the Apache License, Version 2.0 (the "License"); you may
3
# not use this file except in compliance with the License. You may obtain
4
# a copy of the License at
6
# http://www.apache.org/licenses/LICENSE-2.0
8
# Unless required by applicable law or agreed to in writing, software
9
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11
# License for the specific language governing permissions and limitations
13
"""Tests for swift notification events."""
16
from ceilometer.objectstore import notifications
17
from ceilometer.tests import base as test
21
u'_context_request_id': u'req-a8bfa89b-d28b-4b95-9e4b-7d7875275650',
22
u'_context_quota_class': None,
23
u'event_type': u'objectstore.http.request',
24
u'_context_service_catalog': [],
25
u'_context_auth_token': None,
26
u'_context_user_id': None,
28
u'_context_is_admin': True,
29
u'_context_user': None,
30
u'publisher_id': u'ceilometermiddleware',
31
u'message_id': u'6eccedba-120e-4db8-9735-2ad5f061e5ee',
32
u'_context_remote_address': None,
33
u'_context_roles': [],
34
u'timestamp': u'2013-07-29 06:51:34.474815',
35
u'_context_timestamp': u'2013-07-29T06:51:34.348091',
36
u'_unique_id': u'0ee26117077648e18d88ac76e28a72e2',
37
u'_context_project_name': None,
38
u'_context_read_deleted': u'no',
39
u'_context_tenant': None,
40
u'_context_instance_lock_checked': False,
41
u'_context_project_id': None,
42
u'_context_user_name': None,
44
'typeURI': 'http: //schemas.dmtf.org/cloud/audit/1.0/event',
45
'eventTime': '2015-01-30T16: 38: 43.233621',
48
'typeURI': 'service/storage/object',
51
'path': '/1.0/CUSTOM_account/container/obj',
53
'container': 'container',
60
'eventType': 'activity',
64
'metricId': 'openstack: uuid',
65
'name': 'storage.objects.outgoing.bytes',
72
'metricId': 'openstack: uuid2',
73
'name': 'storage.objects.incoming.bytes',
80
'typeURI': 'service/security/account/user',
82
'id': 'openstack: 288f6260-bf37-4737-a178-5038c84ba244'
86
'id': 'openstack: 69972bb6-14dd-46e4-bdaf-3148014363dc'
91
class TestMiddlewareNotifications(test.BaseTestCase):
92
def test_middleware_event(self):
93
v = notifications.SwiftWsgiMiddleware(mock.Mock())
94
samples = list(v.process_notification(MIDDLEWARE_EVENT))
95
self.assertEqual(3, len(samples))
97
measure = MIDDLEWARE_EVENT['payload']['measurements'][i]
98
self.assertEqual(measure['metric']['name'], samples[i].name)
99
self.assertEqual(measure['metric']['unit'], samples[i].unit)
100
self.assertEqual(measure['result'], samples[i].volume)
101
target = MIDDLEWARE_EVENT['payload']['target']
102
initiator = MIDDLEWARE_EVENT['payload']['initiator']
104
self.assertEqual(target['id'], samples[i].resource_id)
105
self.assertEqual(initiator['id'], samples[i].user_id)
106
self.assertEqual(initiator['project_id'], samples[i].project_id)