Debian Codegraph @

ironic_tempest_plugin/tests/api/admin/test_ports_negative.py

raw
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.lib.common.utils import data_utils
14 from tempest.lib import decorators
15 from tempest.lib import exceptions as lib_exc
16
17 from ironic_tempest_plugin.tests.api.admin import api_microversion_fixture
18 from ironic_tempest_plugin.tests.api import base
19
20
21 class TestPortsNegative(base.BaseBaremetalTest):
22 """Negative tests for ports."""
23
24 def setUp(self):
25 super(TestPortsNegative, self).setUp()
26
27 _, self.chassis = self.create_chassis()
28 _, self.node = self.create_node(self.chassis['uuid'])
29 self.useFixture(
30 api_microversion_fixture.APIMicroversionFixture('1.31'))
31 # Now with a 1.31 microversion, swap the network interfaces
32 # into place so the test doesn't break depending on
33 # the environment's default state.
34 self.client.update_node(self.node['uuid'],
35 [{'path': '/network_interface',
36 'op': 'replace',
37 'value': 'noop'}])
38 self.useFixture(api_microversion_fixture.APIMicroversionFixture('1.1'))
39
40 @decorators.attr(type=['negative'])
41 @decorators.idempotent_id('0a6ee1f7-d0d9-4069-8778-37f3aa07303a')
42 def test_create_port_malformed_mac(self):
43 node_id = self.node['uuid']
44 address = 'malformed:mac'
45
46 self.assertRaises(lib_exc.BadRequest,
47 self.create_port, node_id=node_id, address=address)
48
49 @decorators.attr(type=['negative'])
50 @decorators.idempotent_id('30277ee8-0c60-4f1d-b125-0e51c2f43369')
51 def test_create_port_nonexsistent_node_id(self):
52 node_id = str(data_utils.rand_uuid())
53 address = data_utils.rand_mac_address()
54 self.assertRaises(lib_exc.BadRequest, self.create_port,
55 node_id=node_id, address=address)
56
57 @decorators.attr(type=['negative'])
58 @decorators.idempotent_id('029190f6-43e1-40a3-b64a-65173ba653a3')
59 def test_show_port_malformed_uuid(self):
60 self.assertRaises(lib_exc.BadRequest, self.client.show_port,
61 'malformed:uuid')
62
63 @decorators.attr(type=['negative'])
64 @decorators.idempotent_id('0d00e13d-e2e0-45b1-bcbc-55a6d90ca793')
65 def test_show_port_nonexistent_uuid(self):
66 self.assertRaises(lib_exc.NotFound, self.client.show_port,
67 data_utils.rand_uuid())
68
69 @decorators.attr(type=['negative'])
70 @decorators.idempotent_id('4ad85266-31e9-4942-99ac-751897dc9e23')
71 def test_show_port_by_mac_not_allowed(self):
72 self.assertRaises(lib_exc.BadRequest, self.client.show_port,
73 data_utils.rand_mac_address())
74
75 @decorators.attr(type=['negative'])
76 @decorators.idempotent_id('89a34380-3c61-4c32-955c-2cd9ce94da21')
77 def test_create_port_duplicated_port_uuid(self):
78 node_id = self.node['uuid']
79 address = data_utils.rand_mac_address()
80 uuid = data_utils.rand_uuid()
81
82 self.create_port(node_id=node_id, address=address, uuid=uuid)
83 self.assertRaises(lib_exc.Conflict, self.create_port, node_id=node_id,
84 address=address, uuid=uuid)
85
86 @decorators.attr(type=['negative'])
87 @decorators.idempotent_id('65e84917-733c-40ae-ae4b-96a4adff931c')
88 def test_create_port_no_mandatory_field_node_id(self):
89 address = data_utils.rand_mac_address()
90
91 self.assertRaises(lib_exc.BadRequest, self.create_port, node_id=None,
92 address=address)
93
94 @decorators.attr(type=['negative'])
95 @decorators.idempotent_id('bcea3476-7033-4183-acfe-e56a30809b46')
96 def test_create_port_no_mandatory_field_mac(self):
97 node_id = self.node['uuid']
98
99 self.assertRaises(lib_exc.BadRequest, self.create_port,
100 node_id=node_id, address=None)
101
102 @decorators.attr(type=['negative'])
103 @decorators.idempotent_id('2b51cd18-fb95-458b-9780-e6257787b649')
104 def test_create_port_malformed_port_uuid(self):
105 node_id = self.node['uuid']
106 address = data_utils.rand_mac_address()
107 uuid = 'malformed:uuid'
108
109 self.assertRaises(lib_exc.BadRequest, self.create_port,
110 node_id=node_id, address=address, uuid=uuid)
111
112 @decorators.attr(type=['negative'])
113 @decorators.idempotent_id('583a6856-6a30-4ac4-889f-14e2adff8105')
114 def test_create_port_malformed_node_id(self):
115 address = data_utils.rand_mac_address()
116 self.assertRaises(lib_exc.BadRequest, self.create_port,
117 node_id='malformed:nodeid', address=address)
118
119 @decorators.attr(type=['negative'])
120 @decorators.idempotent_id('e27f8b2e-42c6-4a43-a3cd-accff716bc5c')
121 def test_create_port_duplicated_mac(self):
122 node_id = self.node['uuid']
123 address = data_utils.rand_mac_address()
124 self.create_port(node_id=node_id, address=address)
125 self.assertRaises(lib_exc.Conflict,
126 self.create_port, node_id=node_id,
127 address=address)
128
129 @decorators.attr(type=['negative'])
130 @decorators.idempotent_id('8907082d-ac5e-4be3-b05f-d072ede82020')
131 def test_update_port_by_mac_not_allowed(self):
132 node_id = self.node['uuid']
133 address = data_utils.rand_mac_address()
134 extra = {'key': 'value'}
135
136 self.create_port(node_id=node_id, address=address, extra=extra)
137
138 patch = [{'path': '/extra/key',
139 'op': 'replace',
140 'value': 'new-value'}]
141
142 self.assertRaises(lib_exc.BadRequest,
143 self.client.update_port, address,
144 patch)
145
146 @decorators.attr(type=['negative'])
147 @decorators.idempotent_id('df1ac70c-db9f-41d9-90f1-78cd6b905718')
148 def test_update_port_nonexistent(self):
149 node_id = self.node['uuid']
150 address = data_utils.rand_mac_address()
151 extra = {'key': 'value'}
152
153 _, port = self.create_port(node_id=node_id, address=address,
154 extra=extra)
155 port_id = port['uuid']
156
157 _, body = self.client.delete_port(port_id)
158
159 patch = [{'path': '/extra/key',
160 'op': 'replace',
161 'value': 'new-value'}]
162 self.assertRaises(lib_exc.NotFound,
163 self.client.update_port, port_id, patch)
164
165 @decorators.attr(type=['negative'])
166 @decorators.idempotent_id('c701e315-aa52-41ea-817c-65c5ca8ca2a8')
167 def test_update_port_malformed_port_uuid(self):
168 node_id = self.node['uuid']
169 address = data_utils.rand_mac_address()
170
171 self.create_port(node_id=node_id, address=address)
172
173 new_address = data_utils.rand_mac_address()
174 self.assertRaises(lib_exc.BadRequest, self.client.update_port,
175 uuid='malformed:uuid',
176 patch=[{'path': '/address', 'op': 'replace',
177 'value': new_address}])
178
179 @decorators.attr(type=['negative'])
180 @decorators.idempotent_id('f8f15803-34d6-45dc-b06f-e5e04bf1b38b')
181 def test_update_port_add_nonexistent_property(self):
182 node_id = self.node['uuid']
183 address = data_utils.rand_mac_address()
184
185 _, port = self.create_port(node_id=node_id, address=address)
186 port_id = port['uuid']
187
188 self.assertRaises(lib_exc.BadRequest, self.client.update_port, port_id,
189 [{'path': '/nonexistent', ' op': 'add',
190 'value': 'value'}])
191
192 @decorators.attr(type=['negative'])
193 @decorators.idempotent_id('898ec904-38b1-4fcb-9584-1187d4263a2a')
194 def test_update_port_replace_node_id_with_malformed(self):
195 node_id = self.node['uuid']
196 address = data_utils.rand_mac_address()
197
198 _, port = self.create_port(node_id=node_id, address=address)
199 port_id = port['uuid']
200
201 patch = [{'path': '/node_uuid',
202 'op': 'replace',
203 'value': 'malformed:node_uuid'}]
204 self.assertRaises(lib_exc.BadRequest,
205 self.client.update_port, port_id, patch)
206
207 @decorators.attr(type=['negative'])
208 @decorators.idempotent_id('2949f30f-5f59-43fa-a6d9-4eac578afab4')
209 def test_update_port_replace_mac_with_duplicated(self):
210 node_id = self.node['uuid']
211 address1 = data_utils.rand_mac_address()
212 address2 = data_utils.rand_mac_address()
213
214 _, port1 = self.create_port(node_id=node_id, address=address1)
215
216 _, port2 = self.create_port(node_id=node_id, address=address2)
217 port_id = port2['uuid']
218
219 patch = [{'path': '/address',
220 'op': 'replace',
221 'value': address1}]
222 self.assertRaises(lib_exc.Conflict,
223 self.client.update_port, port_id, patch)
224
225 @decorators.attr(type=['negative'])
226 @decorators.idempotent_id('97f6e048-6e4f-4eba-a09d-fbbc78b77a77')
227 def test_update_port_replace_node_id_with_nonexistent(self):
228 node_id = self.node['uuid']
229 address = data_utils.rand_mac_address()
230
231 _, port = self.create_port(node_id=node_id, address=address)
232 port_id = port['uuid']
233
234 patch = [{'path': '/node_uuid',
235 'op': 'replace',
236 'value': data_utils.rand_uuid()}]
237 self.assertRaises(lib_exc.BadRequest,
238 self.client.update_port, port_id, patch)
239
240 @decorators.attr(type=['negative'])
241 @decorators.idempotent_id('375022c5-9e9e-4b11-9ca4-656729c0c9b2')
242 def test_update_port_replace_mac_with_malformed(self):
243 node_id = self.node['uuid']
244 address = data_utils.rand_mac_address()
245
246 _, port = self.create_port(node_id=node_id, address=address)
247 port_id = port['uuid']
248
249 patch = [{'path': '/address',
250 'op': 'replace',
251 'value': 'malformed:mac'}]
252
253 self.assertRaises(lib_exc.BadRequest,
254 self.client.update_port, port_id, patch)
255
256 @decorators.attr(type=['negative'])
257 @decorators.idempotent_id('5722b853-03fc-4854-8308-2036a1b67d85')
258 def test_update_port_replace_nonexistent_property(self):
259 node_id = self.node['uuid']
260 address = data_utils.rand_mac_address()
261
262 _, port = self.create_port(node_id=node_id, address=address)
263 port_id = port['uuid']
264
265 patch = [{'path': '/nonexistent', ' op': 'replace', 'value': 'value'}]
266
267 self.assertRaises(lib_exc.BadRequest,
268 self.client.update_port, port_id, patch)
269
270 @decorators.attr(type=['negative'])
271 @decorators.idempotent_id('ae2696ca-930a-4a7f-918f-30ae97c60f56')
272 def test_update_port_remove_mandatory_field_mac(self):
273 node_id = self.node['uuid']
274 address = data_utils.rand_mac_address()
275
276 _, port = self.create_port(node_id=node_id, address=address)
277 port_id = port['uuid']
278
279 self.assertRaises(lib_exc.BadRequest, self.client.update_port, port_id,
280 [{'path': '/address', 'op': 'remove'}])
281
282 @decorators.attr(type=['negative'])
283 @decorators.idempotent_id('5392c1f0-2071-4697-9064-ec2d63019018')
284 def test_update_port_remove_mandatory_field_port_uuid(self):
285 node_id = self.node['uuid']
286 address = data_utils.rand_mac_address()
287
288 _, port = self.create_port(node_id=node_id, address=address)
289 port_id = port['uuid']
290
291 self.assertRaises(lib_exc.BadRequest, self.client.update_port, port_id,
292 [{'path': '/uuid', 'op': 'remove'}])
293
294 @decorators.attr(type=['negative'])
295 @decorators.idempotent_id('06b50d82-802a-47ef-b079-0a3311cf85a2')
296 def test_update_port_remove_nonexistent_property(self):
297 node_id = self.node['uuid']
298 address = data_utils.rand_mac_address()
299
300 _, port = self.create_port(node_id=node_id, address=address)
301 port_id = port['uuid']
302
303 self.assertRaises(lib_exc.BadRequest, self.client.update_port, port_id,
304 [{'path': '/nonexistent', 'op': 'remove'}])
305
306 @decorators.attr(type=['negative'])
307 @decorators.idempotent_id('03d42391-2145-4a6c-95bf-63fe55eb64fd')
308 def test_delete_port_by_mac_not_allowed(self):
309 node_id = self.node['uuid']
310 address = data_utils.rand_mac_address()
311
312 self.create_port(node_id=node_id, address=address)
313 self.assertRaises(lib_exc.BadRequest, self.client.delete_port, address)
314
315 @decorators.attr(type=['negative'])
316 @decorators.idempotent_id('0629e002-818e-4763-b25b-ae5e07b1cb23')
317 def test_update_port_mixed_ops_integrity(self):
318 node_id = self.node['uuid']
319 address = data_utils.rand_mac_address()
320 extra = {'key1': 'value1', 'key2': 'value2'}
321
322 _, port = self.create_port(node_id=node_id, address=address,
323 extra=extra)
324 port_id = port['uuid']
325
326 new_address = data_utils.rand_mac_address()
327 new_extra = {'key1': 'new-value1', 'key3': 'new-value3'}
328
329 patch = [{'path': '/address',
330 'op': 'replace',
331 'value': new_address},
332 {'path': '/extra/key1',
333 'op': 'replace',
334 'value': new_extra['key1']},
335 {'path': '/extra/key2',
336 'op': 'remove'},
337 {'path': '/extra/key3',
338 'op': 'add',
339 'value': new_extra['key3']},
340 {'path': '/nonexistent',
341 'op': 'replace',
342 'value': 'value'}]
343
344 self.assertRaises(lib_exc.BadRequest, self.client.update_port, port_id,
345 patch)
346
347 # patch should not be applied
348 _, body = self.client.show_port(port_id)
349 self.assertEqual(address, body['address'])
350 self.assertEqual(extra, body['extra'])
351
352
353 class TestPortsWithPhysicalNetworkOldAPI(base.BaseBaremetalTest):
354 """Negative tests for ports with physical network information."""
355
356 def setUp(self):
357 super(TestPortsWithPhysicalNetworkOldAPI, self).setUp()
358 _, self.chassis = self.create_chassis()
359 _, self.node = self.create_node(self.chassis['uuid'])
360
361 @decorators.attr(type=['negative'])
362 @decorators.idempotent_id('307e57e9-082f-4830-9480-91affcbfda08')
363 def test_create_port_with_physical_network_old_api(self):
364 node_id = self.node['uuid']
365 address = data_utils.rand_mac_address()
366
367 self.assertRaises((lib_exc.BadRequest, lib_exc.NotAcceptable),
368 self.create_port,
369 node_id=node_id, address=address,
370 physical_network='physnet1')
371
372 @decorators.attr(type=['negative'])
373 @decorators.idempotent_id('0b278c0a-d334-424e-a5c5-b6d001c2a715')
374 def test_update_port_replace_physical_network_old_api(self):
375 _, port = self.create_port(self.node['uuid'],
376 data_utils.rand_mac_address())
377
378 new_physnet = 'physnet1'
379
380 patch = [{'path': '/physical_network',
381 'op': 'replace',
382 'value': new_physnet}]
383
384 self.assertRaises((lib_exc.BadRequest, lib_exc.NotAcceptable),
385 self.client.update_port,
386 port['uuid'], patch)
387
388
389 class TestPortsNegativeWithPhysicalNetwork(base.BaseBaremetalTest):
390 """Negative tests for ports with physical network information."""
391
392 min_microversion = '1.34'
393
394 def setUp(self):
395 super(TestPortsNegativeWithPhysicalNetwork, self).setUp()
396
397 self.useFixture(
398 api_microversion_fixture.APIMicroversionFixture(
399 TestPortsNegativeWithPhysicalNetwork.min_microversion)
400 )
401 _, self.chassis = self.create_chassis()
402 _, self.node = self.create_node(self.chassis['uuid'])
403
404 @decorators.attr(type=['negative'])
405 @decorators.idempotent_id('e20156fb-956b-4d5b-89a4-f379044a1d3c')
406 def test_create_ports_in_portgroup_with_inconsistent_physical_network(
407 self):
408 node_id = self.node['uuid']
409 address = data_utils.rand_mac_address()
410
411 _, portgroup = self.create_portgroup(node_id, address=address)
412
413 _, _ = self.create_port(node_id=node_id, address=address,
414 portgroup_uuid=portgroup['uuid'],
415 physical_network='physnet1')
416
417 address = data_utils.rand_mac_address()
418 self.assertRaises(lib_exc.Conflict,
419 self.create_port,
420 node_id=node_id, address=address,
421 portgroup_uuid=portgroup['uuid'],
422 physical_network='physnet2')
423
424 @decorators.attr(type=['negative'])
425 @decorators.idempotent_id('050e792c-22c9-4e4a-ae89-dfbfc52ad00d')
426 def test_update_ports_in_portgroup_with_inconsistent_physical_network(
427 self):
428 node_id = self.node['uuid']
429 address = data_utils.rand_mac_address()
430
431 _, portgroup = self.create_portgroup(node_id, address=address)
432
433 _, _ = self.create_port(node_id=node_id, address=address,
434 portgroup_uuid=portgroup['uuid'],
435 physical_network='physnet1')
436
437 address = data_utils.rand_mac_address()
438 _, port2 = self.create_port(node_id=node_id, address=address,
439 physical_network='physnet2')
440
441 patch = [{'path': '/portgroup_uuid',
442 'op': 'replace',
443 'value': portgroup['uuid']}]
444
445 self.assertRaises(lib_exc.Conflict,
446 self.client.update_port,
447 port2['uuid'], patch)
448
449 @decorators.attr(type=['negative'])
450 @decorators.idempotent_id('3cd1c8ec-57d1-40cb-922b-dd02431beea3')
451 def test_update_ports_in_portgroup_with_inconsistent_physical_network_2(
452 self):
453 node_id = self.node['uuid']
454 address = data_utils.rand_mac_address()
455
456 _, portgroup = self.create_portgroup(node_id, address=address)
457
458 _, _ = self.create_port(node_id=node_id, address=address,
459 portgroup_uuid=portgroup['uuid'],
460 physical_network='physnet1')
461
462 address = data_utils.rand_mac_address()
463 _, port2 = self.create_port(node_id=node_id, address=address,
464 portgroup_uuid=portgroup['uuid'],
465 physical_network='physnet1')
466
467 patch = [{'path': '/physical_network',
468 'op': 'replace',
469 'value': 'physnet2'}]
470
471 self.assertRaises(lib_exc.Conflict,
472 self.client.update_port,
473 port2['uuid'], patch)