Debian Codegraph @

ironic_tempest_plugin/tests/api/admin/test_nodes.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
14 from oslo_utils import uuidutils
15 from tempest.common import compute
16 from tempest import config
17 from tempest.lib.common.utils import data_utils
18 from tempest.lib import decorators
19 from tempest.lib import exceptions as lib_exc
20
21 from ironic_tempest_plugin.common import waiters
22 from ironic_tempest_plugin.tests.api.admin import api_microversion_fixture
23 from ironic_tempest_plugin.tests.api import base
24
25 CONF = config.CONF
26
27
28 class TestNodes(base.BaseBaremetalTest):
29 """Tests for baremetal nodes."""
30
31 def setUp(self):
32 super(TestNodes, self).setUp()
33
34 _, self.chassis = self.create_chassis()
35 _, self.node = self.create_node(self.chassis['uuid'])
36
37 def _associate_node_with_instance(self):
38 self.client.set_node_power_state(self.node['uuid'], 'power off')
39 waiters.wait_for_bm_node_status(self.client, self.node['uuid'],
40 'power_state', 'power off')
41 instance_uuid = data_utils.rand_uuid()
42 self.client.update_node(self.node['uuid'],
43 instance_uuid=instance_uuid)
44 self.addCleanup(self.client.update_node,
45 uuid=self.node['uuid'], instance_uuid=None)
46 return instance_uuid
47
48 @decorators.idempotent_id('4e939eb2-8a69-4e84-8652-6fffcbc9db8f')
49 def test_create_node(self):
50 params = {'cpu_arch': 'x86_64',
51 'cpus': '12',
52 'local_gb': '10',
53 'memory_mb': '1024'}
54
55 _, body = self.create_node(self.chassis['uuid'], **params)
56 self._assertExpected(params, body['properties'])
57
58 @decorators.idempotent_id('9ade60a4-505e-4259-9ec4-71352cbbaf47')
59 def test_delete_node(self):
60 _, node = self.create_node(self.chassis['uuid'])
61
62 self.delete_node(node['uuid'])
63
64 self.assertRaises(lib_exc.NotFound, self.client.show_node,
65 node['uuid'])
66
67 @decorators.idempotent_id('55451300-057c-4ecf-8255-ba42a83d3a03')
68 def test_show_node(self):
69 _, loaded_node = self.client.show_node(self.node['uuid'])
70 self._assertExpected(self.node, loaded_node)
71
72 @decorators.idempotent_id('4ca123c4-160d-4d8d-a3f7-15feda812263')
73 def test_list_nodes(self):
74 _, body = self.client.list_nodes()
75 self.assertIn(self.node['uuid'],
76 [i['uuid'] for i in body['nodes']])
77
78 @decorators.idempotent_id('85b1f6e0-57fd-424c-aeff-c3422920556f')
79 def test_list_nodes_association(self):
80 _, body = self.client.list_nodes(associated=True)
81 self.assertNotIn(self.node['uuid'],
82 [n['uuid'] for n in body['nodes']])
83
84 self._associate_node_with_instance()
85
86 _, body = self.client.list_nodes(associated=True)
87 self.assertIn(self.node['uuid'], [n['uuid'] for n in body['nodes']])
88
89 _, body = self.client.list_nodes(associated=False)
90 self.assertNotIn(self.node['uuid'], [n['uuid'] for n in body['nodes']])
91
92 @decorators.idempotent_id('18c4ebd8-f83a-4df7-9653-9fb33a329730')
93 def test_node_port_list(self):
94 _, port = self.create_port(self.node['uuid'],
95 data_utils.rand_mac_address())
96 _, body = self.client.list_node_ports(self.node['uuid'])
97 self.assertIn(port['uuid'],
98 [p['uuid'] for p in body['ports']])
99
100 @decorators.idempotent_id('78c4ebd8-f83a-4df7-9653-9fb33a329730')
101 def test_node_ports_detail(self):
102 _, port = self.create_port(self.node['uuid'],
103 data_utils.rand_mac_address())
104 _, body = self.client.list_node_ports_detail(self.node['uuid'])
105 self.assertIn(port['uuid'],
106 [p['uuid'] for p in body['ports']])
107 self.assertIn(port['node_uuid'],
108 [p['node_uuid'] for p in body['ports']])
109 self.assertIn(port['address'],
110 [p['address'] for p in body['ports']])
111
112 @decorators.idempotent_id('72591acb-f215-49db-8395-710d14eb86ab')
113 def test_node_port_list_no_ports(self):
114 _, node = self.create_node(self.chassis['uuid'])
115 _, body = self.client.list_node_ports(node['uuid'])
116 self.assertEmpty(body['ports'])
117
118 @decorators.idempotent_id('4fed270a-677a-4d19-be87-fd38ae490320')
119 def test_update_node(self):
120 props = {'cpu_arch': 'x86_64',
121 'cpus': '12',
122 'local_gb': '10',
123 'memory_mb': '128'}
124
125 _, node = self.create_node(self.chassis['uuid'], **props)
126
127 new_p = {'cpu_arch': 'arm64',
128 'cpus': '1',
129 'local_gb': '10000',
130 'memory_mb': '12300'}
131
132 _, body = self.client.update_node(node['uuid'], properties=new_p)
133 _, node = self.client.show_node(node['uuid'])
134 self._assertExpected(new_p, node['properties'])
135
136 @decorators.idempotent_id('cbf1f515-5f4b-4e49-945c-86bcaccfeb1d')
137 def test_validate_driver_interface(self):
138 _, body = self.client.validate_driver_interface(self.node['uuid'])
139 core_interfaces = ['power', 'deploy']
140 for interface in core_interfaces:
141 self.assertIn(interface, body)
142
143 @decorators.idempotent_id('5519371c-26a2-46e9-aa1a-f74226e9d71f')
144 def test_set_node_boot_device(self):
145 self.client.set_node_boot_device(self.node['uuid'], 'pxe')
146
147 @decorators.idempotent_id('9ea73775-f578-40b9-bc34-efc639c4f21f')
148 def test_get_node_boot_device(self):
149 body = self.client.get_node_boot_device(self.node['uuid'])
150 self.assertIn('boot_device', body)
151 self.assertIn('persistent', body)
152 self.assertIsInstance(body['boot_device'], str)
153 self.assertIsInstance(body['persistent'], bool)
154
155 @decorators.idempotent_id('3622bc6f-3589-4bc2-89f3-50419c66b133')
156 def test_get_node_supported_boot_devices(self):
157 body = self.client.get_node_supported_boot_devices(self.node['uuid'])
158 self.assertIn('supported_boot_devices', body)
159 self.assertIsInstance(body['supported_boot_devices'], list)
160
161 @decorators.idempotent_id('f63b6288-1137-4426-8cfe-0d5b7eb87c06')
162 def test_get_console(self):
163 _, body = self.client.get_console(self.node['uuid'])
164 con_info = ['console_enabled', 'console_info']
165 for key in con_info:
166 self.assertIn(key, body)
167
168 @decorators.idempotent_id('80504575-9b21-4670-92d1-143b948f9437')
169 def test_set_console_mode(self):
170 self.client.set_console_mode(self.node['uuid'], True)
171 waiters.wait_for_bm_node_status(self.client, self.node['uuid'],
172 'console_enabled', True)
173
174 @decorators.idempotent_id('b02a4f38-5e8b-44b2-aed2-a69a36ecfd69')
175 def test_get_node_by_instance_uuid(self):
176 instance_uuid = self._associate_node_with_instance()
177 _, body = self.client.show_node_by_instance_uuid(instance_uuid)
178 self.assertEqual(1, len(body['nodes']))
179 self.assertIn(self.node['uuid'], [n['uuid'] for n in body['nodes']])
180
181 @decorators.idempotent_id('b85af8c6-572b-4f20-815e-1cf31844b9f6')
182 def test_fault_hidden(self):
183 _, loaded_node = self.client.show_node(self.node['uuid'])
184 self.assertNotIn('fault', loaded_node)
185
186 @decorators.idempotent_id('e5470656-bb65-4173-be83-2df3fc9aed24')
187 def test_conductor_hidden(self):
188 _, loaded_node = self.client.show_node(self.node['uuid'])
189 self.assertNotIn('conductor', loaded_node)
190
191 @decorators.idempotent_id('5e7f4c54-8216-42d3-83cc-7bd776ffd16f')
192 def test_description_hidden(self):
193 _, loaded_node = self.client.show_node(self.node['uuid'])
194 self.assertNotIn('description', loaded_node)
195
196
197 class TestNodesWithJsonExtSupport(base.BaseBaremetalTest):
198 """Tests for baremetal nodes to validate appending .json extension to a
199
200 node's `name` or `uuid` in API versions 1.90 and prior works.
201 """
202
203 max_microversion = '1.90' # Max API version allowed for testing: 1.90
204 min_microversion = '1.90' # Min API version allowed for testing: 1.90
205
206 def setUp(self):
207 super(TestNodesWithJsonExtSupport, self).setUp()
208
209 _, self.chassis = self.create_chassis()
210 _, self.node = self.create_node(self.chassis['uuid'])
211
212 @decorators.idempotent_id('2ffec2ec-3dca-4e4f-ac6c-dee7c44cdef5')
213 def test_update_node_with_json(self):
214 """Update a node while appending .json extension to its uuid"""
215 props = {'cpu_arch': 'x86_64',
216 'cpus': '12',
217 'local_gb': '10',
218 'memory_mb': '128'}
219
220 _, node = self.create_node(self.chassis['uuid'], **props)
221
222 new_p = {'cpu_arch': 'arm64',
223 'cpus': '1',
224 'local_gb': '10000',
225 'memory_mb': '12300'}
226
227 _, body = self.client.update_node('%s.json' % node['uuid'],
228 properties=new_p)
229 _, node = self.client.show_node(node['uuid'])
230 self._assertExpected(new_p, node['properties'])
231
232 @decorators.idempotent_id('4c376a23-04b8-4fc8-955f-abc5668d34c3')
233 def test_delete_node_with_json(self):
234 """Delete a node while appending .json extension to its uuid"""
235 _, node = self.create_node(self.chassis['uuid'])
236
237 self.delete_node('%s.json' % node['uuid'])
238
239 self.assertRaises(lib_exc.NotFound, self.client.show_node,
240 node['uuid'])
241
242 @decorators.idempotent_id('bc1134aa-2950-409c-b91c-b2d85df9b065')
243 def test_show_node_with_json(self):
244 """Show a node while appending .json extension to its uuid"""
245 _, loaded_node = self.client.show_node('%s.json' % self.node['uuid'])
246 self._assertExpected(self.node, loaded_node)
247
248
249 class TestNodesWithoutJsonExtSupport(base.BaseBaremetalTest):
250 """Tests for baremetal nodes to validate appending .json extension to a
251
252 node's `name` or `uuid` in API versions later than 1.90 is disabled.
253 """
254
255 min_microversion = '1.91' # Min API version allowed for testing: 1.91
256
257 def setUp(self):
258 super(TestNodesWithoutJsonExtSupport, self).setUp()
259
260 _, self.chassis = self.create_chassis()
261 _, self.node = self.create_node(self.chassis['uuid'])
262
263 @decorators.idempotent_id('65505002-3ac7-4a07-9f66-2e3bcb0f5e95')
264 def test_update_node_with_json(self):
265 """Trying to update a node while appending .json extension 404s"""
266 props = {'cpu_arch': 'x86_64',
267 'cpus': '12',
268 'local_gb': '10',
269 'memory_mb': '128'}
270
271 _, node = self.create_node(self.chassis['uuid'], **props)
272
273 new_p = {'cpu_arch': 'arm64',
274 'cpus': '1',
275 'local_gb': '10000',
276 'memory_mb': '12300'}
277
278 self.assertRaises(lib_exc.NotFound, self.client.update_node,
279 '%s.json' % node['uuid'], properties=new_p)
280
281 @decorators.idempotent_id('594160b6-a608-4024-98d1-818f75d2d895')
282 def test_delete_node_with_json(self):
283 """Trying to delete a node while appending .json extension 404s"""
284 _, node = self.create_node(self.chassis['uuid'])
285 self.assertRaises(lib_exc.NotFound, self.client.delete_node,
286 '%s.json' % node['uuid'])
287
288 @decorators.idempotent_id('e83cd539-4d09-46d0-a448-365a219ca353')
289 def test_show_node_with_json(self):
290 """Trying to show a node while appending .json extension 404s"""
291
292 self.assertRaises(lib_exc.NotFound, self.client.show_node,
293 '%s.json' % self.node['uuid'])
294
295
296 class TestNodesResourceClass(base.BaseBaremetalTest):
297
298 min_microversion = '1.21'
299
300 def setUp(self):
301 super(TestNodesResourceClass, self).setUp()
302 self.useFixture(
303 api_microversion_fixture.APIMicroversionFixture(
304 TestNodesResourceClass.min_microversion)
305 )
306 _, self.chassis = self.create_chassis()
307 self.resource_class = data_utils.rand_name(name='Resource_Class')
308 _, self.node = self.create_node(
309 self.chassis['uuid'], resource_class=self.resource_class)
310
311 @decorators.idempotent_id('2a00340c-8152-4a61-9fc5-0b3cdefec258')
312 def test_create_node_resource_class_long(self):
313 """Create new node with specified longest name of resource class."""
314 res_class_long_name = data_utils.arbitrary_string(80)
315 _, body = self.create_node(
316 self.chassis['uuid'],
317 resource_class=res_class_long_name)
318 self.assertEqual(res_class_long_name, body['resource_class'])
319
320 @decorators.idempotent_id('142db00d-ac0f-415b-8da8-9095fbb561f7')
321 def test_update_node_resource_class(self):
322 """Update existing node with specified resource class."""
323 new_res_class_name = data_utils.rand_name(name='Resource_Class')
324 _, body = self.client.update_node(
325 self.node['uuid'], resource_class=new_res_class_name)
326 _, body = self.client.show_node(self.node['uuid'])
327 self.assertEqual(new_res_class_name, body['resource_class'])
328
329 @decorators.idempotent_id('73e6f7b5-3e51-49ea-af5b-146cd49f40ee')
330 def test_show_node_resource_class(self):
331 """Show resource class field of specified node."""
332 _, body = self.client.show_node(self.node['uuid'])
333 self.assertEqual(self.resource_class, body['resource_class'])
334
335 @decorators.idempotent_id('f2bf4465-280c-4fdc-bbf7-fcf5188befa4')
336 def test_list_nodes_resource_class(self):
337 """List nodes of specified resource class only."""
338 res_class = 'ResClass-{0}'.format(data_utils.rand_uuid())
339 for node in range(3):
340 _, body = self.create_node(
341 self.chassis['uuid'], resource_class=res_class)
342
343 _, body = self.client.list_nodes(resource_class=res_class)
344 self.assertEqual(3, len([i['uuid'] for i in body['nodes']]))
345
346 @decorators.idempotent_id('40733bad-bb79-445e-a094-530a44042995')
347 def test_list_nodes_detail_resource_class(self):
348 """Get detailed nodes list of specified resource class only."""
349 res_class = 'ResClass-{0}'.format(data_utils.rand_uuid())
350 for node in range(3):
351 _, body = self.create_node(
352 self.chassis['uuid'], resource_class=res_class)
353
354 _, body = self.client.list_nodes_detail(resource_class=res_class)
355 self.assertEqual(3, len([i['uuid'] for i in body['nodes']]))
356
357 for node in body['nodes']:
358 self.assertEqual(res_class, node['resource_class'])
359
360 @decorators.attr(type='negative')
361 @decorators.idempotent_id('e75136d4-0690-48a5-aef3-75040aee73ad')
362 def test_create_node_resource_class_too_long(self):
363 """Try to create a node with too long resource class name."""
364 resource_class = data_utils.arbitrary_string(81)
365 self.assertRaises(lib_exc.BadRequest, self.create_node,
366 self.chassis['uuid'], resource_class=resource_class)
367
368 @decorators.attr(type='negative')
369 @decorators.idempotent_id('f0aeece4-8671-44ea-a482-b4047fc4cf74')
370 def test_update_node_resource_class_too_long(self):
371 """Try to update a node with too long resource class name."""
372 resource_class = data_utils.arbitrary_string(81)
373 self.assertRaises(lib_exc.BadRequest, self.client.update_node,
374 self.node['uuid'], resource_class=resource_class)
375
376
377 class TestNodesResourceClassOldApi(base.BaseBaremetalTest):
378
379 def setUp(self):
380 super(TestNodesResourceClassOldApi, self).setUp()
381 _, self.chassis = self.create_chassis()
382 _, self.node = self.create_node(self.chassis['uuid'])
383
384 @decorators.attr(type='negative')
385 @decorators.idempotent_id('2c364408-4746-4b3c-9821-20d47b57bdec')
386 def test_create_node_resource_class_old_api(self):
387 """Try to create a node with resource class using older api version."""
388 resource_class = data_utils.arbitrary_string()
389 self.assertRaises(lib_exc.NotAcceptable, self.create_node,
390 self.chassis['uuid'], resource_class=resource_class)
391
392 @decorators.attr(type='negative')
393 @decorators.idempotent_id('666f3c1a-4922-4a3d-b6d9-dea7c74d30bc')
394 def test_update_node_resource_class_old_api(self):
395 """Try to update a node with resource class using older api version."""
396 resource_class = data_utils.arbitrary_string()
397 self.assertRaises(lib_exc.NotAcceptable,
398 self.client.update_node,
399 self.node['uuid'], resource_class=resource_class)
400
401 @decorators.attr(type='negative')
402 @decorators.idempotent_id('95903480-f16d-4774-8775-6c7f87b27c59')
403 def test_list_nodes_by_resource_class_old_api(self):
404 """Try to list nodes with resource class using older api version."""
405 resource_class = data_utils.arbitrary_string()
406 self.assertRaises(
407 lib_exc.NotAcceptable,
408 self.client.list_nodes, resource_class=resource_class)
409 self.assertRaises(
410 lib_exc.NotAcceptable,
411 self.client.list_nodes_detail, resource_class=resource_class)
412
413
414 class TestNodesVif(base.BaseBaremetalTest):
415
416 min_microversion = '1.28'
417
418 @classmethod
419 def skip_checks(cls):
420 super(TestNodesVif, cls).skip_checks()
421 if not CONF.service_available.neutron:
422 raise cls.skipException('Neutron is not enabled.')
423
424 def setUp(self):
425 super(TestNodesVif, self).setUp()
426
427 if CONF.network.shared_physical_network:
428 if not CONF.compute.fixed_network_name:
429 raise self.skipException(
430 'Unable to perform vif test as there is no network '
431 'defined for the [compute]fixed_network_name '
432 'parameter.')
433 self.net = self.os_admin.networks_client.list_networks(
434 name=CONF.compute.fixed_network_name)['networks'][0]
435 else:
436 self.net = self.os_admin.networks_client.\
437 create_network()['network']
438 self.addCleanup(self.os_admin.networks_client.delete_network,
439 self.net['id'])
440
441 _, self.chassis = self.create_chassis()
442 # The tests will mostly fail in this class if exposed to the
443 # noop network interface, which is what the default is.
444 _, self.node = self.create_node(self.chassis['uuid'],
445 network_interface='flat')
446
447 self.nport_id = self.os_admin.ports_client.create_port(
448 network_id=self.net['id'])['port']['id']
449 self.addCleanup(self.os_admin.ports_client.delete_port,
450 self.nport_id)
451
452 @decorators.idempotent_id('a3d319d0-cacb-4e55-a3dc-3fa8b74880f1')
453 def test_vif_on_port(self):
454 """Test attachment and detachment of VIFs on the node with port.
455
456 Test steps:
457 1) Create chassis and node in setUp.
458 2) Create port for the node.
459 3) Attach VIF to the node.
460 4) Check VIF info in VIFs list and port internal_info.
461 5) Detach VIF from the node.
462 6) Check that no more VIF info in VIFs list and port internal_info.
463 """
464 self.useFixture(
465 api_microversion_fixture.APIMicroversionFixture('1.28'))
466 _, self.port = self.create_port(self.node['uuid'],
467 data_utils.rand_mac_address())
468 self.client.vif_attach(self.node['uuid'], self.nport_id)
469 _, body = self.client.vif_list(self.node['uuid'])
470 self.assertEqual({'vifs': [{'id': self.nport_id}]}, body)
471 _, port = self.client.show_port(self.port['uuid'])
472 self.assertEqual(self.nport_id,
473 port['internal_info']['tenant_vif_port_id'])
474 self.client.vif_detach(self.node['uuid'], self.nport_id)
475 _, body = self.client.vif_list(self.node['uuid'])
476 self.assertEqual({'vifs': []}, body)
477 _, port = self.client.show_port(self.port['uuid'])
478 self.assertNotIn('tenant_vif_port_id', port['internal_info'])
479
480 @decorators.idempotent_id('95279515-7d0a-4f5f-987f-93e36aae5585')
481 def test_vif_on_portgroup(self):
482 """Test attachment and detachment of VIFs on the node with port group.
483
484 Test steps:
485 1) Create chassis and node in setUp.
486 2) Create port for the node.
487 3) Create port group for the node.
488 4) Plug port into port group.
489 5) Attach VIF to the node.
490 6) Check VIF info in VIFs list and port group internal_info, but
491 not in port internal_info.
492 7) Detach VIF from the node.
493 8) Check that no VIF info in VIFs list and port group internal_info.
494 """
495 self.useFixture(
496 api_microversion_fixture.APIMicroversionFixture('1.28'))
497 _, self.port = self.create_port(self.node['uuid'],
498 data_utils.rand_mac_address())
499 _, self.portgroup = self.create_portgroup(
500 self.node['uuid'], address=data_utils.rand_mac_address())
501
502 patch = [{'path': '/portgroup_uuid',
503 'op': 'add',
504 'value': self.portgroup['uuid']}]
505 self.client.update_port(self.port['uuid'], patch)
506
507 self.client.vif_attach(self.node['uuid'], self.nport_id)
508 _, body = self.client.vif_list(self.node['uuid'])
509 self.assertEqual({'vifs': [{'id': self.nport_id}]}, body)
510
511 _, port = self.client.show_port(self.port['uuid'])
512 self.assertNotIn('tenant_vif_port_id', port['internal_info'])
513 _, portgroup = self.client.show_portgroup(self.portgroup['uuid'])
514 self.assertEqual(self.nport_id,
515 portgroup['internal_info']['tenant_vif_port_id'])
516
517 self.client.vif_detach(self.node['uuid'], self.nport_id)
518 _, body = self.client.vif_list(self.node['uuid'])
519 self.assertEqual({'vifs': []}, body)
520 _, portgroup = self.client.show_portgroup(self.portgroup['uuid'])
521 self.assertNotIn('tenant_vif_port_id', portgroup['internal_info'])
522
523 @decorators.idempotent_id('a3d319d0-cacb-4e55-a3dc-3fa8b74880f2')
524 def test_vif_already_set(self):
525 self.useFixture(
526 api_microversion_fixture.APIMicroversionFixture('1.28'))
527 _, self.port = self.create_port(self.node['uuid'],
528 data_utils.rand_mac_address())
529 self.client.vif_attach(self.node['uuid'], self.nport_id)
530 _, body = self.client.vif_list(self.node['uuid'])
531 self.assertEqual({'vifs': [{'id': self.nport_id}]}, body)
532
533 self.assertRaises(lib_exc.Conflict, self.client.vif_attach,
534 self.node['uuid'], self.nport_id)
535
536 self.client.vif_detach(self.node['uuid'], self.nport_id)
537
538 @decorators.attr(type='negative')
539 @decorators.idempotent_id('628350f8-4498-4204-b546-f3c01b93c7e3')
540 def test_vif_already_attached_on_internal_info(self):
541 """Negative test for duplicated attachment/detachment of VIFs.
542
543 Test steps:
544 1) Create chassis and node in setUp.
545 2) Create port for the node.
546 3) Attach VIF to the node.
547 4) Try to attach the same VIF to the node.
548 5) Detach VIF from the node.
549 6) Try to detach the same VIF from the node.
550 """
551 self.useFixture(
552 api_microversion_fixture.APIMicroversionFixture('1.28'))
553 _, self.port = self.create_port(self.node['uuid'],
554 data_utils.rand_mac_address())
555 self.client.vif_attach(self.node['uuid'], self.nport_id)
556 _, body = self.client.vif_list(self.node['uuid'])
557
558 self.assertEqual({'vifs': [{'id': self.nport_id}]}, body)
559
560 self.assertRaises(lib_exc.Conflict, self.client.vif_attach,
561 self.node['uuid'], self.nport_id)
562 self.client.vif_detach(self.node['uuid'], self.nport_id)
563 self.assertRaises(lib_exc.BadRequest, self.client.vif_detach,
564 self.node['uuid'], self.nport_id)
565
566 @decorators.attr(type='negative')
567 @decorators.idempotent_id('ec0c14a4-6853-4907-9091-755c9c6c152f')
568 def test_vif_already_attached_with_portgroups(self):
569 """Negative test: try duplicated attachment of VIFs with port groups.
570
571 Test steps:
572 1) Create chassis and node in setUp.
573 2) Create port for the node.
574 3) Create port group for the node.
575 4) Plug port into port group.
576 5) Attach VIF to the node.
577 6) Try to attach the same VIF to the node.
578 7) Check that VIF was not attached to port when portgroup is busy.
579 8) Detach VIF from the node.
580 9) Check there is no VIF data in port group internal info.
581 """
582 _, self.port = self.create_port(self.node['uuid'],
583 data_utils.rand_mac_address())
584 _, self.portgroup = self.create_portgroup(
585 self.node['uuid'], address=data_utils.rand_mac_address())
586
587 patch = [{'path': '/portgroup_uuid',
588 'op': 'add',
589 'value': self.portgroup['uuid']}]
590 self.client.update_port(self.port['uuid'], patch)
591 self.client.vif_attach(self.node['uuid'], self.nport_id)
592 self.assertRaises(lib_exc.Conflict, self.client.vif_attach,
593 self.node['uuid'], self.nport_id)
594
595 _, port = self.client.show_port(self.port['uuid'])
596 self.assertNotIn('tenant_vif_port_id', port['internal_info'])
597
598 self.client.vif_detach(self.node['uuid'], self.nport_id)
599 _, portgroup = self.client.show_portgroup(self.portgroup['uuid'])
600 self.assertNotIn('tenant_vif_port_id', portgroup['internal_info'])
601
602 @decorators.attr(type='negative')
603 @decorators.idempotent_id('91e08d6a-0438-4171-b404-bc86b0bc8861')
604 def test_vif_attach_no_free_port(self):
605 """Negative test for VIF attachment attempt with no free ports.
606
607 Test steps:
608 1) Create chassis and node in setUp.
609 2) Create port for the node.
610 3) Attach VIF to the node.
611 4) Try to attach new VIF to the same node with port.
612 5) Check that VIF still attached with original port.
613 """
614 _, self.port = self.create_port(self.node['uuid'],
615 data_utils.rand_mac_address())
616 self.client.vif_attach(self.node['uuid'], self.nport_id)
617 self.assertRaises(lib_exc.BadRequest, self.client.vif_attach,
618 self.node['uuid'], 'test-vif-new')
619 _, port = self.client.show_port(self.port['uuid'])
620 self.assertEqual(self.nport_id,
621 port['internal_info']['tenant_vif_port_id'])
622 self.client.vif_detach(self.node['uuid'], self.nport_id)
623
624 @decorators.attr(type='negative')
625 @decorators.idempotent_id('85b610cd-5ba8-49a7-8ce2-5e364056fd29')
626 def test_vif_attach_no_port(self):
627 """Negative test for VIF attachment attempt with no ports."""
628 self.assertRaises(lib_exc.BadRequest,
629 self.client.vif_attach,
630 self.node['uuid'], self.nport_id)
631
632 @decorators.attr(type='negative')
633 @decorators.idempotent_id('481777b8-8f0d-4932-af3c-1a8e166949f3')
634 def test_vif_attach_with_empty_portgroup(self):
635 """Negative test for VIF attachment attempt to empty port group.
636
637 Test steps:
638 1) Create chassis and node in setUp.
639 2) Create a port group for the node.
640 3) Try to attach VIF to the node.
641 4) Check that VIF info did not get to port group when there is no port.
642 """
643 _, self.portgroup = self.create_portgroup(
644 self.node['uuid'], address=data_utils.rand_mac_address())
645 self.assertRaises(lib_exc.BadRequest, self.client.vif_attach,
646 self.node['uuid'], self.nport_id)
647 _, portgroup = self.client.show_portgroup(self.portgroup['uuid'])
648 self.assertNotIn('tenant_vif_port_id', portgroup['internal_info'])
649
650 @decorators.attr(type='negative')
651 @decorators.idempotent_id('5572fecc-bc22-461a-a891-7f74e2e936bd')
652 def test_vif_attach_port_not_in_portgroup(self):
653 """Negative test for VIF attachment to the port not in port group.
654
655 Test steps:
656 1) Create chassis and node in setUp.
657 2) Create a port group for the node.
658 3) Create a port for the node.
659 4) Attach VIF to the node.
660 5) Check that VIF was attached to the port.
661 6) Check that VIF was NOT attached to the portgroup.
662 """
663 _, self.portgroup = self.create_portgroup(
664 self.node['uuid'], address=data_utils.rand_mac_address())
665 _, self.port = self.create_port(self.node['uuid'],
666 data_utils.rand_mac_address())
667 self.client.vif_attach(self.node['uuid'], self.nport_id)
668 _, port = self.client.show_port(self.port['uuid'])
669 self.assertEqual(self.nport_id,
670 port['internal_info']['tenant_vif_port_id'])
671 _, portgroup = self.client.show_portgroup(self.portgroup['uuid'])
672 self.assertNotIn('tenant_vif_port_id', portgroup['internal_info'])
673 self.client.vif_detach(self.node['uuid'], self.nport_id)
674
675 @decorators.attr(type='negative')
676 @decorators.idempotent_id('3affca81-9f3f-4dab-ad3d-77c892d8d0d7')
677 def test_vif_attach_node_doesnt_exist(self):
678 """Negative test to try to attach VIF to not-existing node."""
679 self.assertRaises(lib_exc.NotFound,
680 self.client.vif_attach,
681 data_utils.rand_uuid(),
682 self.nport_id)
683
684 @decorators.attr(type='negative')
685 @decorators.idempotent_id('da036225-47b0-43b7-9586-0d6390bd3cd9')
686 def test_vif_detach_not_existing(self):
687 """Negative test for VIF detachment of not existing VIF."""
688 self.assertRaises(lib_exc.BadRequest,
689 self.client.vif_detach,
690 self.node['uuid'], self.nport_id)
691
692 @decorators.attr(type='negative')
693 @decorators.idempotent_id('ff3c9ce2-4979-4a54-a860-fab088a6669f')
694 def test_vif_detach_no_args(self):
695 """Negative test for VIF detachment with lack of arguments."""
696 self.assertRaises(lib_exc.BadRequest,
697 self.client.vif_detach,
698 self.node['uuid'], '')
699 self.assertRaises(lib_exc.NotFound,
700 self.client.vif_detach,
701 '', '')
702 self.assertRaises(lib_exc.NotFound,
703 self.client.vif_detach,
704 '', self.nport_id)
705
706
707 class TestHardwareInterfaces(base.BaseBaremetalTest):
708
709 min_microversion = '1.31'
710 # Subclasses can override this with more interfaces available in later API
711 # versions.
712 hardware_interfaces = [
713 'boot',
714 'console',
715 'deploy',
716 'inspect',
717 'management',
718 'power',
719 'raid',
720 'vendor',
721 ]
722
723 @classmethod
724 def skip_checks(cls):
725 super(TestHardwareInterfaces, cls).skip_checks()
726 if CONF.baremetal.driver != 'fake-hardware':
727 raise cls.skipException('These tests rely on fake-hardware')
728
729 @property
730 def optional_interfaces(self):
731 return set(self.hardware_interfaces) - {'boot', 'deploy',
732 'management', 'power'}
733
734 def setUp(self):
735 super(TestHardwareInterfaces, self).setUp()
736
737 _, self.chassis = self.create_chassis()
738 _, self.node = self.create_node(self.chassis['uuid'])
739
740 # Reset optional interfaces to non-default values
741 for iface in self.optional_interfaces:
742 self.client.update_node(self.node['uuid'],
743 [{'path': '/%s_interface' % iface,
744 'op': 'add',
745 'value': 'no-%s' % iface}])
746
747 def test_set_interfaces(self):
748 for iface in self.hardware_interfaces:
749 field = '%s_interface' % iface
750 self.client.update_node(self.node['uuid'],
751 [{'path': '/%s' % field,
752 'op': 'add',
753 'value': 'fake'}])
754 _, node = self.client.show_node(self.node['uuid'])
755 self.assertEqual('fake', node[field])
756
757 def test_reset_interfaces(self):
758 for iface in self.hardware_interfaces:
759 field = '%s_interface' % iface
760 self.client.update_node(self.node['uuid'],
761 [{'path': '/%s' % field,
762 'op': 'remove'}])
763 _, node = self.client.show_node(self.node['uuid'])
764 if (iface in ['boot', 'deploy', 'inspect', 'network']
765 and 'fake' != node[field]):
766 # NOTE(TheJulia): Depending on the remote configuration
767 # these interfaces may have explicit defaults which the
768 # reset action changes the value to. This is okay, but
769 # we need to not fail when that is the case.
770 self.assertNotEqual(self.node[field], node[field])
771 else:
772 self.assertEqual('fake', node[field])
773
774
775 class TestResetInterfaces(TestHardwareInterfaces):
776
777 min_microversion = '1.45'
778
779 @classmethod
780 def skip_checks(cls):
781 super(TestResetInterfaces, cls).skip_checks()
782 if 'ipmi' not in CONF.baremetal.enabled_hardware_types:
783 raise cls.skipException('These tests rely on ipmi enabled')
784
785 def test_no_reset_by_default(self):
786 self.assertRaises(
787 lib_exc.BadRequest,
788 self.client.update_node,
789 self.node['uuid'],
790 [{'path': '/driver', 'value': 'ipmi', 'op': 'replace'}])
791 _, node = self.client.show_node(self.node['uuid'])
792 self.assertEqual('fake-hardware', node['driver'])
793
794 def test_reset_all_interfaces(self):
795 self.client.update_node(self.node['uuid'],
796 [{'path': '/driver',
797 'value': 'ipmi',
798 'op': 'replace'}],
799 reset_interfaces=True)
800 _, node = self.client.show_node(self.node['uuid'])
801 for iface in self.hardware_interfaces:
802 self.assertNotEqual('fake', node['%s_interface' % iface])
803
804
805 class TestNodesTraits(base.BaseBaremetalTest):
806
807 min_microversion = '1.37'
808
809 def setUp(self):
810 super(TestNodesTraits, self).setUp()
811 self.useFixture(
812 api_microversion_fixture.APIMicroversionFixture(
813 TestNodesTraits.min_microversion)
814 )
815 _, self.chassis = self.create_chassis()
816 # One standard trait & one custom trait.
817 self.traits = ['CUSTOM_TRAIT1', 'HW_CPU_X86_VMX']
818 _, self.node = self.create_node(self.chassis['uuid'])
819
820 @decorators.idempotent_id('5c3a2dd0-af10-474d-a209-d30426e1eb5d')
821 def test_list_node_traits(self):
822 """List traits for a node."""
823 _, body = self.client.list_node_traits(self.node['uuid'])
824 self.assertEqual([], body['traits'])
825
826 self.client.set_node_traits(self.node['uuid'], self.traits)
827 _, body = self.client.list_node_traits(self.node['uuid'])
828 self.assertEqual(self.traits, sorted(body['traits']))
829
830 @decorators.attr(type='negative')
831 @decorators.idempotent_id('3b83dbd3-4a89-4173-920a-ca33ed3aad69')
832 def test_list_node_traits_non_existent_node(self):
833 """Try to list traits for a non-existent node."""
834 node_uuid = uuidutils.generate_uuid()
835 self.assertRaises(
836 lib_exc.NotFound,
837 self.client.list_node_traits, node_uuid)
838
839 @decorators.idempotent_id('aa961bf6-ea2f-484b-961b-eae2da0e6b7e')
840 def test_set_node_traits(self):
841 """Set the traits for a node."""
842 self.client.set_node_traits(self.node['uuid'], self.traits)
843
844 _, body = self.client.list_node_traits(self.node['uuid'])
845 self.assertEqual(self.traits, sorted(body['traits']))
846
847 self.client.set_node_traits(self.node['uuid'], [])
848
849 _, body = self.client.list_node_traits(self.node['uuid'])
850 self.assertEqual([], body['traits'])
851
852 @decorators.idempotent_id('727a5e11-5654-459f-8af6-e14eb987a283')
853 def test_set_node_traits_max_traits(self):
854 """Set the maximum number of traits for a node."""
855 traits = ['CUSTOM_TRAIT%d' % i for i in range(50)]
856 self.client.set_node_traits(self.node['uuid'], traits)
857
858 _, body = self.client.list_node_traits(self.node['uuid'])
859 self.assertEqual(sorted(traits), sorted(body['traits']))
860
861 @decorators.attr(type='negative')
862 @decorators.idempotent_id('75831f5d-ca44-403b-8fd6-f7cad95b1c54')
863 def test_set_node_traits_too_many(self):
864 """Set more than the maximum number of traits for a node."""
865 traits = ['CUSTOM_TRAIT%d' % i for i in range(51)]
866 self.assertRaises(
867 lib_exc.BadRequest,
868 self.client.set_node_traits, self.node['uuid'], traits)
869
870 _, body = self.client.list_node_traits(self.node['uuid'])
871 self.assertEqual([], body['traits'])
872
873 @decorators.idempotent_id('d81ceeab-a50f-427a-bc5a-aa916478d0d3')
874 def test_set_node_traits_duplicate_trait(self):
875 """Set the traits for a node, ensuring duplicates are ignored."""
876 self.client.set_node_traits(self.node['uuid'],
877 ['CUSTOM_TRAIT1', 'CUSTOM_TRAIT1'])
878
879 _, body = self.client.list_node_traits(self.node['uuid'])
880 self.assertEqual(['CUSTOM_TRAIT1'], body['traits'])
881
882 @decorators.attr(type='negative')
883 @decorators.idempotent_id('2fb4c9d9-8e5b-4189-b547-26596014491c')
884 def test_set_node_traits_non_existent_node(self):
885 """Try to set traits for a non-existent node."""
886 node_uuid = uuidutils.generate_uuid()
887 self.assertRaises(
888 lib_exc.NotFound,
889 self.client.set_node_traits, node_uuid, ['CUSTOM_TRAIT1'])
890
891 @decorators.idempotent_id('47db09d9-af2b-424d-9d51-7efca2920f20')
892 def test_add_node_trait_long(self):
893 """Add a node trait of the largest possible length."""
894 trait_long_name = 'CUSTOM_' + data_utils.arbitrary_string(248).upper()
895 self.client.add_node_trait(self.node['uuid'], trait_long_name)
896
897 _, body = self.client.list_node_traits(self.node['uuid'])
898 self.assertEqual([trait_long_name], body['traits'])
899
900 @decorators.attr(type='negative')
901 @decorators.idempotent_id('2a4daa8d-2b85-40ac-a8a0-0462cc9a57ef')
902 def test_add_node_trait_too_long(self):
903 """Try to add a node trait longer than the largest possible length."""
904 trait_long_name = 'CUSTOM_' + data_utils.arbitrary_string(249).upper()
905 self.assertRaises(
906 lib_exc.BadRequest,
907 self.client.add_node_trait, self.node['uuid'], trait_long_name)
908
909 _, body = self.client.list_node_traits(self.node['uuid'])
910 self.assertEqual([], body['traits'])
911
912 @decorators.idempotent_id('4b737e7f-101e-493e-b5ce-494fbffe18fd')
913 def test_add_node_trait_duplicate_trait(self):
914 """Add a node trait that already exists."""
915 self.client.add_node_trait(self.node['uuid'], 'CUSTOM_TRAIT1')
916 self.client.add_node_trait(self.node['uuid'], 'CUSTOM_TRAIT1')
917
918 _, body = self.client.list_node_traits(self.node['uuid'])
919 self.assertEqual(['CUSTOM_TRAIT1'], body['traits'])
920
921 @decorators.attr(type='negative')
922 @decorators.idempotent_id('65bce181-89ce-435e-a7d8-3ba60aafd08d')
923 def test_add_node_trait_too_many(self):
924 """Add a trait to a node that would exceed the maximum."""
925 traits = ['CUSTOM_TRAIT%d' % i for i in range(50)]
926 self.client.set_node_traits(self.node['uuid'], traits)
927
928 self.assertRaises(
929 lib_exc.BadRequest,
930 self.client.add_node_trait, self.node['uuid'], 'CUSTOM_TRAIT50')
931
932 _, body = self.client.list_node_traits(self.node['uuid'])
933 self.assertEqual(sorted(traits), sorted(body['traits']))
934
935 @decorators.attr(type='negative')
936 @decorators.idempotent_id('cca0e831-32af-4ce9-bfce-d3834fea57aa')
937 def test_add_node_trait_non_existent_node(self):
938 """Try to add a trait to a non-existent node."""
939 node_uuid = uuidutils.generate_uuid()
940 self.assertRaises(
941 lib_exc.NotFound,
942 self.client.add_node_trait, node_uuid, 'CUSTOM_TRAIT1')
943
944 @decorators.idempotent_id('e4bf8bf0-3004-44bc-8bfe-f9f1a167d999')
945 def test_remove_node_traits(self):
946 """Remove all traits from a node."""
947 self.client.set_node_traits(self.node['uuid'], self.traits)
948
949 self.client.remove_node_traits(self.node['uuid'])
950
951 _, body = self.client.list_node_traits(self.node['uuid'])
952 self.assertEqual([], body['traits'])
953
954 @decorators.idempotent_id('4d8c9a35-0036-4139-85c1-5f242395680f')
955 def test_remove_node_traits_no_traits(self):
956 """Remove all traits from a node that has no traits."""
957 self.client.remove_node_traits(self.node['uuid'])
958
959 _, body = self.client.list_node_traits(self.node['uuid'])
960 self.assertEqual([], body['traits'])
961
962 @decorators.attr(type='negative')
963 @decorators.idempotent_id('625c911a-48e8-4bef-810b-7cf33c0846a2')
964 def test_remove_node_traits_non_existent_node(self):
965 """Try to remove all traits from a non-existent node."""
966 node_uuid = uuidutils.generate_uuid()
967 self.assertRaises(
968 lib_exc.NotFound,
969 self.client.remove_node_traits, node_uuid)
970
971 @decorators.idempotent_id('3591d514-39b9-425e-9afe-ea74ae347486')
972 def test_remove_node_trait(self):
973 """Remove a trait from a node."""
974 self.client.set_node_traits(self.node['uuid'], self.traits)
975
976 self.client.remove_node_trait(self.node['uuid'], 'CUSTOM_TRAIT1')
977
978 _, body = self.client.list_node_traits(self.node['uuid'])
979 self.assertEqual(['HW_CPU_X86_VMX'], body['traits'])
980
981 @decorators.attr(type='negative')
982 @decorators.idempotent_id('b50ae543-5e5e-4b1a-b2f2-9e00fe55974b')
983 def test_remove_node_trait_non_existent_trait(self):
984 """Try to remove a non-existent trait from a node."""
985 self.assertRaises(
986 lib_exc.NotFound,
987 self.client.remove_node_trait, self.node['uuid'], 'CUSTOM_TRAIT1')
988
989 @decorators.attr(type='negative')
990 @decorators.idempotent_id('f1469745-7cdf-4cae-9699-73d029c47bc3')
991 def test_remove_node_trait_non_existent_node(self):
992 """Try to remove a trait from a non-existent node."""
993 node_uuid = uuidutils.generate_uuid()
994 self.assertRaises(
995 lib_exc.NotFound,
996 self.client.remove_node_trait, node_uuid, 'CUSTOM_TRAIT1')
997
998 @decorators.idempotent_id('03f9e57f-e584-448a-926f-53035e583e7e')
999 def test_list_nodes_detail(self):
1000 """Get detailed nodes list."""
1001 self.client.set_node_traits(self.node['uuid'], self.traits)
1002
1003 _, body = self.client.list_nodes_detail()
1004 self.assertGreaterEqual(len(body['nodes']), 1)
1005
1006 for node in body['nodes']:
1007 self.assertIn('traits', node)
1008 if node['uuid'] == self.node['uuid']:
1009 self.assertEqual(self.traits, sorted(node['traits']))
1010
1011 @decorators.idempotent_id('2b82f704-1580-403a-af92-92c29a7eebb7')
1012 def test_list_nodes_traits_field(self):
1013 """Get nodes list with the traits field."""
1014 self.client.set_node_traits(self.node['uuid'], self.traits)
1015
1016 _, body = self.client.list_nodes(fields='uuid,traits')
1017 self.assertGreaterEqual(len(body['nodes']), 1)
1018
1019 for node in body['nodes']:
1020 self.assertIn('traits', node)
1021 if node['uuid'] == self.node['uuid']:
1022 self.assertEqual(self.traits, sorted(node['traits']))
1023
1024 @decorators.idempotent_id('c83c537a-76aa-4d8a-8673-128d01ee403d')
1025 def test_show_node(self):
1026 """Show a node with traits."""
1027 self.client.set_node_traits(self.node['uuid'], self.traits)
1028
1029 _, body = self.client.show_node(self.node['uuid'])
1030
1031 self.assertIn('traits', body)
1032 self.assertEqual(self.traits, sorted(body['traits']))
1033
1034 @decorators.attr(type='negative')
1035 @decorators.idempotent_id('9ab6a19c-83b9-4600-b55b-325a51e2f8f6')
1036 def test_update_node_traits(self):
1037 """Try updating an existing node with traits."""
1038 patch = [{'path': '/traits',
1039 'op': 'add',
1040 'value': ['CUSTOM_TRAIT1']}]
1041 self.assertRaises(
1042 lib_exc.BadRequest,
1043 self.client.update_node, self.node['uuid'], patch)
1044
1045 _, body = self.client.list_node_traits(self.node['uuid'])
1046 self.assertEqual([], body['traits'])
1047
1048
1049 class TestNodesTraitsOldApi(base.BaseBaremetalTest):
1050
1051 def setUp(self):
1052 super(TestNodesTraitsOldApi, self).setUp()
1053 _, self.chassis = self.create_chassis()
1054 _, self.node = self.create_node(self.chassis['uuid'])
1055
1056 @decorators.attr(type='negative')
1057 @decorators.idempotent_id('5419af7b-4e27-4be4-88f6-e01c598a8102')
1058 def test_list_node_traits_old_api(self):
1059 """Try to list traits for a node using an older api version."""
1060 self.assertRaises(
1061 lib_exc.NotAcceptable,
1062 self.client.list_node_traits, self.node['uuid'])
1063
1064 @decorators.attr(type='negative')
1065 @decorators.idempotent_id('a4353f3a-bedc-4579-9c7e-4bebcd95903d')
1066 def test_add_node_trait_old_api(self):
1067 """Try to add a trait to a node using an older api version."""
1068 exc = self.assertRaises(
1069 lib_exc.UnexpectedResponseCode,
1070 self.client.add_node_trait, self.node['uuid'], 'CUSTOM_TRAIT1')
1071 self.assertEqual(405, exc.resp.status)
1072
1073 @decorators.attr(type='negative')
1074 @decorators.idempotent_id('91cc43d8-2f6f-4b1b-95e9-68dedca54e6b')
1075 def test_set_node_traits_old_api(self):
1076 """Try to set traits for a node using an older api version."""
1077 exc = self.assertRaises(
1078 lib_exc.UnexpectedResponseCode,
1079 self.client.set_node_traits, self.node['uuid'], ['CUSTOM_TRAIT1'])
1080 self.assertEqual(405, exc.resp.status)
1081
1082 @decorators.attr(type='negative')
1083 @decorators.idempotent_id('0f9af890-a57a-4c25-86c8-6418d1b8f4d4')
1084 def test_remove_node_trait_old_api(self):
1085 """Try to remove a trait from a node using an older api version."""
1086 self.assertRaises(
1087 lib_exc.NotFound,
1088 self.client.remove_node_trait, self.node['uuid'], 'CUSTOM_TRAIT1')
1089
1090 @decorators.attr(type='negative')
1091 @decorators.idempotent_id('f8375b3c-1939-4d1c-97c4-d23e10680090')
1092 def test_remove_node_traits_old_api(self):
1093 """Try to remove all traits from a node using an older api version."""
1094 self.assertRaises(
1095 lib_exc.NotFound,
1096 self.client.remove_node_traits, self.node['uuid'])
1097
1098 @decorators.attr(type='negative')
1099 @decorators.idempotent_id('525eeb59-b7ce-413d-a37b-401e67402a4c')
1100 def test_list_nodes_detail_old_api(self):
1101 """Get detailed nodes list, ensure they have no traits."""
1102 _, body = self.client.list_nodes_detail()
1103 self.assertGreaterEqual(len(body['nodes']), 1)
1104
1105 for node in body['nodes']:
1106 self.assertNotIn('traits', node)
1107
1108 @decorators.attr(type='negative')
1109 @decorators.idempotent_id('eb75b3c8-ac9c-4399-90a2-c0030bfde7a6')
1110 def test_list_nodes_traits_field(self):
1111 """Try to list nodes' traits field using older api version."""
1112 self.assertRaises(
1113 lib_exc.NotAcceptable,
1114 self.client.list_nodes, fields='traits')
1115
1116 @decorators.attr(type='negative')
1117 @decorators.idempotent_id('214ae7fc-149b-4657-b6bc-66353d49ade8')
1118 def test_show_node_old_api(self):
1119 """Show a node, ensure it has no traits."""
1120 _, body = self.client.show_node(self.node['uuid'])
1121 self.assertNotIn('traits', body)
1122
1123
1124 class TestNodeFault(base.BaseBaremetalTest):
1125 """Tests for fault of baremetal nodes."""
1126
1127 min_microversion = '1.42'
1128
1129 def setUp(self):
1130 super(TestNodeFault, self).setUp()
1131
1132 _, self.chassis = self.create_chassis()
1133 _, self.node = self.create_node(self.chassis['uuid'])
1134
1135 @decorators.idempotent_id('649b4660-4f76-4d67-94df-6631a2cb2cd9')
1136 def test_fault_shown(self):
1137 _, loaded_node = self.client.show_node(self.node['uuid'])
1138 self.assertIn('fault', loaded_node)
1139
1140 @decorators.idempotent_id('62f453be-8f30-4cfe-a19a-23656068e546')
1141 def test_list_nodes_fault(self):
1142 _, body = self.client.list_nodes()
1143 self.assertIn(self.node['uuid'], [n['uuid'] for n in body['nodes']])
1144
1145 _, body = self.client.list_nodes(fault='power failure')
1146 self.assertNotIn(self.node['uuid'],
1147 [n['uuid'] for n in body['nodes']])
1148
1149 @decorators.idempotent_id('c8fb55f1-873f-4fb9-bd57-6f1de0479873')
1150 def test_list_nodes_with_invalid_fault(self):
1151 self.assertRaises(
1152 lib_exc.BadRequest,
1153 self.client.list_nodes, fault='somefake')
1154
1155
1156 class TestNodeProtected(base.BaseBaremetalTest):
1157 """Tests for protected baremetal nodes."""
1158
1159 min_microversion = '1.48'
1160
1161 def setUp(self):
1162 super(TestNodeProtected, self).setUp()
1163
1164 _, self.chassis = self.create_chassis()
1165 _, self.node = self.create_node(
1166 self.chassis['uuid'],
1167 # Fake deploy interface to bypass cleaning in the test flow.
1168 deploy_interface='fake',
1169 # Noop network interface to skip networking involvement.
1170 network_interface='noop')
1171 self.provide_node(self.node['uuid'])
1172
1173 @decorators.idempotent_id('52f0cb1c-ad7b-43dc-8e22-a76438b67716')
1174 def test_node_protected_set_unset(self):
1175 self.deploy_node(self.node['uuid'])
1176 _, self.node = self.client.show_node(self.node['uuid'])
1177 self.assertFalse(self.node['protected'])
1178 self.assertIsNone(self.node['protected_reason'])
1179
1180 self.client.update_node(self.node['uuid'], protected=True,
1181 protected_reason='reason!')
1182 _, self.node = self.client.show_node(self.node['uuid'])
1183 self.assertTrue(self.node['protected'])
1184 self.assertEqual('reason!', self.node['protected_reason'])
1185
1186 self.client.update_node(self.node['uuid'], protected=False)
1187 _, self.node = self.client.show_node(self.node['uuid'])
1188 self.assertFalse(self.node['protected'])
1189 self.assertIsNone(self.node['protected_reason'])
1190
1191 @decorators.idempotent_id('8fbd101e-90e6-4843-b41a-556b34802972')
1192 def test_node_protected(self):
1193 self.deploy_node(self.node['uuid'])
1194 self.client.update_node(self.node['uuid'], protected=True)
1195
1196 self.assertRaises(lib_exc.Forbidden,
1197 self.set_node_provision_state,
1198 self.node['uuid'], 'deleted', 'available')
1199 self.assertRaises(lib_exc.Forbidden,
1200 self.set_node_provision_state,
1201 self.node['uuid'], 'rebuild', 'active')
1202 self.client.update_node(self.node['uuid'], protected=False)
1203
1204 @decorators.idempotent_id('04a21b51-2991-4213-8c2f-a96cfdada802')
1205 def test_node_protected_from_deletion(self):
1206 self.deploy_node(self.node['uuid'])
1207 self.client.update_node(self.node['uuid'], protected=True,
1208 maintenance=True)
1209 # undo maintenance because we can't teardown something
1210 # in maintenance.
1211 self.addCleanup(self.client.update_node, self.node['uuid'],
1212 maintenance=False)
1213 self.assertRaises(lib_exc.Forbidden,
1214 self.client.delete_node,
1215 self.node['uuid'])
1216 self.client.update_node(self.node['uuid'], protected=False)
1217
1218 @decorators.attr(type='negative')
1219 @decorators.idempotent_id('1c819f4c-6c1d-4150-ba4a-3b0dcb3c8694')
1220 def test_node_protected_negative(self):
1221 # Cannot be set for available nodes
1222 self.assertRaises(lib_exc.Conflict,
1223 self.client.update_node,
1224 self.node['uuid'], protected=True)
1225
1226 self.deploy_node(self.node['uuid'])
1227
1228 # Reason cannot be set for nodes that are not protected
1229 self.assertRaises(lib_exc.BadRequest,
1230 self.client.update_node,
1231 self.node['uuid'], protected_reason='reason!')
1232 self.client.update_node(self.node['uuid'], protected=False)
1233
1234
1235 class TestNodesProtectedOldApi(base.BaseBaremetalTest):
1236
1237 def setUp(self):
1238 super(TestNodesProtectedOldApi, self).setUp()
1239 _, self.chassis = self.create_chassis()
1240
1241 _, self.node = self.create_node(self.chassis['uuid'])
1242 self.useFixture(
1243 api_microversion_fixture.APIMicroversionFixture('1.31'))
1244 # Now with a 1.31 microversion, swap the deploy and network
1245 # interfaces into place so the test doesn't break depending on
1246 # the environment's default state.
1247 self.client.update_node(self.node['uuid'],
1248 [{'path': '/deploy_interface',
1249 'op': 'replace',
1250 'value': 'fake'},
1251 {'path': '/network_interface',
1252 'op': 'replace',
1253 'value': 'noop'}])
1254 self.useFixture(api_microversion_fixture.APIMicroversionFixture('1.1'))
1255 self.deploy_node(self.node['uuid'])
1256 _, self.node = self.client.show_node(self.node['uuid'])
1257
1258 @decorators.attr(type='negative')
1259 @decorators.idempotent_id('08971546-27cc-40ab-851e-ba7bb52c00ab')
1260 def test_node_protected_old_api(self):
1261 exc = self.assertRaises(
1262 lib_exc.RestClientException,
1263 self.client.update_node, self.node['uuid'], protected=True)
1264 # 400 for old ironic, 406 for new ironic with old microversion.
1265 self.assertIn(exc.resp.status, (400, 406))
1266
1267
1268 class TestNodeConductor(base.BaseBaremetalTest):
1269 """Tests for conductor field of baremetal nodes."""
1270
1271 min_microversion = '1.49'
1272
1273 def setUp(self):
1274 super(TestNodeConductor, self).setUp()
1275
1276 _, self.chassis = self.create_chassis()
1277 _, self.node = self.create_node(self.chassis['uuid'])
1278
1279 @decorators.idempotent_id('1af888b2-2a19-43da-8181-a5381d6ff536')
1280 def test_conductor_exposed(self):
1281 _, loaded_node = self.client.show_node(self.node['uuid'])
1282 self.assertIn('conductor', loaded_node)
1283
1284 @decorators.idempotent_id('53bcef99-2989-4755-aa8f-c31037cd15de')
1285 def test_list_nodes_by_conductor(self):
1286 _, loaded_node = self.client.show_node(self.node['uuid'])
1287 hostname = loaded_node['conductor']
1288
1289 _, nodes = self.client.list_nodes(conductor=hostname)
1290 self.assertIn(self.node['uuid'],
1291 [n['uuid'] for n in nodes['nodes']])
1292
1293
1294 class TestNodeDescription(base.BaseBaremetalTest):
1295 """Tests for the description field."""
1296
1297 min_microversion = '1.51'
1298
1299 def setUp(self):
1300 super(TestNodeDescription, self).setUp()
1301
1302 _, self.chassis = self.create_chassis()
1303 _, self.node = self.create_node(self.chassis['uuid'])
1304
1305 @decorators.idempotent_id('66d0da49-e5ac-4f49-b065-9d2207d8a3af')
1306 def test_description_exposed(self):
1307 _, loaded_node = self.client.show_node(self.node['uuid'])
1308 self.assertIn('description', loaded_node)
1309
1310 @decorators.idempotent_id('85b4a4b5-37e5-4b60-8dc7-f5a26dfa78a3')
1311 def test_node_description_set_unset(self):
1312 self.client.update_node(self.node['uuid'], description='meow')
1313 _, self.node = self.client.show_node(self.node['uuid'])
1314 self.assertEqual('meow', self.node['description'])
1315
1316 self.client.update_node(self.node['uuid'], description=None)
1317 _, self.node = self.client.show_node(self.node['uuid'])
1318 self.assertIsNone(self.node['description'])
1319
1320 @decorators.idempotent_id('3d649bb3-a58b-4b9e-8dfa-41ab634b1153')
1321 def test_create_node_with_description(self):
1322 _, body = self.create_node(self.chassis['uuid'], description='meow')
1323 self.assertEqual('meow', body['description'])
1324
1325
1326 class TestNodeGraphicalConsole(base.BaseBaremetalTest,
1327 compute.NoVNCValidateMixin):
1328 """Tests for fake-graphical console connection."""
1329
1330 min_microversion = '1.96'
1331
1332 @classmethod
1333 def skip_checks(cls):
1334 super(TestNodeGraphicalConsole, cls).skip_checks()
1335 if CONF.baremetal.driver != 'fake-hardware':
1336 raise cls.skipException('These tests rely on fake-hardware')
1337 if 'fake-graphical' not in CONF.baremetal.enabled_console_interfaces:
1338 raise cls.skipException('These tests rely on fake-graphical being'
1339 'included in enabled_console_interfaces')
1340
1341 def setUp(self):
1342 super(TestNodeGraphicalConsole, self).setUp()
1343
1344 _, self.chassis = self.create_chassis()
1345 _, self.node = self.create_node(self.chassis['uuid'],
1346 console_interface="fake-graphical")
1347
1348 @decorators.idempotent_id('80504575-9b21-4670-92d1-143b948f9437')
1349 def test_graphical_console_connection(self):
1350 self.client.set_console_mode(self.node['uuid'], True)
1351 waiters.wait_for_bm_node_status(self.client, self.node['uuid'],
1352 'console_enabled', True)
1353 self.addCleanup(self.client.set_console_mode, self.node['uuid'],
1354 False)
1355
1356 _, body = self.client.get_console(self.node['uuid'])
1357 console_info = body['console_info']
1358 self.assertEqual('vnc', console_info['type'])
1359 # Do the initial HTTP Request to novncproxy to get the NoVNC JavaScript
1360 self.validate_novnc_html(console_info['url'])
1361 # Do the WebSockify HTTP Request to novncproxy to do the RFB connection
1362 self.websocket = compute.create_websocket(console_info['url'])
1363 self.addCleanup(self.websocket.close)
1364 # Validate that we successfully connected and upgraded to Web Sockets
1365 self.validate_websocket_upgrade()
1366 # Validate the RFB Negotiation to determine if a valid VNC session
1367 self.validate_rfb_negotiation()