Hoisaleshwara Madan V S | e4476cd | 2013-11-08 12:49:48 +0530 | [diff] [blame] | 1 | # 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 S | e4476cd | 2013-11-08 12:49:48 +0530 | [diff] [blame] | 17 | from tempest.api.image import base |
Ken'ichi Ohmichi | d079c89 | 2016-04-19 11:23:36 -0700 | [diff] [blame] | 18 | from tempest.lib.common.utils import data_utils |
Ken'ichi Ohmichi | f35efa2 | 2017-01-27 17:55:24 -0800 | [diff] [blame] | 19 | from tempest.lib import decorators |
Andrea Frittoli (andreaf) | db9672e | 2016-02-23 14:07:24 -0500 | [diff] [blame] | 20 | from tempest.lib import exceptions as lib_exc |
Hoisaleshwara Madan V S | e4476cd | 2013-11-08 12:49:48 +0530 | [diff] [blame] | 21 | |
| 22 | |
| 23 | class ImagesNegativeTest(base.BaseV2ImageTest): |
| 24 | |
Ken'ichi Ohmichi | 9e3dac0 | 2015-11-19 07:01:07 +0000 | [diff] [blame] | 25 | """here we have -ve tests for show_image and delete_image api |
Hoisaleshwara Madan V S | e4476cd | 2013-11-08 12:49:48 +0530 | [diff] [blame] | 26 | |
| 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 yunxian | 2743304 | 2016-07-29 13:14:39 +0800 | [diff] [blame] | 32 | ** delete image with image_id=NULL |
Hoisaleshwara Madan V S | e4476cd | 2013-11-08 12:49:48 +0530 | [diff] [blame] | 33 | ** delete the deleted image |
| 34 | """ |
| 35 | |
Jordan Pittier | 3b46d27 | 2017-04-12 16:17:28 +0200 | [diff] [blame] | 36 | @decorators.attr(type=['negative']) |
Ken'ichi Ohmichi | f35efa2 | 2017-01-27 17:55:24 -0800 | [diff] [blame] | 37 | @decorators.idempotent_id('668743d5-08ad-4480-b2b8-15da34f81d9f') |
Hoisaleshwara Madan V S | e4476cd | 2013-11-08 12:49:48 +0530 | [diff] [blame] | 38 | def test_get_non_existent_image(self): |
| 39 | # get the non-existent image |
Ken'ichi Ohmichi | d079c89 | 2016-04-19 11:23:36 -0700 | [diff] [blame] | 40 | non_existent_id = data_utils.rand_uuid() |
Ken'ichi Ohmichi | 5d41076 | 2015-05-22 01:10:03 +0000 | [diff] [blame] | 41 | self.assertRaises(lib_exc.NotFound, self.client.show_image, |
Hoisaleshwara Madan V S | e4476cd | 2013-11-08 12:49:48 +0530 | [diff] [blame] | 42 | non_existent_id) |
| 43 | |
Jordan Pittier | 3b46d27 | 2017-04-12 16:17:28 +0200 | [diff] [blame] | 44 | @decorators.attr(type=['negative']) |
Ken'ichi Ohmichi | f35efa2 | 2017-01-27 17:55:24 -0800 | [diff] [blame] | 45 | @decorators.idempotent_id('ef45000d-0a72-4781-866d-4cb7bf2562ad') |
Hoisaleshwara Madan V S | e4476cd | 2013-11-08 12:49:48 +0530 | [diff] [blame] | 46 | def test_get_image_null_id(self): |
| 47 | # get image with image_id = NULL |
| 48 | image_id = "" |
Ken'ichi Ohmichi | 5d41076 | 2015-05-22 01:10:03 +0000 | [diff] [blame] | 49 | self.assertRaises(lib_exc.NotFound, self.client.show_image, image_id) |
Hoisaleshwara Madan V S | e4476cd | 2013-11-08 12:49:48 +0530 | [diff] [blame] | 50 | |
Jordan Pittier | 3b46d27 | 2017-04-12 16:17:28 +0200 | [diff] [blame] | 51 | @decorators.attr(type=['negative']) |
Ken'ichi Ohmichi | f35efa2 | 2017-01-27 17:55:24 -0800 | [diff] [blame] | 52 | @decorators.idempotent_id('e57fc127-7ba0-4693-92d7-1d8a05ebcba9') |
Hoisaleshwara Madan V S | e4476cd | 2013-11-08 12:49:48 +0530 | [diff] [blame] | 53 | def test_get_delete_deleted_image(self): |
| 54 | # get and delete the deleted image |
| 55 | # create and delete image |
lkuchlan | b334879 | 2016-09-29 10:42:21 +0300 | [diff] [blame] | 56 | 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 S | e4476cd | 2013-11-08 12:49:48 +0530 | [diff] [blame] | 61 | |
| 62 | # get the deleted image |
lkuchlan | b334879 | 2016-09-29 10:42:21 +0300 | [diff] [blame] | 63 | self.assertRaises(lib_exc.NotFound, |
| 64 | self.client.show_image, image['id']) |
Hoisaleshwara Madan V S | e4476cd | 2013-11-08 12:49:48 +0530 | [diff] [blame] | 65 | |
| 66 | # delete the deleted image |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 67 | self.assertRaises(lib_exc.NotFound, self.client.delete_image, |
lkuchlan | b334879 | 2016-09-29 10:42:21 +0300 | [diff] [blame] | 68 | image['id']) |
Hoisaleshwara Madan V S | e4476cd | 2013-11-08 12:49:48 +0530 | [diff] [blame] | 69 | |
Jordan Pittier | 3b46d27 | 2017-04-12 16:17:28 +0200 | [diff] [blame] | 70 | @decorators.attr(type=['negative']) |
Ken'ichi Ohmichi | f35efa2 | 2017-01-27 17:55:24 -0800 | [diff] [blame] | 71 | @decorators.idempotent_id('6fe40f1c-57bd-4918-89cc-8500f850f3de') |
Hoisaleshwara Madan V S | e4476cd | 2013-11-08 12:49:48 +0530 | [diff] [blame] | 72 | def test_delete_non_existing_image(self): |
| 73 | # delete non-existent image |
Ken'ichi Ohmichi | d079c89 | 2016-04-19 11:23:36 -0700 | [diff] [blame] | 74 | non_existent_image_id = data_utils.rand_uuid() |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 75 | self.assertRaises(lib_exc.NotFound, self.client.delete_image, |
Hoisaleshwara Madan V S | e4476cd | 2013-11-08 12:49:48 +0530 | [diff] [blame] | 76 | non_existent_image_id) |
| 77 | |
Jordan Pittier | 3b46d27 | 2017-04-12 16:17:28 +0200 | [diff] [blame] | 78 | @decorators.attr(type=['negative']) |
Ken'ichi Ohmichi | f35efa2 | 2017-01-27 17:55:24 -0800 | [diff] [blame] | 79 | @decorators.idempotent_id('32248db1-ab88-4821-9604-c7c369f1f88c') |
Hoisaleshwara Madan V S | e4476cd | 2013-11-08 12:49:48 +0530 | [diff] [blame] | 80 | def test_delete_image_null_id(self): |
| 81 | # delete image with image_id=NULL |
| 82 | image_id = "" |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 83 | self.assertRaises(lib_exc.NotFound, self.client.delete_image, |
Hoisaleshwara Madan V S | e4476cd | 2013-11-08 12:49:48 +0530 | [diff] [blame] | 84 | image_id) |
Hoisaleshwara Madan V S | 7cba108 | 2013-11-26 12:43:04 +0530 | [diff] [blame] | 85 | |
Jordan Pittier | 3b46d27 | 2017-04-12 16:17:28 +0200 | [diff] [blame] | 86 | @decorators.attr(type=['negative']) |
Ken'ichi Ohmichi | f35efa2 | 2017-01-27 17:55:24 -0800 | [diff] [blame] | 87 | @decorators.idempotent_id('292bd310-369b-41c7-a7a3-10276ef76753') |
Hoisaleshwara Madan V S | 7cba108 | 2013-11-26 12:43:04 +0530 | [diff] [blame] | 88 | def test_register_with_invalid_container_format(self): |
| 89 | # Negative tests for invalid data supplied to POST /images |
Masayuki Igawa | 4b29e47 | 2015-02-16 10:41:54 +0900 | [diff] [blame] | 90 | self.assertRaises(lib_exc.BadRequest, self.client.create_image, |
Ken'ichi Ohmichi | 25b3016 | 2015-11-30 11:27:13 +0000 | [diff] [blame] | 91 | name='test', container_format='wrong', |
| 92 | disk_format='vhd') |
Hoisaleshwara Madan V S | 7cba108 | 2013-11-26 12:43:04 +0530 | [diff] [blame] | 93 | |
Jordan Pittier | 3b46d27 | 2017-04-12 16:17:28 +0200 | [diff] [blame] | 94 | @decorators.attr(type=['negative']) |
Ken'ichi Ohmichi | f35efa2 | 2017-01-27 17:55:24 -0800 | [diff] [blame] | 95 | @decorators.idempotent_id('70c6040c-5a97-4111-9e13-e73665264ce1') |
Hoisaleshwara Madan V S | 7cba108 | 2013-11-26 12:43:04 +0530 | [diff] [blame] | 96 | def test_register_with_invalid_disk_format(self): |
Masayuki Igawa | 4b29e47 | 2015-02-16 10:41:54 +0900 | [diff] [blame] | 97 | self.assertRaises(lib_exc.BadRequest, self.client.create_image, |
Ken'ichi Ohmichi | 25b3016 | 2015-11-30 11:27:13 +0000 | [diff] [blame] | 98 | name='test', container_format='bare', |
| 99 | disk_format='wrong') |
lkuchlan | 0884488 | 2017-02-19 16:08:45 +0200 | [diff] [blame] | 100 | |
Jordan Pittier | 3b46d27 | 2017-04-12 16:17:28 +0200 | [diff] [blame] | 101 | @decorators.attr(type=['negative']) |
lkuchlan | 0884488 | 2017-02-19 16:08:45 +0200 | [diff] [blame] | 102 | @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']) |