blob: 2b422fd736429c56e360fecb8fbc5f9e29680777 [file] [log] [blame]
Yassine Lamgarchal05638762013-12-27 20:10:32 +01001# Licensed under the Apache License, Version 2.0 (the "License"); you may
2# not use this file except in compliance with the License. You may obtain
3# a copy of the License at
4#
5# http://www.apache.org/licenses/LICENSE-2.0
6#
7# Unless required by applicable law or agreed to in writing, software
8# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10# License for the specific language governing permissions and limitations
11# under the License.
12
Vadim Rovachev7bcea352013-12-26 15:56:17 +040013import time
14
vrovachev95a16cc2014-02-04 15:29:48 +040015from tempest.common.utils import data_utils
Yassine Lamgarchal05638762013-12-27 20:10:32 +010016from tempest import config
vrovachev95a16cc2014-02-04 15:29:48 +040017from tempest import exceptions
Vadim Rovachev7bcea352013-12-26 15:56:17 +040018from tempest.openstack.common import timeutils
Yassine Lamgarchal05638762013-12-27 20:10:32 +010019import tempest.test
20
21CONF = config.CONF
22
23
24class BaseTelemetryTest(tempest.test.BaseTestCase):
25
26 """Base test case class for all Telemetry API tests."""
27
28 @classmethod
29 def setUpClass(cls):
Yassine Lamgarchal05638762013-12-27 20:10:32 +010030 if not CONF.service_available.ceilometer:
31 raise cls.skipException("Ceilometer support is required")
vrovachev95a16cc2014-02-04 15:29:48 +040032 super(BaseTelemetryTest, cls).setUpClass()
33 os = cls.get_client_manager()
34 cls.telemetry_client = os.telemetry_client
Vadim Rovachev7bcea352013-12-26 15:56:17 +040035 cls.servers_client = os.servers_client
36 cls.flavors_client = os.flavors_client
37
38 cls.nova_notifications = ['memory', 'vcpus', 'disk.root.size',
39 'disk.ephemeral.size']
40 cls.server_ids = []
vrovachev95a16cc2014-02-04 15:29:48 +040041 cls.alarm_ids = []
42
43 @classmethod
44 def create_alarm(cls, **kwargs):
45 resp, body = cls.telemetry_client.create_alarm(
46 name=data_utils.rand_name('telemetry_alarm'),
47 type='threshold', **kwargs)
48 if resp['status'] == '201':
49 cls.alarm_ids.append(body['alarm_id'])
50 return resp, body
51
52 @classmethod
Vadim Rovachev7bcea352013-12-26 15:56:17 +040053 def create_server(cls):
54 resp, body = cls.servers_client.create_server(
55 data_utils.rand_name('ceilometer-instance'),
56 CONF.compute.image_ref, CONF.compute.flavor_ref,
57 wait_until='ACTIVE')
58 if resp['status'] == '202':
59 cls.server_ids.append(body['id'])
60 return resp, body
61
62 @staticmethod
63 def cleanup_resources(method, list_of_ids):
64 for resource_id in list_of_ids:
vrovachev95a16cc2014-02-04 15:29:48 +040065 try:
Vadim Rovachev7bcea352013-12-26 15:56:17 +040066 method(resource_id)
vrovachev95a16cc2014-02-04 15:29:48 +040067 except exceptions.NotFound:
68 pass
Vadim Rovachev7bcea352013-12-26 15:56:17 +040069
70 @classmethod
71 def tearDownClass(cls):
72 cls.cleanup_resources(cls.telemetry_client.delete_alarm, cls.alarm_ids)
73 cls.cleanup_resources(cls.servers_client.delete_server, cls.server_ids)
vrovachev95a16cc2014-02-04 15:29:48 +040074 cls.clear_isolated_creds()
75 super(BaseTelemetryTest, cls).tearDownClass()
Vadim Rovachev7bcea352013-12-26 15:56:17 +040076
77 def await_samples(self, metric, query):
78 """
79 This method is to wait for sample to add it to database.
80 There are long time delays when using Postgresql (or Mysql)
81 database as ceilometer backend
82 """
83 timeout = CONF.compute.build_timeout
84 start = timeutils.utcnow()
85 while timeutils.delta_seconds(start, timeutils.utcnow()) < timeout:
86 resp, body = self.telemetry_client.list_samples(metric, query)
87 self.assertEqual(resp.status, 200)
88 if body:
89 return resp, body
90 time.sleep(CONF.compute.build_interval)
91
92 raise exceptions.TimeoutException(
93 'Sample for metric:%s with query:%s has not been added to the '
94 'database within %d seconds' % (metric, query,
95 CONF.compute.build_timeout))