blob: 062d63e333de811f6e04f99662204710db5fcb24 [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):
Matthew Treinishe09b3c22013-07-23 16:49:36 -040031 cls.isolated_creds = []
Matthew Treinishce3ef922013-03-11 14:02:46 -040032 cls.created_images = []
Matthew Treinishe09b3c22013-07-23 16:49:36 -040033 cls._interface = 'json'
Matthew Treinish853ae442013-07-19 16:36:07 -040034 if not cls.config.service_available.glance:
35 skip_msg = ("%s skipped as glance is not available" % cls.__name__)
36 raise cls.skipException(skip_msg)
Matthew Treinishe09b3c22013-07-23 16:49:36 -040037 if cls.config.compute.allow_tenant_isolation:
38 creds = cls._get_isolated_creds()
39 username, tenant_name, password = creds
40 cls.os = clients.Manager(username=username,
41 password=password,
42 tenant_name=tenant_name)
43 else:
44 cls.os = clients.Manager()
Matthew Treinishce3ef922013-03-11 14:02:46 -040045
46 @classmethod
47 def tearDownClass(cls):
48 for image_id in cls.created_images:
49 try:
50 cls.client.delete_image(image_id)
51 except exceptions.NotFound:
52 pass
53
54 for image_id in cls.created_images:
55 cls.client.wait_for_resource_deletion(image_id)
Matthew Treinishe09b3c22013-07-23 16:49:36 -040056 cls._clear_isolated_creds()
Matthew Treinishce3ef922013-03-11 14:02:46 -040057
58 @classmethod
59 def create_image(cls, **kwargs):
60 """Wrapper that returns a test image."""
61 name = rand_name(cls.__name__ + "-instance")
62
63 if 'name' in kwargs:
64 name = kwargs.pop('name')
65
66 container_format = kwargs.pop('container_format')
67 disk_format = kwargs.pop('disk_format')
68
69 resp, image = cls.client.create_image(name, container_format,
70 disk_format, **kwargs)
71 cls.created_images.append(image['id'])
72 return resp, image
73
Matthew Treinishc0f768f2013-03-11 14:24:16 -040074 @classmethod
75 def _check_version(cls, version):
76 __, versions = cls.client.get_versions()
77 if version == 'v2.0':
78 if 'v2.0' in versions:
79 return True
80 elif version == 'v1.0':
81 if 'v1.1' in versions or 'v1.0' in versions:
82 return True
83 return False
84
Matthew Treinishce3ef922013-03-11 14:02:46 -040085
86class BaseV1ImageTest(BaseImageTest):
87
88 @classmethod
89 def setUpClass(cls):
90 super(BaseV1ImageTest, cls).setUpClass()
91 cls.client = cls.os.image_client
Matthew Treinishc0f768f2013-03-11 14:24:16 -040092 if not cls._check_version('v1.0'):
93 msg = "Glance API v1 not supported"
94 raise cls.skipException(msg)
Matthew Treinishce3ef922013-03-11 14:02:46 -040095
96
97class BaseV2ImageTest(BaseImageTest):
98
99 @classmethod
100 def setUpClass(cls):
101 super(BaseV2ImageTest, cls).setUpClass()
102 cls.client = cls.os.image_client_v2
Matthew Treinishc0f768f2013-03-11 14:24:16 -0400103 if not cls._check_version('v2.0'):
104 msg = "Glance API v2 not supported"
105 raise cls.skipException(msg)