blob: bb6ead956b51c08082987503473647294b2c3800 [file] [log] [blame]
Jay Pipes13b479b2012-06-11 14:52:27 -04001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
ZhiQiang Fan39f97222013-09-20 04:49:44 +08003# Copyright 2012 OpenStack Foundation
Jay Pipes13b479b2012-06-11 14:52:27 -04004#
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
Sean Dague1937d092013-05-17 16:36:38 -040017from tempest.api import compute
18from tempest.api.compute import base
Matthew Treinish481466b2012-12-20 17:16:01 -050019from tempest import clients
Matthew Treinisha83a16e2012-12-07 13:44:02 -050020from tempest.common.utils.data_utils import parse_image_id
21from tempest.common.utils.data_utils import rand_name
Jay Pipes13b479b2012-06-11 14:52:27 -040022from tempest import exceptions
Chris Yeoh9465b0b2013-02-09 22:19:15 +103023from tempest.test import attr
Jay Pipes7f757632011-12-02 15:53:32 -050024
Daryl Walleck73a9e7a2011-11-15 17:43:31 -060025
ivan-zhuf2b00502013-10-18 10:06:52 +080026class ImagesTestJSON(base.BaseV2ComputeTest):
Attila Fazekas19044d52013-02-16 07:35:06 +010027 _interface = 'json'
28
29 @classmethod
30 def setUpClass(cls):
31 super(ImagesTestJSON, cls).setUpClass()
Matthew Treinish853ae442013-07-19 16:36:07 -040032 if not cls.config.service_available.glance:
33 skip_msg = ("%s skipped as glance is not available" % cls.__name__)
34 raise cls.skipException(skip_msg)
Attila Fazekas19044d52013-02-16 07:35:06 +010035 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:
Matthew Treinishb86cda92013-07-29 11:22:23 -040042 creds = cls.isolated_creds.get_alt_creds()
Attila Fazekas19044d52013-02-16 07:35:06 +010043 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
saradpatel5ba4ff22013-03-11 22:08:17 -070059 def __create_image__(self, server_id, name, meta=None):
60 resp, body = self.client.create_image(server_id, name, meta)
61 image_id = parse_image_id(resp['location'])
saradpatel5ba4ff22013-03-11 22:08:17 -070062 self.client.wait_for_image_status(image_id, 'ACTIVE')
63 self.image_ids.append(image_id)
64 return resp, body
65
Giampaolo Lauriae9c77022013-05-22 01:23:58 -040066 @attr(type=['negative', 'gate'])
Ravikumar Venkatesan94d81172012-01-09 21:53:14 -080067 def test_create_image_from_deleted_server(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050068 # An image should not be created if the server instance is removed
Ken'ichi Ohmichicfc052e2013-10-23 11:50:04 +090069 resp, server = self.create_test_server(wait_until='ACTIVE')
Ravikumar Venkatesan94d81172012-01-09 21:53:14 -080070
71 # Delete server before trying to create server
72 self.servers_client.delete_server(server['id'])
saradpatel5ba4ff22013-03-11 22:08:17 -070073 self.servers_client.wait_for_server_termination(server['id'])
74 # Create a new image after server is deleted
75 name = rand_name('image')
76 meta = {'image_type': 'test'}
77 self.assertRaises(exceptions.NotFound,
78 self.__create_image__,
79 server['id'], name, meta)
rajalakshmi-ganesan32f8db62012-05-18 19:13:40 +053080
Giampaolo Lauriae9c77022013-05-22 01:23:58 -040081 @attr(type=['negative', 'gate'])
rajalakshmi-ganesan32f8db62012-05-18 19:13:40 +053082 def test_create_image_from_invalid_server(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050083 # An image should not be created with invalid server id
saradpatel5ba4ff22013-03-11 22:08:17 -070084 # Create a new image with invalid server id
85 name = rand_name('image')
86 meta = {'image_type': 'test'}
87 resp = {}
88 resp['status'] = None
89 self.assertRaises(exceptions.NotFound, self.__create_image__,
90 '!@#$%^&*()', name, meta)
rajalakshmi-ganesan32f8db62012-05-18 19:13:40 +053091
Giampaolo Lauriae9c77022013-05-22 01:23:58 -040092 @attr(type=['negative', 'gate'])
Liu, Zhi Kun3fb36952013-07-18 00:05:05 +080093 def test_create_image_from_stopped_server(self):
Ken'ichi Ohmichicfc052e2013-10-23 11:50:04 +090094 resp, server = self.create_test_server(wait_until='ACTIVE')
Liu, Zhi Kun3fb36952013-07-18 00:05:05 +080095 self.servers_client.stop(server['id'])
96 self.servers_client.wait_for_server_status(server['id'],
97 'SHUTOFF')
98 self.addCleanup(self.servers_client.delete_server, server['id'])
99 snapshot_name = rand_name('test-snap-')
100 resp, image = self.create_image_from_server(server['id'],
101 name=snapshot_name,
102 wait_until='ACTIVE')
103 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):
108 snapshot_name = 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
Chris Yeohe04628e2013-02-25 17:12:21 +1030120 snapshot_name = rand_name('test-snap-')
121 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
Chris Yeohe04628e2013-02-25 17:12:21 +1030128 snapshot_name = rand_name('test-snap-')
129 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'