~ubuntu-branches/ubuntu/vivid/ceilometer/vivid

« back to all changes in this revision

Viewing changes to ceilometer/tests/objectstore/test_notifications.py

  • Committer: Package Import Robot
  • Author(s): James Page, Corey Bryant, James Page
  • Date: 2015-02-19 14:59:07 UTC
  • mfrom: (1.2.3)
  • Revision ID: package-import@ubuntu.com-20150219145907-9jojybdsl64zcn14
Tags: 2015.1~b2-0ubuntu1
[ Corey Bryant ]
* New upstream release.
  - d/control: Align requirements with upstream.
  - d/p/skip-test.patch: Rebased.

[ James Page ]
* d/rules,d/p/skip-gabbi.patch: Skip tests that rely on python-gabbi until
  packaging and MIR is complete.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
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
 
5
#
 
6
#      http://www.apache.org/licenses/LICENSE-2.0
 
7
#
 
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
 
12
# under the License.
 
13
"""Tests for swift notification events."""
 
14
import mock
 
15
 
 
16
from ceilometer.objectstore import notifications
 
17
from ceilometer.tests import base as test
 
18
 
 
19
 
 
20
MIDDLEWARE_EVENT = {
 
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,
 
27
    u'priority': u'INFO',
 
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,
 
43
    u'payload': {
 
44
        'typeURI': 'http: //schemas.dmtf.org/cloud/audit/1.0/event',
 
45
        'eventTime': '2015-01-30T16: 38: 43.233621',
 
46
        'target': {
 
47
            'action': 'get',
 
48
            'typeURI': 'service/storage/object',
 
49
            'id': 'account',
 
50
            'metadata': {
 
51
                'path': '/1.0/CUSTOM_account/container/obj',
 
52
                'version': '1.0',
 
53
                'container': 'container',
 
54
                'object': 'obj'
 
55
            }
 
56
        },
 
57
        'observer': {
 
58
            'id': 'target'
 
59
        },
 
60
        'eventType': 'activity',
 
61
        'measurements': [
 
62
            {
 
63
                'metric': {
 
64
                    'metricId': 'openstack: uuid',
 
65
                    'name': 'storage.objects.outgoing.bytes',
 
66
                    'unit': 'B'
 
67
                },
 
68
                'result': 28
 
69
            },
 
70
            {
 
71
                'metric': {
 
72
                    'metricId': 'openstack: uuid2',
 
73
                    'name': 'storage.objects.incoming.bytes',
 
74
                    'unit': 'B'
 
75
                },
 
76
                'result': 1
 
77
            }
 
78
        ],
 
79
        'initiator': {
 
80
            'typeURI': 'service/security/account/user',
 
81
            'project_id': None,
 
82
            'id': 'openstack: 288f6260-bf37-4737-a178-5038c84ba244'
 
83
        },
 
84
        'action': 'read',
 
85
        'outcome': 'success',
 
86
        'id': 'openstack: 69972bb6-14dd-46e4-bdaf-3148014363dc'
 
87
    }
 
88
}
 
89
 
 
90
 
 
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))
 
96
        for i in range(2):
 
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']
 
103
        for i in range(3):
 
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)