Yassine Lamgarchal | 0563876 | 2013-12-27 20:10:32 +0100 | [diff] [blame] | 1 | # 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 Rovachev | 7bcea35 | 2013-12-26 15:56:17 +0400 | [diff] [blame] | 13 | import time |
| 14 | |
vrovachev | 95a16cc | 2014-02-04 15:29:48 +0400 | [diff] [blame] | 15 | from tempest.common.utils import data_utils |
Yassine Lamgarchal | 0563876 | 2013-12-27 20:10:32 +0100 | [diff] [blame] | 16 | from tempest import config |
vrovachev | 95a16cc | 2014-02-04 15:29:48 +0400 | [diff] [blame] | 17 | from tempest import exceptions |
Vadim Rovachev | 7bcea35 | 2013-12-26 15:56:17 +0400 | [diff] [blame] | 18 | from tempest.openstack.common import timeutils |
Yassine Lamgarchal | 0563876 | 2013-12-27 20:10:32 +0100 | [diff] [blame] | 19 | import tempest.test |
| 20 | |
| 21 | CONF = config.CONF |
| 22 | |
| 23 | |
| 24 | class BaseTelemetryTest(tempest.test.BaseTestCase): |
| 25 | |
| 26 | """Base test case class for all Telemetry API tests.""" |
| 27 | |
| 28 | @classmethod |
Andrea Frittoli | c76d04d | 2014-09-15 13:14:54 +0100 | [diff] [blame] | 29 | def resource_setup(cls): |
Yassine Lamgarchal | 0563876 | 2013-12-27 20:10:32 +0100 | [diff] [blame] | 30 | if not CONF.service_available.ceilometer: |
| 31 | raise cls.skipException("Ceilometer support is required") |
gordon chung | f59ac3b | 2014-08-20 11:35:13 -0400 | [diff] [blame] | 32 | cls.set_network_resources() |
Andrea Frittoli | c76d04d | 2014-09-15 13:14:54 +0100 | [diff] [blame] | 33 | super(BaseTelemetryTest, cls).resource_setup() |
vrovachev | 95a16cc | 2014-02-04 15:29:48 +0400 | [diff] [blame] | 34 | os = cls.get_client_manager() |
| 35 | cls.telemetry_client = os.telemetry_client |
Vadim Rovachev | 7bcea35 | 2013-12-26 15:56:17 +0400 | [diff] [blame] | 36 | cls.servers_client = os.servers_client |
| 37 | cls.flavors_client = os.flavors_client |
Vadim Rovachev | 80ee4e1 | 2014-02-05 16:59:07 +0400 | [diff] [blame] | 38 | cls.image_client = os.image_client |
| 39 | cls.image_client_v2 = os.image_client_v2 |
Vadim Rovachev | 7bcea35 | 2013-12-26 15:56:17 +0400 | [diff] [blame] | 40 | |
| 41 | cls.nova_notifications = ['memory', 'vcpus', 'disk.root.size', |
| 42 | 'disk.ephemeral.size'] |
Vadim Rovachev | 80ee4e1 | 2014-02-05 16:59:07 +0400 | [diff] [blame] | 43 | |
| 44 | cls.glance_notifications = ['image.update', 'image.upload', |
| 45 | 'image.delete'] |
| 46 | |
| 47 | cls.glance_v2_notifications = ['image.download', 'image.serve'] |
| 48 | |
Vadim Rovachev | 7bcea35 | 2013-12-26 15:56:17 +0400 | [diff] [blame] | 49 | cls.server_ids = [] |
vrovachev | 95a16cc | 2014-02-04 15:29:48 +0400 | [diff] [blame] | 50 | cls.alarm_ids = [] |
Vadim Rovachev | 80ee4e1 | 2014-02-05 16:59:07 +0400 | [diff] [blame] | 51 | cls.image_ids = [] |
vrovachev | 95a16cc | 2014-02-04 15:29:48 +0400 | [diff] [blame] | 52 | |
| 53 | @classmethod |
| 54 | def create_alarm(cls, **kwargs): |
David Kranz | 20d06f4 | 2015-02-09 14:54:15 -0500 | [diff] [blame^] | 55 | body = cls.telemetry_client.create_alarm( |
vrovachev | 95a16cc | 2014-02-04 15:29:48 +0400 | [diff] [blame] | 56 | name=data_utils.rand_name('telemetry_alarm'), |
| 57 | type='threshold', **kwargs) |
Vadim Rovachev | 80ee4e1 | 2014-02-05 16:59:07 +0400 | [diff] [blame] | 58 | cls.alarm_ids.append(body['alarm_id']) |
David Kranz | 20d06f4 | 2015-02-09 14:54:15 -0500 | [diff] [blame^] | 59 | return body |
vrovachev | 95a16cc | 2014-02-04 15:29:48 +0400 | [diff] [blame] | 60 | |
| 61 | @classmethod |
Vadim Rovachev | 7bcea35 | 2013-12-26 15:56:17 +0400 | [diff] [blame] | 62 | def create_server(cls): |
| 63 | resp, body = cls.servers_client.create_server( |
| 64 | data_utils.rand_name('ceilometer-instance'), |
| 65 | CONF.compute.image_ref, CONF.compute.flavor_ref, |
| 66 | wait_until='ACTIVE') |
Vadim Rovachev | 80ee4e1 | 2014-02-05 16:59:07 +0400 | [diff] [blame] | 67 | cls.server_ids.append(body['id']) |
| 68 | return resp, body |
| 69 | |
| 70 | @classmethod |
| 71 | def create_image(cls, client): |
David Kranz | a5299eb | 2015-01-15 17:24:05 -0500 | [diff] [blame] | 72 | body = client.create_image( |
Vadim Rovachev | 80ee4e1 | 2014-02-05 16:59:07 +0400 | [diff] [blame] | 73 | data_utils.rand_name('image'), container_format='bare', |
| 74 | disk_format='raw', visibility='private') |
| 75 | cls.image_ids.append(body['id']) |
David Kranz | a5299eb | 2015-01-15 17:24:05 -0500 | [diff] [blame] | 76 | return body |
Vadim Rovachev | 7bcea35 | 2013-12-26 15:56:17 +0400 | [diff] [blame] | 77 | |
| 78 | @staticmethod |
| 79 | def cleanup_resources(method, list_of_ids): |
| 80 | for resource_id in list_of_ids: |
vrovachev | 95a16cc | 2014-02-04 15:29:48 +0400 | [diff] [blame] | 81 | try: |
Vadim Rovachev | 7bcea35 | 2013-12-26 15:56:17 +0400 | [diff] [blame] | 82 | method(resource_id) |
vrovachev | 95a16cc | 2014-02-04 15:29:48 +0400 | [diff] [blame] | 83 | except exceptions.NotFound: |
| 84 | pass |
Vadim Rovachev | 7bcea35 | 2013-12-26 15:56:17 +0400 | [diff] [blame] | 85 | |
| 86 | @classmethod |
Andrea Frittoli | c76d04d | 2014-09-15 13:14:54 +0100 | [diff] [blame] | 87 | def resource_cleanup(cls): |
Vadim Rovachev | 7bcea35 | 2013-12-26 15:56:17 +0400 | [diff] [blame] | 88 | cls.cleanup_resources(cls.telemetry_client.delete_alarm, cls.alarm_ids) |
| 89 | cls.cleanup_resources(cls.servers_client.delete_server, cls.server_ids) |
Vadim Rovachev | 80ee4e1 | 2014-02-05 16:59:07 +0400 | [diff] [blame] | 90 | cls.cleanup_resources(cls.image_client.delete_image, cls.image_ids) |
vrovachev | 95a16cc | 2014-02-04 15:29:48 +0400 | [diff] [blame] | 91 | cls.clear_isolated_creds() |
Andrea Frittoli | c76d04d | 2014-09-15 13:14:54 +0100 | [diff] [blame] | 92 | super(BaseTelemetryTest, cls).resource_cleanup() |
Vadim Rovachev | 7bcea35 | 2013-12-26 15:56:17 +0400 | [diff] [blame] | 93 | |
| 94 | def await_samples(self, metric, query): |
| 95 | """ |
| 96 | This method is to wait for sample to add it to database. |
| 97 | There are long time delays when using Postgresql (or Mysql) |
| 98 | database as ceilometer backend |
| 99 | """ |
| 100 | timeout = CONF.compute.build_timeout |
| 101 | start = timeutils.utcnow() |
| 102 | while timeutils.delta_seconds(start, timeutils.utcnow()) < timeout: |
David Kranz | 20d06f4 | 2015-02-09 14:54:15 -0500 | [diff] [blame^] | 103 | body = self.telemetry_client.list_samples(metric, query) |
Vadim Rovachev | 7bcea35 | 2013-12-26 15:56:17 +0400 | [diff] [blame] | 104 | if body: |
David Kranz | 20d06f4 | 2015-02-09 14:54:15 -0500 | [diff] [blame^] | 105 | return body |
Vadim Rovachev | 7bcea35 | 2013-12-26 15:56:17 +0400 | [diff] [blame] | 106 | time.sleep(CONF.compute.build_interval) |
| 107 | |
| 108 | raise exceptions.TimeoutException( |
| 109 | 'Sample for metric:%s with query:%s has not been added to the ' |
| 110 | 'database within %d seconds' % (metric, query, |
| 111 | CONF.compute.build_timeout)) |