blob: 58fc20d668120c87cd4f85893424b088ed34ff7f [file] [log] [blame]
nayna-patel26f48592014-02-28 09:30:38 +00001# 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
15from tempest.api.compute import base
16from tempest.common.utils import data_utils
17from tempest import config
18from tempest import exceptions
19from tempest import test
20
21CONF = config.CONF
22
23
24class ImagesNegativeTestJSON(base.BaseV2ComputeTest):
25
26 @classmethod
Andrea Frittoli50bb80d2014-09-15 12:34:27 +010027 def resource_setup(cls):
28 super(ImagesNegativeTestJSON, cls).resource_setup()
nayna-patel26f48592014-02-28 09:30:38 +000029 if not CONF.service_available.glance:
30 skip_msg = ("%s skipped as glance is not available" % cls.__name__)
31 raise cls.skipException(skip_msg)
Adam Gandelmanfbc95ac2014-06-19 17:33:43 -070032
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
nayna-patel26f48592014-02-28 09:30:38 +000038 cls.client = cls.images_client
39 cls.servers_client = cls.servers_client
40
41 @test.attr(type=['negative', 'gate'])
42 def test_create_image_from_deleted_server(self):
43 # An image should not be created if the server instance is removed
44 resp, server = self.create_test_server(wait_until='ACTIVE')
45
46 # Delete server before trying to create server
47 self.servers_client.delete_server(server['id'])
48 self.servers_client.wait_for_server_termination(server['id'])
Matthew Treinishc795b9e2014-06-09 17:01:10 -040049 # Create a new image after server is deleted
nayna-patel26f48592014-02-28 09:30:38 +000050 name = data_utils.rand_name('image')
51 meta = {'image_type': 'test'}
52 self.assertRaises(exceptions.NotFound,
53 self.create_image_from_server,
54 server['id'], name=name, meta=meta)
55
56 @test.attr(type=['negative', 'gate'])
57 def test_create_image_from_invalid_server(self):
58 # An image should not be created with invalid server id
59 # Create a new image with invalid server id
60 name = data_utils.rand_name('image')
61 meta = {'image_type': 'test'}
62 resp = {}
63 resp['status'] = None
64 self.assertRaises(exceptions.NotFound, self.create_image_from_server,
65 '!@#$%^&*()', name=name, meta=meta)
66
67 @test.attr(type=['negative', 'gate'])
68 def test_create_image_from_stopped_server(self):
69 resp, server = self.create_test_server(wait_until='ACTIVE')
70 self.servers_client.stop(server['id'])
71 self.servers_client.wait_for_server_status(server['id'],
72 'SHUTOFF')
73 self.addCleanup(self.servers_client.delete_server, server['id'])
74 snapshot_name = data_utils.rand_name('test-snap-')
David Kranza5299eb2015-01-15 17:24:05 -050075 image = self.create_image_from_server(server['id'],
76 name=snapshot_name,
77 wait_until='ACTIVE',
78 wait_for_server=False)
nayna-patel26f48592014-02-28 09:30:38 +000079 self.addCleanup(self.client.delete_image, image['id'])
80 self.assertEqual(snapshot_name, image['name'])
81
82 @test.attr(type=['negative', 'gate'])
83 def test_create_image_specify_uuid_35_characters_or_less(self):
84 # Return an error if Image ID passed is 35 characters or less
85 snapshot_name = data_utils.rand_name('test-snap-')
86 test_uuid = ('a' * 35)
87 self.assertRaises(exceptions.NotFound, self.client.create_image,
88 test_uuid, snapshot_name)
89
90 @test.attr(type=['negative', 'gate'])
91 def test_create_image_specify_uuid_37_characters_or_more(self):
92 # Return an error if Image ID passed is 37 characters or more
93 snapshot_name = data_utils.rand_name('test-snap-')
94 test_uuid = ('a' * 37)
95 self.assertRaises(exceptions.NotFound, self.client.create_image,
96 test_uuid, snapshot_name)
97
98 @test.attr(type=['negative', 'gate'])
99 def test_delete_image_with_invalid_image_id(self):
100 # An image should not be deleted with invalid image id
101 self.assertRaises(exceptions.NotFound, self.client.delete_image,
102 '!@$%^&*()')
103
104 @test.attr(type=['negative', 'gate'])
105 def test_delete_non_existent_image(self):
106 # Return an error while trying to delete a non-existent image
107
108 non_existent_image_id = '11a22b9-12a9-5555-cc11-00ab112223fa'
109 self.assertRaises(exceptions.NotFound, self.client.delete_image,
110 non_existent_image_id)
111
112 @test.attr(type=['negative', 'gate'])
113 def test_delete_image_blank_id(self):
114 # Return an error while trying to delete an image with blank Id
115 self.assertRaises(exceptions.NotFound, self.client.delete_image, '')
116
117 @test.attr(type=['negative', 'gate'])
118 def test_delete_image_non_hex_string_id(self):
119 # Return an error while trying to delete an image with non hex id
120 image_id = '11a22b9-120q-5555-cc11-00ab112223gj'
121 self.assertRaises(exceptions.NotFound, self.client.delete_image,
122 image_id)
123
124 @test.attr(type=['negative', 'gate'])
125 def test_delete_image_negative_image_id(self):
126 # Return an error while trying to delete an image with negative id
127 self.assertRaises(exceptions.NotFound, self.client.delete_image, -1)
128
129 @test.attr(type=['negative', 'gate'])
130 def test_delete_image_id_is_over_35_character_limit(self):
131 # Return an error while trying to delete image with id over limit
132 self.assertRaises(exceptions.NotFound, self.client.delete_image,
133 '11a22b9-12a9-5555-cc11-00ab112223fa-3fac')