blob: e27ec133e956548be3d80d76d1da2bb522b4633f [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 = []
Matthew Treinish853ae442013-07-19 16:36:07 -040033 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 Treinishce3ef922013-03-11 14:02:46 -040036
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 Treinishc0f768f2013-03-11 14:24:16 -040064 @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 Treinishce3ef922013-03-11 14:02:46 -040075
76class BaseV1ImageTest(BaseImageTest):
77
78 @classmethod
79 def setUpClass(cls):
80 super(BaseV1ImageTest, cls).setUpClass()
81 cls.client = cls.os.image_client
Matthew Treinishc0f768f2013-03-11 14:24:16 -040082 if not cls._check_version('v1.0'):
83 msg = "Glance API v1 not supported"
84 raise cls.skipException(msg)
Matthew Treinishce3ef922013-03-11 14:02:46 -040085
86
87class BaseV2ImageTest(BaseImageTest):
88
89 @classmethod
90 def setUpClass(cls):
91 super(BaseV2ImageTest, cls).setUpClass()
92 cls.client = cls.os.image_client_v2
Matthew Treinishc0f768f2013-03-11 14:24:16 -040093 if not cls._check_version('v2.0'):
94 msg = "Glance API v2 not supported"
95 raise cls.skipException(msg)