Matthew Treinish | ce3ef92 | 2013-03-11 14:02:46 -0400 | [diff] [blame] | 1 | # vim: tabstop=4 shiftwidth=4 softtabstop=4 |
| 2 | |
| 3 | # Copyright 2013 IBM Corp. |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 6 | # not use this file except in compliance with the License. You may obtain |
| 7 | # a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 14 | # License for the specific language governing permissions and limitations |
| 15 | # under the License. |
| 16 | |
Matthew Treinish | ce3ef92 | 2013-03-11 14:02:46 -0400 | [diff] [blame] | 17 | from tempest import clients |
Mitsuhiko Yamazaki | 46818aa | 2013-04-18 17:49:17 +0900 | [diff] [blame] | 18 | from tempest.common import log as logging |
Matthew Treinish | ce3ef92 | 2013-03-11 14:02:46 -0400 | [diff] [blame] | 19 | from tempest.common.utils.data_utils import rand_name |
| 20 | from tempest import exceptions |
| 21 | import tempest.test |
| 22 | |
| 23 | LOG = logging.getLogger(__name__) |
| 24 | |
| 25 | |
| 26 | class BaseImageTest(tempest.test.BaseTestCase): |
| 27 | """Base test class for Image API tests.""" |
| 28 | |
| 29 | @classmethod |
| 30 | def setUpClass(cls): |
| 31 | cls.os = clients.Manager() |
| 32 | cls.created_images = [] |
Matthew Treinish | 853ae44 | 2013-07-19 16:36:07 -0400 | [diff] [blame] | 33 | if not cls.config.service_available.glance: |
| 34 | skip_msg = ("%s skipped as glance is not available" % cls.__name__) |
| 35 | raise cls.skipException(skip_msg) |
Matthew Treinish | ce3ef92 | 2013-03-11 14:02:46 -0400 | [diff] [blame] | 36 | |
| 37 | @classmethod |
| 38 | def tearDownClass(cls): |
| 39 | for image_id in cls.created_images: |
| 40 | try: |
| 41 | cls.client.delete_image(image_id) |
| 42 | except exceptions.NotFound: |
| 43 | pass |
| 44 | |
| 45 | for image_id in cls.created_images: |
| 46 | cls.client.wait_for_resource_deletion(image_id) |
| 47 | |
| 48 | @classmethod |
| 49 | def create_image(cls, **kwargs): |
| 50 | """Wrapper that returns a test image.""" |
| 51 | name = rand_name(cls.__name__ + "-instance") |
| 52 | |
| 53 | if 'name' in kwargs: |
| 54 | name = kwargs.pop('name') |
| 55 | |
| 56 | container_format = kwargs.pop('container_format') |
| 57 | disk_format = kwargs.pop('disk_format') |
| 58 | |
| 59 | resp, image = cls.client.create_image(name, container_format, |
| 60 | disk_format, **kwargs) |
| 61 | cls.created_images.append(image['id']) |
| 62 | return resp, image |
| 63 | |
Matthew Treinish | c0f768f | 2013-03-11 14:24:16 -0400 | [diff] [blame] | 64 | @classmethod |
| 65 | def _check_version(cls, version): |
| 66 | __, versions = cls.client.get_versions() |
| 67 | if version == 'v2.0': |
| 68 | if 'v2.0' in versions: |
| 69 | return True |
| 70 | elif version == 'v1.0': |
| 71 | if 'v1.1' in versions or 'v1.0' in versions: |
| 72 | return True |
| 73 | return False |
| 74 | |
Matthew Treinish | ce3ef92 | 2013-03-11 14:02:46 -0400 | [diff] [blame] | 75 | |
| 76 | class BaseV1ImageTest(BaseImageTest): |
| 77 | |
| 78 | @classmethod |
| 79 | def setUpClass(cls): |
| 80 | super(BaseV1ImageTest, cls).setUpClass() |
| 81 | cls.client = cls.os.image_client |
Matthew Treinish | c0f768f | 2013-03-11 14:24:16 -0400 | [diff] [blame] | 82 | if not cls._check_version('v1.0'): |
| 83 | msg = "Glance API v1 not supported" |
| 84 | raise cls.skipException(msg) |
Matthew Treinish | ce3ef92 | 2013-03-11 14:02:46 -0400 | [diff] [blame] | 85 | |
| 86 | |
| 87 | class BaseV2ImageTest(BaseImageTest): |
| 88 | |
| 89 | @classmethod |
| 90 | def setUpClass(cls): |
| 91 | super(BaseV2ImageTest, cls).setUpClass() |
| 92 | cls.client = cls.os.image_client_v2 |
Matthew Treinish | c0f768f | 2013-03-11 14:24:16 -0400 | [diff] [blame] | 93 | if not cls._check_version('v2.0'): |
| 94 | msg = "Glance API v2 not supported" |
| 95 | raise cls.skipException(msg) |