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