blob: 6c97072b3348863da8bac171ea7c4d0060881455 [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
zhufl796f3b92016-12-09 09:57:18 +080049 # Delete server before trying to create image
nayna-patel26f48592014-02-28 09:30:38 +000050 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 meta = {'image_type': 'test'}
Masayuki Igawabfa07602015-01-20 18:47:17 +090054 self.assertRaises(lib_exc.NotFound,
nayna-patel26f48592014-02-28 09:30:38 +000055 self.create_image_from_server,
zhufl0f649f12017-01-12 14:31:02 +080056 server['id'], meta=meta)
nayna-patel26f48592014-02-28 09:30:38 +000057
Sean Dague639f2fa2015-04-27 09:00:33 -040058 @test.attr(type=['negative'])
Chris Hoge7579c1a2015-02-26 14:12:15 -080059 @test.idempotent_id('82c5b0c4-9dbd-463c-872b-20c4755aae7f')
nayna-patel26f48592014-02-28 09:30:38 +000060 def test_create_image_from_invalid_server(self):
61 # An image should not be created with invalid server id
62 # Create a new image with invalid server id
nayna-patel26f48592014-02-28 09:30:38 +000063 meta = {'image_type': 'test'}
Masayuki Igawabfa07602015-01-20 18:47:17 +090064 self.assertRaises(lib_exc.NotFound, self.create_image_from_server,
ghanshyam9e294c42017-01-12 06:52:41 +000065 data_utils.rand_name('invalid'), meta=meta)
nayna-patel26f48592014-02-28 09:30:38 +000066
Sean Dague639f2fa2015-04-27 09:00:33 -040067 @test.attr(type=['negative'])
Chris Hoge7579c1a2015-02-26 14:12:15 -080068 @test.idempotent_id('ec176029-73dc-4037-8d72-2e4ff60cf538')
nayna-patel26f48592014-02-28 09:30:38 +000069 def test_create_image_specify_uuid_35_characters_or_less(self):
70 # Return an error if Image ID passed is 35 characters or less
Ken'ichi Ohmichi4937f562015-03-23 00:15:01 +000071 snapshot_name = data_utils.rand_name('test-snap')
nayna-patel26f48592014-02-28 09:30:38 +000072 test_uuid = ('a' * 35)
Masayuki Igawabfa07602015-01-20 18:47:17 +090073 self.assertRaises(lib_exc.NotFound, self.client.create_image,
Ken'ichi Ohmichi28f18672015-07-17 10:00:38 +000074 test_uuid, name=snapshot_name)
nayna-patel26f48592014-02-28 09:30:38 +000075
Sean Dague639f2fa2015-04-27 09:00:33 -040076 @test.attr(type=['negative'])
Chris Hoge7579c1a2015-02-26 14:12:15 -080077 @test.idempotent_id('36741560-510e-4cc2-8641-55fe4dfb2437')
nayna-patel26f48592014-02-28 09:30:38 +000078 def test_create_image_specify_uuid_37_characters_or_more(self):
79 # Return an error if Image ID passed is 37 characters or more
Ken'ichi Ohmichi4937f562015-03-23 00:15:01 +000080 snapshot_name = data_utils.rand_name('test-snap')
nayna-patel26f48592014-02-28 09:30:38 +000081 test_uuid = ('a' * 37)
Masayuki Igawabfa07602015-01-20 18:47:17 +090082 self.assertRaises(lib_exc.NotFound, self.client.create_image,
Ken'ichi Ohmichi28f18672015-07-17 10:00:38 +000083 test_uuid, name=snapshot_name)
nayna-patel26f48592014-02-28 09:30:38 +000084
Sean Dague639f2fa2015-04-27 09:00:33 -040085 @test.attr(type=['negative'])
Chris Hoge7579c1a2015-02-26 14:12:15 -080086 @test.idempotent_id('381acb65-785a-4942-94ce-d8f8c84f1f0f')
nayna-patel26f48592014-02-28 09:30:38 +000087 def test_delete_image_with_invalid_image_id(self):
88 # An image should not be deleted with invalid image id
Masayuki Igawabfa07602015-01-20 18:47:17 +090089 self.assertRaises(lib_exc.NotFound, self.client.delete_image,
ghanshyam9e294c42017-01-12 06:52:41 +000090 data_utils.rand_name('invalid'))
nayna-patel26f48592014-02-28 09:30:38 +000091
Sean Dague639f2fa2015-04-27 09:00:33 -040092 @test.attr(type=['negative'])
Chris Hoge7579c1a2015-02-26 14:12:15 -080093 @test.idempotent_id('137aef61-39f7-44a1-8ddf-0adf82511701')
nayna-patel26f48592014-02-28 09:30:38 +000094 def test_delete_non_existent_image(self):
95 # Return an error while trying to delete a non-existent image
96
zhufl557124e2016-12-02 16:51:54 +080097 non_existent_image_id = data_utils.rand_uuid()
Masayuki Igawabfa07602015-01-20 18:47:17 +090098 self.assertRaises(lib_exc.NotFound, self.client.delete_image,
nayna-patel26f48592014-02-28 09:30:38 +000099 non_existent_image_id)
100
Sean Dague639f2fa2015-04-27 09:00:33 -0400101 @test.attr(type=['negative'])
Chris Hoge7579c1a2015-02-26 14:12:15 -0800102 @test.idempotent_id('e6e41425-af5c-4fe6-a4b5-7b7b963ffda5')
nayna-patel26f48592014-02-28 09:30:38 +0000103 def test_delete_image_blank_id(self):
104 # Return an error while trying to delete an image with blank Id
Masayuki Igawabfa07602015-01-20 18:47:17 +0900105 self.assertRaises(lib_exc.NotFound, self.client.delete_image, '')
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('924540c3-f1f1-444c-8f58-718958b6724e')
nayna-patel26f48592014-02-28 09:30:38 +0000109 def test_delete_image_non_hex_string_id(self):
110 # Return an error while trying to delete an image with non hex id
zhufl557124e2016-12-02 16:51:54 +0800111 invalid_image_id = data_utils.rand_uuid()[:-1] + "j"
Masayuki Igawabfa07602015-01-20 18:47:17 +0900112 self.assertRaises(lib_exc.NotFound, self.client.delete_image,
zhufl557124e2016-12-02 16:51:54 +0800113 invalid_image_id)
nayna-patel26f48592014-02-28 09:30:38 +0000114
Sean Dague639f2fa2015-04-27 09:00:33 -0400115 @test.attr(type=['negative'])
Chris Hoge7579c1a2015-02-26 14:12:15 -0800116 @test.idempotent_id('68e2c175-bd26-4407-ac0f-4ea9ce2139ea')
nayna-patel26f48592014-02-28 09:30:38 +0000117 def test_delete_image_negative_image_id(self):
118 # Return an error while trying to delete an image with negative id
Masayuki Igawabfa07602015-01-20 18:47:17 +0900119 self.assertRaises(lib_exc.NotFound, self.client.delete_image, -1)
nayna-patel26f48592014-02-28 09:30:38 +0000120
Sean Dague639f2fa2015-04-27 09:00:33 -0400121 @test.attr(type=['negative'])
Chris Hoge7579c1a2015-02-26 14:12:15 -0800122 @test.idempotent_id('b340030d-82cd-4066-a314-c72fb7c59277')
zhufl557124e2016-12-02 16:51:54 +0800123 def test_delete_image_with_id_over_character_limit(self):
nayna-patel26f48592014-02-28 09:30:38 +0000124 # Return an error while trying to delete image with id over limit
zhufl557124e2016-12-02 16:51:54 +0800125 invalid_image_id = data_utils.rand_uuid() + "1"
Masayuki Igawabfa07602015-01-20 18:47:17 +0900126 self.assertRaises(lib_exc.NotFound, self.client.delete_image,
zhufl557124e2016-12-02 16:51:54 +0800127 invalid_image_id)