blob: 538d5be98cdeff1d9c4bfd2abe22e7dc31201d35 [file] [log] [blame]
Rohit Karajgidd47d7e2012-07-31 04:11:01 -07001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
ZhiQiang Fan39f97222013-09-20 04:49:44 +08003# Copyright 2012 OpenStack Foundation
Rohit Karajgidd47d7e2012-07-31 04:11:01 -07004# All Rights Reserved.
5#
6# Licensed under the Apache License, Version 2.0 (the "License"); you may
7# not use this file except in compliance with the License. You may obtain
8# a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15# License for the specific language governing permissions and limitations
16# under the License.
17
Zhi Kun Liu3bdfe092013-09-02 01:31:58 +080018import uuid
19
Sean Dague1937d092013-05-17 16:36:38 -040020from tempest.api.volume import base
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070021from tempest.common.utils.data_utils import rand_name
Matthew Treinisha83a16e2012-12-07 13:44:02 -050022from tempest import exceptions
Giulio Fidente8b311902013-05-12 15:40:31 +020023from tempest.test import attr
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070024
25
Attila Fazekas3dcdae12013-02-14 12:50:04 +010026class VolumesNegativeTest(base.BaseVolumeTest):
27 _interface = 'json'
28
29 @classmethod
30 def setUpClass(cls):
31 super(VolumesNegativeTest, cls).setUpClass()
32 cls.client = cls.volumes_client
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070033
Zhi Kun Liu3bdfe092013-09-02 01:31:58 +080034 # Create a test shared instance and volume for attach/detach tests
35 vol_name = rand_name('Volume-')
36
37 cls.volume = cls.create_volume(size=1, display_name=vol_name)
38 cls.client.wait_for_volume_status(cls.volume['id'], 'available')
39 cls.mountpoint = "/dev/vdc"
40
wanghaoc2abb6c2013-09-29 19:14:09 +080041 @attr(type=['negative', 'gate'])
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070042 def test_volume_get_nonexistant_volume_id(self):
Zhi Kun Liu3bdfe092013-09-02 01:31:58 +080043 # Should not be able to get a non-existant volume
Chris Yeoh8b4eaa52013-02-06 18:03:10 +103044 self.assertRaises(exceptions.NotFound, self.client.get_volume,
Zhi Kun Liu3bdfe092013-09-02 01:31:58 +080045 str(uuid.uuid4()))
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070046
wanghaoc2abb6c2013-09-29 19:14:09 +080047 @attr(type=['negative', 'gate'])
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070048 def test_volume_delete_nonexistant_volume_id(self):
Zhi Kun Liu3bdfe092013-09-02 01:31:58 +080049 # Should not be able to delete a non-existant Volume
Chris Yeoh8b4eaa52013-02-06 18:03:10 +103050 self.assertRaises(exceptions.NotFound, self.client.delete_volume,
Zhi Kun Liu3bdfe092013-09-02 01:31:58 +080051 str(uuid.uuid4()))
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070052
wanghaoc2abb6c2013-09-29 19:14:09 +080053 @attr(type=['negative', 'gate'])
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070054 def test_create_volume_with_invalid_size(self):
Sean Dague72a00382013-01-03 17:53:38 -050055 # Should not be able to create volume with invalid size
56 # in request
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070057 v_name = rand_name('Volume-')
58 metadata = {'Type': 'work'}
Chris Yeoh8b4eaa52013-02-06 18:03:10 +103059 self.assertRaises(exceptions.BadRequest, self.client.create_volume,
60 size='#$%', display_name=v_name, metadata=metadata)
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070061
wanghaoc2abb6c2013-09-29 19:14:09 +080062 @attr(type=['negative', 'gate'])
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070063 def test_create_volume_with_out_passing_size(self):
Sean Dague72a00382013-01-03 17:53:38 -050064 # Should not be able to create volume without passing size
65 # in request
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070066 v_name = rand_name('Volume-')
67 metadata = {'Type': 'work'}
Chris Yeoh8b4eaa52013-02-06 18:03:10 +103068 self.assertRaises(exceptions.BadRequest, self.client.create_volume,
69 size='', display_name=v_name, metadata=metadata)
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070070
wanghaoc2abb6c2013-09-29 19:14:09 +080071 @attr(type=['negative', 'gate'])
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070072 def test_create_volume_with_size_zero(self):
Sean Dague72a00382013-01-03 17:53:38 -050073 # Should not be able to create volume with size zero
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070074 v_name = rand_name('Volume-')
75 metadata = {'Type': 'work'}
Chris Yeoh8b4eaa52013-02-06 18:03:10 +103076 self.assertRaises(exceptions.BadRequest, self.client.create_volume,
77 size='0', display_name=v_name, metadata=metadata)
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070078
wanghaoc2abb6c2013-09-29 19:14:09 +080079 @attr(type=['negative', 'gate'])
80 def test_create_volume_with_size_negative(self):
81 # Should not be able to create volume with size negative
82 v_name = rand_name('Volume-')
83 metadata = {'Type': 'work'}
84 self.assertRaises(exceptions.BadRequest, self.client.create_volume,
85 size='-1', display_name=v_name, metadata=metadata)
86
87 @attr(type=['negative', 'gate'])
zhangyanzib866f052013-10-12 11:41:32 +080088 def test_create_volume_with_nonexistant_volume_type(self):
89 # Should not be able to create volume with non-existant volume type
90 v_name = rand_name('Volume-')
91 metadata = {'Type': 'work'}
92 self.assertRaises(exceptions.NotFound, self.client.create_volume,
93 size='1', volume_type=str(uuid.uuid4()),
94 display_name=v_name, metadata=metadata)
95
96 @attr(type=['negative', 'gate'])
97 def test_create_volume_with_nonexistant_snapshot_id(self):
98 # Should not be able to create volume with non-existant snapshot
99 v_name = rand_name('Volume-')
100 metadata = {'Type': 'work'}
101 self.assertRaises(exceptions.NotFound, self.client.create_volume,
102 size='1', snapshot_id=str(uuid.uuid4()),
103 display_name=v_name, metadata=metadata)
104
105 @attr(type=['negative', 'gate'])
106 def test_create_volume_with_nonexistant_source_volid(self):
107 # Should not be able to create volume with non-existant source volume
108 v_name = rand_name('Volume-')
109 metadata = {'Type': 'work'}
110 self.assertRaises(exceptions.NotFound, self.client.create_volume,
111 size='1', source_volid=str(uuid.uuid4()),
112 display_name=v_name, metadata=metadata)
113
114 @attr(type=['negative', 'gate'])
wanghaoc2abb6c2013-09-29 19:14:09 +0800115 def test_update_volume_with_nonexistant_volume_id(self):
116 v_name = rand_name('Volume-')
117 metadata = {'Type': 'work'}
118 self.assertRaises(exceptions.NotFound, self.client.update_volume,
119 volume_id=str(uuid.uuid4()), display_name=v_name,
120 metadata=metadata)
121
122 @attr(type=['negative', 'gate'])
123 def test_update_volume_with_invalid_volume_id(self):
124 v_name = rand_name('Volume-')
125 metadata = {'Type': 'work'}
126 self.assertRaises(exceptions.NotFound, self.client.update_volume,
127 volume_id='#$%%&^&^', display_name=v_name,
128 metadata=metadata)
129
130 @attr(type=['negative', 'gate'])
131 def test_update_volume_with_empty_volume_id(self):
132 v_name = rand_name('Volume-')
133 metadata = {'Type': 'work'}
134 self.assertRaises(exceptions.NotFound, self.client.update_volume,
135 volume_id='', display_name=v_name,
136 metadata=metadata)
137
138 @attr(type=['negative', 'gate'])
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700139 def test_get_invalid_volume_id(self):
Sean Dague72a00382013-01-03 17:53:38 -0500140 # Should not be able to get volume with invalid id
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030141 self.assertRaises(exceptions.NotFound, self.client.get_volume,
142 '#$%%&^&^')
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700143
wanghaoc2abb6c2013-09-29 19:14:09 +0800144 @attr(type=['negative', 'gate'])
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700145 def test_get_volume_without_passing_volume_id(self):
Sean Dague72a00382013-01-03 17:53:38 -0500146 # Should not be able to get volume when empty ID is passed
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030147 self.assertRaises(exceptions.NotFound, self.client.get_volume, '')
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700148
wanghaoc2abb6c2013-09-29 19:14:09 +0800149 @attr(type=['negative', 'gate'])
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700150 def test_delete_invalid_volume_id(self):
Sean Dague72a00382013-01-03 17:53:38 -0500151 # Should not be able to delete volume when invalid ID is passed
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030152 self.assertRaises(exceptions.NotFound, self.client.delete_volume,
153 '!@#$%^&*()')
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700154
wanghaoc2abb6c2013-09-29 19:14:09 +0800155 @attr(type=['negative', 'gate'])
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700156 def test_delete_volume_without_passing_volume_id(self):
Sean Dague72a00382013-01-03 17:53:38 -0500157 # Should not be able to delete volume when empty ID is passed
Chris Yeoh8b4eaa52013-02-06 18:03:10 +1030158 self.assertRaises(exceptions.NotFound, self.client.delete_volume, '')
Matthew Treinish9854d5b2012-09-20 10:22:13 -0400159
Zhi Kun Liu3bdfe092013-09-02 01:31:58 +0800160 @attr(type=['negative', 'gate'])
161 def test_attach_volumes_with_nonexistent_volume_id(self):
162 srv_name = rand_name('Instance-')
163 resp, server = self.servers_client.create_server(srv_name,
164 self.image_ref,
165 self.flavor_ref)
166 self.addCleanup(self.servers_client.delete_server, server['id'])
167 self.servers_client.wait_for_server_status(server['id'], 'ACTIVE')
168 self.assertRaises(exceptions.NotFound,
169 self.client.attach_volume,
170 str(uuid.uuid4()),
171 server['id'],
172 self.mountpoint)
173
174 @attr(type=['negative', 'gate'])
175 def test_detach_volumes_with_invalid_volume_id(self):
176 self.assertRaises(exceptions.NotFound,
177 self.client.detach_volume,
178 'xxx')
179
wanghao5b981752013-10-22 11:41:41 +0800180 @attr(type=['negative', 'gate'])
181 def test_volume_extend_with_size_smaller_than_original_size(self):
182 # Extend volume with smaller size than original size.
183 extend_size = 0
184 self.assertRaises(exceptions.BadRequest, self.client.extend_volume,
185 self.volume['id'], extend_size)
186
187 @attr(type=['negative', 'gate'])
188 def test_volume_extend_with_non_number_size(self):
189 # Extend volume when size is non number.
190 extend_size = 'abc'
191 self.assertRaises(exceptions.BadRequest, self.client.extend_volume,
192 self.volume['id'], extend_size)
193
194 @attr(type=['negative', 'gate'])
195 def test_volume_extend_with_None_size(self):
196 # Extend volume with None size.
197 extend_size = None
198 self.assertRaises(exceptions.BadRequest, self.client.extend_volume,
199 self.volume['id'], extend_size)
200
201 @attr(type=['negative', 'gate'])
202 def test_volume_extend_with_nonexistent_volume_id(self):
203 # Extend volume size when volume is nonexistent.
204 extend_size = int(self.volume['size']) + 1
205 self.assertRaises(exceptions.NotFound, self.client.extend_volume,
206 str(uuid.uuid4()), extend_size)
207
208 @attr(type=['negative', 'gate'])
209 def test_volume_extend_without_passing_volume_id(self):
210 # Extend volume size when passing volume id is None.
211 extend_size = int(self.volume['size']) + 1
212 self.assertRaises(exceptions.NotFound, self.client.extend_volume,
213 None, extend_size)
214
zhangyanzi6b632432013-10-24 19:08:50 +0800215 @attr(type=['negative', 'gate'])
216 def test_reserve_volume_with_nonexistent_volume_id(self):
217 self.assertRaises(exceptions.NotFound,
218 self.client.reserve_volume,
219 str(uuid.uuid4()))
220
221 @attr(type=['negative', 'gate'])
222 def test_unreserve_volume_with_nonexistent_volume_id(self):
223 self.assertRaises(exceptions.NotFound,
224 self.client.unreserve_volume,
225 str(uuid.uuid4()))
226
227 @attr(type=['negative', 'gate'])
228 def test_reserve_volume_with_negative_volume_status(self):
229 # Mark volume as reserved.
230 resp, body = self.client.reserve_volume(self.volume['id'])
231 self.assertEqual(202, resp.status)
232 # Mark volume which is marked as reserved before
233 self.assertRaises(exceptions.BadRequest,
234 self.client.reserve_volume,
235 self.volume['id'])
236 # Unmark volume as reserved.
237 resp, body = self.client.unreserve_volume(self.volume['id'])
238 self.assertEqual(202, resp.status)
239
Matthew Treinish9854d5b2012-09-20 10:22:13 -0400240
Attila Fazekas3dcdae12013-02-14 12:50:04 +0100241class VolumesNegativeTestXML(VolumesNegativeTest):
242 _interface = 'xml'