blob: 86013d45ba1bc4e76abb9bb12ea10a115064849c [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
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +000016from tempest.common import waiters
nayna-patel26f48592014-02-28 09:30:38 +000017from tempest import config
Ken'ichi Ohmichi757833a2017-03-10 10:30:30 -080018from tempest.lib.common.utils import data_utils
Ken'ichi Ohmichi6c92edf2017-01-27 17:32:10 -080019from tempest.lib import decorators
Andrea Frittoli (andreaf)db9672e2016-02-23 14:07:24 -050020from tempest.lib import exceptions as lib_exc
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()
Ghanshyamae76c122015-12-22 13:41:35 +090042 cls.client = cls.compute_images_client
nayna-patel26f48592014-02-28 09:30:38 +000043
Sean Dague639f2fa2015-04-27 09:00:33 -040044 @test.attr(type=['negative'])
Ken'ichi Ohmichi6c92edf2017-01-27 17:32:10 -080045 @decorators.idempotent_id('6cd5a89d-5b47-46a7-93bc-3916f0d84973')
nayna-patel26f48592014-02-28 09:30:38 +000046 def test_create_image_from_deleted_server(self):
47 # An image should not be created if the server instance is removed
David Kranz0fb14292015-02-11 15:55:20 -050048 server = self.create_test_server(wait_until='ACTIVE')
nayna-patel26f48592014-02-28 09:30:38 +000049
zhufl796f3b92016-12-09 09:57:18 +080050 # Delete server before trying to create image
nayna-patel26f48592014-02-28 09:30:38 +000051 self.servers_client.delete_server(server['id'])
Ken'ichi Ohmichie91a0c62015-08-13 02:09:16 +000052 waiters.wait_for_server_termination(self.servers_client, server['id'])
Matthew Treinishc795b9e2014-06-09 17:01:10 -040053 # Create a new image after server is deleted
nayna-patel26f48592014-02-28 09:30:38 +000054 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,
zhufl35a694b2017-02-14 17:10:53 +080057 server['id'], metadata=meta)
nayna-patel26f48592014-02-28 09:30:38 +000058
Sean Dague639f2fa2015-04-27 09:00:33 -040059 @test.attr(type=['negative'])
Ken'ichi Ohmichi6c92edf2017-01-27 17:32:10 -080060 @decorators.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
nayna-patel26f48592014-02-28 09:30:38 +000064 meta = {'image_type': 'test'}
Masayuki Igawabfa07602015-01-20 18:47:17 +090065 self.assertRaises(lib_exc.NotFound, self.create_image_from_server,
zhufl35a694b2017-02-14 17:10:53 +080066 data_utils.rand_name('invalid'), metadata=meta)
nayna-patel26f48592014-02-28 09:30:38 +000067
Sean Dague639f2fa2015-04-27 09:00:33 -040068 @test.attr(type=['negative'])
Ken'ichi Ohmichi6c92edf2017-01-27 17:32:10 -080069 @decorators.idempotent_id('ec176029-73dc-4037-8d72-2e4ff60cf538')
nayna-patel26f48592014-02-28 09:30:38 +000070 def test_create_image_specify_uuid_35_characters_or_less(self):
71 # Return an error if Image ID passed is 35 characters or less
Ken'ichi Ohmichi4937f562015-03-23 00:15:01 +000072 snapshot_name = data_utils.rand_name('test-snap')
nayna-patel26f48592014-02-28 09:30:38 +000073 test_uuid = ('a' * 35)
Masayuki Igawabfa07602015-01-20 18:47:17 +090074 self.assertRaises(lib_exc.NotFound, self.client.create_image,
Ken'ichi Ohmichi28f18672015-07-17 10:00:38 +000075 test_uuid, name=snapshot_name)
nayna-patel26f48592014-02-28 09:30:38 +000076
Sean Dague639f2fa2015-04-27 09:00:33 -040077 @test.attr(type=['negative'])
Ken'ichi Ohmichi6c92edf2017-01-27 17:32:10 -080078 @decorators.idempotent_id('36741560-510e-4cc2-8641-55fe4dfb2437')
nayna-patel26f48592014-02-28 09:30:38 +000079 def test_create_image_specify_uuid_37_characters_or_more(self):
80 # Return an error if Image ID passed is 37 characters or more
Ken'ichi Ohmichi4937f562015-03-23 00:15:01 +000081 snapshot_name = data_utils.rand_name('test-snap')
nayna-patel26f48592014-02-28 09:30:38 +000082 test_uuid = ('a' * 37)
Masayuki Igawabfa07602015-01-20 18:47:17 +090083 self.assertRaises(lib_exc.NotFound, self.client.create_image,
Ken'ichi Ohmichi28f18672015-07-17 10:00:38 +000084 test_uuid, name=snapshot_name)
nayna-patel26f48592014-02-28 09:30:38 +000085
Sean Dague639f2fa2015-04-27 09:00:33 -040086 @test.attr(type=['negative'])
Ken'ichi Ohmichi6c92edf2017-01-27 17:32:10 -080087 @decorators.idempotent_id('381acb65-785a-4942-94ce-d8f8c84f1f0f')
nayna-patel26f48592014-02-28 09:30:38 +000088 def test_delete_image_with_invalid_image_id(self):
89 # An image should not be deleted with invalid image id
Masayuki Igawabfa07602015-01-20 18:47:17 +090090 self.assertRaises(lib_exc.NotFound, self.client.delete_image,
ghanshyam9e294c42017-01-12 06:52:41 +000091 data_utils.rand_name('invalid'))
nayna-patel26f48592014-02-28 09:30:38 +000092
Sean Dague639f2fa2015-04-27 09:00:33 -040093 @test.attr(type=['negative'])
Ken'ichi Ohmichi6c92edf2017-01-27 17:32:10 -080094 @decorators.idempotent_id('137aef61-39f7-44a1-8ddf-0adf82511701')
nayna-patel26f48592014-02-28 09:30:38 +000095 def test_delete_non_existent_image(self):
96 # Return an error while trying to delete a non-existent image
97
zhufl557124e2016-12-02 16:51:54 +080098 non_existent_image_id = data_utils.rand_uuid()
Masayuki Igawabfa07602015-01-20 18:47:17 +090099 self.assertRaises(lib_exc.NotFound, self.client.delete_image,
nayna-patel26f48592014-02-28 09:30:38 +0000100 non_existent_image_id)
101
Sean Dague639f2fa2015-04-27 09:00:33 -0400102 @test.attr(type=['negative'])
Ken'ichi Ohmichi6c92edf2017-01-27 17:32:10 -0800103 @decorators.idempotent_id('e6e41425-af5c-4fe6-a4b5-7b7b963ffda5')
nayna-patel26f48592014-02-28 09:30:38 +0000104 def test_delete_image_blank_id(self):
105 # Return an error while trying to delete an image with blank Id
Masayuki Igawabfa07602015-01-20 18:47:17 +0900106 self.assertRaises(lib_exc.NotFound, self.client.delete_image, '')
nayna-patel26f48592014-02-28 09:30:38 +0000107
Sean Dague639f2fa2015-04-27 09:00:33 -0400108 @test.attr(type=['negative'])
Ken'ichi Ohmichi6c92edf2017-01-27 17:32:10 -0800109 @decorators.idempotent_id('924540c3-f1f1-444c-8f58-718958b6724e')
nayna-patel26f48592014-02-28 09:30:38 +0000110 def test_delete_image_non_hex_string_id(self):
111 # Return an error while trying to delete an image with non hex id
zhufl557124e2016-12-02 16:51:54 +0800112 invalid_image_id = data_utils.rand_uuid()[:-1] + "j"
Masayuki Igawabfa07602015-01-20 18:47:17 +0900113 self.assertRaises(lib_exc.NotFound, self.client.delete_image,
zhufl557124e2016-12-02 16:51:54 +0800114 invalid_image_id)
nayna-patel26f48592014-02-28 09:30:38 +0000115
Sean Dague639f2fa2015-04-27 09:00:33 -0400116 @test.attr(type=['negative'])
Ken'ichi Ohmichi6c92edf2017-01-27 17:32:10 -0800117 @decorators.idempotent_id('68e2c175-bd26-4407-ac0f-4ea9ce2139ea')
nayna-patel26f48592014-02-28 09:30:38 +0000118 def test_delete_image_negative_image_id(self):
119 # Return an error while trying to delete an image with negative id
Masayuki Igawabfa07602015-01-20 18:47:17 +0900120 self.assertRaises(lib_exc.NotFound, self.client.delete_image, -1)
nayna-patel26f48592014-02-28 09:30:38 +0000121
Sean Dague639f2fa2015-04-27 09:00:33 -0400122 @test.attr(type=['negative'])
Ken'ichi Ohmichi6c92edf2017-01-27 17:32:10 -0800123 @decorators.idempotent_id('b340030d-82cd-4066-a314-c72fb7c59277')
zhufl557124e2016-12-02 16:51:54 +0800124 def test_delete_image_with_id_over_character_limit(self):
nayna-patel26f48592014-02-28 09:30:38 +0000125 # Return an error while trying to delete image with id over limit
zhufl557124e2016-12-02 16:51:54 +0800126 invalid_image_id = data_utils.rand_uuid() + "1"
Masayuki Igawabfa07602015-01-20 18:47:17 +0900127 self.assertRaises(lib_exc.NotFound, self.client.delete_image,
zhufl557124e2016-12-02 16:51:54 +0800128 invalid_image_id)