blob: 7f23730dd485070e2f74937a0677144580f5860c [file] [log] [blame]
nayna-patel26f48592014-02-28 09:30:38 +00001# Copyright 2012 OpenStack Foundation
2#
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
Masayuki Igawabfa07602015-01-20 18:47:17 +090015from tempest_lib import exceptions as lib_exc
16
nayna-patel26f48592014-02-28 09:30:38 +000017from tempest.api.compute import base
Fei Long Wangd39431f2015-05-14 11:30:48 +120018from tempest.common.utils import data_utils
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +000019from tempest.common import waiters
nayna-patel26f48592014-02-28 09:30:38 +000020from tempest import config
nayna-patel26f48592014-02-28 09:30:38 +000021from tempest import test
22
23CONF = config.CONF
24
25
26class ImagesNegativeTestJSON(base.BaseV2ComputeTest):
27
28 @classmethod
Rohan Kanade60b73092015-02-04 17:58:19 +053029 def skip_checks(cls):
30 super(ImagesNegativeTestJSON, cls).skip_checks()
nayna-patel26f48592014-02-28 09:30:38 +000031 if not CONF.service_available.glance:
32 skip_msg = ("%s skipped as glance is not available" % cls.__name__)
33 raise cls.skipException(skip_msg)
Adam Gandelmanfbc95ac2014-06-19 17:33:43 -070034 if not CONF.compute_feature_enabled.snapshot:
35 skip_msg = ("%s skipped as instance snapshotting is not supported"
36 % cls.__name__)
37 raise cls.skipException(skip_msg)
38
Rohan Kanade60b73092015-02-04 17:58:19 +053039 @classmethod
40 def setup_clients(cls):
41 super(ImagesNegativeTestJSON, cls).setup_clients()
nayna-patel26f48592014-02-28 09:30:38 +000042 cls.client = cls.images_client
43 cls.servers_client = cls.servers_client
44
Sean Dague639f2fa2015-04-27 09:00:33 -040045 @test.attr(type=['negative'])
Chris Hoge7579c1a2015-02-26 14:12:15 -080046 @test.idempotent_id('6cd5a89d-5b47-46a7-93bc-3916f0d84973')
nayna-patel26f48592014-02-28 09:30:38 +000047 def test_create_image_from_deleted_server(self):
48 # An image should not be created if the server instance is removed
David Kranz0fb14292015-02-11 15:55:20 -050049 server = self.create_test_server(wait_until='ACTIVE')
nayna-patel26f48592014-02-28 09:30:38 +000050
51 # Delete server before trying to create server
52 self.servers_client.delete_server(server['id'])
Ken'ichi Ohmichie91a0c62015-08-13 02:09:16 +000053 waiters.wait_for_server_termination(self.servers_client, server['id'])
Matthew Treinishc795b9e2014-06-09 17:01:10 -040054 # Create a new image after server is deleted
nayna-patel26f48592014-02-28 09:30:38 +000055 name = data_utils.rand_name('image')
56 meta = {'image_type': 'test'}
Masayuki Igawabfa07602015-01-20 18:47:17 +090057 self.assertRaises(lib_exc.NotFound,
nayna-patel26f48592014-02-28 09:30:38 +000058 self.create_image_from_server,
59 server['id'], name=name, meta=meta)
60
Sean Dague639f2fa2015-04-27 09:00:33 -040061 @test.attr(type=['negative'])
Chris Hoge7579c1a2015-02-26 14:12:15 -080062 @test.idempotent_id('82c5b0c4-9dbd-463c-872b-20c4755aae7f')
nayna-patel26f48592014-02-28 09:30:38 +000063 def test_create_image_from_invalid_server(self):
64 # An image should not be created with invalid server id
65 # Create a new image with invalid server id
66 name = data_utils.rand_name('image')
67 meta = {'image_type': 'test'}
68 resp = {}
69 resp['status'] = None
Masayuki Igawabfa07602015-01-20 18:47:17 +090070 self.assertRaises(lib_exc.NotFound, self.create_image_from_server,
nayna-patel26f48592014-02-28 09:30:38 +000071 '!@#$%^&*()', name=name, meta=meta)
72
Sean Dague639f2fa2015-04-27 09:00:33 -040073 @test.attr(type=['negative'])
Chris Hoge7579c1a2015-02-26 14:12:15 -080074 @test.idempotent_id('aaacd1d0-55a2-4ce8-818a-b5439df8adc9')
nayna-patel26f48592014-02-28 09:30:38 +000075 def test_create_image_from_stopped_server(self):
David Kranz0fb14292015-02-11 15:55:20 -050076 server = self.create_test_server(wait_until='ACTIVE')
nayna-patel26f48592014-02-28 09:30:38 +000077 self.servers_client.stop(server['id'])
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +000078 waiters.wait_for_server_status(self.servers_client,
79 server['id'], 'SHUTOFF')
nayna-patel26f48592014-02-28 09:30:38 +000080 self.addCleanup(self.servers_client.delete_server, server['id'])
Ken'ichi Ohmichi4937f562015-03-23 00:15:01 +000081 snapshot_name = data_utils.rand_name('test-snap')
David Kranza5299eb2015-01-15 17:24:05 -050082 image = self.create_image_from_server(server['id'],
83 name=snapshot_name,
84 wait_until='ACTIVE',
85 wait_for_server=False)
nayna-patel26f48592014-02-28 09:30:38 +000086 self.addCleanup(self.client.delete_image, image['id'])
87 self.assertEqual(snapshot_name, image['name'])
88
Sean Dague639f2fa2015-04-27 09:00:33 -040089 @test.attr(type=['negative'])
Chris Hoge7579c1a2015-02-26 14:12:15 -080090 @test.idempotent_id('ec176029-73dc-4037-8d72-2e4ff60cf538')
nayna-patel26f48592014-02-28 09:30:38 +000091 def test_create_image_specify_uuid_35_characters_or_less(self):
92 # Return an error if Image ID passed is 35 characters or less
Ken'ichi Ohmichi4937f562015-03-23 00:15:01 +000093 snapshot_name = data_utils.rand_name('test-snap')
nayna-patel26f48592014-02-28 09:30:38 +000094 test_uuid = ('a' * 35)
Masayuki Igawabfa07602015-01-20 18:47:17 +090095 self.assertRaises(lib_exc.NotFound, self.client.create_image,
Ken'ichi Ohmichi28f18672015-07-17 10:00:38 +000096 test_uuid, name=snapshot_name)
nayna-patel26f48592014-02-28 09:30:38 +000097
Sean Dague639f2fa2015-04-27 09:00:33 -040098 @test.attr(type=['negative'])
Chris Hoge7579c1a2015-02-26 14:12:15 -080099 @test.idempotent_id('36741560-510e-4cc2-8641-55fe4dfb2437')
nayna-patel26f48592014-02-28 09:30:38 +0000100 def test_create_image_specify_uuid_37_characters_or_more(self):
101 # Return an error if Image ID passed is 37 characters or more
Ken'ichi Ohmichi4937f562015-03-23 00:15:01 +0000102 snapshot_name = data_utils.rand_name('test-snap')
nayna-patel26f48592014-02-28 09:30:38 +0000103 test_uuid = ('a' * 37)
Masayuki Igawabfa07602015-01-20 18:47:17 +0900104 self.assertRaises(lib_exc.NotFound, self.client.create_image,
Ken'ichi Ohmichi28f18672015-07-17 10:00:38 +0000105 test_uuid, name=snapshot_name)
nayna-patel26f48592014-02-28 09:30:38 +0000106
Sean Dague639f2fa2015-04-27 09:00:33 -0400107 @test.attr(type=['negative'])
Chris Hoge7579c1a2015-02-26 14:12:15 -0800108 @test.idempotent_id('381acb65-785a-4942-94ce-d8f8c84f1f0f')
nayna-patel26f48592014-02-28 09:30:38 +0000109 def test_delete_image_with_invalid_image_id(self):
110 # An image should not be deleted with invalid image id
Masayuki Igawabfa07602015-01-20 18:47:17 +0900111 self.assertRaises(lib_exc.NotFound, self.client.delete_image,
Marian Horban64a5e352015-04-24 09:51:23 -0400112 '!@$^&*()')
nayna-patel26f48592014-02-28 09:30:38 +0000113
Sean Dague639f2fa2015-04-27 09:00:33 -0400114 @test.attr(type=['negative'])
Chris Hoge7579c1a2015-02-26 14:12:15 -0800115 @test.idempotent_id('137aef61-39f7-44a1-8ddf-0adf82511701')
nayna-patel26f48592014-02-28 09:30:38 +0000116 def test_delete_non_existent_image(self):
117 # Return an error while trying to delete a non-existent image
118
119 non_existent_image_id = '11a22b9-12a9-5555-cc11-00ab112223fa'
Masayuki Igawabfa07602015-01-20 18:47:17 +0900120 self.assertRaises(lib_exc.NotFound, self.client.delete_image,
nayna-patel26f48592014-02-28 09:30:38 +0000121 non_existent_image_id)
122
Sean Dague639f2fa2015-04-27 09:00:33 -0400123 @test.attr(type=['negative'])
Chris Hoge7579c1a2015-02-26 14:12:15 -0800124 @test.idempotent_id('e6e41425-af5c-4fe6-a4b5-7b7b963ffda5')
nayna-patel26f48592014-02-28 09:30:38 +0000125 def test_delete_image_blank_id(self):
126 # Return an error while trying to delete an image with blank Id
Masayuki Igawabfa07602015-01-20 18:47:17 +0900127 self.assertRaises(lib_exc.NotFound, self.client.delete_image, '')
nayna-patel26f48592014-02-28 09:30:38 +0000128
Sean Dague639f2fa2015-04-27 09:00:33 -0400129 @test.attr(type=['negative'])
Chris Hoge7579c1a2015-02-26 14:12:15 -0800130 @test.idempotent_id('924540c3-f1f1-444c-8f58-718958b6724e')
nayna-patel26f48592014-02-28 09:30:38 +0000131 def test_delete_image_non_hex_string_id(self):
132 # Return an error while trying to delete an image with non hex id
133 image_id = '11a22b9-120q-5555-cc11-00ab112223gj'
Masayuki Igawabfa07602015-01-20 18:47:17 +0900134 self.assertRaises(lib_exc.NotFound, self.client.delete_image,
nayna-patel26f48592014-02-28 09:30:38 +0000135 image_id)
136
Sean Dague639f2fa2015-04-27 09:00:33 -0400137 @test.attr(type=['negative'])
Chris Hoge7579c1a2015-02-26 14:12:15 -0800138 @test.idempotent_id('68e2c175-bd26-4407-ac0f-4ea9ce2139ea')
nayna-patel26f48592014-02-28 09:30:38 +0000139 def test_delete_image_negative_image_id(self):
140 # Return an error while trying to delete an image with negative id
Masayuki Igawabfa07602015-01-20 18:47:17 +0900141 self.assertRaises(lib_exc.NotFound, self.client.delete_image, -1)
nayna-patel26f48592014-02-28 09:30:38 +0000142
Sean Dague639f2fa2015-04-27 09:00:33 -0400143 @test.attr(type=['negative'])
Chris Hoge7579c1a2015-02-26 14:12:15 -0800144 @test.idempotent_id('b340030d-82cd-4066-a314-c72fb7c59277')
nayna-patel26f48592014-02-28 09:30:38 +0000145 def test_delete_image_id_is_over_35_character_limit(self):
146 # Return an error while trying to delete image with id over limit
Masayuki Igawabfa07602015-01-20 18:47:17 +0900147 self.assertRaises(lib_exc.NotFound, self.client.delete_image,
nayna-patel26f48592014-02-28 09:30:38 +0000148 '11a22b9-12a9-5555-cc11-00ab112223fa-3fac')