Matthew Treinish | ce3ef92 | 2013-03-11 14:02:46 -0400 | [diff] [blame] | 1 | # Copyright 2013 IBM Corp. |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 | # not use this file except in compliance with the License. You may obtain |
| 5 | # a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | # License for the specific language governing permissions and limitations |
| 13 | # under the License. |
| 14 | |
Doug Hellmann | 583ce2c | 2015-03-11 14:55:46 +0000 | [diff] [blame] | 15 | from oslo_log import log as logging |
Matthew Treinish | b0c65f2 | 2015-04-23 09:09:41 -0400 | [diff] [blame] | 16 | from six import moves |
Matthew Treinish | 01472ff | 2015-02-20 17:26:52 -0500 | [diff] [blame] | 17 | from tempest_lib.common.utils import data_utils |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 18 | from tempest_lib import exceptions as lib_exc |
Attila Fazekas | a709b76 | 2013-10-08 11:52:44 +0200 | [diff] [blame] | 19 | |
Matthew Treinish | 5ba84e3 | 2014-01-29 16:52:57 +0000 | [diff] [blame] | 20 | from tempest import config |
Matthew Treinish | ce3ef92 | 2013-03-11 14:02:46 -0400 | [diff] [blame] | 21 | import tempest.test |
| 22 | |
Matthew Treinish | 5ba84e3 | 2014-01-29 16:52:57 +0000 | [diff] [blame] | 23 | CONF = config.CONF |
| 24 | |
Matthew Treinish | ce3ef92 | 2013-03-11 14:02:46 -0400 | [diff] [blame] | 25 | LOG = logging.getLogger(__name__) |
| 26 | |
| 27 | |
| 28 | class BaseImageTest(tempest.test.BaseTestCase): |
| 29 | """Base test class for Image API tests.""" |
| 30 | |
Andrea Frittoli | b21de6c | 2015-02-06 20:12:38 +0000 | [diff] [blame] | 31 | credentials = ['primary'] |
| 32 | |
Matthew Treinish | ce3ef92 | 2013-03-11 14:02:46 -0400 | [diff] [blame] | 33 | @classmethod |
Rohan Kanade | 3bbbed0 | 2015-02-05 18:18:28 +0530 | [diff] [blame] | 34 | def skip_checks(cls): |
| 35 | super(BaseImageTest, cls).skip_checks() |
| 36 | if not CONF.service_available.glance: |
| 37 | skip_msg = ("%s skipped as glance is not available" % cls.__name__) |
| 38 | raise cls.skipException(skip_msg) |
| 39 | |
| 40 | @classmethod |
| 41 | def setup_credentials(cls): |
Andrea Frittoli | b21de6c | 2015-02-06 20:12:38 +0000 | [diff] [blame] | 42 | cls.set_network_resources() |
Rohan Kanade | 3bbbed0 | 2015-02-05 18:18:28 +0530 | [diff] [blame] | 43 | super(BaseImageTest, cls).setup_credentials() |
Rohan Kanade | 3bbbed0 | 2015-02-05 18:18:28 +0530 | [diff] [blame] | 44 | |
| 45 | @classmethod |
Andrea Frittoli | 69a6b63 | 2014-09-15 13:14:53 +0100 | [diff] [blame] | 46 | def resource_setup(cls): |
Andrea Frittoli | 69a6b63 | 2014-09-15 13:14:53 +0100 | [diff] [blame] | 47 | super(BaseImageTest, cls).resource_setup() |
Matthew Treinish | ce3ef92 | 2013-03-11 14:02:46 -0400 | [diff] [blame] | 48 | cls.created_images = [] |
| 49 | |
| 50 | @classmethod |
Andrea Frittoli | 69a6b63 | 2014-09-15 13:14:53 +0100 | [diff] [blame] | 51 | def resource_cleanup(cls): |
Matthew Treinish | ce3ef92 | 2013-03-11 14:02:46 -0400 | [diff] [blame] | 52 | for image_id in cls.created_images: |
| 53 | try: |
| 54 | cls.client.delete_image(image_id) |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 55 | except lib_exc.NotFound: |
Matthew Treinish | ce3ef92 | 2013-03-11 14:02:46 -0400 | [diff] [blame] | 56 | pass |
| 57 | |
| 58 | for image_id in cls.created_images: |
| 59 | cls.client.wait_for_resource_deletion(image_id) |
Andrea Frittoli | 69a6b63 | 2014-09-15 13:14:53 +0100 | [diff] [blame] | 60 | super(BaseImageTest, cls).resource_cleanup() |
Matthew Treinish | ce3ef92 | 2013-03-11 14:02:46 -0400 | [diff] [blame] | 61 | |
| 62 | @classmethod |
| 63 | def create_image(cls, **kwargs): |
| 64 | """Wrapper that returns a test image.""" |
Attila Fazekas | 689e265 | 2013-10-07 18:06:57 +0200 | [diff] [blame] | 65 | name = data_utils.rand_name(cls.__name__ + "-instance") |
Matthew Treinish | ce3ef92 | 2013-03-11 14:02:46 -0400 | [diff] [blame] | 66 | |
| 67 | if 'name' in kwargs: |
| 68 | name = kwargs.pop('name') |
| 69 | |
| 70 | container_format = kwargs.pop('container_format') |
| 71 | disk_format = kwargs.pop('disk_format') |
| 72 | |
David Kranz | 34f1878 | 2015-01-06 13:43:55 -0500 | [diff] [blame] | 73 | image = cls.client.create_image(name, container_format, |
| 74 | disk_format, **kwargs) |
Matthew Treinish | ce3ef92 | 2013-03-11 14:02:46 -0400 | [diff] [blame] | 75 | cls.created_images.append(image['id']) |
David Kranz | 34f1878 | 2015-01-06 13:43:55 -0500 | [diff] [blame] | 76 | return image |
Matthew Treinish | ce3ef92 | 2013-03-11 14:02:46 -0400 | [diff] [blame] | 77 | |
| 78 | |
| 79 | class BaseV1ImageTest(BaseImageTest): |
| 80 | |
| 81 | @classmethod |
Rohan Kanade | 3bbbed0 | 2015-02-05 18:18:28 +0530 | [diff] [blame] | 82 | def skip_checks(cls): |
| 83 | super(BaseV1ImageTest, cls).skip_checks() |
Matthew Treinish | 5ba84e3 | 2014-01-29 16:52:57 +0000 | [diff] [blame] | 84 | if not CONF.image_feature_enabled.api_v1: |
Matthew Treinish | c0f768f | 2013-03-11 14:24:16 -0400 | [diff] [blame] | 85 | msg = "Glance API v1 not supported" |
| 86 | raise cls.skipException(msg) |
Matthew Treinish | ce3ef92 | 2013-03-11 14:02:46 -0400 | [diff] [blame] | 87 | |
Rohan Kanade | 3bbbed0 | 2015-02-05 18:18:28 +0530 | [diff] [blame] | 88 | @classmethod |
| 89 | def setup_clients(cls): |
| 90 | super(BaseV1ImageTest, cls).setup_clients() |
| 91 | cls.client = cls.os.image_client |
| 92 | |
Matthew Treinish | ce3ef92 | 2013-03-11 14:02:46 -0400 | [diff] [blame] | 93 | |
Attila Fazekas | a709b76 | 2013-10-08 11:52:44 +0200 | [diff] [blame] | 94 | class BaseV1ImageMembersTest(BaseV1ImageTest): |
Rohan Kanade | 3bbbed0 | 2015-02-05 18:18:28 +0530 | [diff] [blame] | 95 | |
Andrea Frittoli | b21de6c | 2015-02-06 20:12:38 +0000 | [diff] [blame] | 96 | credentials = ['primary', 'alt'] |
Rohan Kanade | 3bbbed0 | 2015-02-05 18:18:28 +0530 | [diff] [blame] | 97 | |
| 98 | @classmethod |
| 99 | def setup_clients(cls): |
| 100 | super(BaseV1ImageMembersTest, cls).setup_clients() |
| 101 | cls.alt_img_cli = cls.os_alt.image_client |
| 102 | |
Attila Fazekas | a709b76 | 2013-10-08 11:52:44 +0200 | [diff] [blame] | 103 | @classmethod |
Andrea Frittoli | 69a6b63 | 2014-09-15 13:14:53 +0100 | [diff] [blame] | 104 | def resource_setup(cls): |
| 105 | super(BaseV1ImageMembersTest, cls).resource_setup() |
Andrea Frittoli | 9612e81 | 2014-03-13 10:57:26 +0000 | [diff] [blame] | 106 | cls.alt_tenant_id = cls.alt_img_cli.tenant_id |
Attila Fazekas | a709b76 | 2013-10-08 11:52:44 +0200 | [diff] [blame] | 107 | |
| 108 | def _create_image(self): |
Matthew Treinish | b0c65f2 | 2015-04-23 09:09:41 -0400 | [diff] [blame] | 109 | image_file = moves.cStringIO(data_utils.random_bytes()) |
David Kranz | 34f1878 | 2015-01-06 13:43:55 -0500 | [diff] [blame] | 110 | image = self.create_image(container_format='bare', |
| 111 | disk_format='raw', |
| 112 | is_public=False, |
| 113 | data=image_file) |
Attila Fazekas | a709b76 | 2013-10-08 11:52:44 +0200 | [diff] [blame] | 114 | image_id = image['id'] |
| 115 | return image_id |
| 116 | |
| 117 | |
Matthew Treinish | ce3ef92 | 2013-03-11 14:02:46 -0400 | [diff] [blame] | 118 | class BaseV2ImageTest(BaseImageTest): |
| 119 | |
| 120 | @classmethod |
Rohan Kanade | 3bbbed0 | 2015-02-05 18:18:28 +0530 | [diff] [blame] | 121 | def skip_checks(cls): |
| 122 | super(BaseV2ImageTest, cls).skip_checks() |
Matthew Treinish | 5ba84e3 | 2014-01-29 16:52:57 +0000 | [diff] [blame] | 123 | if not CONF.image_feature_enabled.api_v2: |
Matthew Treinish | c0f768f | 2013-03-11 14:24:16 -0400 | [diff] [blame] | 124 | msg = "Glance API v2 not supported" |
| 125 | raise cls.skipException(msg) |
Attila Fazekas | 689e265 | 2013-10-07 18:06:57 +0200 | [diff] [blame] | 126 | |
Rohan Kanade | 3bbbed0 | 2015-02-05 18:18:28 +0530 | [diff] [blame] | 127 | @classmethod |
| 128 | def setup_clients(cls): |
| 129 | super(BaseV2ImageTest, cls).setup_clients() |
| 130 | cls.client = cls.os.image_client_v2 |
| 131 | |
Attila Fazekas | 689e265 | 2013-10-07 18:06:57 +0200 | [diff] [blame] | 132 | |
JordanP | 236da42 | 2014-01-16 14:38:07 +0000 | [diff] [blame] | 133 | class BaseV2MemberImageTest(BaseV2ImageTest): |
Attila Fazekas | 689e265 | 2013-10-07 18:06:57 +0200 | [diff] [blame] | 134 | |
Andrea Frittoli | b21de6c | 2015-02-06 20:12:38 +0000 | [diff] [blame] | 135 | credentials = ['primary', 'alt'] |
Rohan Kanade | 3bbbed0 | 2015-02-05 18:18:28 +0530 | [diff] [blame] | 136 | |
| 137 | @classmethod |
| 138 | def setup_clients(cls): |
| 139 | super(BaseV2MemberImageTest, cls).setup_clients() |
Attila Fazekas | 689e265 | 2013-10-07 18:06:57 +0200 | [diff] [blame] | 140 | cls.os_img_client = cls.os.image_client_v2 |
| 141 | cls.alt_img_client = cls.os_alt.image_client_v2 |
Rohan Kanade | 3bbbed0 | 2015-02-05 18:18:28 +0530 | [diff] [blame] | 142 | |
| 143 | @classmethod |
| 144 | def resource_setup(cls): |
| 145 | super(BaseV2MemberImageTest, cls).resource_setup() |
Zhi Kun Liu | d752c60 | 2014-05-16 13:25:28 +0800 | [diff] [blame] | 146 | cls.alt_tenant_id = cls.alt_img_client.tenant_id |
Attila Fazekas | 689e265 | 2013-10-07 18:06:57 +0200 | [diff] [blame] | 147 | |
| 148 | def _list_image_ids_as_alt(self): |
Ken'ichi Ohmichi | e3acc12 | 2015-05-22 00:32:54 +0000 | [diff] [blame] | 149 | image_list = self.alt_img_client.list_images() |
Attila Fazekas | 689e265 | 2013-10-07 18:06:57 +0200 | [diff] [blame] | 150 | image_ids = map(lambda x: x['id'], image_list) |
| 151 | return image_ids |
| 152 | |
| 153 | def _create_image(self): |
| 154 | name = data_utils.rand_name('image') |
David Kranz | 34f1878 | 2015-01-06 13:43:55 -0500 | [diff] [blame] | 155 | image = self.os_img_client.create_image(name, |
| 156 | container_format='bare', |
| 157 | disk_format='raw') |
Attila Fazekas | 689e265 | 2013-10-07 18:06:57 +0200 | [diff] [blame] | 158 | image_id = image['id'] |
| 159 | self.addCleanup(self.os_img_client.delete_image, image_id) |
| 160 | return image_id |