blob: c48367fbf53b57e201e638ca86cbb8d347a90072 [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
15from tempest.api.compute import base
Fei Long Wangd39431f2015-05-14 11:30:48 +120016from tempest.common.utils import data_utils
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +000017from tempest.common import waiters
nayna-patel26f48592014-02-28 09:30:38 +000018from tempest import config
Andrea Frittoli (andreaf)db9672e2016-02-23 14:07:24 -050019from tempest.lib import exceptions as lib_exc
nayna-patel26f48592014-02-28 09:30:38 +000020from tempest import test
21
22CONF = config.CONF
23
24
25class ImagesNegativeTestJSON(base.BaseV2ComputeTest):
26
27 @classmethod
Rohan Kanade60b73092015-02-04 17:58:19 +053028 def skip_checks(cls):
29 super(ImagesNegativeTestJSON, cls).skip_checks()
nayna-patel26f48592014-02-28 09:30:38 +000030 if not CONF.service_available.glance:
31 skip_msg = ("%s skipped as glance is not available" % cls.__name__)
32 raise cls.skipException(skip_msg)
Adam Gandelmanfbc95ac2014-06-19 17:33:43 -070033 if not CONF.compute_feature_enabled.snapshot:
34 skip_msg = ("%s skipped as instance snapshotting is not supported"
35 % cls.__name__)
36 raise cls.skipException(skip_msg)
37
Rohan Kanade60b73092015-02-04 17:58:19 +053038 @classmethod
39 def setup_clients(cls):
40 super(ImagesNegativeTestJSON, cls).setup_clients()
Ghanshyamae76c122015-12-22 13:41:35 +090041 cls.client = cls.compute_images_client
nayna-patel26f48592014-02-28 09:30:38 +000042
Sean Dague639f2fa2015-04-27 09:00:33 -040043 @test.attr(type=['negative'])
Chris Hoge7579c1a2015-02-26 14:12:15 -080044 @test.idempotent_id('6cd5a89d-5b47-46a7-93bc-3916f0d84973')
nayna-patel26f48592014-02-28 09:30:38 +000045 def test_create_image_from_deleted_server(self):
46 # An image should not be created if the server instance is removed
David Kranz0fb14292015-02-11 15:55:20 -050047 server = self.create_test_server(wait_until='ACTIVE')
nayna-patel26f48592014-02-28 09:30:38 +000048
49 # Delete server before trying to create server
50 self.servers_client.delete_server(server['id'])
Ken'ichi Ohmichie91a0c62015-08-13 02:09:16 +000051 waiters.wait_for_server_termination(self.servers_client, server['id'])
Matthew Treinishc795b9e2014-06-09 17:01:10 -040052 # Create a new image after server is deleted
nayna-patel26f48592014-02-28 09:30:38 +000053 name = data_utils.rand_name('image')
54 meta = {'image_type': 'test'}
Masayuki Igawabfa07602015-01-20 18:47:17 +090055 self.assertRaises(lib_exc.NotFound,
nayna-patel26f48592014-02-28 09:30:38 +000056 self.create_image_from_server,
57 server['id'], name=name, meta=meta)
58
Sean Dague639f2fa2015-04-27 09:00:33 -040059 @test.attr(type=['negative'])
Chris Hoge7579c1a2015-02-26 14:12:15 -080060 @test.idempotent_id('82c5b0c4-9dbd-463c-872b-20c4755aae7f')
nayna-patel26f48592014-02-28 09:30:38 +000061 def test_create_image_from_invalid_server(self):
62 # An image should not be created with invalid server id
63 # Create a new image with invalid server id
64 name = data_utils.rand_name('image')
65 meta = {'image_type': 'test'}
Masayuki Igawabfa07602015-01-20 18:47:17 +090066 self.assertRaises(lib_exc.NotFound, self.create_image_from_server,
Sergey Nikitinb39559a2016-02-26 15:05:40 +030067 '!@$^&*()', name=name, meta=meta)
nayna-patel26f48592014-02-28 09:30:38 +000068
Sean Dague639f2fa2015-04-27 09:00:33 -040069 @test.attr(type=['negative'])
Chris Hoge7579c1a2015-02-26 14:12:15 -080070 @test.idempotent_id('ec176029-73dc-4037-8d72-2e4ff60cf538')
nayna-patel26f48592014-02-28 09:30:38 +000071 def test_create_image_specify_uuid_35_characters_or_less(self):
72 # Return an error if Image ID passed is 35 characters or less
Ken'ichi Ohmichi4937f562015-03-23 00:15:01 +000073 snapshot_name = data_utils.rand_name('test-snap')
nayna-patel26f48592014-02-28 09:30:38 +000074 test_uuid = ('a' * 35)
Masayuki Igawabfa07602015-01-20 18:47:17 +090075 self.assertRaises(lib_exc.NotFound, self.client.create_image,
Ken'ichi Ohmichi28f18672015-07-17 10:00:38 +000076 test_uuid, name=snapshot_name)
nayna-patel26f48592014-02-28 09:30:38 +000077
Sean Dague639f2fa2015-04-27 09:00:33 -040078 @test.attr(type=['negative'])
Chris Hoge7579c1a2015-02-26 14:12:15 -080079 @test.idempotent_id('36741560-510e-4cc2-8641-55fe4dfb2437')
nayna-patel26f48592014-02-28 09:30:38 +000080 def test_create_image_specify_uuid_37_characters_or_more(self):
81 # Return an error if Image ID passed is 37 characters or more
Ken'ichi Ohmichi4937f562015-03-23 00:15:01 +000082 snapshot_name = data_utils.rand_name('test-snap')
nayna-patel26f48592014-02-28 09:30:38 +000083 test_uuid = ('a' * 37)
Masayuki Igawabfa07602015-01-20 18:47:17 +090084 self.assertRaises(lib_exc.NotFound, self.client.create_image,
Ken'ichi Ohmichi28f18672015-07-17 10:00:38 +000085 test_uuid, name=snapshot_name)
nayna-patel26f48592014-02-28 09:30:38 +000086
Sean Dague639f2fa2015-04-27 09:00:33 -040087 @test.attr(type=['negative'])
Chris Hoge7579c1a2015-02-26 14:12:15 -080088 @test.idempotent_id('381acb65-785a-4942-94ce-d8f8c84f1f0f')
nayna-patel26f48592014-02-28 09:30:38 +000089 def test_delete_image_with_invalid_image_id(self):
90 # An image should not be deleted with invalid image id
Masayuki Igawabfa07602015-01-20 18:47:17 +090091 self.assertRaises(lib_exc.NotFound, self.client.delete_image,
Marian Horban64a5e352015-04-24 09:51:23 -040092 '!@$^&*()')
nayna-patel26f48592014-02-28 09:30:38 +000093
Sean Dague639f2fa2015-04-27 09:00:33 -040094 @test.attr(type=['negative'])
Chris Hoge7579c1a2015-02-26 14:12:15 -080095 @test.idempotent_id('137aef61-39f7-44a1-8ddf-0adf82511701')
nayna-patel26f48592014-02-28 09:30:38 +000096 def test_delete_non_existent_image(self):
97 # Return an error while trying to delete a non-existent image
98
zhufl557124e2016-12-02 16:51:54 +080099 non_existent_image_id = data_utils.rand_uuid()
Masayuki Igawabfa07602015-01-20 18:47:17 +0900100 self.assertRaises(lib_exc.NotFound, self.client.delete_image,
nayna-patel26f48592014-02-28 09:30:38 +0000101 non_existent_image_id)
102
Sean Dague639f2fa2015-04-27 09:00:33 -0400103 @test.attr(type=['negative'])
Chris Hoge7579c1a2015-02-26 14:12:15 -0800104 @test.idempotent_id('e6e41425-af5c-4fe6-a4b5-7b7b963ffda5')
nayna-patel26f48592014-02-28 09:30:38 +0000105 def test_delete_image_blank_id(self):
106 # Return an error while trying to delete an image with blank Id
Masayuki Igawabfa07602015-01-20 18:47:17 +0900107 self.assertRaises(lib_exc.NotFound, self.client.delete_image, '')
nayna-patel26f48592014-02-28 09:30:38 +0000108
Sean Dague639f2fa2015-04-27 09:00:33 -0400109 @test.attr(type=['negative'])
Chris Hoge7579c1a2015-02-26 14:12:15 -0800110 @test.idempotent_id('924540c3-f1f1-444c-8f58-718958b6724e')
nayna-patel26f48592014-02-28 09:30:38 +0000111 def test_delete_image_non_hex_string_id(self):
112 # Return an error while trying to delete an image with non hex id
zhufl557124e2016-12-02 16:51:54 +0800113 invalid_image_id = data_utils.rand_uuid()[:-1] + "j"
Masayuki Igawabfa07602015-01-20 18:47:17 +0900114 self.assertRaises(lib_exc.NotFound, self.client.delete_image,
zhufl557124e2016-12-02 16:51:54 +0800115 invalid_image_id)
nayna-patel26f48592014-02-28 09:30:38 +0000116
Sean Dague639f2fa2015-04-27 09:00:33 -0400117 @test.attr(type=['negative'])
Chris Hoge7579c1a2015-02-26 14:12:15 -0800118 @test.idempotent_id('68e2c175-bd26-4407-ac0f-4ea9ce2139ea')
nayna-patel26f48592014-02-28 09:30:38 +0000119 def test_delete_image_negative_image_id(self):
120 # Return an error while trying to delete an image with negative id
Masayuki Igawabfa07602015-01-20 18:47:17 +0900121 self.assertRaises(lib_exc.NotFound, self.client.delete_image, -1)
nayna-patel26f48592014-02-28 09:30:38 +0000122
Sean Dague639f2fa2015-04-27 09:00:33 -0400123 @test.attr(type=['negative'])
Chris Hoge7579c1a2015-02-26 14:12:15 -0800124 @test.idempotent_id('b340030d-82cd-4066-a314-c72fb7c59277')
zhufl557124e2016-12-02 16:51:54 +0800125 def test_delete_image_with_id_over_character_limit(self):
nayna-patel26f48592014-02-28 09:30:38 +0000126 # Return an error while trying to delete image with id over limit
zhufl557124e2016-12-02 16:51:54 +0800127 invalid_image_id = data_utils.rand_uuid() + "1"
Masayuki Igawabfa07602015-01-20 18:47:17 +0900128 self.assertRaises(lib_exc.NotFound, self.client.delete_image,
zhufl557124e2016-12-02 16:51:54 +0800129 invalid_image_id)