Roman Prykhodchenko | 62b1ed1 | 2013-10-16 21:51:47 +0300 | [diff] [blame] | 1 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 2 | # not use this file except in compliance with the License. You may obtain |
| 3 | # a copy of the License at |
| 4 | # |
| 5 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | # |
| 7 | # Unless required by applicable law or agreed to in writing, software |
| 8 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 9 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 10 | # License for the specific language governing permissions and limitations |
| 11 | # under the License. |
| 12 | |
| 13 | from tempest.api.baremetal import base |
| 14 | from tempest.common.utils import data_utils |
| 15 | from tempest import exceptions as exc |
| 16 | from tempest import test |
| 17 | |
| 18 | |
| 19 | class TestPortsNegative(base.BaseBaremetalTest): |
| 20 | """Negative tests for ports.""" |
| 21 | |
| 22 | def setUp(self): |
| 23 | super(TestPortsNegative, self).setUp() |
| 24 | |
Adam Gandelman | b3348f7 | 2014-06-17 00:16:54 -0700 | [diff] [blame] | 25 | resp, self.chassis = self.create_chassis() |
| 26 | self.assertEqual('201', resp['status']) |
| 27 | |
| 28 | resp, self.node = self.create_node(self.chassis['uuid']) |
| 29 | self.assertEqual('201', resp['status']) |
Roman Prykhodchenko | 62b1ed1 | 2013-10-16 21:51:47 +0300 | [diff] [blame] | 30 | |
Sergey Nikitin | 0d43eb5 | 2014-02-03 14:50:02 +0400 | [diff] [blame] | 31 | @test.attr(type=['negative', 'smoke']) |
| 32 | def test_create_port_malformed_mac(self): |
Roman Prykhodchenko | 62b1ed1 | 2013-10-16 21:51:47 +0300 | [diff] [blame] | 33 | node_id = self.node['uuid'] |
Sergey Nikitin | 0d43eb5 | 2014-02-03 14:50:02 +0400 | [diff] [blame] | 34 | address = 'malformed:mac' |
Roman Prykhodchenko | 62b1ed1 | 2013-10-16 21:51:47 +0300 | [diff] [blame] | 35 | |
| 36 | self.assertRaises(exc.BadRequest, |
| 37 | self.create_port, node_id=node_id, address=address) |
| 38 | |
Sergey Nikitin | 0d43eb5 | 2014-02-03 14:50:02 +0400 | [diff] [blame] | 39 | @test.attr(type=['negative', 'smoke']) |
| 40 | def test_create_port_malformed_extra(self): |
| 41 | node_id = self.node['uuid'] |
| 42 | address = data_utils.rand_mac_address() |
| 43 | extra = {'key': 0.123} |
| 44 | self.assertRaises(exc.BadRequest, |
| 45 | self.create_port, node_id=node_id, |
| 46 | address=address, extra=extra) |
Roman Prykhodchenko | 62b1ed1 | 2013-10-16 21:51:47 +0300 | [diff] [blame] | 47 | |
Sergey Nikitin | 0d43eb5 | 2014-02-03 14:50:02 +0400 | [diff] [blame] | 48 | @test.attr(type=['negative', 'smoke']) |
| 49 | def test_create_port_nonexsistent_node_id(self): |
| 50 | node_id = str(data_utils.rand_uuid()) |
| 51 | address = data_utils.rand_mac_address() |
| 52 | self.assertRaises(exc.BadRequest, self.create_port, node_id=node_id, |
| 53 | address=address) |
| 54 | |
| 55 | @test.attr(type=['negative', 'smoke']) |
| 56 | def test_show_port_malformed_uuid(self): |
| 57 | self.assertRaises(exc.BadRequest, self.client.show_port, |
| 58 | 'malformed:uuid') |
| 59 | |
| 60 | @test.attr(type=['negative', 'smoke']) |
| 61 | def test_show_port_nonexistent_uuid(self): |
| 62 | self.assertRaises(exc.NotFound, self.client.show_port, |
| 63 | data_utils.rand_uuid()) |
| 64 | |
| 65 | @test.attr(type=['negative', 'smoke']) |
| 66 | def test_show_port_by_mac_not_allowed(self): |
| 67 | self.assertRaises(exc.BadRequest, self.client.show_port, |
| 68 | data_utils.rand_mac_address()) |
| 69 | |
| 70 | @test.attr(type=['negative', 'smoke']) |
| 71 | def test_create_port_duplicated_port_uuid(self): |
| 72 | node_id = self.node['uuid'] |
| 73 | address = data_utils.rand_mac_address() |
| 74 | uuid = data_utils.rand_uuid() |
| 75 | |
| 76 | self.create_port(node_id=node_id, address=address, uuid=uuid) |
| 77 | self.assertRaises(exc.Conflict, self.create_port, node_id=node_id, |
| 78 | address=address, uuid=uuid) |
| 79 | |
| 80 | @test.attr(type=['negative', 'smoke']) |
| 81 | def test_create_port_no_mandatory_field_node_id(self): |
| 82 | address = data_utils.rand_mac_address() |
| 83 | |
| 84 | self.assertRaises(exc.BadRequest, self.create_port, node_id=None, |
| 85 | address=address) |
| 86 | |
| 87 | @test.attr(type=['negative', 'smoke']) |
| 88 | def test_create_port_no_mandatory_field_mac(self): |
| 89 | node_id = self.node['uuid'] |
| 90 | |
| 91 | self.assertRaises(exc.BadRequest, self.create_port, node_id=node_id, |
| 92 | address=None) |
| 93 | |
| 94 | @test.attr(type=['negative', 'smoke']) |
| 95 | def test_create_port_malformed_port_uuid(self): |
| 96 | node_id = self.node['uuid'] |
| 97 | address = data_utils.rand_mac_address() |
| 98 | uuid = 'malformed:uuid' |
| 99 | |
| 100 | self.assertRaises(exc.BadRequest, self.create_port, node_id=node_id, |
| 101 | address=address, uuid=uuid) |
| 102 | |
| 103 | @test.attr(type=['negative', 'smoke']) |
| 104 | def test_create_port_malformed_node_id(self): |
| 105 | address = data_utils.rand_mac_address() |
| 106 | self.assertRaises(exc.BadRequest, self.create_port, |
| 107 | node_id='malformed:nodeid', address=address) |
| 108 | |
| 109 | @test.attr(type=['negative', 'smoke']) |
| 110 | def test_create_port_duplicated_mac(self): |
| 111 | node_id = self.node['uuid'] |
| 112 | address = data_utils.rand_mac_address() |
| 113 | self.create_port(node_id=node_id, address=address) |
| 114 | self.assertRaises(exc.Conflict, |
| 115 | self.create_port, node_id=node_id, |
| 116 | address=address) |
| 117 | |
| 118 | @test.attr(type=['negative', 'smoke']) |
| 119 | def test_update_port_by_mac_not_allowed(self): |
| 120 | node_id = self.node['uuid'] |
| 121 | address = data_utils.rand_mac_address() |
| 122 | extra = {'key': 'value'} |
| 123 | |
| 124 | self.create_port(node_id=node_id, address=address, extra=extra) |
| 125 | |
| 126 | patch = [{'path': '/extra/key', |
| 127 | 'op': 'replace', |
| 128 | 'value': 'new-value'}] |
| 129 | |
| 130 | self.assertRaises(exc.BadRequest, |
| 131 | self.client.update_port, address, |
| 132 | patch) |
| 133 | |
| 134 | @test.attr(type=['negative', 'smoke']) |
| 135 | def test_update_port_nonexistent(self): |
| 136 | node_id = self.node['uuid'] |
| 137 | address = data_utils.rand_mac_address() |
| 138 | extra = {'key': 'value'} |
| 139 | |
Adam Gandelman | b3348f7 | 2014-06-17 00:16:54 -0700 | [diff] [blame] | 140 | resp, port = self.create_port(node_id=node_id, address=address, |
| 141 | extra=extra) |
| 142 | self.assertEqual('201', resp['status']) |
| 143 | port_id = port['uuid'] |
| 144 | |
| 145 | resp, body = self.client.delete_port(port_id) |
| 146 | self.assertEqual('204', resp['status']) |
Sergey Nikitin | 0d43eb5 | 2014-02-03 14:50:02 +0400 | [diff] [blame] | 147 | |
| 148 | patch = [{'path': '/extra/key', |
| 149 | 'op': 'replace', |
| 150 | 'value': 'new-value'}] |
| 151 | self.assertRaises(exc.NotFound, |
| 152 | self.client.update_port, port_id, patch) |
| 153 | |
| 154 | @test.attr(type=['negative', 'smoke']) |
| 155 | def test_update_port_malformed_port_uuid(self): |
| 156 | node_id = self.node['uuid'] |
| 157 | address = data_utils.rand_mac_address() |
| 158 | |
| 159 | self.create_port(node_id=node_id, address=address) |
| 160 | |
| 161 | new_address = data_utils.rand_mac_address() |
| 162 | self.assertRaises(exc.BadRequest, self.client.update_port, |
| 163 | uuid='malformed:uuid', |
| 164 | patch=[{'path': '/address', 'op': 'replace', |
| 165 | 'value': new_address}]) |
| 166 | |
| 167 | @test.attr(type=['negative', 'smoke']) |
| 168 | def test_update_port_add_malformed_extra(self): |
| 169 | node_id = self.node['uuid'] |
| 170 | address = data_utils.rand_mac_address() |
| 171 | |
Adam Gandelman | b3348f7 | 2014-06-17 00:16:54 -0700 | [diff] [blame] | 172 | resp, port = self.create_port(node_id=node_id, address=address) |
| 173 | self.assertEqual('201', resp['status']) |
| 174 | port_id = port['uuid'] |
Sergey Nikitin | 0d43eb5 | 2014-02-03 14:50:02 +0400 | [diff] [blame] | 175 | |
| 176 | self.assertRaises(exc.BadRequest, self.client.update_port, port_id, |
| 177 | [{'path': '/extra/key', ' op': 'add', |
| 178 | 'value': 0.123}]) |
| 179 | |
| 180 | @test.attr(type=['negative', 'smoke']) |
| 181 | def test_update_port_add_whole_malformed_extra(self): |
| 182 | node_id = self.node['uuid'] |
| 183 | address = data_utils.rand_mac_address() |
| 184 | |
Adam Gandelman | b3348f7 | 2014-06-17 00:16:54 -0700 | [diff] [blame] | 185 | resp, port = self.create_port(node_id=node_id, address=address) |
| 186 | self.assertEqual('201', resp['status']) |
| 187 | port_id = port['uuid'] |
Sergey Nikitin | 0d43eb5 | 2014-02-03 14:50:02 +0400 | [diff] [blame] | 188 | |
| 189 | self.assertRaises(exc.BadRequest, self.client.update_port, port_id, |
| 190 | [{'path': '/extra', |
| 191 | 'op': 'add', |
| 192 | 'value': [1, 2, 3, 4, 'a']}]) |
| 193 | |
| 194 | @test.attr(type=['negative', 'smoke']) |
| 195 | def test_update_port_add_nonexistent_property(self): |
| 196 | node_id = self.node['uuid'] |
| 197 | address = data_utils.rand_mac_address() |
| 198 | |
Adam Gandelman | b3348f7 | 2014-06-17 00:16:54 -0700 | [diff] [blame] | 199 | resp, port = self.create_port(node_id=node_id, address=address) |
| 200 | self.assertEqual('201', resp['status']) |
| 201 | port_id = port['uuid'] |
| 202 | |
Sergey Nikitin | 0d43eb5 | 2014-02-03 14:50:02 +0400 | [diff] [blame] | 203 | self.assertRaises(exc.BadRequest, self.client.update_port, port_id, |
| 204 | [{'path': '/nonexistent', ' op': 'add', |
| 205 | 'value': 'value'}]) |
| 206 | |
| 207 | @test.attr(type=['negative', 'smoke']) |
| 208 | def test_update_port_replace_node_id_with_malformed(self): |
| 209 | node_id = self.node['uuid'] |
| 210 | address = data_utils.rand_mac_address() |
| 211 | |
Adam Gandelman | b3348f7 | 2014-06-17 00:16:54 -0700 | [diff] [blame] | 212 | resp, port = self.create_port(node_id=node_id, address=address) |
| 213 | self.assertEqual('201', resp['status']) |
| 214 | port_id = port['uuid'] |
Sergey Nikitin | 0d43eb5 | 2014-02-03 14:50:02 +0400 | [diff] [blame] | 215 | |
| 216 | patch = [{'path': '/node_uuid', |
| 217 | 'op': 'replace', |
| 218 | 'value': 'malformed:node_uuid'}] |
| 219 | self.assertRaises(exc.BadRequest, |
| 220 | self.client.update_port, port_id, patch) |
| 221 | |
| 222 | @test.attr(type=['negative', 'smoke']) |
| 223 | def test_update_port_replace_mac_with_duplicated(self): |
| 224 | node_id = self.node['uuid'] |
| 225 | address1 = data_utils.rand_mac_address() |
| 226 | address2 = data_utils.rand_mac_address() |
| 227 | |
Adam Gandelman | b3348f7 | 2014-06-17 00:16:54 -0700 | [diff] [blame] | 228 | resp, port1 = self.create_port(node_id=node_id, address=address1) |
| 229 | self.assertEqual('201', resp['status']) |
| 230 | |
| 231 | resp, port2 = self.create_port(node_id=node_id, address=address2) |
| 232 | self.assertEqual('201', resp['status']) |
| 233 | port_id = port2['uuid'] |
| 234 | |
Sergey Nikitin | 0d43eb5 | 2014-02-03 14:50:02 +0400 | [diff] [blame] | 235 | patch = [{'path': '/address', |
| 236 | 'op': 'replace', |
| 237 | 'value': address1}] |
| 238 | self.assertRaises(exc.Conflict, |
| 239 | self.client.update_port, port_id, patch) |
| 240 | |
| 241 | @test.attr(type=['negative', 'smoke']) |
| 242 | def test_update_port_replace_node_id_with_nonexistent(self): |
| 243 | node_id = self.node['uuid'] |
| 244 | address = data_utils.rand_mac_address() |
| 245 | |
Adam Gandelman | b3348f7 | 2014-06-17 00:16:54 -0700 | [diff] [blame] | 246 | resp, port = self.create_port(node_id=node_id, address=address) |
| 247 | self.assertEqual('201', resp['status']) |
| 248 | port_id = port['uuid'] |
Sergey Nikitin | 0d43eb5 | 2014-02-03 14:50:02 +0400 | [diff] [blame] | 249 | |
| 250 | patch = [{'path': '/node_uuid', |
| 251 | 'op': 'replace', |
| 252 | 'value': data_utils.rand_uuid()}] |
| 253 | self.assertRaises(exc.BadRequest, |
| 254 | self.client.update_port, port_id, patch) |
| 255 | |
| 256 | @test.attr(type=['negative', 'smoke']) |
| 257 | def test_update_port_replace_mac_with_malformed(self): |
| 258 | node_id = self.node['uuid'] |
| 259 | address = data_utils.rand_mac_address() |
| 260 | |
Adam Gandelman | b3348f7 | 2014-06-17 00:16:54 -0700 | [diff] [blame] | 261 | resp, port = self.create_port(node_id=node_id, address=address) |
| 262 | self.assertEqual('201', resp['status']) |
| 263 | port_id = port['uuid'] |
| 264 | |
Sergey Nikitin | 0d43eb5 | 2014-02-03 14:50:02 +0400 | [diff] [blame] | 265 | patch = [{'path': '/address', |
| 266 | 'op': 'replace', |
| 267 | 'value': 'malformed:mac'}] |
| 268 | |
| 269 | self.assertRaises(exc.BadRequest, |
| 270 | self.client.update_port, port_id, patch) |
| 271 | |
| 272 | @test.attr(type=['negative', 'smoke']) |
| 273 | def test_update_port_replace_extra_item_with_malformed(self): |
| 274 | node_id = self.node['uuid'] |
| 275 | address = data_utils.rand_mac_address() |
| 276 | extra = {'key': 'value'} |
| 277 | |
Adam Gandelman | b3348f7 | 2014-06-17 00:16:54 -0700 | [diff] [blame] | 278 | resp, port = self.create_port(node_id=node_id, address=address, |
| 279 | extra=extra) |
| 280 | self.assertEqual('201', resp['status']) |
| 281 | port_id = port['uuid'] |
| 282 | |
Sergey Nikitin | 0d43eb5 | 2014-02-03 14:50:02 +0400 | [diff] [blame] | 283 | patch = [{'path': '/extra/key', |
| 284 | 'op': 'replace', |
| 285 | 'value': 0.123}] |
Sergey Nikitin | 0d43eb5 | 2014-02-03 14:50:02 +0400 | [diff] [blame] | 286 | self.assertRaises(exc.BadRequest, |
| 287 | self.client.update_port, port_id, patch) |
| 288 | |
| 289 | @test.attr(type=['negative', 'smoke']) |
| 290 | def test_update_port_replace_whole_extra_with_malformed(self): |
| 291 | node_id = self.node['uuid'] |
| 292 | address = data_utils.rand_mac_address() |
Sergey Nikitin | 0d43eb5 | 2014-02-03 14:50:02 +0400 | [diff] [blame] | 293 | |
Adam Gandelman | b3348f7 | 2014-06-17 00:16:54 -0700 | [diff] [blame] | 294 | resp, port = self.create_port(node_id=node_id, address=address) |
| 295 | self.assertEqual('201', resp['status']) |
| 296 | port_id = port['uuid'] |
| 297 | |
Sergey Nikitin | 0d43eb5 | 2014-02-03 14:50:02 +0400 | [diff] [blame] | 298 | patch = [{'path': '/extra', |
| 299 | 'op': 'replace', |
| 300 | 'value': [1, 2, 3, 4, 'a']}] |
| 301 | |
| 302 | self.assertRaises(exc.BadRequest, |
| 303 | self.client.update_port, port_id, patch) |
| 304 | |
| 305 | @test.attr(type=['negative', 'smoke']) |
| 306 | def test_update_port_replace_nonexistent_property(self): |
| 307 | node_id = self.node['uuid'] |
| 308 | address = data_utils.rand_mac_address() |
| 309 | |
Adam Gandelman | b3348f7 | 2014-06-17 00:16:54 -0700 | [diff] [blame] | 310 | resp, port = self.create_port(node_id=node_id, address=address) |
| 311 | self.assertEqual('201', resp['status']) |
| 312 | port_id = port['uuid'] |
Sergey Nikitin | 0d43eb5 | 2014-02-03 14:50:02 +0400 | [diff] [blame] | 313 | |
| 314 | patch = [{'path': '/nonexistent', ' op': 'replace', 'value': 'value'}] |
| 315 | |
| 316 | self.assertRaises(exc.BadRequest, |
| 317 | self.client.update_port, port_id, patch) |
| 318 | |
| 319 | @test.attr(type=['negative', 'smoke']) |
| 320 | def test_update_port_remove_mandatory_field_mac(self): |
| 321 | node_id = self.node['uuid'] |
| 322 | address = data_utils.rand_mac_address() |
| 323 | |
Adam Gandelman | b3348f7 | 2014-06-17 00:16:54 -0700 | [diff] [blame] | 324 | resp, port = self.create_port(node_id=node_id, address=address) |
| 325 | self.assertEqual('201', resp['status']) |
| 326 | port_id = port['uuid'] |
| 327 | |
Sergey Nikitin | 0d43eb5 | 2014-02-03 14:50:02 +0400 | [diff] [blame] | 328 | self.assertRaises(exc.BadRequest, self.client.update_port, port_id, |
| 329 | [{'path': '/address', 'op': 'remove'}]) |
| 330 | |
| 331 | @test.attr(type=['negative', 'smoke']) |
| 332 | def test_update_port_remove_mandatory_field_port_uuid(self): |
| 333 | node_id = self.node['uuid'] |
| 334 | address = data_utils.rand_mac_address() |
| 335 | |
Adam Gandelman | b3348f7 | 2014-06-17 00:16:54 -0700 | [diff] [blame] | 336 | resp, port = self.create_port(node_id=node_id, address=address) |
| 337 | self.assertEqual('201', resp['status']) |
| 338 | port_id = port['uuid'] |
| 339 | |
Sergey Nikitin | 0d43eb5 | 2014-02-03 14:50:02 +0400 | [diff] [blame] | 340 | self.assertRaises(exc.BadRequest, self.client.update_port, port_id, |
| 341 | [{'path': '/uuid', 'op': 'remove'}]) |
| 342 | |
| 343 | @test.attr(type=['negative', 'smoke']) |
| 344 | def test_update_port_remove_nonexistent_property(self): |
| 345 | node_id = self.node['uuid'] |
| 346 | address = data_utils.rand_mac_address() |
| 347 | |
Adam Gandelman | b3348f7 | 2014-06-17 00:16:54 -0700 | [diff] [blame] | 348 | resp, port = self.create_port(node_id=node_id, address=address) |
| 349 | self.assertEqual('201', resp['status']) |
| 350 | port_id = port['uuid'] |
| 351 | |
Sergey Nikitin | 0d43eb5 | 2014-02-03 14:50:02 +0400 | [diff] [blame] | 352 | self.assertRaises(exc.BadRequest, self.client.update_port, port_id, |
| 353 | [{'path': '/nonexistent', 'op': 'remove'}]) |
| 354 | |
| 355 | @test.attr(type=['negative', 'smoke']) |
| 356 | def test_delete_port_by_mac_not_allowed(self): |
| 357 | node_id = self.node['uuid'] |
| 358 | address = data_utils.rand_mac_address() |
| 359 | |
| 360 | self.create_port(node_id=node_id, address=address) |
| 361 | self.assertRaises(exc.BadRequest, self.client.delete_port, address) |
| 362 | |
| 363 | @test.attr(type=['negative', 'smoke']) |
| 364 | def test_update_port_mixed_ops_integrity(self): |
| 365 | node_id = self.node['uuid'] |
| 366 | address = data_utils.rand_mac_address() |
| 367 | extra = {'key1': 'value1', 'key2': 'value2'} |
| 368 | |
Adam Gandelman | b3348f7 | 2014-06-17 00:16:54 -0700 | [diff] [blame] | 369 | resp, port = self.create_port(node_id=node_id, address=address, |
| 370 | extra=extra) |
| 371 | self.assertEqual('201', resp['status']) |
| 372 | port_id = port['uuid'] |
Sergey Nikitin | 0d43eb5 | 2014-02-03 14:50:02 +0400 | [diff] [blame] | 373 | |
| 374 | new_address = data_utils.rand_mac_address() |
| 375 | new_extra = {'key1': 'new-value1', 'key3': 'new-value3'} |
| 376 | |
| 377 | patch = [{'path': '/address', |
| 378 | 'op': 'replace', |
| 379 | 'value': new_address}, |
| 380 | {'path': '/extra/key1', |
| 381 | 'op': 'replace', |
| 382 | 'value': new_extra['key1']}, |
| 383 | {'path': '/extra/key2', |
| 384 | 'op': 'remove'}, |
| 385 | {'path': '/extra/key3', |
| 386 | 'op': 'add', |
| 387 | 'value': new_extra['key3']}, |
| 388 | {'path': '/nonexistent', |
| 389 | 'op': 'replace', |
| 390 | 'value': 'value'}] |
| 391 | |
| 392 | self.assertRaises(exc.BadRequest, self.client.update_port, port_id, |
| 393 | patch) |
| 394 | |
| 395 | # patch should not be applied |
| 396 | resp, body = self.client.show_port(port_id) |
| 397 | self.assertEqual(200, resp.status) |
| 398 | self.assertEqual(address, body['address']) |
| 399 | self.assertEqual(extra, body['extra']) |