Ryota MIBU | f0832d5 | 2015-12-10 15:32:13 +0900 | [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 | |
| 13 | import time |
| 14 | |
| 15 | from oslo_utils import timeutils |
Ryota MIBU | f0832d5 | 2015-12-10 15:32:13 +0900 | [diff] [blame] | 16 | from tempest.common import compute |
| 17 | from tempest.common.utils import data_utils |
| 18 | from tempest import config |
| 19 | from tempest import exceptions |
Ryota MIBU | 08ff867 | 2015-12-10 15:54:38 +0900 | [diff] [blame] | 20 | from tempest.lib import exceptions as lib_exc |
Ryota MIBU | f0832d5 | 2015-12-10 15:32:13 +0900 | [diff] [blame] | 21 | import tempest.test |
| 22 | |
Ryota MIBU | 08ff867 | 2015-12-10 15:54:38 +0900 | [diff] [blame] | 23 | from ceilometer.tests.tempest.service import client |
| 24 | |
| 25 | |
Ryota MIBU | f0832d5 | 2015-12-10 15:32:13 +0900 | [diff] [blame] | 26 | CONF = config.CONF |
| 27 | |
| 28 | |
Ryota MIBU | 08ff867 | 2015-12-10 15:54:38 +0900 | [diff] [blame] | 29 | class ClientManager(client.Manager): |
| 30 | |
| 31 | load_clients = [ |
| 32 | 'servers_client', |
| 33 | 'compute_networks_client', |
| 34 | 'compute_floating_ips_client', |
| 35 | 'flavors_client', |
Ryota MIBU | 08ff867 | 2015-12-10 15:54:38 +0900 | [diff] [blame] | 36 | 'image_client_v2', |
| 37 | 'telemetry_client', |
| 38 | ] |
| 39 | |
| 40 | |
Ryota MIBU | f0832d5 | 2015-12-10 15:32:13 +0900 | [diff] [blame] | 41 | class BaseTelemetryTest(tempest.test.BaseTestCase): |
| 42 | |
| 43 | """Base test case class for all Telemetry API tests.""" |
| 44 | |
| 45 | credentials = ['primary'] |
Ryota MIBU | 08ff867 | 2015-12-10 15:54:38 +0900 | [diff] [blame] | 46 | client_manager = ClientManager |
Ryota MIBU | f0832d5 | 2015-12-10 15:32:13 +0900 | [diff] [blame] | 47 | |
| 48 | @classmethod |
| 49 | def skip_checks(cls): |
| 50 | super(BaseTelemetryTest, cls).skip_checks() |
ghanshyam | 905e081 | 2016-04-14 11:45:56 +0900 | [diff] [blame] | 51 | if not CONF.service_available.ceilometer: |
Ryota MIBU | f0832d5 | 2015-12-10 15:32:13 +0900 | [diff] [blame] | 52 | raise cls.skipException("Ceilometer support is required") |
| 53 | |
| 54 | @classmethod |
| 55 | def setup_credentials(cls): |
| 56 | cls.set_network_resources() |
| 57 | super(BaseTelemetryTest, cls).setup_credentials() |
| 58 | |
| 59 | @classmethod |
| 60 | def setup_clients(cls): |
| 61 | super(BaseTelemetryTest, cls).setup_clients() |
Ryota MIBU | 08ff867 | 2015-12-10 15:54:38 +0900 | [diff] [blame] | 62 | cls.telemetry_client = cls.os_primary.telemetry_client |
| 63 | cls.servers_client = cls.os_primary.servers_client |
| 64 | cls.flavors_client = cls.os_primary.flavors_client |
Ryota MIBU | 08ff867 | 2015-12-10 15:54:38 +0900 | [diff] [blame] | 65 | cls.image_client_v2 = cls.os_primary.image_client_v2 |
Ryota MIBU | f0832d5 | 2015-12-10 15:32:13 +0900 | [diff] [blame] | 66 | |
| 67 | @classmethod |
| 68 | def resource_setup(cls): |
| 69 | super(BaseTelemetryTest, cls).resource_setup() |
| 70 | cls.nova_notifications = ['memory', 'vcpus', 'disk.root.size', |
| 71 | 'disk.ephemeral.size'] |
| 72 | |
Ryota MIBU | f0832d5 | 2015-12-10 15:32:13 +0900 | [diff] [blame] | 73 | cls.glance_v2_notifications = ['image.download', 'image.serve'] |
| 74 | |
| 75 | cls.server_ids = [] |
| 76 | cls.image_ids = [] |
| 77 | |
| 78 | @classmethod |
| 79 | def create_server(cls): |
| 80 | tenant_network = cls.get_tenant_network() |
| 81 | body, server = compute.create_test_server( |
Ryota MIBU | 08ff867 | 2015-12-10 15:54:38 +0900 | [diff] [blame] | 82 | cls.os_primary, |
Ryota MIBU | f0832d5 | 2015-12-10 15:32:13 +0900 | [diff] [blame] | 83 | tenant_network=tenant_network, |
| 84 | name=data_utils.rand_name('ceilometer-instance'), |
| 85 | wait_until='ACTIVE') |
| 86 | cls.server_ids.append(body['id']) |
| 87 | return body |
| 88 | |
| 89 | @classmethod |
Ryota MIBU | 08ff867 | 2015-12-10 15:54:38 +0900 | [diff] [blame] | 90 | def create_image(cls, client, **kwargs): |
| 91 | body = client.create_image(name=data_utils.rand_name('image'), |
| 92 | container_format='bare', |
| 93 | disk_format='raw', |
| 94 | **kwargs) |
Ryota MIBU | f0832d5 | 2015-12-10 15:32:13 +0900 | [diff] [blame] | 95 | # TODO(jswarren) Move ['image'] up to initial body value assignment |
| 96 | # once both v1 and v2 glance clients include the full response |
| 97 | # object. |
| 98 | if 'image' in body: |
| 99 | body = body['image'] |
| 100 | cls.image_ids.append(body['id']) |
| 101 | return body |
| 102 | |
| 103 | @staticmethod |
| 104 | def cleanup_resources(method, list_of_ids): |
| 105 | for resource_id in list_of_ids: |
| 106 | try: |
| 107 | method(resource_id) |
| 108 | except lib_exc.NotFound: |
| 109 | pass |
| 110 | |
| 111 | @classmethod |
| 112 | def resource_cleanup(cls): |
| 113 | cls.cleanup_resources(cls.servers_client.delete_server, cls.server_ids) |
liusheng | e65b391 | 2016-11-17 15:22:39 +0800 | [diff] [blame] | 114 | cls.cleanup_resources(cls.image_client_v2.delete_image, cls.image_ids) |
Ryota MIBU | f0832d5 | 2015-12-10 15:32:13 +0900 | [diff] [blame] | 115 | super(BaseTelemetryTest, cls).resource_cleanup() |
| 116 | |
| 117 | def await_samples(self, metric, query): |
| 118 | """This method is to wait for sample to add it to database. |
| 119 | |
| 120 | There are long time delays when using Postgresql (or Mysql) |
| 121 | database as ceilometer backend |
| 122 | """ |
| 123 | timeout = CONF.compute.build_timeout |
| 124 | start = timeutils.utcnow() |
| 125 | while timeutils.delta_seconds(start, timeutils.utcnow()) < timeout: |
| 126 | body = self.telemetry_client.list_samples(metric, query) |
| 127 | if body: |
| 128 | return body |
| 129 | time.sleep(CONF.compute.build_interval) |
| 130 | |
| 131 | raise exceptions.TimeoutException( |
| 132 | 'Sample for metric:%s with query:%s has not been added to the ' |
| 133 | 'database within %d seconds' % (metric, query, |
| 134 | CONF.compute.build_timeout)) |
| 135 | |
| 136 | |
| 137 | class BaseTelemetryAdminTest(BaseTelemetryTest): |
| 138 | """Base test case class for admin Telemetry API tests.""" |
| 139 | |
| 140 | credentials = ['primary', 'admin'] |
| 141 | |
| 142 | @classmethod |
| 143 | def setup_clients(cls): |
| 144 | super(BaseTelemetryAdminTest, cls).setup_clients() |
| 145 | cls.telemetry_admin_client = cls.os_adm.telemetry_client |