blob: fc09741501e4e57bed08ab7ed0a1940e2c11c41a [file] [log] [blame]
ZhiQiang Fan39f97222013-09-20 04:49:44 +08001# Copyright 2012 OpenStack Foundation
Jay Pipes13b479b2012-06-11 14:52:27 -04002#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
14
Sean Dague1937d092013-05-17 16:36:38 -040015from tempest.api.compute import base
Matthew Treinish481466b2012-12-20 17:16:01 -050016from tempest import clients
Masayuki Igawa259c1132013-10-31 17:48:44 +090017from tempest.common.utils import data_utils
Jay Pipes13b479b2012-06-11 14:52:27 -040018from tempest import exceptions
Chris Yeoh9465b0b2013-02-09 22:19:15 +103019from tempest.test import attr
Jay Pipes7f757632011-12-02 15:53:32 -050020
Daryl Walleck73a9e7a2011-11-15 17:43:31 -060021
ivan-zhuf2b00502013-10-18 10:06:52 +080022class ImagesTestJSON(base.BaseV2ComputeTest):
Attila Fazekas19044d52013-02-16 07:35:06 +010023 _interface = 'json'
24
25 @classmethod
26 def setUpClass(cls):
27 super(ImagesTestJSON, cls).setUpClass()
Matthew Treinish853ae442013-07-19 16:36:07 -040028 if not cls.config.service_available.glance:
29 skip_msg = ("%s skipped as glance is not available" % cls.__name__)
30 raise cls.skipException(skip_msg)
Attila Fazekas19044d52013-02-16 07:35:06 +010031 cls.client = cls.images_client
32 cls.servers_client = cls.servers_client
33
34 cls.image_ids = []
35
Matthew Treinishf7fca6a2013-12-09 16:27:23 +000036 if cls.multi_user:
Attila Fazekas19044d52013-02-16 07:35:06 +010037 if cls.config.compute.allow_tenant_isolation:
Matthew Treinishb86cda92013-07-29 11:22:23 -040038 creds = cls.isolated_creds.get_alt_creds()
Attila Fazekas19044d52013-02-16 07:35:06 +010039 username, tenant_name, password = creds
40 cls.alt_manager = clients.Manager(username=username,
41 password=password,
42 tenant_name=tenant_name)
43 else:
44 # Use the alt_XXX credentials in the config file
45 cls.alt_manager = clients.AltManager()
46 cls.alt_client = cls.alt_manager.images_client
Rohit Karajgiea462ae2012-05-27 21:23:21 -070047
48 def tearDown(self):
Sean Daguef237ccb2013-01-04 15:19:14 -050049 """Terminate test instances created after a test is executed."""
Rohit Karajgiea462ae2012-05-27 21:23:21 -070050 for image_id in self.image_ids:
51 self.client.delete_image(image_id)
52 self.image_ids.remove(image_id)
Attila Fazekas19044d52013-02-16 07:35:06 +010053 super(ImagesTestJSON, self).tearDown()
Daryl Walleck73a9e7a2011-11-15 17:43:31 -060054
saradpatel5ba4ff22013-03-11 22:08:17 -070055 def __create_image__(self, server_id, name, meta=None):
56 resp, body = self.client.create_image(server_id, name, meta)
Masayuki Igawa259c1132013-10-31 17:48:44 +090057 image_id = data_utils.parse_image_id(resp['location'])
saradpatel5ba4ff22013-03-11 22:08:17 -070058 self.client.wait_for_image_status(image_id, 'ACTIVE')
59 self.image_ids.append(image_id)
60 return resp, body
61
Giampaolo Lauriae9c77022013-05-22 01:23:58 -040062 @attr(type=['negative', 'gate'])
Ravikumar Venkatesan94d81172012-01-09 21:53:14 -080063 def test_create_image_from_deleted_server(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050064 # An image should not be created if the server instance is removed
Ken'ichi Ohmichicfc052e2013-10-23 11:50:04 +090065 resp, server = self.create_test_server(wait_until='ACTIVE')
Ravikumar Venkatesan94d81172012-01-09 21:53:14 -080066
67 # Delete server before trying to create server
68 self.servers_client.delete_server(server['id'])
saradpatel5ba4ff22013-03-11 22:08:17 -070069 self.servers_client.wait_for_server_termination(server['id'])
70 # Create a new image after server is deleted
Masayuki Igawa259c1132013-10-31 17:48:44 +090071 name = data_utils.rand_name('image')
saradpatel5ba4ff22013-03-11 22:08:17 -070072 meta = {'image_type': 'test'}
73 self.assertRaises(exceptions.NotFound,
74 self.__create_image__,
75 server['id'], name, meta)
rajalakshmi-ganesan32f8db62012-05-18 19:13:40 +053076
Giampaolo Lauriae9c77022013-05-22 01:23:58 -040077 @attr(type=['negative', 'gate'])
rajalakshmi-ganesan32f8db62012-05-18 19:13:40 +053078 def test_create_image_from_invalid_server(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050079 # An image should not be created with invalid server id
saradpatel5ba4ff22013-03-11 22:08:17 -070080 # Create a new image with invalid server id
Masayuki Igawa259c1132013-10-31 17:48:44 +090081 name = data_utils.rand_name('image')
saradpatel5ba4ff22013-03-11 22:08:17 -070082 meta = {'image_type': 'test'}
83 resp = {}
84 resp['status'] = None
85 self.assertRaises(exceptions.NotFound, self.__create_image__,
86 '!@#$%^&*()', name, meta)
rajalakshmi-ganesan32f8db62012-05-18 19:13:40 +053087
Giampaolo Lauriae9c77022013-05-22 01:23:58 -040088 @attr(type=['negative', 'gate'])
Liu, Zhi Kun3fb36952013-07-18 00:05:05 +080089 def test_create_image_from_stopped_server(self):
Ken'ichi Ohmichicfc052e2013-10-23 11:50:04 +090090 resp, server = self.create_test_server(wait_until='ACTIVE')
Liu, Zhi Kun3fb36952013-07-18 00:05:05 +080091 self.servers_client.stop(server['id'])
92 self.servers_client.wait_for_server_status(server['id'],
93 'SHUTOFF')
94 self.addCleanup(self.servers_client.delete_server, server['id'])
Masayuki Igawa259c1132013-10-31 17:48:44 +090095 snapshot_name = data_utils.rand_name('test-snap-')
Liu, Zhi Kun3fb36952013-07-18 00:05:05 +080096 resp, image = self.create_image_from_server(server['id'],
97 name=snapshot_name,
Bob Ball621e4602013-12-06 19:53:43 +000098 wait_until='ACTIVE',
99 wait_for_server=False)
Liu, Zhi Kun3fb36952013-07-18 00:05:05 +0800100 self.addCleanup(self.client.delete_image, image['id'])
101 self.assertEqual(snapshot_name, image['name'])
102
103 @attr(type='gate')
104 def test_delete_saving_image(self):
Masayuki Igawa259c1132013-10-31 17:48:44 +0900105 snapshot_name = data_utils.rand_name('test-snap-')
Ken'ichi Ohmichicfc052e2013-10-23 11:50:04 +0900106 resp, server = self.create_test_server(wait_until='ACTIVE')
Liu, Zhi Kun3fb36952013-07-18 00:05:05 +0800107 self.addCleanup(self.servers_client.delete_server, server['id'])
108 resp, image = self.create_image_from_server(server['id'],
109 name=snapshot_name,
110 wait_until='SAVING')
111 resp, body = self.client.delete_image(image['id'])
112 self.assertEqual('204', resp['status'])
113
114 @attr(type=['negative', 'gate'])
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700115 def test_create_image_specify_uuid_35_characters_or_less(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500116 # Return an error if Image ID passed is 35 characters or less
Masayuki Igawa259c1132013-10-31 17:48:44 +0900117 snapshot_name = data_utils.rand_name('test-snap-')
Chris Yeohe04628e2013-02-25 17:12:21 +1030118 test_uuid = ('a' * 35)
119 self.assertRaises(exceptions.NotFound, self.client.create_image,
120 test_uuid, snapshot_name)
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700121
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400122 @attr(type=['negative', 'gate'])
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700123 def test_create_image_specify_uuid_37_characters_or_more(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500124 # Return an error if Image ID passed is 37 characters or more
Masayuki Igawa259c1132013-10-31 17:48:44 +0900125 snapshot_name = data_utils.rand_name('test-snap-')
Chris Yeohe04628e2013-02-25 17:12:21 +1030126 test_uuid = ('a' * 37)
127 self.assertRaises(exceptions.NotFound, self.client.create_image,
128 test_uuid, snapshot_name)
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700129
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400130 @attr(type=['negative', 'gate'])
rajalakshmi-ganesan32f8db62012-05-18 19:13:40 +0530131 def test_delete_image_with_invalid_image_id(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500132 # An image should not be deleted with invalid image id
Chris Yeohe04628e2013-02-25 17:12:21 +1030133 self.assertRaises(exceptions.NotFound, self.client.delete_image,
134 '!@$%^&*()')
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700135
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400136 @attr(type=['negative', 'gate'])
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700137 def test_delete_non_existent_image(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500138 # Return an error while trying to delete a non-existent image
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700139
140 non_existent_image_id = '11a22b9-12a9-5555-cc11-00ab112223fa'
141 self.assertRaises(exceptions.NotFound, self.client.delete_image,
142 non_existent_image_id)
143
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400144 @attr(type=['negative', 'gate'])
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700145 def test_delete_image_blank_id(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500146 # Return an error while trying to delete an image with blank Id
Chris Yeohe04628e2013-02-25 17:12:21 +1030147 self.assertRaises(exceptions.NotFound, self.client.delete_image, '')
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700148
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400149 @attr(type=['negative', 'gate'])
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700150 def test_delete_image_non_hex_string_id(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500151 # Return an error while trying to delete an image with non hex id
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700152 image_id = '11a22b9-120q-5555-cc11-00ab112223gj'
Chris Yeohe04628e2013-02-25 17:12:21 +1030153 self.assertRaises(exceptions.NotFound, self.client.delete_image,
154 image_id)
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700155
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400156 @attr(type=['negative', 'gate'])
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700157 def test_delete_image_negative_image_id(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500158 # Return an error while trying to delete an image with negative id
Chris Yeohe04628e2013-02-25 17:12:21 +1030159 self.assertRaises(exceptions.NotFound, self.client.delete_image, -1)
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700160
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400161 @attr(type=['negative', 'gate'])
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700162 def test_delete_image_id_is_over_35_character_limit(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500163 # Return an error while trying to delete image with id over limit
Chris Yeohe04628e2013-02-25 17:12:21 +1030164 self.assertRaises(exceptions.NotFound, self.client.delete_image,
Ken'ichi Ohmichi64a42e02013-09-17 10:01:22 +0900165 '11a22b9-12a9-5555-cc11-00ab112223fa-3fac')
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700166
Dan Smithe7316bb2012-08-14 12:35:34 -0700167
Attila Fazekas19044d52013-02-16 07:35:06 +0100168class ImagesTestXML(ImagesTestJSON):
169 _interface = 'xml'