Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 1 | # vim: tabstop=4 shiftwidth=4 softtabstop=4 |
| 2 | |
ZhiQiang Fan | 39f9722 | 2013-09-20 04:49:44 +0800 | [diff] [blame] | 3 | # Copyright 2012 OpenStack Foundation |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 4 | # 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 Liu | 3bdfe09 | 2013-09-02 01:31:58 +0800 | [diff] [blame] | 18 | import uuid |
| 19 | |
Sean Dague | 1937d09 | 2013-05-17 16:36:38 -0400 | [diff] [blame] | 20 | from tempest.api.volume import base |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 21 | from tempest.common.utils.data_utils import rand_name |
Matthew Treinish | a83a16e | 2012-12-07 13:44:02 -0500 | [diff] [blame] | 22 | from tempest import exceptions |
Giulio Fidente | 8b31190 | 2013-05-12 15:40:31 +0200 | [diff] [blame] | 23 | from tempest.test import attr |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 24 | |
| 25 | |
Attila Fazekas | 3dcdae1 | 2013-02-14 12:50:04 +0100 | [diff] [blame] | 26 | class 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 Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 33 | |
Zhi Kun Liu | 3bdfe09 | 2013-09-02 01:31:58 +0800 | [diff] [blame] | 34 | # 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 | |
wanghao | c2abb6c | 2013-09-29 19:14:09 +0800 | [diff] [blame] | 41 | @attr(type=['negative', 'gate']) |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 42 | def test_volume_get_nonexistant_volume_id(self): |
Zhi Kun Liu | 3bdfe09 | 2013-09-02 01:31:58 +0800 | [diff] [blame] | 43 | # Should not be able to get a non-existant volume |
Chris Yeoh | 8b4eaa5 | 2013-02-06 18:03:10 +1030 | [diff] [blame] | 44 | self.assertRaises(exceptions.NotFound, self.client.get_volume, |
Zhi Kun Liu | 3bdfe09 | 2013-09-02 01:31:58 +0800 | [diff] [blame] | 45 | str(uuid.uuid4())) |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 46 | |
wanghao | c2abb6c | 2013-09-29 19:14:09 +0800 | [diff] [blame] | 47 | @attr(type=['negative', 'gate']) |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 48 | def test_volume_delete_nonexistant_volume_id(self): |
Zhi Kun Liu | 3bdfe09 | 2013-09-02 01:31:58 +0800 | [diff] [blame] | 49 | # Should not be able to delete a non-existant Volume |
Chris Yeoh | 8b4eaa5 | 2013-02-06 18:03:10 +1030 | [diff] [blame] | 50 | self.assertRaises(exceptions.NotFound, self.client.delete_volume, |
Zhi Kun Liu | 3bdfe09 | 2013-09-02 01:31:58 +0800 | [diff] [blame] | 51 | str(uuid.uuid4())) |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 52 | |
wanghao | c2abb6c | 2013-09-29 19:14:09 +0800 | [diff] [blame] | 53 | @attr(type=['negative', 'gate']) |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 54 | def test_create_volume_with_invalid_size(self): |
Sean Dague | 72a0038 | 2013-01-03 17:53:38 -0500 | [diff] [blame] | 55 | # Should not be able to create volume with invalid size |
| 56 | # in request |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 57 | v_name = rand_name('Volume-') |
| 58 | metadata = {'Type': 'work'} |
Chris Yeoh | 8b4eaa5 | 2013-02-06 18:03:10 +1030 | [diff] [blame] | 59 | self.assertRaises(exceptions.BadRequest, self.client.create_volume, |
| 60 | size='#$%', display_name=v_name, metadata=metadata) |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 61 | |
wanghao | c2abb6c | 2013-09-29 19:14:09 +0800 | [diff] [blame] | 62 | @attr(type=['negative', 'gate']) |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 63 | def test_create_volume_with_out_passing_size(self): |
Sean Dague | 72a0038 | 2013-01-03 17:53:38 -0500 | [diff] [blame] | 64 | # Should not be able to create volume without passing size |
| 65 | # in request |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 66 | v_name = rand_name('Volume-') |
| 67 | metadata = {'Type': 'work'} |
Chris Yeoh | 8b4eaa5 | 2013-02-06 18:03:10 +1030 | [diff] [blame] | 68 | self.assertRaises(exceptions.BadRequest, self.client.create_volume, |
| 69 | size='', display_name=v_name, metadata=metadata) |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 70 | |
wanghao | c2abb6c | 2013-09-29 19:14:09 +0800 | [diff] [blame] | 71 | @attr(type=['negative', 'gate']) |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 72 | def test_create_volume_with_size_zero(self): |
Sean Dague | 72a0038 | 2013-01-03 17:53:38 -0500 | [diff] [blame] | 73 | # Should not be able to create volume with size zero |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 74 | v_name = rand_name('Volume-') |
| 75 | metadata = {'Type': 'work'} |
Chris Yeoh | 8b4eaa5 | 2013-02-06 18:03:10 +1030 | [diff] [blame] | 76 | self.assertRaises(exceptions.BadRequest, self.client.create_volume, |
| 77 | size='0', display_name=v_name, metadata=metadata) |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 78 | |
wanghao | c2abb6c | 2013-09-29 19:14:09 +0800 | [diff] [blame] | 79 | @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']) |
zhangyanzi | b866f05 | 2013-10-12 11:41:32 +0800 | [diff] [blame] | 88 | 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']) |
wanghao | c2abb6c | 2013-09-29 19:14:09 +0800 | [diff] [blame] | 115 | 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 Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 139 | def test_get_invalid_volume_id(self): |
Sean Dague | 72a0038 | 2013-01-03 17:53:38 -0500 | [diff] [blame] | 140 | # Should not be able to get volume with invalid id |
Chris Yeoh | 8b4eaa5 | 2013-02-06 18:03:10 +1030 | [diff] [blame] | 141 | self.assertRaises(exceptions.NotFound, self.client.get_volume, |
| 142 | '#$%%&^&^') |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 143 | |
wanghao | c2abb6c | 2013-09-29 19:14:09 +0800 | [diff] [blame] | 144 | @attr(type=['negative', 'gate']) |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 145 | def test_get_volume_without_passing_volume_id(self): |
Sean Dague | 72a0038 | 2013-01-03 17:53:38 -0500 | [diff] [blame] | 146 | # Should not be able to get volume when empty ID is passed |
Chris Yeoh | 8b4eaa5 | 2013-02-06 18:03:10 +1030 | [diff] [blame] | 147 | self.assertRaises(exceptions.NotFound, self.client.get_volume, '') |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 148 | |
wanghao | c2abb6c | 2013-09-29 19:14:09 +0800 | [diff] [blame] | 149 | @attr(type=['negative', 'gate']) |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 150 | def test_delete_invalid_volume_id(self): |
Sean Dague | 72a0038 | 2013-01-03 17:53:38 -0500 | [diff] [blame] | 151 | # Should not be able to delete volume when invalid ID is passed |
Chris Yeoh | 8b4eaa5 | 2013-02-06 18:03:10 +1030 | [diff] [blame] | 152 | self.assertRaises(exceptions.NotFound, self.client.delete_volume, |
| 153 | '!@#$%^&*()') |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 154 | |
wanghao | c2abb6c | 2013-09-29 19:14:09 +0800 | [diff] [blame] | 155 | @attr(type=['negative', 'gate']) |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 156 | def test_delete_volume_without_passing_volume_id(self): |
Sean Dague | 72a0038 | 2013-01-03 17:53:38 -0500 | [diff] [blame] | 157 | # Should not be able to delete volume when empty ID is passed |
Chris Yeoh | 8b4eaa5 | 2013-02-06 18:03:10 +1030 | [diff] [blame] | 158 | self.assertRaises(exceptions.NotFound, self.client.delete_volume, '') |
Matthew Treinish | 9854d5b | 2012-09-20 10:22:13 -0400 | [diff] [blame] | 159 | |
Zhi Kun Liu | 3bdfe09 | 2013-09-02 01:31:58 +0800 | [diff] [blame] | 160 | @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 | |
wanghao | 5b98175 | 2013-10-22 11:41:41 +0800 | [diff] [blame] | 180 | @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 | |
zhangyanzi | 6b63243 | 2013-10-24 19:08:50 +0800 | [diff] [blame^] | 215 | @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 Treinish | 9854d5b | 2012-09-20 10:22:13 -0400 | [diff] [blame] | 240 | |
Attila Fazekas | 3dcdae1 | 2013-02-14 12:50:04 +0100 | [diff] [blame] | 241 | class VolumesNegativeTestXML(VolumesNegativeTest): |
| 242 | _interface = 'xml' |