Jay Pipes | 13b479b | 2012-06-11 14:52:27 -0400 | [diff] [blame] | 1 | # 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 Dague | 1937d09 | 2013-05-17 16:36:38 -0400 | [diff] [blame] | 18 | from tempest.api import compute |
| 19 | from tempest.api.compute import base |
Matthew Treinish | 481466b | 2012-12-20 17:16:01 -0500 | [diff] [blame] | 20 | from tempest import clients |
Matthew Treinish | a83a16e | 2012-12-07 13:44:02 -0500 | [diff] [blame] | 21 | from tempest.common.utils.data_utils import parse_image_id |
| 22 | from tempest.common.utils.data_utils import rand_name |
Jay Pipes | 13b479b | 2012-06-11 14:52:27 -0400 | [diff] [blame] | 23 | from tempest import exceptions |
Chris Yeoh | 9465b0b | 2013-02-09 22:19:15 +1030 | [diff] [blame] | 24 | from tempest.test import attr |
Jay Pipes | 7f75763 | 2011-12-02 15:53:32 -0500 | [diff] [blame] | 25 | |
Daryl Walleck | 73a9e7a | 2011-11-15 17:43:31 -0600 | [diff] [blame] | 26 | |
Attila Fazekas | 19044d5 | 2013-02-16 07:35:06 +0100 | [diff] [blame] | 27 | class ImagesTestJSON(base.BaseComputeTest): |
| 28 | _interface = 'json' |
| 29 | |
| 30 | @classmethod |
| 31 | def setUpClass(cls): |
| 32 | super(ImagesTestJSON, cls).setUpClass() |
Matthew Treinish | 853ae44 | 2013-07-19 16:36:07 -0400 | [diff] [blame^] | 33 | if not cls.config.service_available.glance: |
| 34 | skip_msg = ("%s skipped as glance is not available" % cls.__name__) |
| 35 | raise cls.skipException(skip_msg) |
Attila Fazekas | 19044d5 | 2013-02-16 07:35:06 +0100 | [diff] [blame] | 36 | cls.client = cls.images_client |
| 37 | cls.servers_client = cls.servers_client |
| 38 | |
| 39 | cls.image_ids = [] |
| 40 | |
| 41 | if compute.MULTI_USER: |
| 42 | if cls.config.compute.allow_tenant_isolation: |
| 43 | creds = cls._get_isolated_creds() |
| 44 | username, tenant_name, password = creds |
| 45 | cls.alt_manager = clients.Manager(username=username, |
| 46 | password=password, |
| 47 | tenant_name=tenant_name) |
| 48 | else: |
| 49 | # Use the alt_XXX credentials in the config file |
| 50 | cls.alt_manager = clients.AltManager() |
| 51 | cls.alt_client = cls.alt_manager.images_client |
Rohit Karajgi | ea462ae | 2012-05-27 21:23:21 -0700 | [diff] [blame] | 52 | |
| 53 | def tearDown(self): |
Sean Dague | f237ccb | 2013-01-04 15:19:14 -0500 | [diff] [blame] | 54 | """Terminate test instances created after a test is executed.""" |
Rohit Karajgi | ea462ae | 2012-05-27 21:23:21 -0700 | [diff] [blame] | 55 | for image_id in self.image_ids: |
| 56 | self.client.delete_image(image_id) |
| 57 | self.image_ids.remove(image_id) |
Attila Fazekas | 19044d5 | 2013-02-16 07:35:06 +0100 | [diff] [blame] | 58 | super(ImagesTestJSON, self).tearDown() |
Daryl Walleck | 73a9e7a | 2011-11-15 17:43:31 -0600 | [diff] [blame] | 59 | |
saradpatel | 5ba4ff2 | 2013-03-11 22:08:17 -0700 | [diff] [blame] | 60 | def __create_image__(self, server_id, name, meta=None): |
| 61 | resp, body = self.client.create_image(server_id, name, meta) |
| 62 | image_id = parse_image_id(resp['location']) |
| 63 | self.client.wait_for_image_resp_code(image_id, 200) |
| 64 | self.client.wait_for_image_status(image_id, 'ACTIVE') |
| 65 | self.image_ids.append(image_id) |
| 66 | return resp, body |
| 67 | |
Giampaolo Lauria | e9c7702 | 2013-05-22 01:23:58 -0400 | [diff] [blame] | 68 | @attr(type=['negative', 'gate']) |
Ravikumar Venkatesan | 94d8117 | 2012-01-09 21:53:14 -0800 | [diff] [blame] | 69 | def test_create_image_from_deleted_server(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 70 | # An image should not be created if the server instance is removed |
Sean Dague | 22897e1 | 2013-02-25 17:54:09 -0500 | [diff] [blame] | 71 | resp, server = self.create_server(wait_until='ACTIVE') |
Ravikumar Venkatesan | 94d8117 | 2012-01-09 21:53:14 -0800 | [diff] [blame] | 72 | |
| 73 | # Delete server before trying to create server |
| 74 | self.servers_client.delete_server(server['id']) |
saradpatel | 5ba4ff2 | 2013-03-11 22:08:17 -0700 | [diff] [blame] | 75 | self.servers_client.wait_for_server_termination(server['id']) |
| 76 | # Create a new image after server is deleted |
| 77 | name = rand_name('image') |
| 78 | meta = {'image_type': 'test'} |
| 79 | self.assertRaises(exceptions.NotFound, |
| 80 | self.__create_image__, |
| 81 | server['id'], name, meta) |
rajalakshmi-ganesan | 32f8db6 | 2012-05-18 19:13:40 +0530 | [diff] [blame] | 82 | |
Giampaolo Lauria | e9c7702 | 2013-05-22 01:23:58 -0400 | [diff] [blame] | 83 | @attr(type=['negative', 'gate']) |
rajalakshmi-ganesan | 32f8db6 | 2012-05-18 19:13:40 +0530 | [diff] [blame] | 84 | def test_create_image_from_invalid_server(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 85 | # An image should not be created with invalid server id |
saradpatel | 5ba4ff2 | 2013-03-11 22:08:17 -0700 | [diff] [blame] | 86 | # Create a new image with invalid server id |
| 87 | name = rand_name('image') |
| 88 | meta = {'image_type': 'test'} |
| 89 | resp = {} |
| 90 | resp['status'] = None |
| 91 | self.assertRaises(exceptions.NotFound, self.__create_image__, |
| 92 | '!@#$%^&*()', name, meta) |
rajalakshmi-ganesan | 32f8db6 | 2012-05-18 19:13:40 +0530 | [diff] [blame] | 93 | |
Giampaolo Lauria | e9c7702 | 2013-05-22 01:23:58 -0400 | [diff] [blame] | 94 | @attr(type=['negative', 'gate']) |
Rohit Karajgi | ea462ae | 2012-05-27 21:23:21 -0700 | [diff] [blame] | 95 | def test_create_image_specify_uuid_35_characters_or_less(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 96 | # Return an error if Image ID passed is 35 characters or less |
Chris Yeoh | e04628e | 2013-02-25 17:12:21 +1030 | [diff] [blame] | 97 | snapshot_name = rand_name('test-snap-') |
| 98 | test_uuid = ('a' * 35) |
| 99 | self.assertRaises(exceptions.NotFound, self.client.create_image, |
| 100 | test_uuid, snapshot_name) |
Rohit Karajgi | ea462ae | 2012-05-27 21:23:21 -0700 | [diff] [blame] | 101 | |
Giampaolo Lauria | e9c7702 | 2013-05-22 01:23:58 -0400 | [diff] [blame] | 102 | @attr(type=['negative', 'gate']) |
Rohit Karajgi | ea462ae | 2012-05-27 21:23:21 -0700 | [diff] [blame] | 103 | def test_create_image_specify_uuid_37_characters_or_more(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 104 | # Return an error if Image ID passed is 37 characters or more |
Chris Yeoh | e04628e | 2013-02-25 17:12:21 +1030 | [diff] [blame] | 105 | snapshot_name = rand_name('test-snap-') |
| 106 | test_uuid = ('a' * 37) |
| 107 | self.assertRaises(exceptions.NotFound, self.client.create_image, |
| 108 | test_uuid, snapshot_name) |
Rohit Karajgi | ea462ae | 2012-05-27 21:23:21 -0700 | [diff] [blame] | 109 | |
Giampaolo Lauria | e9c7702 | 2013-05-22 01:23:58 -0400 | [diff] [blame] | 110 | @attr(type=['negative', 'gate']) |
rajalakshmi-ganesan | 32f8db6 | 2012-05-18 19:13:40 +0530 | [diff] [blame] | 111 | def test_delete_image_with_invalid_image_id(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 112 | # An image should not be deleted with invalid image id |
Chris Yeoh | e04628e | 2013-02-25 17:12:21 +1030 | [diff] [blame] | 113 | self.assertRaises(exceptions.NotFound, self.client.delete_image, |
| 114 | '!@$%^&*()') |
Rohit Karajgi | ea462ae | 2012-05-27 21:23:21 -0700 | [diff] [blame] | 115 | |
Giampaolo Lauria | e9c7702 | 2013-05-22 01:23:58 -0400 | [diff] [blame] | 116 | @attr(type=['negative', 'gate']) |
Rohit Karajgi | ea462ae | 2012-05-27 21:23:21 -0700 | [diff] [blame] | 117 | def test_delete_non_existent_image(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 118 | # Return an error while trying to delete a non-existent image |
Rohit Karajgi | ea462ae | 2012-05-27 21:23:21 -0700 | [diff] [blame] | 119 | |
| 120 | non_existent_image_id = '11a22b9-12a9-5555-cc11-00ab112223fa' |
| 121 | self.assertRaises(exceptions.NotFound, self.client.delete_image, |
| 122 | non_existent_image_id) |
| 123 | |
Giampaolo Lauria | e9c7702 | 2013-05-22 01:23:58 -0400 | [diff] [blame] | 124 | @attr(type=['negative', 'gate']) |
Rohit Karajgi | ea462ae | 2012-05-27 21:23:21 -0700 | [diff] [blame] | 125 | def test_delete_image_blank_id(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 126 | # Return an error while trying to delete an image with blank Id |
Chris Yeoh | e04628e | 2013-02-25 17:12:21 +1030 | [diff] [blame] | 127 | self.assertRaises(exceptions.NotFound, self.client.delete_image, '') |
Rohit Karajgi | ea462ae | 2012-05-27 21:23:21 -0700 | [diff] [blame] | 128 | |
Giampaolo Lauria | e9c7702 | 2013-05-22 01:23:58 -0400 | [diff] [blame] | 129 | @attr(type=['negative', 'gate']) |
Rohit Karajgi | ea462ae | 2012-05-27 21:23:21 -0700 | [diff] [blame] | 130 | def test_delete_image_non_hex_string_id(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 131 | # Return an error while trying to delete an image with non hex id |
Rohit Karajgi | ea462ae | 2012-05-27 21:23:21 -0700 | [diff] [blame] | 132 | image_id = '11a22b9-120q-5555-cc11-00ab112223gj' |
Chris Yeoh | e04628e | 2013-02-25 17:12:21 +1030 | [diff] [blame] | 133 | self.assertRaises(exceptions.NotFound, self.client.delete_image, |
| 134 | image_id) |
Rohit Karajgi | ea462ae | 2012-05-27 21:23:21 -0700 | [diff] [blame] | 135 | |
Giampaolo Lauria | e9c7702 | 2013-05-22 01:23:58 -0400 | [diff] [blame] | 136 | @attr(type=['negative', 'gate']) |
Rohit Karajgi | ea462ae | 2012-05-27 21:23:21 -0700 | [diff] [blame] | 137 | def test_delete_image_negative_image_id(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 138 | # Return an error while trying to delete an image with negative id |
Chris Yeoh | e04628e | 2013-02-25 17:12:21 +1030 | [diff] [blame] | 139 | self.assertRaises(exceptions.NotFound, self.client.delete_image, -1) |
Rohit Karajgi | ea462ae | 2012-05-27 21:23:21 -0700 | [diff] [blame] | 140 | |
Giampaolo Lauria | e9c7702 | 2013-05-22 01:23:58 -0400 | [diff] [blame] | 141 | @attr(type=['negative', 'gate']) |
Rohit Karajgi | ea462ae | 2012-05-27 21:23:21 -0700 | [diff] [blame] | 142 | def test_delete_image_id_is_over_35_character_limit(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 143 | # Return an error while trying to delete image with id over limit |
Chris Yeoh | e04628e | 2013-02-25 17:12:21 +1030 | [diff] [blame] | 144 | self.assertRaises(exceptions.NotFound, self.client.delete_image, |
| 145 | '11a22b9-120q-5555-cc11-00ab112223gj-3fac') |
Rohit Karajgi | ea462ae | 2012-05-27 21:23:21 -0700 | [diff] [blame] | 146 | |
Dan Smith | e7316bb | 2012-08-14 12:35:34 -0700 | [diff] [blame] | 147 | |
Attila Fazekas | 19044d5 | 2013-02-16 07:35:06 +0100 | [diff] [blame] | 148 | class ImagesTestXML(ImagesTestJSON): |
| 149 | _interface = 'xml' |