blob: 9e67c25d0c509a258c126470899c73b5f0d4ccab [file] [log] [blame]
ivan-zhu3867a1c2013-10-11 14:16:58 +08001# 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 Igawabfa07602015-01-20 18:47:17 +090016
ivan-zhu3867a1c2013-10-11 14:16:58 +080017from tempest.api.image import base
Andrea Frittoli (andreaf)db9672e2016-02-23 14:07:24 -050018from tempest.lib import exceptions as lib_exc
Eiichi Aikawa9012f462014-03-05 16:43:32 +090019from tempest import test
ivan-zhu3867a1c2013-10-11 14:16:58 +080020
21
22class CreateDeleteImagesNegativeTest(base.BaseV1ImageTest):
23 """Here are negative tests for the deletion and creation of images."""
24
Sean Dague639f2fa2015-04-27 09:00:33 -040025 @test.attr(type=['negative'])
Chris Hoge7579c1a2015-02-26 14:12:15 -080026 @test.idempotent_id('036ede36-6160-4463-8c01-c781eee6369d')
ivan-zhu3867a1c2013-10-11 14:16:58 +080027 def test_register_with_invalid_container_format(self):
28 # Negative tests for invalid data supplied to POST /images
Masayuki Igawa4b29e472015-02-16 10:41:54 +090029 self.assertRaises(lib_exc.BadRequest, self.client.create_image,
Ken'ichi Ohmichi02bcdf32016-06-17 16:41:26 -070030 headers={'x-image-meta-name': 'test',
31 'x-image-meta-container_format': 'wrong',
32 'x-image-meta-disk_format': 'vhd'})
ivan-zhu3867a1c2013-10-11 14:16:58 +080033
Sean Dague639f2fa2015-04-27 09:00:33 -040034 @test.attr(type=['negative'])
Chris Hoge7579c1a2015-02-26 14:12:15 -080035 @test.idempotent_id('993face5-921d-4e84-aabf-c1bba4234a67')
ivan-zhu3867a1c2013-10-11 14:16:58 +080036 def test_register_with_invalid_disk_format(self):
Masayuki Igawa4b29e472015-02-16 10:41:54 +090037 self.assertRaises(lib_exc.BadRequest, self.client.create_image,
Ken'ichi Ohmichi02bcdf32016-06-17 16:41:26 -070038 headers={'x-image-meta-name': 'test',
39 'x-image-meta-container_format': 'bare',
40 'x-image-meta-disk_format': 'wrong'})
ivan-zhu3867a1c2013-10-11 14:16:58 +080041
Sean Dague639f2fa2015-04-27 09:00:33 -040042 @test.attr(type=['negative'])
Chris Hoge7579c1a2015-02-26 14:12:15 -080043 @test.idempotent_id('bb016f15-0820-4f27-a92d-09b2f67d2488')
ivan-zhu3867a1c2013-10-11 14:16:58 +080044 def test_delete_image_with_invalid_image_id(self):
45 # An image should not be deleted with invalid image id
Masayuki Igawabfa07602015-01-20 18:47:17 +090046 self.assertRaises(lib_exc.NotFound, self.client.delete_image,
ivan-zhu3867a1c2013-10-11 14:16:58 +080047 '!@$%^&*()')
48
Sean Dague639f2fa2015-04-27 09:00:33 -040049 @test.attr(type=['negative'])
Chris Hoge7579c1a2015-02-26 14:12:15 -080050 @test.idempotent_id('ec652588-7e3c-4b67-a2f2-0fa96f57c8fc')
ivan-zhu3867a1c2013-10-11 14:16:58 +080051 def test_delete_non_existent_image(self):
52 # Return an error while trying to delete a non-existent image
53
54 non_existent_image_id = '11a22b9-12a9-5555-cc11-00ab112223fa'
Masayuki Igawabfa07602015-01-20 18:47:17 +090055 self.assertRaises(lib_exc.NotFound, self.client.delete_image,
ivan-zhu3867a1c2013-10-11 14:16:58 +080056 non_existent_image_id)
57
Sean Dague639f2fa2015-04-27 09:00:33 -040058 @test.attr(type=['negative'])
Chris Hoge7579c1a2015-02-26 14:12:15 -080059 @test.idempotent_id('04f72aa3-fcec-45a3-81a3-308ef7cc82bc')
ivan-zhu3867a1c2013-10-11 14:16:58 +080060 def test_delete_image_blank_id(self):
61 # Return an error while trying to delete an image with blank Id
Masayuki Igawabfa07602015-01-20 18:47:17 +090062 self.assertRaises(lib_exc.NotFound, self.client.delete_image, '')
ivan-zhu3867a1c2013-10-11 14:16:58 +080063
Sean Dague639f2fa2015-04-27 09:00:33 -040064 @test.attr(type=['negative'])
Chris Hoge7579c1a2015-02-26 14:12:15 -080065 @test.idempotent_id('950e5054-a3c7-4dee-ada5-e576f1087abd')
ivan-zhu3867a1c2013-10-11 14:16:58 +080066 def test_delete_image_non_hex_string_id(self):
67 # Return an error while trying to delete an image with non hex id
68 image_id = '11a22b9-120q-5555-cc11-00ab112223gj'
Masayuki Igawabfa07602015-01-20 18:47:17 +090069 self.assertRaises(lib_exc.NotFound, self.client.delete_image,
ivan-zhu3867a1c2013-10-11 14:16:58 +080070 image_id)
71
Sean Dague639f2fa2015-04-27 09:00:33 -040072 @test.attr(type=['negative'])
Chris Hoge7579c1a2015-02-26 14:12:15 -080073 @test.idempotent_id('4ed757cd-450c-44b1-9fd1-c819748c650d')
ivan-zhu3867a1c2013-10-11 14:16:58 +080074 def test_delete_image_negative_image_id(self):
75 # Return an error while trying to delete an image with negative id
Masayuki Igawabfa07602015-01-20 18:47:17 +090076 self.assertRaises(lib_exc.NotFound, self.client.delete_image, -1)
ivan-zhu3867a1c2013-10-11 14:16:58 +080077
Sean Dague639f2fa2015-04-27 09:00:33 -040078 @test.attr(type=['negative'])
Chris Hoge7579c1a2015-02-26 14:12:15 -080079 @test.idempotent_id('a4a448ab-3db2-4d2d-b9b2-6a1271241dfe')
ivan-zhu3867a1c2013-10-11 14:16:58 +080080 def test_delete_image_id_is_over_35_character_limit(self):
81 # Return an error while trying to delete image with id over limit
Masayuki Igawabfa07602015-01-20 18:47:17 +090082 self.assertRaises(lib_exc.NotFound, self.client.delete_image,
ivan-zhu3867a1c2013-10-11 14:16:58 +080083 '11a22b9-12a9-5555-cc11-00ab112223fa-3fac')