blob: 1e902029a9135f39fb0ab90cff89bc7b222c2173 [file] [log] [blame]
Jay Pipes13b479b2012-06-11 14:52:27 -04001# 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
Daryl Walleck73a9e7a2011-11-15 17:43:31 -060019
Matthew Treinish481466b2012-12-20 17:16:01 -050020from tempest import clients
Matthew Treinisha83a16e2012-12-07 13:44:02 -050021from tempest.common.utils.data_utils import parse_image_id
22from tempest.common.utils.data_utils import rand_name
Jay Pipes13b479b2012-06-11 14:52:27 -040023from tempest import exceptions
Chris Yeoh9465b0b2013-02-09 22:19:15 +103024from tempest.test import attr
Jay Pipesf38eaac2012-06-21 13:37:35 -040025from tempest.tests import compute
Matthew Treinisha83a16e2012-12-07 13:44:02 -050026from tempest.tests.compute import base
Jay Pipes7f757632011-12-02 15:53:32 -050027
Daryl Walleck73a9e7a2011-11-15 17:43:31 -060028
Attila Fazekas19044d52013-02-16 07:35:06 +010029class ImagesTestJSON(base.BaseComputeTest):
30 _interface = 'json'
31
32 @classmethod
33 def setUpClass(cls):
34 super(ImagesTestJSON, cls).setUpClass()
35 cls.client = cls.images_client
36 cls.servers_client = cls.servers_client
37
38 cls.image_ids = []
39
40 if compute.MULTI_USER:
41 if cls.config.compute.allow_tenant_isolation:
42 creds = cls._get_isolated_creds()
43 username, tenant_name, password = creds
44 cls.alt_manager = clients.Manager(username=username,
45 password=password,
46 tenant_name=tenant_name)
47 else:
48 # Use the alt_XXX credentials in the config file
49 cls.alt_manager = clients.AltManager()
50 cls.alt_client = cls.alt_manager.images_client
Rohit Karajgiea462ae2012-05-27 21:23:21 -070051
52 def tearDown(self):
Sean Daguef237ccb2013-01-04 15:19:14 -050053 """Terminate test instances created after a test is executed."""
Rohit Karajgiea462ae2012-05-27 21:23:21 -070054 for image_id in self.image_ids:
55 self.client.delete_image(image_id)
56 self.image_ids.remove(image_id)
Attila Fazekas19044d52013-02-16 07:35:06 +010057 super(ImagesTestJSON, self).tearDown()
Daryl Walleck73a9e7a2011-11-15 17:43:31 -060058
Ravikumar Venkatesan94d81172012-01-09 21:53:14 -080059 @attr(type='negative')
60 def test_create_image_from_deleted_server(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050061 # An image should not be created if the server instance is removed
Sean Dague22897e12013-02-25 17:54:09 -050062 resp, server = self.create_server(wait_until='ACTIVE')
Ravikumar Venkatesan94d81172012-01-09 21:53:14 -080063
64 # Delete server before trying to create server
65 self.servers_client.delete_server(server['id'])
66
67 try:
68 # Create a new image after server is deleted
69 name = rand_name('image')
70 meta = {'image_type': 'test'}
71 resp, body = self.client.create_image(server['id'], name, meta)
72
Matthew Treinish05d9fb92012-12-07 16:14:05 -050073 except Exception:
Ravikumar Venkatesan94d81172012-01-09 21:53:14 -080074 pass
75
76 else:
Jay Pipesf38eaac2012-06-21 13:37:35 -040077 image_id = parse_image_id(resp['location'])
Daryl Walleckade49f92012-01-16 23:14:26 -060078 self.client.wait_for_image_resp_code(image_id, 200)
79 self.client.wait_for_image_status(image_id, 'ACTIVE')
Jay Pipes04b70812012-01-11 10:53:24 -050080 self.client.delete_image(image_id)
Daryl Walleckade49f92012-01-16 23:14:26 -060081 self.fail("Should not create snapshot from deleted instance!")
rajalakshmi-ganesan32f8db62012-05-18 19:13:40 +053082
83 @attr(type='negative')
84 def test_create_image_from_invalid_server(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050085 # An image should not be created with invalid server id
rajalakshmi-ganesan32f8db62012-05-18 19:13:40 +053086 try:
87 # Create a new image with invalid server id
88 name = rand_name('image')
89 meta = {'image_type': 'test'}
90 resp = {}
91 resp['status'] = None
92 resp, body = self.client.create_image('!@#$%^&*()', name, meta)
93
94 except exceptions.NotFound:
95 pass
96
97 finally:
Zhongyue Luoe471d6e2012-09-17 17:02:43 +080098 if (resp['status'] is not None):
Jay Pipesf38eaac2012-06-21 13:37:35 -040099 image_id = parse_image_id(resp['location'])
rajalakshmi-ganesan32f8db62012-05-18 19:13:40 +0530100 resp, _ = self.client.delete_image(image_id)
Zhongyue Luoe0884a32012-09-25 17:24:17 +0800101 self.fail("An image should not be created "
102 "with invalid server id")
rajalakshmi-ganesan32f8db62012-05-18 19:13:40 +0530103
104 @attr(type='negative')
Attila Fazekas46a1d922013-01-11 10:19:42 +0100105 def test_create_image_when_server_is_terminating(self):
106 # Return an error when creating image of server that is terminating
Sean Dague22897e12013-02-25 17:54:09 -0500107 resp, server = self.create_server(wait_until='ACTIVE')
Attila Fazekas46a1d922013-01-11 10:19:42 +0100108 self.servers_client.delete_server(server['id'])
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700109
110 snapshot_name = rand_name('test-snap-')
Attila Fazekas46a1d922013-01-11 10:19:42 +0100111 self.assertRaises(exceptions.Duplicate, self.client.create_image,
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700112 server['id'], snapshot_name)
113
114 @attr(type='negative')
115 def test_create_image_when_server_is_building(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500116 # Return error when creating an image of a server that is building
Sean Dague22897e12013-02-25 17:54:09 -0500117 resp, server = self.create_server(wait_until='BUILD')
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700118 snapshot_name = rand_name('test-snap-')
119 self.assertRaises(exceptions.Duplicate, self.client.create_image,
120 server['id'], snapshot_name)
121
ivan-zhu1feeb382013-01-24 10:14:39 +0800122 @testtools.skip("Until Bug 1039739 is fixed")
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700123 @attr(type='negative')
124 def test_create_image_when_server_is_rebooting(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500125 # Return error when creating an image of server that is rebooting
Sean Dague22897e12013-02-25 17:54:09 -0500126 resp, server = self.create_server()
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700127 self.servers_client.reboot(server['id'], 'HARD')
128
129 snapshot_name = rand_name('test-snap-')
130 self.assertRaises(exceptions.Duplicate, self.client.create_image,
131 server['id'], snapshot_name)
132
133 @attr(type='negative')
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700134 def test_create_image_specify_uuid_35_characters_or_less(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500135 # Return an error if Image ID passed is 35 characters or less
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700136 try:
137 snapshot_name = rand_name('test-snap-')
138 test_uuid = ('a' * 35)
Joe Gordonf26620f2012-09-13 12:34:35 -0700139 self.assertRaises(exceptions.NotFound, self.client.create_image,
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700140 test_uuid, snapshot_name)
Matthew Treinish05d9fb92012-12-07 16:14:05 -0500141 except Exception:
Joe Gordonf26620f2012-09-13 12:34:35 -0700142 self.fail("Should return 404 Not Found if server uuid is 35"
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700143 " characters or less")
144
145 @attr(type='negative')
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700146 def test_create_image_specify_uuid_37_characters_or_more(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500147 # Return an error if Image ID passed is 37 characters or more
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700148 try:
149 snapshot_name = rand_name('test-snap-')
150 test_uuid = ('a' * 37)
Joe Gordonf26620f2012-09-13 12:34:35 -0700151 self.assertRaises(exceptions.NotFound, self.client.create_image,
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700152 test_uuid, snapshot_name)
Matthew Treinish05d9fb92012-12-07 16:14:05 -0500153 except Exception:
Joe Gordonf26620f2012-09-13 12:34:35 -0700154 self.fail("Should return 404 Not Found if server uuid is 37"
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700155 " characters or more")
156
157 @attr(type='negative')
rajalakshmi-ganesan32f8db62012-05-18 19:13:40 +0530158 def test_delete_image_with_invalid_image_id(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500159 # An image should not be deleted with invalid image id
rajalakshmi-ganesan32f8db62012-05-18 19:13:40 +0530160 try:
161 # Delete an image with invalid image id
162 resp, _ = self.client.delete_image('!@$%^&*()')
163
164 except exceptions.NotFound:
165 pass
166
167 else:
Zhongyue Luoe0884a32012-09-25 17:24:17 +0800168 self.fail("DELETE image request should rasie NotFound exception "
169 "when requested with invalid image")
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700170
171 @attr(type='negative')
172 def test_delete_non_existent_image(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500173 # Return an error while trying to delete a non-existent image
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700174
175 non_existent_image_id = '11a22b9-12a9-5555-cc11-00ab112223fa'
176 self.assertRaises(exceptions.NotFound, self.client.delete_image,
177 non_existent_image_id)
178
179 @attr(type='negative')
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700180 def test_delete_image_blank_id(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500181 # Return an error while trying to delete an image with blank Id
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700182
183 try:
David Kranz28e35c52012-07-10 10:14:38 -0400184 self.assertRaises(exceptions.NotFound, self.client.delete_image,
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700185 '')
Matthew Treinish05d9fb92012-12-07 16:14:05 -0500186 except Exception:
David Kranz28e35c52012-07-10 10:14:38 -0400187 self.fail("Did not return HTTP 404 NotFound for blank image id")
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700188
189 @attr(type='negative')
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700190 def test_delete_image_non_hex_string_id(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500191 # Return an error while trying to delete an image with non hex id
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700192
193 image_id = '11a22b9-120q-5555-cc11-00ab112223gj'
194 try:
David Kranz28e35c52012-07-10 10:14:38 -0400195 self.assertRaises(exceptions.NotFound, self.client.delete_image,
Zhongyue Luo79d8d362012-09-25 13:49:27 +0800196 image_id)
Matthew Treinish05d9fb92012-12-07 16:14:05 -0500197 except Exception:
David Kranz28e35c52012-07-10 10:14:38 -0400198 self.fail("Did not return HTTP 404 NotFound for non hex image")
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700199
200 @attr(type='negative')
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700201 def test_delete_image_negative_image_id(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500202 # Return an error while trying to delete an image with negative id
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700203
204 try:
David Kranz28e35c52012-07-10 10:14:38 -0400205 self.assertRaises(exceptions.NotFound, self.client.delete_image,
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700206 -1)
Matthew Treinish05d9fb92012-12-07 16:14:05 -0500207 except Exception:
Zhongyue Luo79d8d362012-09-25 13:49:27 +0800208 self.fail("Did not return HTTP 404 NotFound for negative image id")
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700209
210 @attr(type='negative')
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700211 def test_delete_image_id_is_over_35_character_limit(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500212 # Return an error while trying to delete image with id over limit
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700213
214 try:
David Kranz28e35c52012-07-10 10:14:38 -0400215 self.assertRaises(exceptions.NotFound, self.client.delete_image,
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700216 '11a22b9-120q-5555-cc11-00ab112223gj-3fac')
Matthew Treinish05d9fb92012-12-07 16:14:05 -0500217 except Exception:
David Kranz28e35c52012-07-10 10:14:38 -0400218 self.fail("Did not return HTTP 404 NotFound for image id that "
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700219 "exceeds 35 character ID length limit")
220
Dan Smithe7316bb2012-08-14 12:35:34 -0700221
Attila Fazekas19044d52013-02-16 07:35:06 +0100222class ImagesTestXML(ImagesTestJSON):
223 _interface = 'xml'