~ubuntu-branches/ubuntu/saucy/ceilometer/saucy

« back to all changes in this revision

Viewing changes to tests/api/v2/list_meters.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Yolanda Robla, Chuck Short, James Page
  • Date: 2013-07-19 10:04:36 UTC
  • mfrom: (1.1.5)
  • Revision ID: package-import@ubuntu.com-20130719100436-8ppgb9laoyr60zyr
Tags: 2013.2~b2-0ubuntu1
[ Yolanda Robla ]
* debian/patches/default-dbconnection-sqlite.patch: updated db section

[ Chuck Short ]
* New upstream version.
* debian/patches/default-dbconnection-sqlite.patch: Refreshed.
* debian/control: Bump requirements for stevedore to 0.9.
* debian/control: Add python-simplejson
* debian/control: Drop python-keystoneclient hardcoded version.
* debian/control: Add python-testscenarios as a build depends.
* debian/control: Add python-cinderclient as a build depends.
* debian/control: Add python-ceilometerclient as a build depends.
* debian/control: Add python-alembic as build depends.
* debian/control: Add python-oslo.sphinx as build-depends.
* debian/control: Update runtime depends.
* debian/control: Add python-happybase.
* debian/ceilometer-common.install: Add ceilometer-alarm-singleton,
  ceilometer-alarm-notifier, and ceilometer-expirer.
* debian/patches/skip-database-tests.patch: Skip database tests
  if the database is not installed.

[ James Page ]
* d/control: Update VCS fields for new branch locations.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- encoding: utf-8 -*-
 
2
#
 
3
# Copyright 2012 Red Hat, Inc.
 
4
#
 
5
# Author: Angus Salkeld <asalkeld@redhat.com>
 
6
#
 
7
# Licensed under the Apache License, Version 2.0 (the "License"); you may
 
8
# not use this file except in compliance with the License. You may obtain
 
9
# a copy of the License at
 
10
#
 
11
#      http://www.apache.org/licenses/LICENSE-2.0
 
12
#
 
13
# Unless required by applicable law or agreed to in writing, software
 
14
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 
15
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 
16
# License for the specific language governing permissions and limitations
 
17
# under the License.
 
18
"""Test listing meters.
 
19
"""
 
20
 
 
21
import datetime
 
22
import logging
 
23
 
 
24
from oslo.config import cfg
 
25
 
 
26
from ceilometer.publisher import rpc
 
27
from ceilometer import counter
 
28
 
 
29
from .base import FunctionalTest
 
30
 
 
31
LOG = logging.getLogger(__name__)
 
32
 
 
33
 
 
34
class TestListEmptyMeters(FunctionalTest):
 
35
 
 
36
    def test_empty(self):
 
37
        data = self.get_json('/meters')
 
38
        self.assertEquals([], data)
 
39
 
 
40
 
 
41
class TestListMeters(FunctionalTest):
 
42
 
 
43
    def setUp(self):
 
44
        super(TestListMeters, self).setUp()
 
45
 
 
46
        for cnt in [
 
47
                counter.Counter(
 
48
                    'meter.test',
 
49
                    'cumulative',
 
50
                    '',
 
51
                    1,
 
52
                    'user-id',
 
53
                    'project-id',
 
54
                    'resource-id',
 
55
                    timestamp=datetime.datetime(2012, 7, 2, 10, 40),
 
56
                    resource_metadata={'display_name': 'test-server',
 
57
                                       'tag': 'self.counter'}),
 
58
                counter.Counter(
 
59
                    'meter.test',
 
60
                    'cumulative',
 
61
                    '',
 
62
                    3,
 
63
                    'user-id',
 
64
                    'project-id',
 
65
                    'resource-id',
 
66
                    timestamp=datetime.datetime(2012, 7, 2, 11, 40),
 
67
                    resource_metadata={'display_name': 'test-server',
 
68
                                       'tag': 'self.counter'}),
 
69
                counter.Counter(
 
70
                    'meter.mine',
 
71
                    'gauge',
 
72
                    '',
 
73
                    1,
 
74
                    'user-id',
 
75
                    'project-id',
 
76
                    'resource-id2',
 
77
                    timestamp=datetime.datetime(2012, 7, 2, 10, 41),
 
78
                    resource_metadata={'display_name': 'test-server',
 
79
                                       'tag': 'self.counter2'}),
 
80
                counter.Counter(
 
81
                    'meter.test',
 
82
                    'cumulative',
 
83
                    '',
 
84
                    1,
 
85
                    'user-id2',
 
86
                    'project-id2',
 
87
                    'resource-id3',
 
88
                    timestamp=datetime.datetime(2012, 7, 2, 10, 42),
 
89
                    resource_metadata={'display_name': 'test-server',
 
90
                                       'tag': 'self.counter3'}),
 
91
                counter.Counter(
 
92
                    'meter.mine',
 
93
                    'gauge',
 
94
                    '',
 
95
                    1,
 
96
                    'user-id4',
 
97
                    'project-id2',
 
98
                    'resource-id4',
 
99
                    timestamp=datetime.datetime(2012, 7, 2, 10, 43),
 
100
                    resource_metadata={'display_name': 'test-server',
 
101
                                       'tag': 'self.counter4'})]:
 
102
            msg = rpc.meter_message_from_counter(
 
103
                cnt,
 
104
                cfg.CONF.publisher_rpc.metering_secret,
 
105
                'test_source')
 
106
            self.conn.record_metering_data(msg)
 
107
 
 
108
    def test_list_meters(self):
 
109
        data = self.get_json('/meters')
 
110
        self.assertEquals(4, len(data))
 
111
        self.assertEquals(set(r['resource_id'] for r in data),
 
112
                          set(['resource-id',
 
113
                               'resource-id2',
 
114
                               'resource-id3',
 
115
                               'resource-id4']))
 
116
        self.assertEquals(set(r['name'] for r in data),
 
117
                          set(['meter.test',
 
118
                               'meter.mine']))
 
119
 
 
120
    def test_with_resource(self):
 
121
        data = self.get_json('/meters', q=[{'field': 'resource_id',
 
122
                                            'value': 'resource-id',
 
123
                                            }])
 
124
        ids = set(r['name'] for r in data)
 
125
        self.assertEquals(set(['meter.test']), ids)
 
126
 
 
127
    def test_with_source(self):
 
128
        data = self.get_json('/meters', q=[{'field': 'source',
 
129
                                            'value': 'test_source',
 
130
                                            }])
 
131
        ids = set(r['resource_id'] for r in data)
 
132
        self.assertEquals(set(['resource-id',
 
133
                               'resource-id2',
 
134
                               'resource-id3',
 
135
                               'resource-id4']), ids)
 
136
 
 
137
    def test_with_source_non_existent(self):
 
138
        data = self.get_json('/meters',
 
139
                             q=[{'field': 'source',
 
140
                                 'value': 'test_source_doesnt_exist',
 
141
                                 }],
 
142
                             )
 
143
        assert not data
 
144
 
 
145
    def test_with_user(self):
 
146
        data = self.get_json('/meters',
 
147
                             q=[{'field': 'user_id',
 
148
                                 'value': 'user-id',
 
149
                                 }],
 
150
                             )
 
151
 
 
152
        uids = set(r['user_id'] for r in data)
 
153
        self.assertEquals(set(['user-id']), uids)
 
154
 
 
155
        nids = set(r['name'] for r in data)
 
156
        self.assertEquals(set(['meter.mine', 'meter.test']), nids)
 
157
 
 
158
        rids = set(r['resource_id'] for r in data)
 
159
        self.assertEquals(set(['resource-id', 'resource-id2']), rids)
 
160
 
 
161
    def test_with_user_non_existent(self):
 
162
        data = self.get_json('/meters',
 
163
                             q=[{'field': 'user_id',
 
164
                                 'value': 'user-id-foobar123',
 
165
                                 }],
 
166
                             )
 
167
        self.assertEquals(data, [])
 
168
 
 
169
    def test_with_project(self):
 
170
        data = self.get_json('/meters',
 
171
                             q=[{'field': 'project_id',
 
172
                                 'value': 'project-id2',
 
173
                                 }],
 
174
                             )
 
175
        ids = set(r['resource_id'] for r in data)
 
176
        self.assertEquals(set(['resource-id3', 'resource-id4']), ids)
 
177
 
 
178
    def test_with_project_non_existent(self):
 
179
        data = self.get_json('/meters',
 
180
                             q=[{'field': 'project_id',
 
181
                                 'value': 'jd-was-here',
 
182
                                 }],
 
183
                             )
 
184
        self.assertEquals(data, [])