blob: a74bb689209afafbbbb544e3543fba2319bdd1aa [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
Sean Dague1937d092013-05-17 16:36:38 -040018from tempest.api import compute
19from tempest.api.compute import base
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 Pipes7f757632011-12-02 15:53:32 -050025
Daryl Walleck73a9e7a2011-11-15 17:43:31 -060026
Attila Fazekas19044d52013-02-16 07:35:06 +010027class ImagesTestJSON(base.BaseComputeTest):
28 _interface = 'json'
29
30 @classmethod
31 def setUpClass(cls):
32 super(ImagesTestJSON, cls).setUpClass()
33 cls.client = cls.images_client
34 cls.servers_client = cls.servers_client
35
36 cls.image_ids = []
37
38 if compute.MULTI_USER:
39 if cls.config.compute.allow_tenant_isolation:
40 creds = cls._get_isolated_creds()
41 username, tenant_name, password = creds
42 cls.alt_manager = clients.Manager(username=username,
43 password=password,
44 tenant_name=tenant_name)
45 else:
46 # Use the alt_XXX credentials in the config file
47 cls.alt_manager = clients.AltManager()
48 cls.alt_client = cls.alt_manager.images_client
Rohit Karajgiea462ae2012-05-27 21:23:21 -070049
50 def tearDown(self):
Sean Daguef237ccb2013-01-04 15:19:14 -050051 """Terminate test instances created after a test is executed."""
Rohit Karajgiea462ae2012-05-27 21:23:21 -070052 for image_id in self.image_ids:
53 self.client.delete_image(image_id)
54 self.image_ids.remove(image_id)
Attila Fazekas19044d52013-02-16 07:35:06 +010055 super(ImagesTestJSON, self).tearDown()
Daryl Walleck73a9e7a2011-11-15 17:43:31 -060056
saradpatel5ba4ff22013-03-11 22:08:17 -070057 def __create_image__(self, server_id, name, meta=None):
58 resp, body = self.client.create_image(server_id, name, meta)
59 image_id = parse_image_id(resp['location'])
60 self.client.wait_for_image_resp_code(image_id, 200)
61 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
Sean Dague22897e12013-02-25 17:54:09 -050068 resp, server = self.create_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
74 name = rand_name('image')
75 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
84 name = rand_name('image')
85 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'])
Attila Fazekas46a1d922013-01-11 10:19:42 +010092 def test_create_image_when_server_is_terminating(self):
93 # Return an error when creating image of server that is terminating
Sean Dague22897e12013-02-25 17:54:09 -050094 resp, server = self.create_server(wait_until='ACTIVE')
Attila Fazekas46a1d922013-01-11 10:19:42 +010095 self.servers_client.delete_server(server['id'])
Rohit Karajgiea462ae2012-05-27 21:23:21 -070096
97 snapshot_name = rand_name('test-snap-')
Attila Fazekas46a1d922013-01-11 10:19:42 +010098 self.assertRaises(exceptions.Duplicate, self.client.create_image,
Rohit Karajgiea462ae2012-05-27 21:23:21 -070099 server['id'], snapshot_name)
100
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400101 @attr(type=['negative', 'gate'])
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700102 def test_create_image_when_server_is_rebooting(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500103 # Return error when creating an image of server that is rebooting
JordanPfd8d49d2013-05-29 10:09:36 +0200104 resp, server = self.create_server(wait_until='ACTIVE')
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700105 self.servers_client.reboot(server['id'], 'HARD')
106
107 snapshot_name = rand_name('test-snap-')
108 self.assertRaises(exceptions.Duplicate, self.client.create_image,
109 server['id'], snapshot_name)
110
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400111 @attr(type=['negative', 'gate'])
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700112 def test_create_image_specify_uuid_35_characters_or_less(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500113 # Return an error if Image ID passed is 35 characters or less
Chris Yeohe04628e2013-02-25 17:12:21 +1030114 snapshot_name = rand_name('test-snap-')
115 test_uuid = ('a' * 35)
116 self.assertRaises(exceptions.NotFound, self.client.create_image,
117 test_uuid, snapshot_name)
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700118
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400119 @attr(type=['negative', 'gate'])
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700120 def test_create_image_specify_uuid_37_characters_or_more(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500121 # Return an error if Image ID passed is 37 characters or more
Chris Yeohe04628e2013-02-25 17:12:21 +1030122 snapshot_name = rand_name('test-snap-')
123 test_uuid = ('a' * 37)
124 self.assertRaises(exceptions.NotFound, self.client.create_image,
125 test_uuid, snapshot_name)
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700126
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400127 @attr(type=['negative', 'gate'])
rajalakshmi-ganesan32f8db62012-05-18 19:13:40 +0530128 def test_delete_image_with_invalid_image_id(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500129 # An image should not be deleted with invalid image id
Chris Yeohe04628e2013-02-25 17:12:21 +1030130 self.assertRaises(exceptions.NotFound, self.client.delete_image,
131 '!@$%^&*()')
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700132
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400133 @attr(type=['negative', 'gate'])
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700134 def test_delete_non_existent_image(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500135 # Return an error while trying to delete a non-existent image
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700136
137 non_existent_image_id = '11a22b9-12a9-5555-cc11-00ab112223fa'
138 self.assertRaises(exceptions.NotFound, self.client.delete_image,
139 non_existent_image_id)
140
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400141 @attr(type=['negative', 'gate'])
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700142 def test_delete_image_blank_id(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500143 # Return an error while trying to delete an image with blank Id
Chris Yeohe04628e2013-02-25 17:12:21 +1030144 self.assertRaises(exceptions.NotFound, self.client.delete_image, '')
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700145
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400146 @attr(type=['negative', 'gate'])
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700147 def test_delete_image_non_hex_string_id(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500148 # Return an error while trying to delete an image with non hex id
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700149 image_id = '11a22b9-120q-5555-cc11-00ab112223gj'
Chris Yeohe04628e2013-02-25 17:12:21 +1030150 self.assertRaises(exceptions.NotFound, self.client.delete_image,
151 image_id)
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700152
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400153 @attr(type=['negative', 'gate'])
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700154 def test_delete_image_negative_image_id(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500155 # Return an error while trying to delete an image with negative id
Chris Yeohe04628e2013-02-25 17:12:21 +1030156 self.assertRaises(exceptions.NotFound, self.client.delete_image, -1)
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700157
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400158 @attr(type=['negative', 'gate'])
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700159 def test_delete_image_id_is_over_35_character_limit(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500160 # Return an error while trying to delete image with id over limit
Chris Yeohe04628e2013-02-25 17:12:21 +1030161 self.assertRaises(exceptions.NotFound, self.client.delete_image,
162 '11a22b9-120q-5555-cc11-00ab112223gj-3fac')
Rohit Karajgiea462ae2012-05-27 21:23:21 -0700163
Dan Smithe7316bb2012-08-14 12:35:34 -0700164
Attila Fazekas19044d52013-02-16 07:35:06 +0100165class ImagesTestXML(ImagesTestJSON):
166 _interface = 'xml'