1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
#
# 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 swift notification events."""
import mock
from ceilometer.objectstore import notifications
from ceilometer.tests import base as test
MIDDLEWARE_EVENT = {
u'_context_request_id': u'req-a8bfa89b-d28b-4b95-9e4b-7d7875275650',
u'_context_quota_class': 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'payload': {
'typeURI': 'http: //schemas.dmtf.org/cloud/audit/1.0/event',
'eventTime': '2015-01-30T16: 38: 43.233621',
'target': {
'action': 'get',
'typeURI': 'service/storage/object',
'id': 'account',
'metadata': {
'path': '/1.0/CUSTOM_account/container/obj',
'version': '1.0',
'container': 'container',
'object': 'obj'
}
},
'observer': {
'id': 'target'
},
'eventType': 'activity',
'measurements': [
{
'metric': {
'metricId': 'openstack: uuid',
'name': 'storage.objects.outgoing.bytes',
'unit': 'B'
},
'result': 28
},
{
'metric': {
'metricId': 'openstack: uuid2',
'name': 'storage.objects.incoming.bytes',
'unit': 'B'
},
'result': 1
}
],
'initiator': {
'typeURI': 'service/security/account/user',
'project_id': None,
'id': 'openstack: 288f6260-bf37-4737-a178-5038c84ba244'
},
'action': 'read',
'outcome': 'success',
'id': 'openstack: 69972bb6-14dd-46e4-bdaf-3148014363dc'
}
}
class TestMiddlewareNotifications(test.BaseTestCase):
def test_middleware_event(self):
v = notifications.SwiftWsgiMiddleware(mock.Mock())
samples = list(v.process_notification(MIDDLEWARE_EVENT))
self.assertEqual(3, len(samples))
for i in range(2):
measure = MIDDLEWARE_EVENT['payload']['measurements'][i]
self.assertEqual(measure['metric']['name'], samples[i].name)
self.assertEqual(measure['metric']['unit'], samples[i].unit)
self.assertEqual(measure['result'], samples[i].volume)
target = MIDDLEWARE_EVENT['payload']['target']
initiator = MIDDLEWARE_EVENT['payload']['initiator']
for i in range(3):
self.assertEqual(target['id'], samples[i].resource_id)
self.assertEqual(initiator['id'], samples[i].user_id)
self.assertEqual(initiator['project_id'], samples[i].project_id)
|