blob: 4f54a157f1891c3200b5bd2eeb8b59994c987d00 [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
Matthew Treinishb86cda92013-07-29 11:22:23 -040018from tempest.common import isolated_creds
Matthew Treinishce3ef922013-03-11 14:02:46 -040019from tempest.common.utils.data_utils import rand_name
20from tempest import exceptions
Matthew Treinishf4a9b0f2013-07-26 16:58:26 -040021from tempest.openstack.common import log as logging
Matthew Treinishce3ef922013-03-11 14:02:46 -040022import tempest.test
23
24LOG = logging.getLogger(__name__)
25
26
27class BaseImageTest(tempest.test.BaseTestCase):
28 """Base test class for Image API tests."""
29
30 @classmethod
31 def setUpClass(cls):
Attila Fazekasf86fa312013-07-30 19:56:39 +020032 super(BaseImageTest, cls).setUpClass()
Matthew Treinishce3ef922013-03-11 14:02:46 -040033 cls.created_images = []
Matthew Treinishe09b3c22013-07-23 16:49:36 -040034 cls._interface = 'json'
Matthew Treinishb86cda92013-07-29 11:22:23 -040035 cls.isolated_creds = isolated_creds.IsolatedCreds(cls.__name__)
Matthew Treinish853ae442013-07-19 16:36:07 -040036 if not cls.config.service_available.glance:
37 skip_msg = ("%s skipped as glance is not available" % cls.__name__)
38 raise cls.skipException(skip_msg)
Matthew Treinishe09b3c22013-07-23 16:49:36 -040039 if cls.config.compute.allow_tenant_isolation:
Matthew Treinishb86cda92013-07-29 11:22:23 -040040 creds = cls.isolated_creds.get_primary_creds()
Matthew Treinishe09b3c22013-07-23 16:49:36 -040041 username, tenant_name, password = creds
42 cls.os = clients.Manager(username=username,
43 password=password,
44 tenant_name=tenant_name)
45 else:
46 cls.os = clients.Manager()
Matthew Treinishce3ef922013-03-11 14:02:46 -040047
48 @classmethod
49 def tearDownClass(cls):
50 for image_id in cls.created_images:
51 try:
52 cls.client.delete_image(image_id)
53 except exceptions.NotFound:
54 pass
55
56 for image_id in cls.created_images:
57 cls.client.wait_for_resource_deletion(image_id)
Matthew Treinishb86cda92013-07-29 11:22:23 -040058 cls.isolated_creds.clear_isolated_creds()
59 super(BaseImageTest, cls).tearDownClass()
Matthew Treinishce3ef922013-03-11 14:02:46 -040060
61 @classmethod
62 def create_image(cls, **kwargs):
63 """Wrapper that returns a test image."""
64 name = rand_name(cls.__name__ + "-instance")
65
66 if 'name' in kwargs:
67 name = kwargs.pop('name')
68
69 container_format = kwargs.pop('container_format')
70 disk_format = kwargs.pop('disk_format')
71
72 resp, image = cls.client.create_image(name, container_format,
73 disk_format, **kwargs)
74 cls.created_images.append(image['id'])
75 return resp, image
76
Matthew Treinishc0f768f2013-03-11 14:24:16 -040077 @classmethod
78 def _check_version(cls, version):
79 __, versions = cls.client.get_versions()
80 if version == 'v2.0':
81 if 'v2.0' in versions:
82 return True
83 elif version == 'v1.0':
84 if 'v1.1' in versions or 'v1.0' in versions:
85 return True
86 return False
87
Matthew Treinishce3ef922013-03-11 14:02:46 -040088
89class BaseV1ImageTest(BaseImageTest):
90
91 @classmethod
92 def setUpClass(cls):
93 super(BaseV1ImageTest, cls).setUpClass()
94 cls.client = cls.os.image_client
Matthew Treinishc0f768f2013-03-11 14:24:16 -040095 if not cls._check_version('v1.0'):
96 msg = "Glance API v1 not supported"
97 raise cls.skipException(msg)
Matthew Treinishce3ef922013-03-11 14:02:46 -040098
99
100class BaseV2ImageTest(BaseImageTest):
101
102 @classmethod
103 def setUpClass(cls):
104 super(BaseV2ImageTest, cls).setUpClass()
105 cls.client = cls.os.image_client_v2
Matthew Treinishc0f768f2013-03-11 14:24:16 -0400106 if not cls._check_version('v2.0'):
107 msg = "Glance API v2 not supported"
108 raise cls.skipException(msg)