blob: 866bd87c14f0997134393594e7672925fb6328a4 [file] [log] [blame]
ZhiQiang Fan39f97222013-09-20 04:49:44 +08001# Copyright 2012 OpenStack Foundation
Rohit Karajgidd47d7e2012-07-31 04:11:01 -07002# 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
jeremy.zhang0a427162017-04-21 12:47:56 +080016import six
17
Sean Dague1937d092013-05-17 16:36:38 -040018from tempest.api.volume import base
Andrea Frittolicd368412017-08-14 21:37:56 +010019from tempest.common import utils
jeremy.zhang0a427162017-04-21 12:47:56 +080020from tempest.common import waiters
21from tempest import config
Ken'ichi Ohmichief1c1ce2017-03-10 11:07:10 -080022from tempest.lib.common.utils import data_utils
jeremy.zhang0a427162017-04-21 12:47:56 +080023from tempest.lib.common.utils import test_utils
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080024from tempest.lib import decorators
Andrea Frittoli (andreaf)db9672e2016-02-23 14:07:24 -050025from tempest.lib import exceptions as lib_exc
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070026
jeremy.zhang0a427162017-04-21 12:47:56 +080027CONF = config.CONF
28
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070029
Ken'ichi Ohmichie8afb8c2017-03-27 11:25:37 -070030class VolumesNegativeTest(base.BaseVolumeTest):
Attila Fazekas3dcdae12013-02-14 12:50:04 +010031
32 @classmethod
Andrea Frittoli61a12e22014-09-15 13:14:54 +010033 def resource_setup(cls):
Ken'ichi Ohmichie8afb8c2017-03-27 11:25:37 -070034 super(VolumesNegativeTest, cls).resource_setup()
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070035
Zhi Kun Liu3bdfe092013-09-02 01:31:58 +080036 # Create a test shared instance and volume for attach/detach tests
Ken'ichi Ohmichi5687d552013-12-26 19:00:12 +090037 cls.volume = cls.create_volume()
Zhi Kun Liu3bdfe092013-09-02 01:31:58 +080038
lkuchlan13736ae2017-04-24 14:49:45 +030039 def create_image(self):
40 # Create image
41 image_name = data_utils.rand_name(self.__class__.__name__ + "-image")
42 image = self.images_client.create_image(
43 name=image_name,
44 container_format=CONF.image.container_formats[0],
45 disk_format=CONF.image.disk_formats[0],
46 visibility='private',
47 min_disk=CONF.volume.volume_size + 1)
48 self.addCleanup(test_utils.call_and_ignore_notfound_exc,
49 self.images_client.delete_image, image['id'])
50
51 # Upload image with 1KB data
52 image_file = six.BytesIO(data_utils.random_bytes())
53 self.images_client.store_image_file(image['id'], image_file)
54 waiters.wait_for_image_status(self.images_client,
55 image['id'], 'active')
56 return image
57
Jordan Pittier3b46d272017-04-12 16:17:28 +020058 @decorators.attr(type=['negative'])
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080059 @decorators.idempotent_id('f131c586-9448-44a4-a8b0-54ca838aa43e')
nayna-patel179077c2014-01-15 12:27:16 +000060 def test_volume_get_nonexistent_volume_id(self):
61 # Should not be able to get a non-existent volume
lkuchlanb21fc572016-11-28 12:25:22 +020062 self.assertRaises(lib_exc.NotFound, self.volumes_client.show_volume,
Ken'ichi Ohmichid079c892016-04-19 11:23:36 -070063 data_utils.rand_uuid())
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070064
Jordan Pittier3b46d272017-04-12 16:17:28 +020065 @decorators.attr(type=['negative'])
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080066 @decorators.idempotent_id('555efa6e-efcd-44ef-8a3b-4a7ca4837a29')
nayna-patel179077c2014-01-15 12:27:16 +000067 def test_volume_delete_nonexistent_volume_id(self):
68 # Should not be able to delete a non-existent Volume
lkuchlanb21fc572016-11-28 12:25:22 +020069 self.assertRaises(lib_exc.NotFound, self.volumes_client.delete_volume,
Ken'ichi Ohmichid079c892016-04-19 11:23:36 -070070 data_utils.rand_uuid())
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070071
Jordan Pittier3b46d272017-04-12 16:17:28 +020072 @decorators.attr(type=['negative'])
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080073 @decorators.idempotent_id('1ed83a8a-682d-4dfb-a30e-ee63ffd6c049')
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070074 def test_create_volume_with_invalid_size(self):
zhufl9751b3d2017-03-29 18:01:01 +080075 # Should not be able to create volume with invalid size in request
lkuchlanb21fc572016-11-28 12:25:22 +020076 self.assertRaises(lib_exc.BadRequest,
zhufl9751b3d2017-03-29 18:01:01 +080077 self.volumes_client.create_volume, size='#$%')
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070078
Jordan Pittier3b46d272017-04-12 16:17:28 +020079 @decorators.attr(type=['negative'])
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080080 @decorators.idempotent_id('9387686f-334f-4d31-a439-33494b9e2683')
zhufle2fb43e2016-11-24 10:52:16 +080081 def test_create_volume_without_passing_size(self):
Sean Dague72a00382013-01-03 17:53:38 -050082 # Should not be able to create volume without passing size
83 # in request
lkuchlanb21fc572016-11-28 12:25:22 +020084 self.assertRaises(lib_exc.BadRequest,
zhufl9751b3d2017-03-29 18:01:01 +080085 self.volumes_client.create_volume, size='')
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070086
Jordan Pittier3b46d272017-04-12 16:17:28 +020087 @decorators.attr(type=['negative'])
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080088 @decorators.idempotent_id('41331caa-eaf4-4001-869d-bc18c1869360')
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070089 def test_create_volume_with_size_zero(self):
Sean Dague72a00382013-01-03 17:53:38 -050090 # Should not be able to create volume with size zero
lkuchlanb21fc572016-11-28 12:25:22 +020091 self.assertRaises(lib_exc.BadRequest,
zhufl9751b3d2017-03-29 18:01:01 +080092 self.volumes_client.create_volume, size='0')
Rohit Karajgidd47d7e2012-07-31 04:11:01 -070093
Jordan Pittier3b46d272017-04-12 16:17:28 +020094 @decorators.attr(type=['negative'])
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080095 @decorators.idempotent_id('8b472729-9eba-446e-a83b-916bdb34bef7')
wanghaoc2abb6c2013-09-29 19:14:09 +080096 def test_create_volume_with_size_negative(self):
97 # Should not be able to create volume with size negative
lkuchlanb21fc572016-11-28 12:25:22 +020098 self.assertRaises(lib_exc.BadRequest,
zhufl9751b3d2017-03-29 18:01:01 +080099 self.volumes_client.create_volume, size='-1')
wanghaoc2abb6c2013-09-29 19:14:09 +0800100
Jordan Pittier3b46d272017-04-12 16:17:28 +0200101 @decorators.attr(type=['negative'])
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -0800102 @decorators.idempotent_id('10254ed8-3849-454e-862e-3ab8e6aa01d2')
nayna-patel179077c2014-01-15 12:27:16 +0000103 def test_create_volume_with_nonexistent_volume_type(self):
104 # Should not be able to create volume with non-existent volume type
lkuchlanb21fc572016-11-28 12:25:22 +0200105 self.assertRaises(lib_exc.NotFound, self.volumes_client.create_volume,
TommyLikefcda77b2018-01-18 15:25:12 +0800106 size=CONF.volume.volume_size,
107 volume_type=data_utils.rand_uuid())
zhangyanzib866f052013-10-12 11:41:32 +0800108
Jordan Pittier3b46d272017-04-12 16:17:28 +0200109 @decorators.attr(type=['negative'])
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -0800110 @decorators.idempotent_id('0c36f6ae-4604-4017-b0a9-34fdc63096f9')
nayna-patel179077c2014-01-15 12:27:16 +0000111 def test_create_volume_with_nonexistent_snapshot_id(self):
112 # Should not be able to create volume with non-existent snapshot
lkuchlanb21fc572016-11-28 12:25:22 +0200113 self.assertRaises(lib_exc.NotFound, self.volumes_client.create_volume,
TommyLikefcda77b2018-01-18 15:25:12 +0800114 size=CONF.volume.volume_size,
115 snapshot_id=data_utils.rand_uuid())
zhangyanzib866f052013-10-12 11:41:32 +0800116
Jordan Pittier3b46d272017-04-12 16:17:28 +0200117 @decorators.attr(type=['negative'])
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -0800118 @decorators.idempotent_id('47c73e08-4be8-45bb-bfdf-0c4e79b88344')
nayna-patel179077c2014-01-15 12:27:16 +0000119 def test_create_volume_with_nonexistent_source_volid(self):
120 # Should not be able to create volume with non-existent source volume
lkuchlanb21fc572016-11-28 12:25:22 +0200121 self.assertRaises(lib_exc.NotFound, self.volumes_client.create_volume,
TommyLikefcda77b2018-01-18 15:25:12 +0800122 size=CONF.volume.volume_size,
123 source_volid=data_utils.rand_uuid())
zhangyanzib866f052013-10-12 11:41:32 +0800124
Jordan Pittier3b46d272017-04-12 16:17:28 +0200125 @decorators.attr(type=['negative'])
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -0800126 @decorators.idempotent_id('0186422c-999a-480e-a026-6a665744c30c')
nayna-patel179077c2014-01-15 12:27:16 +0000127 def test_update_volume_with_nonexistent_volume_id(self):
lkuchlanb21fc572016-11-28 12:25:22 +0200128 self.assertRaises(lib_exc.NotFound, self.volumes_client.update_volume,
zhufl9751b3d2017-03-29 18:01:01 +0800129 volume_id=data_utils.rand_uuid())
wanghaoc2abb6c2013-09-29 19:14:09 +0800130
Jordan Pittier3b46d272017-04-12 16:17:28 +0200131 @decorators.attr(type=['negative'])
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -0800132 @decorators.idempotent_id('e66e40d6-65e6-4e75-bdc7-636792fa152d')
wanghaoc2abb6c2013-09-29 19:14:09 +0800133 def test_update_volume_with_invalid_volume_id(self):
lkuchlanb21fc572016-11-28 12:25:22 +0200134 self.assertRaises(lib_exc.NotFound, self.volumes_client.update_volume,
zhufl9751b3d2017-03-29 18:01:01 +0800135 volume_id=data_utils.rand_name('invalid'))
wanghaoc2abb6c2013-09-29 19:14:09 +0800136
Jordan Pittier3b46d272017-04-12 16:17:28 +0200137 @decorators.attr(type=['negative'])
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -0800138 @decorators.idempotent_id('72aeca85-57a5-4c1f-9057-f320f9ea575b')
wanghaoc2abb6c2013-09-29 19:14:09 +0800139 def test_update_volume_with_empty_volume_id(self):
lkuchlanb21fc572016-11-28 12:25:22 +0200140 self.assertRaises(lib_exc.NotFound, self.volumes_client.update_volume,
zhufl9751b3d2017-03-29 18:01:01 +0800141 volume_id='')
wanghaoc2abb6c2013-09-29 19:14:09 +0800142
Jordan Pittier3b46d272017-04-12 16:17:28 +0200143 @decorators.attr(type=['negative'])
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -0800144 @decorators.idempotent_id('30799cfd-7ee4-446c-b66c-45b383ed211b')
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700145 def test_get_invalid_volume_id(self):
Sean Dague72a00382013-01-03 17:53:38 -0500146 # Should not be able to get volume with invalid id
lkuchlanb21fc572016-11-28 12:25:22 +0200147 self.assertRaises(lib_exc.NotFound, self.volumes_client.show_volume,
ghanshyam9e294c42017-01-12 06:52:41 +0000148 data_utils.rand_name('invalid'))
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700149
Jordan Pittier3b46d272017-04-12 16:17:28 +0200150 @decorators.attr(type=['negative'])
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -0800151 @decorators.idempotent_id('c6c3db06-29ad-4e91-beb0-2ab195fe49e3')
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700152 def test_get_volume_without_passing_volume_id(self):
Sean Dague72a00382013-01-03 17:53:38 -0500153 # Should not be able to get volume when empty ID is passed
lkuchlanb21fc572016-11-28 12:25:22 +0200154 self.assertRaises(lib_exc.NotFound,
155 self.volumes_client.show_volume, '')
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700156
Jordan Pittier3b46d272017-04-12 16:17:28 +0200157 @decorators.attr(type=['negative'])
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -0800158 @decorators.idempotent_id('1f035827-7c32-4019-9240-b4ec2dbd9dfd')
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700159 def test_delete_invalid_volume_id(self):
Sean Dague72a00382013-01-03 17:53:38 -0500160 # Should not be able to delete volume when invalid ID is passed
lkuchlanb21fc572016-11-28 12:25:22 +0200161 self.assertRaises(lib_exc.NotFound, self.volumes_client.delete_volume,
ghanshyam9e294c42017-01-12 06:52:41 +0000162 data_utils.rand_name('invalid'))
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700163
Jordan Pittier3b46d272017-04-12 16:17:28 +0200164 @decorators.attr(type=['negative'])
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -0800165 @decorators.idempotent_id('441a1550-5d44-4b30-af0f-a6d402f52026')
Rohit Karajgidd47d7e2012-07-31 04:11:01 -0700166 def test_delete_volume_without_passing_volume_id(self):
Sean Dague72a00382013-01-03 17:53:38 -0500167 # Should not be able to delete volume when empty ID is passed
lkuchlanb21fc572016-11-28 12:25:22 +0200168 self.assertRaises(lib_exc.NotFound,
169 self.volumes_client.delete_volume, '')
Matthew Treinish9854d5b2012-09-20 10:22:13 -0400170
Jordan Pittier3b46d272017-04-12 16:17:28 +0200171 @decorators.attr(type=['negative'])
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -0800172 @decorators.idempotent_id('f5e56b0a-5d02-43c1-a2a7-c9b792c2e3f6')
Andrea Frittolicd368412017-08-14 21:37:56 +0100173 @utils.services('compute')
Zhi Kun Liu3bdfe092013-09-02 01:31:58 +0800174 def test_attach_volumes_with_nonexistent_volume_id(self):
lkuchland4ecd0e2017-06-11 12:01:27 +0300175 server = self.create_server()
Joseph Lanouxa074c012015-08-04 15:44:07 +0000176
Masayuki Igawabfa07602015-01-20 18:47:17 +0900177 self.assertRaises(lib_exc.NotFound,
lkuchlanb21fc572016-11-28 12:25:22 +0200178 self.volumes_client.attach_volume,
Ken'ichi Ohmichid079c892016-04-19 11:23:36 -0700179 data_utils.rand_uuid(),
Ghanshyam8fc0ed22015-12-18 10:25:14 +0900180 instance_uuid=server['id'],
lkuchlana54f1702017-09-11 11:06:55 +0300181 mountpoint="/dev/vdc")
Zhi Kun Liu3bdfe092013-09-02 01:31:58 +0800182
Jordan Pittier3b46d272017-04-12 16:17:28 +0200183 @decorators.attr(type=['negative'])
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -0800184 @decorators.idempotent_id('9f9c24e4-011d-46b5-b992-952140ce237a')
Zhi Kun Liu3bdfe092013-09-02 01:31:58 +0800185 def test_detach_volumes_with_invalid_volume_id(self):
Masayuki Igawabfa07602015-01-20 18:47:17 +0900186 self.assertRaises(lib_exc.NotFound,
lkuchlanb21fc572016-11-28 12:25:22 +0200187 self.volumes_client.detach_volume,
Zhi Kun Liu3bdfe092013-09-02 01:31:58 +0800188 'xxx')
189
Jordan Pittier3b46d272017-04-12 16:17:28 +0200190 @decorators.attr(type=['negative'])
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -0800191 @decorators.idempotent_id('e0c75c74-ee34-41a9-9288-2a2051452854')
wanghao5b981752013-10-22 11:41:41 +0800192 def test_volume_extend_with_size_smaller_than_original_size(self):
193 # Extend volume with smaller size than original size.
194 extend_size = 0
lkuchlanb21fc572016-11-28 12:25:22 +0200195 self.assertRaises(lib_exc.BadRequest,
196 self.volumes_client.extend_volume,
Ghanshyam58a9e872015-12-18 10:46:07 +0900197 self.volume['id'], new_size=extend_size)
wanghao5b981752013-10-22 11:41:41 +0800198
Jordan Pittier3b46d272017-04-12 16:17:28 +0200199 @decorators.attr(type=['negative'])
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -0800200 @decorators.idempotent_id('5d0b480d-e833-439f-8a5a-96ad2ed6f22f')
wanghao5b981752013-10-22 11:41:41 +0800201 def test_volume_extend_with_non_number_size(self):
202 # Extend volume when size is non number.
203 extend_size = 'abc'
lkuchlanb21fc572016-11-28 12:25:22 +0200204 self.assertRaises(lib_exc.BadRequest,
205 self.volumes_client.extend_volume,
Ghanshyam58a9e872015-12-18 10:46:07 +0900206 self.volume['id'], new_size=extend_size)
wanghao5b981752013-10-22 11:41:41 +0800207
Jordan Pittier3b46d272017-04-12 16:17:28 +0200208 @decorators.attr(type=['negative'])
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -0800209 @decorators.idempotent_id('355218f1-8991-400a-a6bb-971239287d92')
wanghao5b981752013-10-22 11:41:41 +0800210 def test_volume_extend_with_None_size(self):
211 # Extend volume with None size.
212 extend_size = None
lkuchlanb21fc572016-11-28 12:25:22 +0200213 self.assertRaises(lib_exc.BadRequest,
214 self.volumes_client.extend_volume,
Ghanshyam58a9e872015-12-18 10:46:07 +0900215 self.volume['id'], new_size=extend_size)
wanghao5b981752013-10-22 11:41:41 +0800216
Jordan Pittier3b46d272017-04-12 16:17:28 +0200217 @decorators.attr(type=['negative'])
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -0800218 @decorators.idempotent_id('8f05a943-013c-4063-ac71-7baf561e82eb')
wanghao5b981752013-10-22 11:41:41 +0800219 def test_volume_extend_with_nonexistent_volume_id(self):
220 # Extend volume size when volume is nonexistent.
Avi Avrahamd77d3d12017-02-15 16:45:25 +0200221 extend_size = self.volume['size'] + 1
lkuchlanb21fc572016-11-28 12:25:22 +0200222 self.assertRaises(lib_exc.NotFound, self.volumes_client.extend_volume,
Ken'ichi Ohmichid079c892016-04-19 11:23:36 -0700223 data_utils.rand_uuid(), new_size=extend_size)
wanghao5b981752013-10-22 11:41:41 +0800224
Jordan Pittier3b46d272017-04-12 16:17:28 +0200225 @decorators.attr(type=['negative'])
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -0800226 @decorators.idempotent_id('aff8ba64-6d6f-4f2e-bc33-41a08ee9f115')
wanghao5b981752013-10-22 11:41:41 +0800227 def test_volume_extend_without_passing_volume_id(self):
228 # Extend volume size when passing volume id is None.
Avi Avrahamd77d3d12017-02-15 16:45:25 +0200229 extend_size = self.volume['size'] + 1
lkuchlanb21fc572016-11-28 12:25:22 +0200230 self.assertRaises(lib_exc.NotFound, self.volumes_client.extend_volume,
Ghanshyam58a9e872015-12-18 10:46:07 +0900231 None, new_size=extend_size)
wanghao5b981752013-10-22 11:41:41 +0800232
Jordan Pittier3b46d272017-04-12 16:17:28 +0200233 @decorators.attr(type=['negative'])
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -0800234 @decorators.idempotent_id('ac6084c0-0546-45f9-b284-38a367e0e0e2')
zhangyanzi6b632432013-10-24 19:08:50 +0800235 def test_reserve_volume_with_nonexistent_volume_id(self):
Masayuki Igawabfa07602015-01-20 18:47:17 +0900236 self.assertRaises(lib_exc.NotFound,
lkuchlanb21fc572016-11-28 12:25:22 +0200237 self.volumes_client.reserve_volume,
Ken'ichi Ohmichid079c892016-04-19 11:23:36 -0700238 data_utils.rand_uuid())
zhangyanzi6b632432013-10-24 19:08:50 +0800239
Jordan Pittier3b46d272017-04-12 16:17:28 +0200240 @decorators.attr(type=['negative'])
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -0800241 @decorators.idempotent_id('eb467654-3dc1-4a72-9b46-47c29d22654c')
zhangyanzi6b632432013-10-24 19:08:50 +0800242 def test_unreserve_volume_with_nonexistent_volume_id(self):
Masayuki Igawabfa07602015-01-20 18:47:17 +0900243 self.assertRaises(lib_exc.NotFound,
lkuchlanb21fc572016-11-28 12:25:22 +0200244 self.volumes_client.unreserve_volume,
Ken'ichi Ohmichid079c892016-04-19 11:23:36 -0700245 data_utils.rand_uuid())
zhangyanzi6b632432013-10-24 19:08:50 +0800246
Jordan Pittier3b46d272017-04-12 16:17:28 +0200247 @decorators.attr(type=['negative'])
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -0800248 @decorators.idempotent_id('449c4ed2-ecdd-47bb-98dc-072aeccf158c')
zhangyanzi6b632432013-10-24 19:08:50 +0800249 def test_reserve_volume_with_negative_volume_status(self):
250 # Mark volume as reserved.
lkuchlanb21fc572016-11-28 12:25:22 +0200251 self.volumes_client.reserve_volume(self.volume['id'])
zhangyanzi6b632432013-10-24 19:08:50 +0800252 # Mark volume which is marked as reserved before
Masayuki Igawa4b29e472015-02-16 10:41:54 +0900253 self.assertRaises(lib_exc.BadRequest,
lkuchlanb21fc572016-11-28 12:25:22 +0200254 self.volumes_client.reserve_volume,
zhangyanzi6b632432013-10-24 19:08:50 +0800255 self.volume['id'])
256 # Unmark volume as reserved.
lkuchlanb21fc572016-11-28 12:25:22 +0200257 self.volumes_client.unreserve_volume(self.volume['id'])
zhangyanzi6b632432013-10-24 19:08:50 +0800258
Jordan Pittier3b46d272017-04-12 16:17:28 +0200259 @decorators.attr(type=['negative'])
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -0800260 @decorators.idempotent_id('0f4aa809-8c7b-418f-8fb3-84c7a5dfc52f')
Zhi Kun Liu42403182013-10-11 18:05:08 +0800261 def test_list_volumes_with_nonexistent_name(self):
zhuflc6ce5392016-08-17 14:34:37 +0800262 v_name = data_utils.rand_name(self.__class__.__name__ + '-Volume')
zhufla57530c2017-03-23 11:38:12 +0800263 params = {'name': v_name}
lkuchlanb21fc572016-11-28 12:25:22 +0200264 fetched_volume = self.volumes_client.list_volumes(
265 params=params)['volumes']
Masayuki Igawaf9009b42017-04-10 14:49:29 +0900266 self.assertEmpty(fetched_volume)
Zhi Kun Liu42403182013-10-11 18:05:08 +0800267
Jordan Pittier3b46d272017-04-12 16:17:28 +0200268 @decorators.attr(type=['negative'])
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -0800269 @decorators.idempotent_id('9ca17820-a0e7-4cbd-a7fa-f4468735e359')
Zhi Kun Liu42403182013-10-11 18:05:08 +0800270 def test_list_volumes_detail_with_nonexistent_name(self):
zhuflc6ce5392016-08-17 14:34:37 +0800271 v_name = data_utils.rand_name(self.__class__.__name__ + '-Volume')
zhufla57530c2017-03-23 11:38:12 +0800272 params = {'name': v_name}
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000273 fetched_volume = \
lkuchlanb21fc572016-11-28 12:25:22 +0200274 self.volumes_client.list_volumes(
275 detail=True, params=params)['volumes']
Masayuki Igawaf9009b42017-04-10 14:49:29 +0900276 self.assertEmpty(fetched_volume)
Zhi Kun Liu42403182013-10-11 18:05:08 +0800277
Jordan Pittier3b46d272017-04-12 16:17:28 +0200278 @decorators.attr(type=['negative'])
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -0800279 @decorators.idempotent_id('143b279b-7522-466b-81be-34a87d564a7c')
Zhi Kun Liu42403182013-10-11 18:05:08 +0800280 def test_list_volumes_with_invalid_status(self):
281 params = {'status': 'null'}
lkuchlanb21fc572016-11-28 12:25:22 +0200282 fetched_volume = self.volumes_client.list_volumes(
283 params=params)['volumes']
Masayuki Igawaf9009b42017-04-10 14:49:29 +0900284 self.assertEmpty(fetched_volume)
Zhi Kun Liu42403182013-10-11 18:05:08 +0800285
Jordan Pittier3b46d272017-04-12 16:17:28 +0200286 @decorators.attr(type=['negative'])
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -0800287 @decorators.idempotent_id('ba94b27b-be3f-496c-a00e-0283b373fa75')
Zhi Kun Liu42403182013-10-11 18:05:08 +0800288 def test_list_volumes_detail_with_invalid_status(self):
289 params = {'status': 'null'}
Joseph Lanoux6809bab2014-12-18 14:57:18 +0000290 fetched_volume = \
lkuchlanb21fc572016-11-28 12:25:22 +0200291 self.volumes_client.list_volumes(detail=True,
292 params=params)['volumes']
Masayuki Igawaf9009b42017-04-10 14:49:29 +0900293 self.assertEmpty(fetched_volume)
jeremy.zhang0a427162017-04-21 12:47:56 +0800294
295 @decorators.attr(type=['negative'])
296 @decorators.idempotent_id('5b810c91-0ad1-47ce-aee8-615f789be78f')
Andrea Frittolicd368412017-08-14 21:37:56 +0100297 @utils.services('image')
jeremy.zhang0a427162017-04-21 12:47:56 +0800298 def test_create_volume_from_image_with_decreasing_size(self):
299 # Create image
lkuchlan13736ae2017-04-24 14:49:45 +0300300 image = self.create_image()
jeremy.zhang0a427162017-04-21 12:47:56 +0800301
302 # Note(jeremyZ): To shorten the test time (uploading a big size image
303 # is time-consuming), here just consider the scenario that volume size
304 # is smaller than the min_disk of image.
305 self.assertRaises(lib_exc.BadRequest,
306 self.volumes_client.create_volume,
307 size=CONF.volume.volume_size,
308 imageRef=image['id'])
lkuchlan13736ae2017-04-24 14:49:45 +0300309
310 @decorators.attr(type=['negative'])
311 @decorators.idempotent_id('d15e7f35-2cfc-48c8-9418-c8223a89bcbb')
Andrea Frittolicd368412017-08-14 21:37:56 +0100312 @utils.services('image')
lkuchlan13736ae2017-04-24 14:49:45 +0300313 def test_create_volume_from_deactivated_image(self):
314 # Create image
315 image = self.create_image()
316
317 # Deactivate the image
318 self.images_client.deactivate_image(image['id'])
319 body = self.images_client.show_image(image['id'])
320 self.assertEqual("deactivated", body['status'])
321 # Try creating a volume from deactivated image
322 self.assertRaises(lib_exc.BadRequest,
323 self.create_volume,
324 imageRef=image['id'])