blob: 4cc36c991001f5b005b8470487011277ba3755bb [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
Matthew Treinishb0a78fc2014-01-29 16:49:12 +000018from tempest import config
Jay Pipes13b479b2012-06-11 14:52:27 -040019from tempest import exceptions
Chris Yeoh9465b0b2013-02-09 22:19:15 +103020from tempest.test import attr
Jay Pipes7f757632011-12-02 15:53:32 -050021
Matthew Treinishb0a78fc2014-01-29 16:49:12 +000022CONF = config.CONF
23
Daryl Walleck73a9e7a2011-11-15 17:43:31 -060024
ivan-zhuf2b00502013-10-18 10:06:52 +080025class ImagesTestJSON(base.BaseV2ComputeTest):
Attila Fazekas19044d52013-02-16 07:35:06 +010026 _interface = 'json'
27
28 @classmethod
29 def setUpClass(cls):
30 super(ImagesTestJSON, cls).setUpClass()
Matthew Treinishb0a78fc2014-01-29 16:49:12 +000031 if not CONF.service_available.glance:
Matthew Treinish853ae442013-07-19 16:36:07 -040032 skip_msg = ("%s skipped as glance is not available" % cls.__name__)
33 raise cls.skipException(skip_msg)
Attila Fazekas19044d52013-02-16 07:35:06 +010034 cls.client = cls.images_client
35 cls.servers_client = cls.servers_client
36
37 cls.image_ids = []
38
Matthew Treinishf7fca6a2013-12-09 16:27:23 +000039 if cls.multi_user:
Matthew Treinishb0a78fc2014-01-29 16:49:12 +000040 if CONF.compute.allow_tenant_isolation:
Matthew Treinishb86cda92013-07-29 11:22:23 -040041 creds = cls.isolated_creds.get_alt_creds()
Attila Fazekas19044d52013-02-16 07:35:06 +010042 username, tenant_name, password = creds
43 cls.alt_manager = clients.Manager(username=username,
44 password=password,
45 tenant_name=tenant_name)
46 else:
47 # Use the alt_XXX credentials in the config file
48 cls.alt_manager = clients.AltManager()
49 cls.alt_client = cls.alt_manager.images_client
Rohit Karajgiea462ae2012-05-27 21:23:21 -070050
51 def tearDown(self):
Sean Daguef237ccb2013-01-04 15:19:14 -050052 """Terminate test instances created after a test is executed."""
Rohit Karajgiea462ae2012-05-27 21:23:21 -070053 for image_id in self.image_ids:
54 self.client.delete_image(image_id)
55 self.image_ids.remove(image_id)
Attila Fazekas19044d52013-02-16 07:35:06 +010056 super(ImagesTestJSON, self).tearDown()
Daryl Walleck73a9e7a2011-11-15 17:43:31 -060057
saradpatel5ba4ff22013-03-11 22:08:17 -070058 def __create_image__(self, server_id, name, meta=None):
59 resp, body = self.client.create_image(server_id, name, meta)
Masayuki Igawa259c1132013-10-31 17:48:44 +090060 image_id = data_utils.parse_image_id(resp['location'])
saradpatel5ba4ff22013-03-11 22:08:17 -070061 self.client.wait_for_image_status(image_id, 'ACTIVE')
62 self.image_ids.append(image_id)
63 return resp, body
64
Giampaolo Lauriae9c77022013-05-22 01:23:58 -040065 @attr(type=['negative', 'gate'])
Ravikumar Venkatesan94d81172012-01-09 21:53:14 -080066 def test_create_image_from_deleted_server(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050067 # An image should not be created if the server instance is removed
Ken'ichi Ohmichicfc052e2013-10-23 11:50:04 +090068 resp, server = self.create_test_server(wait_until='ACTIVE')
Ravikumar Venkatesan94d81172012-01-09 21:53:14 -080069
70 # Delete server before trying to create server
71 self.servers_client.delete_server(server['id'])
saradpatel5ba4ff22013-03-11 22:08:17 -070072 self.servers_client.wait_for_server_termination(server['id'])
73 # Create a new image after server is deleted
Masayuki Igawa259c1132013-10-31 17:48:44 +090074 name = data_utils.rand_name('image')
saradpatel5ba4ff22013-03-11 22:08:17 -070075 meta = {'image_type': 'test'}
76 self.assertRaises(exceptions.NotFound,
77 self.__create_image__,
78 server['id'], name, meta)
rajalakshmi-ganesan32f8db62012-05-18 19:13:40 +053079
Giampaolo Lauriae9c77022013-05-22 01:23:58 -040080 @attr(type=['negative', 'gate'])
rajalakshmi-ganesan32f8db62012-05-18 19:13:40 +053081 def test_create_image_from_invalid_server(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050082 # An image should not be created with invalid server id
saradpatel5ba4ff22013-03-11 22:08:17 -070083 # Create a new image with invalid server id
Masayuki Igawa259c1132013-10-31 17:48:44 +090084 name = data_utils.rand_name('image')
saradpatel5ba4ff22013-03-11 22:08:17 -070085 meta = {'image_type': 'test'}
86 resp = {}
87 resp['status'] = None
88 self.assertRaises(exceptions.NotFound, self.__create_image__,
89 '!@#$%^&*()', name, meta)
rajalakshmi-ganesan32f8db62012-05-18 19:13:40 +053090
Giampaolo Lauriae9c77022013-05-22 01:23:58 -040091 @attr(type=['negative', 'gate'])
Liu, Zhi Kun3fb36952013-07-18 00:05:05 +080092 def test_create_image_from_stopped_server(self):
Ken'ichi Ohmichicfc052e2013-10-23 11:50:04 +090093 resp, server = self.create_test_server(wait_until='ACTIVE')
Liu, Zhi Kun3fb36952013-07-18 00:05:05 +080094 self.servers_client.stop(server['id'])
95 self.servers_client.wait_for_server_status(server['id'],
96 'SHUTOFF')
97 self.addCleanup(self.servers_client.delete_server, server['id'])
Masayuki Igawa259c1132013-10-31 17:48:44 +090098 snapshot_name = data_utils.rand_name('test-snap-')
Liu, Zhi Kun3fb36952013-07-18 00:05:05 +080099 resp, image = self.create_image_from_server(server['id'],
100 name=snapshot_name,
Bob Ball621e4602013-12-06 19:53:43 +0000101 wait_until='ACTIVE',
102 wait_for_server=False)
Liu, Zhi Kun3fb36952013-07-18 00:05:05 +0800103 self.addCleanup(self.client.delete_image, image['id'])
104 self.assertEqual(snapshot_name, image['name'])
105
106 @attr(type='gate')
107 def test_delete_saving_image(self):
Masayuki Igawa259c1132013-10-31 17:48:44 +0900108 snapshot_name = data_utils.rand_name('test-snap-')
Ken'ichi Ohmichicfc052e2013-10-23 11:50:04 +0900109 resp, server = self.create_test_server(wait_until='ACTIVE')
Liu, Zhi Kun3fb36952013-07-18 00:05:05 +0800110 self.addCleanup(self.servers_client.delete_server, server['id'])
111 resp, image = self.create_image_from_server(server['id'],
112 name=snapshot_name,
113 wait_until='SAVING')
114 resp, body = self.client.delete_image(image['id'])
115 self.assertEqual('204', resp['status'])
116
117 @attr(type=['negative', 'gate'])
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700118 def test_create_image_specify_uuid_35_characters_or_less(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500119 # Return an error if Image ID passed is 35 characters or less
Masayuki Igawa259c1132013-10-31 17:48:44 +0900120 snapshot_name = data_utils.rand_name('test-snap-')
Chris Yeohe04628e2013-02-25 17:12:21 +1030121 test_uuid = ('a' * 35)
122 self.assertRaises(exceptions.NotFound, self.client.create_image,
123 test_uuid, snapshot_name)
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700124
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400125 @attr(type=['negative', 'gate'])
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700126 def test_create_image_specify_uuid_37_characters_or_more(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500127 # Return an error if Image ID passed is 37 characters or more
Masayuki Igawa259c1132013-10-31 17:48:44 +0900128 snapshot_name = data_utils.rand_name('test-snap-')
Chris Yeohe04628e2013-02-25 17:12:21 +1030129 test_uuid = ('a' * 37)
130 self.assertRaises(exceptions.NotFound, self.client.create_image,
131 test_uuid, snapshot_name)
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700132
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400133 @attr(type=['negative', 'gate'])
rajalakshmi-ganesan32f8db62012-05-18 19:13:40 +0530134 def test_delete_image_with_invalid_image_id(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500135 # An image should not be deleted with invalid image id
Chris Yeohe04628e2013-02-25 17:12:21 +1030136 self.assertRaises(exceptions.NotFound, self.client.delete_image,
137 '!@$%^&*()')
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700138
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400139 @attr(type=['negative', 'gate'])
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700140 def test_delete_non_existent_image(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500141 # Return an error while trying to delete a non-existent image
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700142
143 non_existent_image_id = '11a22b9-12a9-5555-cc11-00ab112223fa'
144 self.assertRaises(exceptions.NotFound, self.client.delete_image,
145 non_existent_image_id)
146
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400147 @attr(type=['negative', 'gate'])
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700148 def test_delete_image_blank_id(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500149 # Return an error while trying to delete an image with blank Id
Chris Yeohe04628e2013-02-25 17:12:21 +1030150 self.assertRaises(exceptions.NotFound, self.client.delete_image, '')
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700151
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400152 @attr(type=['negative', 'gate'])
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700153 def test_delete_image_non_hex_string_id(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500154 # Return an error while trying to delete an image with non hex id
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700155 image_id = '11a22b9-120q-5555-cc11-00ab112223gj'
Chris Yeohe04628e2013-02-25 17:12:21 +1030156 self.assertRaises(exceptions.NotFound, self.client.delete_image,
157 image_id)
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700158
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400159 @attr(type=['negative', 'gate'])
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700160 def test_delete_image_negative_image_id(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500161 # Return an error while trying to delete an image with negative id
Chris Yeohe04628e2013-02-25 17:12:21 +1030162 self.assertRaises(exceptions.NotFound, self.client.delete_image, -1)
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700163
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400164 @attr(type=['negative', 'gate'])
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700165 def test_delete_image_id_is_over_35_character_limit(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500166 # Return an error while trying to delete image with id over limit
Chris Yeohe04628e2013-02-25 17:12:21 +1030167 self.assertRaises(exceptions.NotFound, self.client.delete_image,
Ken'ichi Ohmichi64a42e02013-09-17 10:01:22 +0900168 '11a22b9-12a9-5555-cc11-00ab112223fa-3fac')
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700169
Dan Smithe7316bb2012-08-14 12:35:34 -0700170
Attila Fazekas19044d52013-02-16 07:35:06 +0100171class ImagesTestXML(ImagesTestJSON):
172 _interface = 'xml'