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 | |
| 25 | chassis = self.create_chassis()['chassis'] |
| 26 | self.node = self.create_node(chassis['uuid'])['node'] |
| 27 | |
Sergey Nikitin | 0d43eb5 | 2014-02-03 14:50:02 +0400 | [diff] [blame] | 28 | @test.attr(type=['negative', 'smoke']) |
| 29 | def test_create_port_malformed_mac(self): |
Roman Prykhodchenko | 62b1ed1 | 2013-10-16 21:51:47 +0300 | [diff] [blame] | 30 | node_id = self.node['uuid'] |
Sergey Nikitin | 0d43eb5 | 2014-02-03 14:50:02 +0400 | [diff] [blame] | 31 | address = 'malformed:mac' |
Roman Prykhodchenko | 62b1ed1 | 2013-10-16 21:51:47 +0300 | [diff] [blame] | 32 | |
| 33 | self.assertRaises(exc.BadRequest, |
| 34 | self.create_port, node_id=node_id, address=address) |
| 35 | |
Sergey Nikitin | 0d43eb5 | 2014-02-03 14:50:02 +0400 | [diff] [blame] | 36 | @test.attr(type=['negative', 'smoke']) |
| 37 | def test_create_port_malformed_extra(self): |
| 38 | node_id = self.node['uuid'] |
| 39 | address = data_utils.rand_mac_address() |
| 40 | extra = {'key': 0.123} |
| 41 | self.assertRaises(exc.BadRequest, |
| 42 | self.create_port, node_id=node_id, |
| 43 | address=address, extra=extra) |
Roman Prykhodchenko | 62b1ed1 | 2013-10-16 21:51:47 +0300 | [diff] [blame] | 44 | |
Sergey Nikitin | 0d43eb5 | 2014-02-03 14:50:02 +0400 | [diff] [blame] | 45 | @test.attr(type=['negative', 'smoke']) |
| 46 | def test_create_port_nonexsistent_node_id(self): |
| 47 | node_id = str(data_utils.rand_uuid()) |
| 48 | address = data_utils.rand_mac_address() |
| 49 | self.assertRaises(exc.BadRequest, self.create_port, node_id=node_id, |
| 50 | address=address) |
| 51 | |
| 52 | @test.attr(type=['negative', 'smoke']) |
| 53 | def test_show_port_malformed_uuid(self): |
| 54 | self.assertRaises(exc.BadRequest, self.client.show_port, |
| 55 | 'malformed:uuid') |
| 56 | |
| 57 | @test.attr(type=['negative', 'smoke']) |
| 58 | def test_show_port_nonexistent_uuid(self): |
| 59 | self.assertRaises(exc.NotFound, self.client.show_port, |
| 60 | data_utils.rand_uuid()) |
| 61 | |
| 62 | @test.attr(type=['negative', 'smoke']) |
| 63 | def test_show_port_by_mac_not_allowed(self): |
| 64 | self.assertRaises(exc.BadRequest, self.client.show_port, |
| 65 | data_utils.rand_mac_address()) |
| 66 | |
| 67 | @test.attr(type=['negative', 'smoke']) |
| 68 | def test_create_port_duplicated_port_uuid(self): |
| 69 | node_id = self.node['uuid'] |
| 70 | address = data_utils.rand_mac_address() |
| 71 | uuid = data_utils.rand_uuid() |
| 72 | |
| 73 | self.create_port(node_id=node_id, address=address, uuid=uuid) |
| 74 | self.assertRaises(exc.Conflict, self.create_port, node_id=node_id, |
| 75 | address=address, uuid=uuid) |
| 76 | |
| 77 | @test.attr(type=['negative', 'smoke']) |
| 78 | def test_create_port_no_mandatory_field_node_id(self): |
| 79 | address = data_utils.rand_mac_address() |
| 80 | |
| 81 | self.assertRaises(exc.BadRequest, self.create_port, node_id=None, |
| 82 | address=address) |
| 83 | |
| 84 | @test.attr(type=['negative', 'smoke']) |
| 85 | def test_create_port_no_mandatory_field_mac(self): |
| 86 | node_id = self.node['uuid'] |
| 87 | |
| 88 | self.assertRaises(exc.BadRequest, self.create_port, node_id=node_id, |
| 89 | address=None) |
| 90 | |
| 91 | @test.attr(type=['negative', 'smoke']) |
| 92 | def test_create_port_malformed_port_uuid(self): |
| 93 | node_id = self.node['uuid'] |
| 94 | address = data_utils.rand_mac_address() |
| 95 | uuid = 'malformed:uuid' |
| 96 | |
| 97 | self.assertRaises(exc.BadRequest, self.create_port, node_id=node_id, |
| 98 | address=address, uuid=uuid) |
| 99 | |
| 100 | @test.attr(type=['negative', 'smoke']) |
| 101 | def test_create_port_malformed_node_id(self): |
| 102 | address = data_utils.rand_mac_address() |
| 103 | self.assertRaises(exc.BadRequest, self.create_port, |
| 104 | node_id='malformed:nodeid', address=address) |
| 105 | |
| 106 | @test.attr(type=['negative', 'smoke']) |
| 107 | def test_create_port_duplicated_mac(self): |
| 108 | node_id = self.node['uuid'] |
| 109 | address = data_utils.rand_mac_address() |
| 110 | self.create_port(node_id=node_id, address=address) |
| 111 | self.assertRaises(exc.Conflict, |
| 112 | self.create_port, node_id=node_id, |
| 113 | address=address) |
| 114 | |
| 115 | @test.attr(type=['negative', 'smoke']) |
| 116 | def test_update_port_by_mac_not_allowed(self): |
| 117 | node_id = self.node['uuid'] |
| 118 | address = data_utils.rand_mac_address() |
| 119 | extra = {'key': 'value'} |
| 120 | |
| 121 | self.create_port(node_id=node_id, address=address, extra=extra) |
| 122 | |
| 123 | patch = [{'path': '/extra/key', |
| 124 | 'op': 'replace', |
| 125 | 'value': 'new-value'}] |
| 126 | |
| 127 | self.assertRaises(exc.BadRequest, |
| 128 | self.client.update_port, address, |
| 129 | patch) |
| 130 | |
| 131 | @test.attr(type=['negative', 'smoke']) |
| 132 | def test_update_port_nonexistent(self): |
| 133 | node_id = self.node['uuid'] |
| 134 | address = data_utils.rand_mac_address() |
| 135 | extra = {'key': 'value'} |
| 136 | |
| 137 | port_id = self.create_port(node_id=node_id, address=address, |
| 138 | extra=extra)['port']['uuid'] |
| 139 | self.client.delete_port(port_id) |
| 140 | |
| 141 | patch = [{'path': '/extra/key', |
| 142 | 'op': 'replace', |
| 143 | 'value': 'new-value'}] |
| 144 | self.assertRaises(exc.NotFound, |
| 145 | self.client.update_port, port_id, patch) |
| 146 | |
| 147 | @test.attr(type=['negative', 'smoke']) |
| 148 | def test_update_port_malformed_port_uuid(self): |
| 149 | node_id = self.node['uuid'] |
| 150 | address = data_utils.rand_mac_address() |
| 151 | |
| 152 | self.create_port(node_id=node_id, address=address) |
| 153 | |
| 154 | new_address = data_utils.rand_mac_address() |
| 155 | self.assertRaises(exc.BadRequest, self.client.update_port, |
| 156 | uuid='malformed:uuid', |
| 157 | patch=[{'path': '/address', 'op': 'replace', |
| 158 | 'value': new_address}]) |
| 159 | |
| 160 | @test.attr(type=['negative', 'smoke']) |
| 161 | def test_update_port_add_malformed_extra(self): |
| 162 | node_id = self.node['uuid'] |
| 163 | address = data_utils.rand_mac_address() |
| 164 | |
| 165 | port_id = self.create_port(node_id=node_id, address=address)['port'][ |
| 166 | 'uuid'] |
| 167 | |
| 168 | self.assertRaises(exc.BadRequest, self.client.update_port, port_id, |
| 169 | [{'path': '/extra/key', ' op': 'add', |
| 170 | 'value': 0.123}]) |
| 171 | |
| 172 | @test.attr(type=['negative', 'smoke']) |
| 173 | def test_update_port_add_whole_malformed_extra(self): |
| 174 | node_id = self.node['uuid'] |
| 175 | address = data_utils.rand_mac_address() |
| 176 | |
| 177 | port_id = self.create_port(node_id=node_id, address=address)['port'][ |
| 178 | 'uuid'] |
| 179 | |
| 180 | self.assertRaises(exc.BadRequest, self.client.update_port, port_id, |
| 181 | [{'path': '/extra', |
| 182 | 'op': 'add', |
| 183 | 'value': [1, 2, 3, 4, 'a']}]) |
| 184 | |
| 185 | @test.attr(type=['negative', 'smoke']) |
| 186 | def test_update_port_add_nonexistent_property(self): |
| 187 | node_id = self.node['uuid'] |
| 188 | address = data_utils.rand_mac_address() |
| 189 | |
| 190 | port_id = self.create_port(node_id=node_id, address=address)['port'][ |
| 191 | 'uuid'] |
| 192 | self.assertRaises(exc.BadRequest, self.client.update_port, port_id, |
| 193 | [{'path': '/nonexistent', ' op': 'add', |
| 194 | 'value': 'value'}]) |
| 195 | |
| 196 | @test.attr(type=['negative', 'smoke']) |
| 197 | def test_update_port_replace_node_id_with_malformed(self): |
| 198 | node_id = self.node['uuid'] |
| 199 | address = data_utils.rand_mac_address() |
| 200 | |
| 201 | port_id = self.create_port(node_id=node_id, |
| 202 | address=address)['port']['uuid'] |
| 203 | |
| 204 | patch = [{'path': '/node_uuid', |
| 205 | 'op': 'replace', |
| 206 | 'value': 'malformed:node_uuid'}] |
| 207 | self.assertRaises(exc.BadRequest, |
| 208 | self.client.update_port, port_id, patch) |
| 209 | |
| 210 | @test.attr(type=['negative', 'smoke']) |
| 211 | def test_update_port_replace_mac_with_duplicated(self): |
| 212 | node_id = self.node['uuid'] |
| 213 | address1 = data_utils.rand_mac_address() |
| 214 | address2 = data_utils.rand_mac_address() |
| 215 | |
| 216 | self.create_port(node_id=node_id, address=address1) |
| 217 | port_id = self.create_port(node_id=node_id, |
| 218 | address=address2)['port']['uuid'] |
| 219 | patch = [{'path': '/address', |
| 220 | 'op': 'replace', |
| 221 | 'value': address1}] |
| 222 | self.assertRaises(exc.Conflict, |
| 223 | self.client.update_port, port_id, patch) |
| 224 | |
| 225 | @test.attr(type=['negative', 'smoke']) |
| 226 | def test_update_port_replace_node_id_with_nonexistent(self): |
| 227 | node_id = self.node['uuid'] |
| 228 | address = data_utils.rand_mac_address() |
| 229 | |
| 230 | port_id = self.create_port(node_id=node_id, |
| 231 | address=address)['port']['uuid'] |
| 232 | |
| 233 | patch = [{'path': '/node_uuid', |
| 234 | 'op': 'replace', |
| 235 | 'value': data_utils.rand_uuid()}] |
| 236 | self.assertRaises(exc.BadRequest, |
| 237 | self.client.update_port, port_id, patch) |
| 238 | |
| 239 | @test.attr(type=['negative', 'smoke']) |
| 240 | def test_update_port_replace_mac_with_malformed(self): |
| 241 | node_id = self.node['uuid'] |
| 242 | address = data_utils.rand_mac_address() |
| 243 | |
| 244 | port_id = self.create_port(node_id=node_id, |
| 245 | address=address)['port']['uuid'] |
| 246 | patch = [{'path': '/address', |
| 247 | 'op': 'replace', |
| 248 | 'value': 'malformed:mac'}] |
| 249 | |
| 250 | self.assertRaises(exc.BadRequest, |
| 251 | self.client.update_port, port_id, patch) |
| 252 | |
| 253 | @test.attr(type=['negative', 'smoke']) |
| 254 | def test_update_port_replace_extra_item_with_malformed(self): |
| 255 | node_id = self.node['uuid'] |
| 256 | address = data_utils.rand_mac_address() |
| 257 | extra = {'key': 'value'} |
| 258 | |
| 259 | port_id = self.create_port(node_id=node_id, |
| 260 | address=address, |
| 261 | extra=extra)['port']['uuid'] |
| 262 | patch = [{'path': '/extra/key', |
| 263 | 'op': 'replace', |
| 264 | 'value': 0.123}] |
| 265 | |
| 266 | self.assertRaises(exc.BadRequest, |
| 267 | self.client.update_port, port_id, patch) |
| 268 | |
| 269 | @test.attr(type=['negative', 'smoke']) |
| 270 | def test_update_port_replace_whole_extra_with_malformed(self): |
| 271 | node_id = self.node['uuid'] |
| 272 | address = data_utils.rand_mac_address() |
| 273 | extra = {'key': 'value'} |
| 274 | |
| 275 | port_id = self.create_port(node_id=node_id, |
| 276 | address=address, |
| 277 | extra=extra)['port']['uuid'] |
| 278 | patch = [{'path': '/extra', |
| 279 | 'op': 'replace', |
| 280 | 'value': [1, 2, 3, 4, 'a']}] |
| 281 | |
| 282 | self.assertRaises(exc.BadRequest, |
| 283 | self.client.update_port, port_id, patch) |
| 284 | |
| 285 | @test.attr(type=['negative', 'smoke']) |
| 286 | def test_update_port_replace_nonexistent_property(self): |
| 287 | node_id = self.node['uuid'] |
| 288 | address = data_utils.rand_mac_address() |
| 289 | |
| 290 | port_id = self.create_port(node_id=node_id, |
| 291 | address=address)['port']['uuid'] |
| 292 | |
| 293 | patch = [{'path': '/nonexistent', ' op': 'replace', 'value': 'value'}] |
| 294 | |
| 295 | self.assertRaises(exc.BadRequest, |
| 296 | self.client.update_port, port_id, patch) |
| 297 | |
| 298 | @test.attr(type=['negative', 'smoke']) |
| 299 | def test_update_port_remove_mandatory_field_mac(self): |
| 300 | node_id = self.node['uuid'] |
| 301 | address = data_utils.rand_mac_address() |
| 302 | |
| 303 | port_id = self.create_port(node_id=node_id, address=address)['port'][ |
| 304 | 'uuid'] |
| 305 | self.assertRaises(exc.BadRequest, self.client.update_port, port_id, |
| 306 | [{'path': '/address', 'op': 'remove'}]) |
| 307 | |
| 308 | @test.attr(type=['negative', 'smoke']) |
| 309 | def test_update_port_remove_mandatory_field_port_uuid(self): |
| 310 | node_id = self.node['uuid'] |
| 311 | address = data_utils.rand_mac_address() |
| 312 | |
| 313 | port_id = self.create_port(node_id=node_id, address=address)['port'][ |
| 314 | 'uuid'] |
| 315 | self.assertRaises(exc.BadRequest, self.client.update_port, port_id, |
| 316 | [{'path': '/uuid', 'op': 'remove'}]) |
| 317 | |
| 318 | @test.attr(type=['negative', 'smoke']) |
| 319 | def test_update_port_remove_nonexistent_property(self): |
| 320 | node_id = self.node['uuid'] |
| 321 | address = data_utils.rand_mac_address() |
| 322 | |
| 323 | port_id = self.create_port(node_id=node_id, address=address)['port'][ |
| 324 | 'uuid'] |
| 325 | self.assertRaises(exc.BadRequest, self.client.update_port, port_id, |
| 326 | [{'path': '/nonexistent', 'op': 'remove'}]) |
| 327 | |
| 328 | @test.attr(type=['negative', 'smoke']) |
| 329 | def test_delete_port_by_mac_not_allowed(self): |
| 330 | node_id = self.node['uuid'] |
| 331 | address = data_utils.rand_mac_address() |
| 332 | |
| 333 | self.create_port(node_id=node_id, address=address) |
| 334 | self.assertRaises(exc.BadRequest, self.client.delete_port, address) |
| 335 | |
| 336 | @test.attr(type=['negative', 'smoke']) |
| 337 | def test_update_port_mixed_ops_integrity(self): |
| 338 | node_id = self.node['uuid'] |
| 339 | address = data_utils.rand_mac_address() |
| 340 | extra = {'key1': 'value1', 'key2': 'value2'} |
| 341 | |
| 342 | port_id = self.create_port(node_id=node_id, address=address, |
| 343 | extra=extra)['port']['uuid'] |
| 344 | |
| 345 | new_address = data_utils.rand_mac_address() |
| 346 | new_extra = {'key1': 'new-value1', 'key3': 'new-value3'} |
| 347 | |
| 348 | patch = [{'path': '/address', |
| 349 | 'op': 'replace', |
| 350 | 'value': new_address}, |
| 351 | {'path': '/extra/key1', |
| 352 | 'op': 'replace', |
| 353 | 'value': new_extra['key1']}, |
| 354 | {'path': '/extra/key2', |
| 355 | 'op': 'remove'}, |
| 356 | {'path': '/extra/key3', |
| 357 | 'op': 'add', |
| 358 | 'value': new_extra['key3']}, |
| 359 | {'path': '/nonexistent', |
| 360 | 'op': 'replace', |
| 361 | 'value': 'value'}] |
| 362 | |
| 363 | self.assertRaises(exc.BadRequest, self.client.update_port, port_id, |
| 364 | patch) |
| 365 | |
| 366 | # patch should not be applied |
| 367 | resp, body = self.client.show_port(port_id) |
| 368 | self.assertEqual(200, resp.status) |
| 369 | self.assertEqual(address, body['address']) |
| 370 | self.assertEqual(extra, body['extra']) |