nayna-patel | 26f4859 | 2014-02-28 09:30:38 +0000 | [diff] [blame] | 1 | # 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 | |
| 15 | from tempest.api.compute import base |
Fei Long Wang | d39431f | 2015-05-14 11:30:48 +1200 | [diff] [blame] | 16 | from tempest.common.utils import data_utils |
Ken'ichi Ohmichi | 0eb153c | 2015-07-13 02:18:25 +0000 | [diff] [blame] | 17 | from tempest.common import waiters |
nayna-patel | 26f4859 | 2014-02-28 09:30:38 +0000 | [diff] [blame] | 18 | from tempest import config |
Andrea Frittoli (andreaf) | db9672e | 2016-02-23 14:07:24 -0500 | [diff] [blame] | 19 | from tempest.lib import exceptions as lib_exc |
nayna-patel | 26f4859 | 2014-02-28 09:30:38 +0000 | [diff] [blame] | 20 | from tempest import test |
| 21 | |
| 22 | CONF = config.CONF |
| 23 | |
| 24 | |
| 25 | class ImagesNegativeTestJSON(base.BaseV2ComputeTest): |
| 26 | |
| 27 | @classmethod |
Rohan Kanade | 60b7309 | 2015-02-04 17:58:19 +0530 | [diff] [blame] | 28 | def skip_checks(cls): |
| 29 | super(ImagesNegativeTestJSON, cls).skip_checks() |
nayna-patel | 26f4859 | 2014-02-28 09:30:38 +0000 | [diff] [blame] | 30 | if not CONF.service_available.glance: |
| 31 | skip_msg = ("%s skipped as glance is not available" % cls.__name__) |
| 32 | raise cls.skipException(skip_msg) |
Adam Gandelman | fbc95ac | 2014-06-19 17:33:43 -0700 | [diff] [blame] | 33 | if not CONF.compute_feature_enabled.snapshot: |
| 34 | skip_msg = ("%s skipped as instance snapshotting is not supported" |
| 35 | % cls.__name__) |
| 36 | raise cls.skipException(skip_msg) |
| 37 | |
Rohan Kanade | 60b7309 | 2015-02-04 17:58:19 +0530 | [diff] [blame] | 38 | @classmethod |
| 39 | def setup_clients(cls): |
| 40 | super(ImagesNegativeTestJSON, cls).setup_clients() |
Ghanshyam | ae76c12 | 2015-12-22 13:41:35 +0900 | [diff] [blame] | 41 | cls.client = cls.compute_images_client |
nayna-patel | 26f4859 | 2014-02-28 09:30:38 +0000 | [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('6cd5a89d-5b47-46a7-93bc-3916f0d84973') |
nayna-patel | 26f4859 | 2014-02-28 09:30:38 +0000 | [diff] [blame] | 45 | def test_create_image_from_deleted_server(self): |
| 46 | # An image should not be created if the server instance is removed |
David Kranz | 0fb1429 | 2015-02-11 15:55:20 -0500 | [diff] [blame] | 47 | server = self.create_test_server(wait_until='ACTIVE') |
nayna-patel | 26f4859 | 2014-02-28 09:30:38 +0000 | [diff] [blame] | 48 | |
| 49 | # Delete server before trying to create server |
| 50 | self.servers_client.delete_server(server['id']) |
Ken'ichi Ohmichi | e91a0c6 | 2015-08-13 02:09:16 +0000 | [diff] [blame] | 51 | waiters.wait_for_server_termination(self.servers_client, server['id']) |
Matthew Treinish | c795b9e | 2014-06-09 17:01:10 -0400 | [diff] [blame] | 52 | # Create a new image after server is deleted |
nayna-patel | 26f4859 | 2014-02-28 09:30:38 +0000 | [diff] [blame] | 53 | name = data_utils.rand_name('image') |
| 54 | meta = {'image_type': 'test'} |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 55 | self.assertRaises(lib_exc.NotFound, |
nayna-patel | 26f4859 | 2014-02-28 09:30:38 +0000 | [diff] [blame] | 56 | self.create_image_from_server, |
| 57 | server['id'], name=name, meta=meta) |
| 58 | |
Sean Dague | 639f2fa | 2015-04-27 09:00:33 -0400 | [diff] [blame] | 59 | @test.attr(type=['negative']) |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 60 | @test.idempotent_id('82c5b0c4-9dbd-463c-872b-20c4755aae7f') |
nayna-patel | 26f4859 | 2014-02-28 09:30:38 +0000 | [diff] [blame] | 61 | 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 |
| 64 | name = data_utils.rand_name('image') |
| 65 | meta = {'image_type': 'test'} |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 66 | self.assertRaises(lib_exc.NotFound, self.create_image_from_server, |
Sergey Nikitin | b39559a | 2016-02-26 15:05:40 +0300 | [diff] [blame] | 67 | '!@$^&*()', name=name, meta=meta) |
nayna-patel | 26f4859 | 2014-02-28 09:30:38 +0000 | [diff] [blame] | 68 | |
Sean Dague | 639f2fa | 2015-04-27 09:00:33 -0400 | [diff] [blame] | 69 | @test.attr(type=['negative']) |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 70 | @test.idempotent_id('ec176029-73dc-4037-8d72-2e4ff60cf538') |
nayna-patel | 26f4859 | 2014-02-28 09:30:38 +0000 | [diff] [blame] | 71 | def test_create_image_specify_uuid_35_characters_or_less(self): |
| 72 | # Return an error if Image ID passed is 35 characters or less |
Ken'ichi Ohmichi | 4937f56 | 2015-03-23 00:15:01 +0000 | [diff] [blame] | 73 | snapshot_name = data_utils.rand_name('test-snap') |
nayna-patel | 26f4859 | 2014-02-28 09:30:38 +0000 | [diff] [blame] | 74 | test_uuid = ('a' * 35) |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 75 | self.assertRaises(lib_exc.NotFound, self.client.create_image, |
Ken'ichi Ohmichi | 28f1867 | 2015-07-17 10:00:38 +0000 | [diff] [blame] | 76 | test_uuid, name=snapshot_name) |
nayna-patel | 26f4859 | 2014-02-28 09:30:38 +0000 | [diff] [blame] | 77 | |
Sean Dague | 639f2fa | 2015-04-27 09:00:33 -0400 | [diff] [blame] | 78 | @test.attr(type=['negative']) |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 79 | @test.idempotent_id('36741560-510e-4cc2-8641-55fe4dfb2437') |
nayna-patel | 26f4859 | 2014-02-28 09:30:38 +0000 | [diff] [blame] | 80 | def test_create_image_specify_uuid_37_characters_or_more(self): |
| 81 | # Return an error if Image ID passed is 37 characters or more |
Ken'ichi Ohmichi | 4937f56 | 2015-03-23 00:15:01 +0000 | [diff] [blame] | 82 | snapshot_name = data_utils.rand_name('test-snap') |
nayna-patel | 26f4859 | 2014-02-28 09:30:38 +0000 | [diff] [blame] | 83 | test_uuid = ('a' * 37) |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 84 | self.assertRaises(lib_exc.NotFound, self.client.create_image, |
Ken'ichi Ohmichi | 28f1867 | 2015-07-17 10:00:38 +0000 | [diff] [blame] | 85 | test_uuid, name=snapshot_name) |
nayna-patel | 26f4859 | 2014-02-28 09:30:38 +0000 | [diff] [blame] | 86 | |
Sean Dague | 639f2fa | 2015-04-27 09:00:33 -0400 | [diff] [blame] | 87 | @test.attr(type=['negative']) |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 88 | @test.idempotent_id('381acb65-785a-4942-94ce-d8f8c84f1f0f') |
nayna-patel | 26f4859 | 2014-02-28 09:30:38 +0000 | [diff] [blame] | 89 | def test_delete_image_with_invalid_image_id(self): |
| 90 | # An image should not be deleted with invalid image id |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 91 | self.assertRaises(lib_exc.NotFound, self.client.delete_image, |
Marian Horban | 64a5e35 | 2015-04-24 09:51:23 -0400 | [diff] [blame] | 92 | '!@$^&*()') |
nayna-patel | 26f4859 | 2014-02-28 09:30:38 +0000 | [diff] [blame] | 93 | |
Sean Dague | 639f2fa | 2015-04-27 09:00:33 -0400 | [diff] [blame] | 94 | @test.attr(type=['negative']) |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 95 | @test.idempotent_id('137aef61-39f7-44a1-8ddf-0adf82511701') |
nayna-patel | 26f4859 | 2014-02-28 09:30:38 +0000 | [diff] [blame] | 96 | def test_delete_non_existent_image(self): |
| 97 | # Return an error while trying to delete a non-existent image |
| 98 | |
zhufl | 557124e | 2016-12-02 16:51:54 +0800 | [diff] [blame^] | 99 | non_existent_image_id = data_utils.rand_uuid() |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 100 | self.assertRaises(lib_exc.NotFound, self.client.delete_image, |
nayna-patel | 26f4859 | 2014-02-28 09:30:38 +0000 | [diff] [blame] | 101 | non_existent_image_id) |
| 102 | |
Sean Dague | 639f2fa | 2015-04-27 09:00:33 -0400 | [diff] [blame] | 103 | @test.attr(type=['negative']) |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 104 | @test.idempotent_id('e6e41425-af5c-4fe6-a4b5-7b7b963ffda5') |
nayna-patel | 26f4859 | 2014-02-28 09:30:38 +0000 | [diff] [blame] | 105 | def test_delete_image_blank_id(self): |
| 106 | # Return an error while trying to delete an image with blank Id |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 107 | self.assertRaises(lib_exc.NotFound, self.client.delete_image, '') |
nayna-patel | 26f4859 | 2014-02-28 09:30:38 +0000 | [diff] [blame] | 108 | |
Sean Dague | 639f2fa | 2015-04-27 09:00:33 -0400 | [diff] [blame] | 109 | @test.attr(type=['negative']) |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 110 | @test.idempotent_id('924540c3-f1f1-444c-8f58-718958b6724e') |
nayna-patel | 26f4859 | 2014-02-28 09:30:38 +0000 | [diff] [blame] | 111 | def test_delete_image_non_hex_string_id(self): |
| 112 | # Return an error while trying to delete an image with non hex id |
zhufl | 557124e | 2016-12-02 16:51:54 +0800 | [diff] [blame^] | 113 | invalid_image_id = data_utils.rand_uuid()[:-1] + "j" |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 114 | self.assertRaises(lib_exc.NotFound, self.client.delete_image, |
zhufl | 557124e | 2016-12-02 16:51:54 +0800 | [diff] [blame^] | 115 | invalid_image_id) |
nayna-patel | 26f4859 | 2014-02-28 09:30:38 +0000 | [diff] [blame] | 116 | |
Sean Dague | 639f2fa | 2015-04-27 09:00:33 -0400 | [diff] [blame] | 117 | @test.attr(type=['negative']) |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 118 | @test.idempotent_id('68e2c175-bd26-4407-ac0f-4ea9ce2139ea') |
nayna-patel | 26f4859 | 2014-02-28 09:30:38 +0000 | [diff] [blame] | 119 | def test_delete_image_negative_image_id(self): |
| 120 | # Return an error while trying to delete an image with negative id |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 121 | self.assertRaises(lib_exc.NotFound, self.client.delete_image, -1) |
nayna-patel | 26f4859 | 2014-02-28 09:30:38 +0000 | [diff] [blame] | 122 | |
Sean Dague | 639f2fa | 2015-04-27 09:00:33 -0400 | [diff] [blame] | 123 | @test.attr(type=['negative']) |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 124 | @test.idempotent_id('b340030d-82cd-4066-a314-c72fb7c59277') |
zhufl | 557124e | 2016-12-02 16:51:54 +0800 | [diff] [blame^] | 125 | def test_delete_image_with_id_over_character_limit(self): |
nayna-patel | 26f4859 | 2014-02-28 09:30:38 +0000 | [diff] [blame] | 126 | # Return an error while trying to delete image with id over limit |
zhufl | 557124e | 2016-12-02 16:51:54 +0800 | [diff] [blame^] | 127 | invalid_image_id = data_utils.rand_uuid() + "1" |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 128 | self.assertRaises(lib_exc.NotFound, self.client.delete_image, |
zhufl | 557124e | 2016-12-02 16:51:54 +0800 | [diff] [blame^] | 129 | invalid_image_id) |