blob: b4baf05d3b4ff41db72e64f76d8026849758eb29 [file] [log] [blame]
Hoisaleshwara Madan V Se4476cd2013-11-08 12:49:48 +05301# Copyright 2013 OpenStack Foundation
2# All Rights Reserved.
3# Copyright 2013 IBM Corp.
4#
5# Licensed under the Apache License, Version 2.0 (the "License"); you may
6# not use this file except in compliance with the License. You may obtain
7# a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14# License for the specific language governing permissions and limitations
15# under the License.
16
Hoisaleshwara Madan V Se4476cd2013-11-08 12:49:48 +053017from tempest.api.image import base
Ken'ichi Ohmichid079c892016-04-19 11:23:36 -070018from tempest.lib.common.utils import data_utils
Ken'ichi Ohmichif35efa22017-01-27 17:55:24 -080019from tempest.lib import decorators
Andrea Frittoli (andreaf)db9672e2016-02-23 14:07:24 -050020from tempest.lib import exceptions as lib_exc
Hoisaleshwara Madan V Se4476cd2013-11-08 12:49:48 +053021
22
23class ImagesNegativeTest(base.BaseV2ImageTest):
24
Ken'ichi Ohmichi9e3dac02015-11-19 07:01:07 +000025 """here we have -ve tests for show_image and delete_image api
Hoisaleshwara Madan V Se4476cd2013-11-08 12:49:48 +053026
27 Tests
28 ** get non-existent image
29 ** get image with image_id=NULL
30 ** get the deleted image
31 ** delete non-existent image
guo yunxian27433042016-07-29 13:14:39 +080032 ** delete image with image_id=NULL
Hoisaleshwara Madan V Se4476cd2013-11-08 12:49:48 +053033 ** delete the deleted image
34 """
35
Jordan Pittier3b46d272017-04-12 16:17:28 +020036 @decorators.attr(type=['negative'])
Ken'ichi Ohmichif35efa22017-01-27 17:55:24 -080037 @decorators.idempotent_id('668743d5-08ad-4480-b2b8-15da34f81d9f')
Hoisaleshwara Madan V Se4476cd2013-11-08 12:49:48 +053038 def test_get_non_existent_image(self):
39 # get the non-existent image
Ken'ichi Ohmichid079c892016-04-19 11:23:36 -070040 non_existent_id = data_utils.rand_uuid()
Ken'ichi Ohmichi5d410762015-05-22 01:10:03 +000041 self.assertRaises(lib_exc.NotFound, self.client.show_image,
Hoisaleshwara Madan V Se4476cd2013-11-08 12:49:48 +053042 non_existent_id)
43
Jordan Pittier3b46d272017-04-12 16:17:28 +020044 @decorators.attr(type=['negative'])
Ken'ichi Ohmichif35efa22017-01-27 17:55:24 -080045 @decorators.idempotent_id('ef45000d-0a72-4781-866d-4cb7bf2562ad')
Hoisaleshwara Madan V Se4476cd2013-11-08 12:49:48 +053046 def test_get_image_null_id(self):
47 # get image with image_id = NULL
48 image_id = ""
Ken'ichi Ohmichi5d410762015-05-22 01:10:03 +000049 self.assertRaises(lib_exc.NotFound, self.client.show_image, image_id)
Hoisaleshwara Madan V Se4476cd2013-11-08 12:49:48 +053050
Jordan Pittier3b46d272017-04-12 16:17:28 +020051 @decorators.attr(type=['negative'])
Ken'ichi Ohmichif35efa22017-01-27 17:55:24 -080052 @decorators.idempotent_id('e57fc127-7ba0-4693-92d7-1d8a05ebcba9')
Hoisaleshwara Madan V Se4476cd2013-11-08 12:49:48 +053053 def test_get_delete_deleted_image(self):
54 # get and delete the deleted image
55 # create and delete image
lkuchlanb3348792016-09-29 10:42:21 +030056 image = self.client.create_image(name='test',
57 container_format='bare',
58 disk_format='raw')
59 self.client.delete_image(image['id'])
60 self.client.wait_for_resource_deletion(image['id'])
Hoisaleshwara Madan V Se4476cd2013-11-08 12:49:48 +053061
62 # get the deleted image
lkuchlanb3348792016-09-29 10:42:21 +030063 self.assertRaises(lib_exc.NotFound,
64 self.client.show_image, image['id'])
Hoisaleshwara Madan V Se4476cd2013-11-08 12:49:48 +053065
66 # delete the deleted image
Masayuki Igawabfa07602015-01-20 18:47:17 +090067 self.assertRaises(lib_exc.NotFound, self.client.delete_image,
lkuchlanb3348792016-09-29 10:42:21 +030068 image['id'])
Hoisaleshwara Madan V Se4476cd2013-11-08 12:49:48 +053069
Jordan Pittier3b46d272017-04-12 16:17:28 +020070 @decorators.attr(type=['negative'])
Ken'ichi Ohmichif35efa22017-01-27 17:55:24 -080071 @decorators.idempotent_id('6fe40f1c-57bd-4918-89cc-8500f850f3de')
Hoisaleshwara Madan V Se4476cd2013-11-08 12:49:48 +053072 def test_delete_non_existing_image(self):
73 # delete non-existent image
Ken'ichi Ohmichid079c892016-04-19 11:23:36 -070074 non_existent_image_id = data_utils.rand_uuid()
Masayuki Igawabfa07602015-01-20 18:47:17 +090075 self.assertRaises(lib_exc.NotFound, self.client.delete_image,
Hoisaleshwara Madan V Se4476cd2013-11-08 12:49:48 +053076 non_existent_image_id)
77
Jordan Pittier3b46d272017-04-12 16:17:28 +020078 @decorators.attr(type=['negative'])
Ken'ichi Ohmichif35efa22017-01-27 17:55:24 -080079 @decorators.idempotent_id('32248db1-ab88-4821-9604-c7c369f1f88c')
Hoisaleshwara Madan V Se4476cd2013-11-08 12:49:48 +053080 def test_delete_image_null_id(self):
81 # delete image with image_id=NULL
82 image_id = ""
Masayuki Igawabfa07602015-01-20 18:47:17 +090083 self.assertRaises(lib_exc.NotFound, self.client.delete_image,
Hoisaleshwara Madan V Se4476cd2013-11-08 12:49:48 +053084 image_id)
Hoisaleshwara Madan V S7cba1082013-11-26 12:43:04 +053085
Jordan Pittier3b46d272017-04-12 16:17:28 +020086 @decorators.attr(type=['negative'])
Ken'ichi Ohmichif35efa22017-01-27 17:55:24 -080087 @decorators.idempotent_id('292bd310-369b-41c7-a7a3-10276ef76753')
Hoisaleshwara Madan V S7cba1082013-11-26 12:43:04 +053088 def test_register_with_invalid_container_format(self):
89 # Negative tests for invalid data supplied to POST /images
Masayuki Igawa4b29e472015-02-16 10:41:54 +090090 self.assertRaises(lib_exc.BadRequest, self.client.create_image,
Ken'ichi Ohmichi25b30162015-11-30 11:27:13 +000091 name='test', container_format='wrong',
92 disk_format='vhd')
Hoisaleshwara Madan V S7cba1082013-11-26 12:43:04 +053093
Jordan Pittier3b46d272017-04-12 16:17:28 +020094 @decorators.attr(type=['negative'])
Ken'ichi Ohmichif35efa22017-01-27 17:55:24 -080095 @decorators.idempotent_id('70c6040c-5a97-4111-9e13-e73665264ce1')
Hoisaleshwara Madan V S7cba1082013-11-26 12:43:04 +053096 def test_register_with_invalid_disk_format(self):
Masayuki Igawa4b29e472015-02-16 10:41:54 +090097 self.assertRaises(lib_exc.BadRequest, self.client.create_image,
Ken'ichi Ohmichi25b30162015-11-30 11:27:13 +000098 name='test', container_format='bare',
99 disk_format='wrong')
lkuchlan08844882017-02-19 16:08:45 +0200100
Jordan Pittier3b46d272017-04-12 16:17:28 +0200101 @decorators.attr(type=['negative'])
lkuchlan08844882017-02-19 16:08:45 +0200102 @decorators.idempotent_id('ab980a34-8410-40eb-872b-f264752f46e5')
103 def test_delete_protected_image(self):
104 # Create a protected image
105 image = self.create_image(protected=True)
106 self.addCleanup(self.client.update_image, image['id'],
107 [dict(replace="/protected", value=False)])
108
109 # Try deleting the protected image
110 self.assertRaises(lib_exc.Forbidden,
111 self.client.delete_image,
112 image['id'])