blob: c7f0b23653cc8e9aa8ca082b20239ec40ad4da09 [file] [log] [blame]
Attila Fazekas46a1d922013-01-11 10:19:42 +01001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
3# Copyright 2012 OpenStack, LLC
4# All Rights Reserved.
5#
6# Licensed under the Apache License, Version 2.0 (the "License"); you may
7# not use this file except in compliance with the License. You may obtain
8# a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15# License for the specific language governing permissions and limitations
16# under the License.
17
ivan-zhu1feeb382013-01-24 10:14:39 +080018import testtools
Attila Fazekas46a1d922013-01-11 10:19:42 +010019
Sean Dague1937d092013-05-17 16:36:38 -040020from tempest.api import compute
21from tempest.api.compute import base
Attila Fazekas46a1d922013-01-11 10:19:42 +010022from tempest import clients
23from tempest.common.utils.data_utils import parse_image_id
24from tempest.common.utils.data_utils import rand_name
Attila Fazekas46a1d922013-01-11 10:19:42 +010025from tempest import exceptions
Chris Yeoh9465b0b2013-02-09 22:19:15 +103026from tempest.test import attr
Attila Fazekas46a1d922013-01-11 10:19:42 +010027
28
Attila Fazekas19044d52013-02-16 07:35:06 +010029class ImagesOneServerTestJSON(base.BaseComputeTest):
30 _interface = 'json'
31
Attila Fazekas46a1d922013-01-11 10:19:42 +010032 def tearDown(self):
33 """Terminate test instances created after a test is executed."""
34 for image_id in self.image_ids:
35 self.client.delete_image(image_id)
36 self.image_ids.remove(image_id)
Attila Fazekas19044d52013-02-16 07:35:06 +010037 super(ImagesOneServerTestJSON, self).tearDown()
38
39 @classmethod
40 def setUpClass(cls):
41 super(ImagesOneServerTestJSON, cls).setUpClass()
42 cls.client = cls.images_client
43 cls.servers_client = cls.servers_client
ivan-zhubf88a632013-03-26 13:29:21 +080044
45 try:
46 resp, cls.server = cls.create_server(wait_until='ACTIVE')
47 except Exception:
48 cls.tearDownClass()
49 raise
Attila Fazekas19044d52013-02-16 07:35:06 +010050
51 cls.image_ids = []
52
53 if compute.MULTI_USER:
54 if cls.config.compute.allow_tenant_isolation:
55 creds = cls._get_isolated_creds()
56 username, tenant_name, password = creds
57 cls.alt_manager = clients.Manager(username=username,
58 password=password,
59 tenant_name=tenant_name)
60 else:
61 # Use the alt_XXX credentials in the config file
62 cls.alt_manager = clients.AltManager()
63 cls.alt_client = cls.alt_manager.images_client
Attila Fazekas46a1d922013-01-11 10:19:42 +010064
Matthew Treinish770e5a42013-03-22 15:35:16 -040065 @testtools.skip("Until Bug #1006725 is fixed")
Giampaolo Lauriae9c77022013-05-22 01:23:58 -040066 @attr(type=['negative', 'gate'])
Attila Fazekas46a1d922013-01-11 10:19:42 +010067 def test_create_image_specify_multibyte_character_image_name(self):
68 # Return an error if the image name has multi-byte characters
Chris Yeohe04628e2013-02-25 17:12:21 +103069 snapshot_name = rand_name('\xef\xbb\xbf')
70 self.assertRaises(exceptions.BadRequest,
71 self.client.create_image, self.server['id'],
72 snapshot_name)
Attila Fazekas46a1d922013-01-11 10:19:42 +010073
Giampaolo Lauriae9c77022013-05-22 01:23:58 -040074 @attr(type=['negative', 'gate'])
Attila Fazekas46a1d922013-01-11 10:19:42 +010075 def test_create_image_specify_invalid_metadata(self):
76 # Return an error when creating image with invalid metadata
Chris Yeohe04628e2013-02-25 17:12:21 +103077 snapshot_name = rand_name('test-snap-')
78 meta = {'': ''}
79 self.assertRaises(exceptions.BadRequest, self.client.create_image,
80 self.server['id'], snapshot_name, meta)
Attila Fazekas46a1d922013-01-11 10:19:42 +010081
Giampaolo Lauriae9c77022013-05-22 01:23:58 -040082 @attr(type=['negative', 'gate'])
Attila Fazekas46a1d922013-01-11 10:19:42 +010083 def test_create_image_specify_metadata_over_limits(self):
84 # Return an error when creating image with meta data over 256 chars
Chris Yeohe04628e2013-02-25 17:12:21 +103085 snapshot_name = rand_name('test-snap-')
86 meta = {'a' * 260: 'b' * 260}
Prem Karat586136a2013-04-25 17:03:48 +053087 self.assertRaises(exceptions.BadRequest, self.client.create_image,
Chris Yeohe04628e2013-02-25 17:12:21 +103088 self.server['id'], snapshot_name, meta)
Attila Fazekas46a1d922013-01-11 10:19:42 +010089
ivan-zhu1feeb382013-01-24 10:14:39 +080090 @testtools.skipUnless(compute.MULTI_USER,
91 'Need multiple users for this test.')
Giampaolo Lauriae9c77022013-05-22 01:23:58 -040092 @attr(type=['negative', 'gate'])
Attila Fazekas46a1d922013-01-11 10:19:42 +010093 def test_delete_image_of_another_tenant(self):
94 # Return an error while trying to delete another tenant's image
95 self.servers_client.wait_for_server_status(self.server['id'], 'ACTIVE')
96 snapshot_name = rand_name('test-snap-')
97 resp, body = self.client.create_image(self.server['id'], snapshot_name)
98 image_id = parse_image_id(resp['location'])
99 self.image_ids.append(image_id)
100 self.client.wait_for_image_resp_code(image_id, 200)
101 self.client.wait_for_image_status(image_id, 'ACTIVE')
102
103 # Delete image
104 self.assertRaises(exceptions.NotFound,
105 self.alt_client.delete_image, image_id)
106
ivan-zhu1feeb382013-01-24 10:14:39 +0800107 @testtools.skipUnless(compute.CREATE_IMAGE_ENABLED,
108 'Environment unable to create images.')
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400109 @attr(type='smoke')
Attila Fazekas46a1d922013-01-11 10:19:42 +0100110 def test_create_delete_image(self):
111
112 # Create a new image
113 name = rand_name('image')
114 meta = {'image_type': 'test'}
115 resp, body = self.client.create_image(self.server['id'], name, meta)
116 self.assertEqual(202, resp.status)
117 image_id = parse_image_id(resp['location'])
118 self.client.wait_for_image_resp_code(image_id, 200)
119 self.client.wait_for_image_status(image_id, 'ACTIVE')
120
121 # Verify the image was created correctly
122 resp, image = self.client.get_image(image_id)
123 self.assertEqual(name, image['name'])
124 self.assertEqual('test', image['metadata']['image_type'])
125
126 # Verify minRAM and minDisk values are the same as the original image
127 resp, original_image = self.client.get_image(self.image_ref)
128 self.assertEqual(original_image['minRam'], image['minRam'])
129 self.assertEqual(original_image['minDisk'], image['minDisk'])
130
Prem Karat325ed282013-04-24 23:57:24 +0530131 # Verify the image was deleted correctly
132 resp, body = self.client.delete_image(image_id)
133 self.assertEqual('204', resp['status'])
134 self.assertRaises(exceptions.NotFound, self.client.get_image, image_id)
135
ivan-zhu1feeb382013-01-24 10:14:39 +0800136 @testtools.skipUnless(compute.MULTI_USER,
137 'Need multiple users for this test.')
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400138 @attr(type=['negative', 'gate'])
Attila Fazekas46a1d922013-01-11 10:19:42 +0100139 def test_create_image_for_server_in_another_tenant(self):
140 # Creating image of another tenant's server should be return error
141
142 snapshot_name = rand_name('test-snap-')
143 self.assertRaises(exceptions.NotFound, self.alt_client.create_image,
144 self.server['id'], snapshot_name)
145
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400146 @attr(type=['negative', 'gate'])
Attila Fazekas46a1d922013-01-11 10:19:42 +0100147 def test_create_second_image_when_first_image_is_being_saved(self):
148 # Disallow creating another image when first image is being saved
149
Chris Yeohe04628e2013-02-25 17:12:21 +1030150 # Create first snapshot
151 snapshot_name = rand_name('test-snap-')
152 resp, body = self.client.create_image(self.server['id'],
153 snapshot_name)
154 self.assertEqual(202, resp.status)
155 image_id = parse_image_id(resp['location'])
156 self.image_ids.append(image_id)
Attila Fazekas46a1d922013-01-11 10:19:42 +0100157
Chris Yeohe04628e2013-02-25 17:12:21 +1030158 # Create second snapshot
159 alt_snapshot_name = rand_name('test-snap-')
160 self.assertRaises(exceptions.Duplicate, self.client.create_image,
161 self.server['id'], alt_snapshot_name)
162 self.client.wait_for_image_status(image_id, 'ACTIVE')
Attila Fazekas46a1d922013-01-11 10:19:42 +0100163
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400164 @attr(type=['negative', 'gate'])
Attila Fazekas46a1d922013-01-11 10:19:42 +0100165 def test_create_image_specify_name_over_256_chars(self):
166 # Return an error if snapshot name over 256 characters is passed
167
Chris Yeohe04628e2013-02-25 17:12:21 +1030168 snapshot_name = rand_name('a' * 260)
169 self.assertRaises(exceptions.BadRequest, self.client.create_image,
170 self.server['id'], snapshot_name)
Attila Fazekas46a1d922013-01-11 10:19:42 +0100171
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400172 @attr(type=['negative', 'gate'])
Attila Fazekas46a1d922013-01-11 10:19:42 +0100173 def test_delete_image_that_is_not_yet_active(self):
174 # Return an error while trying to delete an image what is creating
175
176 snapshot_name = rand_name('test-snap-')
177 resp, body = self.client.create_image(self.server['id'], snapshot_name)
178 self.assertEqual(202, resp.status)
179 image_id = parse_image_id(resp['location'])
180 self.image_ids.append(image_id)
181
182 # Do not wait, attempt to delete the image, ensure it's successful
183 resp, body = self.client.delete_image(image_id)
184 self.assertEqual('204', resp['status'])
185 self.image_ids.remove(image_id)
186
187 self.assertRaises(exceptions.NotFound, self.client.get_image, image_id)
188
189
Attila Fazekas19044d52013-02-16 07:35:06 +0100190class ImagesOneServerTestXML(ImagesOneServerTestJSON):
191 _interface = 'xml'