ivan-zhu | 3867a1c | 2013-10-11 14:16:58 +0800 | [diff] [blame] | 1 | # Copyright 2013 IBM Corp. |
| 2 | # All Rights Reserved. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 5 | # not use this file except in compliance with the License. You may obtain |
| 6 | # a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | # License for the specific language governing permissions and limitations |
| 14 | # under the License. |
| 15 | |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 16 | |
ivan-zhu | 3867a1c | 2013-10-11 14:16:58 +0800 | [diff] [blame] | 17 | from tempest.api.image import base |
zhufl | 224bd9d | 2016-12-23 17:14:35 +0800 | [diff] [blame^] | 18 | from tempest.common.utils import data_utils |
Andrea Frittoli (andreaf) | db9672e | 2016-02-23 14:07:24 -0500 | [diff] [blame] | 19 | from tempest.lib import exceptions as lib_exc |
Eiichi Aikawa | 9012f46 | 2014-03-05 16:43:32 +0900 | [diff] [blame] | 20 | from tempest import test |
ivan-zhu | 3867a1c | 2013-10-11 14:16:58 +0800 | [diff] [blame] | 21 | |
| 22 | |
| 23 | class CreateDeleteImagesNegativeTest(base.BaseV1ImageTest): |
| 24 | """Here are negative tests for the deletion and creation of images.""" |
| 25 | |
Sean Dague | 639f2fa | 2015-04-27 09:00:33 -0400 | [diff] [blame] | 26 | @test.attr(type=['negative']) |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 27 | @test.idempotent_id('036ede36-6160-4463-8c01-c781eee6369d') |
ivan-zhu | 3867a1c | 2013-10-11 14:16:58 +0800 | [diff] [blame] | 28 | def test_register_with_invalid_container_format(self): |
| 29 | # Negative tests for invalid data supplied to POST /images |
Masayuki Igawa | 4b29e47 | 2015-02-16 10:41:54 +0900 | [diff] [blame] | 30 | self.assertRaises(lib_exc.BadRequest, self.client.create_image, |
Ken'ichi Ohmichi | 02bcdf3 | 2016-06-17 16:41:26 -0700 | [diff] [blame] | 31 | headers={'x-image-meta-name': 'test', |
| 32 | 'x-image-meta-container_format': 'wrong', |
| 33 | 'x-image-meta-disk_format': 'vhd'}) |
ivan-zhu | 3867a1c | 2013-10-11 14:16:58 +0800 | [diff] [blame] | 34 | |
Sean Dague | 639f2fa | 2015-04-27 09:00:33 -0400 | [diff] [blame] | 35 | @test.attr(type=['negative']) |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 36 | @test.idempotent_id('993face5-921d-4e84-aabf-c1bba4234a67') |
ivan-zhu | 3867a1c | 2013-10-11 14:16:58 +0800 | [diff] [blame] | 37 | def test_register_with_invalid_disk_format(self): |
Masayuki Igawa | 4b29e47 | 2015-02-16 10:41:54 +0900 | [diff] [blame] | 38 | self.assertRaises(lib_exc.BadRequest, self.client.create_image, |
Ken'ichi Ohmichi | 02bcdf3 | 2016-06-17 16:41:26 -0700 | [diff] [blame] | 39 | headers={'x-image-meta-name': 'test', |
| 40 | 'x-image-meta-container_format': 'bare', |
| 41 | 'x-image-meta-disk_format': 'wrong'}) |
ivan-zhu | 3867a1c | 2013-10-11 14:16:58 +0800 | [diff] [blame] | 42 | |
Sean Dague | 639f2fa | 2015-04-27 09:00:33 -0400 | [diff] [blame] | 43 | @test.attr(type=['negative']) |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 44 | @test.idempotent_id('ec652588-7e3c-4b67-a2f2-0fa96f57c8fc') |
ivan-zhu | 3867a1c | 2013-10-11 14:16:58 +0800 | [diff] [blame] | 45 | def test_delete_non_existent_image(self): |
| 46 | # Return an error while trying to delete a non-existent image |
| 47 | |
zhufl | 224bd9d | 2016-12-23 17:14:35 +0800 | [diff] [blame^] | 48 | non_existent_image_id = data_utils.rand_uuid() |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 49 | self.assertRaises(lib_exc.NotFound, self.client.delete_image, |
ivan-zhu | 3867a1c | 2013-10-11 14:16:58 +0800 | [diff] [blame] | 50 | non_existent_image_id) |
| 51 | |
Sean Dague | 639f2fa | 2015-04-27 09:00:33 -0400 | [diff] [blame] | 52 | @test.attr(type=['negative']) |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 53 | @test.idempotent_id('04f72aa3-fcec-45a3-81a3-308ef7cc82bc') |
ivan-zhu | 3867a1c | 2013-10-11 14:16:58 +0800 | [diff] [blame] | 54 | def test_delete_image_blank_id(self): |
| 55 | # Return an error while trying to delete an image with blank Id |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 56 | self.assertRaises(lib_exc.NotFound, self.client.delete_image, '') |
ivan-zhu | 3867a1c | 2013-10-11 14:16:58 +0800 | [diff] [blame] | 57 | |
Sean Dague | 639f2fa | 2015-04-27 09:00:33 -0400 | [diff] [blame] | 58 | @test.attr(type=['negative']) |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 59 | @test.idempotent_id('950e5054-a3c7-4dee-ada5-e576f1087abd') |
ivan-zhu | 3867a1c | 2013-10-11 14:16:58 +0800 | [diff] [blame] | 60 | def test_delete_image_non_hex_string_id(self): |
| 61 | # Return an error while trying to delete an image with non hex id |
zhufl | 224bd9d | 2016-12-23 17:14:35 +0800 | [diff] [blame^] | 62 | invalid_image_id = data_utils.rand_uuid()[:-1] + "j" |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 63 | self.assertRaises(lib_exc.NotFound, self.client.delete_image, |
zhufl | 224bd9d | 2016-12-23 17:14:35 +0800 | [diff] [blame^] | 64 | invalid_image_id) |
ivan-zhu | 3867a1c | 2013-10-11 14:16:58 +0800 | [diff] [blame] | 65 | |
Sean Dague | 639f2fa | 2015-04-27 09:00:33 -0400 | [diff] [blame] | 66 | @test.attr(type=['negative']) |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 67 | @test.idempotent_id('4ed757cd-450c-44b1-9fd1-c819748c650d') |
ivan-zhu | 3867a1c | 2013-10-11 14:16:58 +0800 | [diff] [blame] | 68 | def test_delete_image_negative_image_id(self): |
| 69 | # Return an error while trying to delete an image with negative id |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 70 | self.assertRaises(lib_exc.NotFound, self.client.delete_image, -1) |
ivan-zhu | 3867a1c | 2013-10-11 14:16:58 +0800 | [diff] [blame] | 71 | |
Sean Dague | 639f2fa | 2015-04-27 09:00:33 -0400 | [diff] [blame] | 72 | @test.attr(type=['negative']) |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 73 | @test.idempotent_id('a4a448ab-3db2-4d2d-b9b2-6a1271241dfe') |
zhufl | 224bd9d | 2016-12-23 17:14:35 +0800 | [diff] [blame^] | 74 | def test_delete_image_id_over_character_limit(self): |
ivan-zhu | 3867a1c | 2013-10-11 14:16:58 +0800 | [diff] [blame] | 75 | # Return an error while trying to delete image with id over limit |
zhufl | 224bd9d | 2016-12-23 17:14:35 +0800 | [diff] [blame^] | 76 | overlimit_image_id = data_utils.rand_uuid() + "1" |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 77 | self.assertRaises(lib_exc.NotFound, self.client.delete_image, |
zhufl | 224bd9d | 2016-12-23 17:14:35 +0800 | [diff] [blame^] | 78 | overlimit_image_id) |