blob: e62d84bba52e9c72026436744c5eb4a19f5113cc [file] [log] [blame]
Matthew Treinishce3ef922013-03-11 14:02:46 -04001# 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 Treinishce3ef922013-03-11 14:02:46 -040017from tempest import clients
Mitsuhiko Yamazaki46818aa2013-04-18 17:49:17 +090018from tempest.common import log as logging
Matthew Treinishce3ef922013-03-11 14:02:46 -040019from tempest.common.utils.data_utils import rand_name
20from tempest import exceptions
21import tempest.test
22
23LOG = logging.getLogger(__name__)
24
25
26class 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 = []
33
34 @classmethod
35 def tearDownClass(cls):
36 for image_id in cls.created_images:
37 try:
38 cls.client.delete_image(image_id)
39 except exceptions.NotFound:
40 pass
41
42 for image_id in cls.created_images:
43 cls.client.wait_for_resource_deletion(image_id)
44
45 @classmethod
46 def create_image(cls, **kwargs):
47 """Wrapper that returns a test image."""
48 name = rand_name(cls.__name__ + "-instance")
49
50 if 'name' in kwargs:
51 name = kwargs.pop('name')
52
53 container_format = kwargs.pop('container_format')
54 disk_format = kwargs.pop('disk_format')
55
56 resp, image = cls.client.create_image(name, container_format,
57 disk_format, **kwargs)
58 cls.created_images.append(image['id'])
59 return resp, image
60
Matthew Treinishc0f768f2013-03-11 14:24:16 -040061 @classmethod
62 def _check_version(cls, version):
63 __, versions = cls.client.get_versions()
64 if version == 'v2.0':
65 if 'v2.0' in versions:
66 return True
67 elif version == 'v1.0':
68 if 'v1.1' in versions or 'v1.0' in versions:
69 return True
70 return False
71
Matthew Treinishce3ef922013-03-11 14:02:46 -040072
73class BaseV1ImageTest(BaseImageTest):
74
75 @classmethod
76 def setUpClass(cls):
77 super(BaseV1ImageTest, cls).setUpClass()
78 cls.client = cls.os.image_client
Matthew Treinishc0f768f2013-03-11 14:24:16 -040079 if not cls._check_version('v1.0'):
80 msg = "Glance API v1 not supported"
81 raise cls.skipException(msg)
Matthew Treinishce3ef922013-03-11 14:02:46 -040082
83
84class BaseV2ImageTest(BaseImageTest):
85
86 @classmethod
87 def setUpClass(cls):
88 super(BaseV2ImageTest, cls).setUpClass()
89 cls.client = cls.os.image_client_v2
Matthew Treinishc0f768f2013-03-11 14:24:16 -040090 if not cls._check_version('v2.0'):
91 msg = "Glance API v2 not supported"
92 raise cls.skipException(msg)