blob: c0733291a714a8df2187ef7177522a5d46dacc84 [file] [log] [blame]
Michal Kobusf6113582019-09-09 15:58:21 +02001package testing
2
3import (
4 "fmt"
5 "net/http"
6 "testing"
7
8 "gerrit.mcp.mirantis.net/debian/gophercloud.git/openstack/baremetal/v1/nodes"
9 th "gerrit.mcp.mirantis.net/debian/gophercloud.git/testhelper"
10 "gerrit.mcp.mirantis.net/debian/gophercloud.git/testhelper/client"
11)
12
13// NodeListBody contains the canned body of a nodes.List response, without detail.
14const NodeListBody = `
15 {
16 "nodes": [
17 {
18 "instance_uuid": null,
19 "links": [
20 {
21 "href": "http://ironic.example.com:6385/v1/nodes/d2630783-6ec8-4836-b556-ab427c4b581e",
22 "rel": "self"
23 },
24 {
25 "href": "http://ironic.example.com:6385/nodes/d2630783-6ec8-4836-b556-ab427c4b581e",
26 "rel": "bookmark"
27 }
28 ],
29 "maintenance": false,
30 "name": "foo",
31 "power_state": null,
32 "provision_state": "enroll"
33 },
34 {
35 "instance_uuid": null,
36 "links": [
37 {
38 "href": "http://ironic.example.com:6385/v1/nodes/08c84581-58f5-4ea2-a0c6-dd2e5d2b3662",
39 "rel": "self"
40 },
41 {
42 "href": "http://ironic.example.com:6385/nodes/08c84581-58f5-4ea2-a0c6-dd2e5d2b3662",
43 "rel": "bookmark"
44 }
45 ],
46 "maintenance": false,
47 "name": "bar",
48 "power_state": null,
49 "provision_state": "enroll"
50 },
51 {
52 "instance_uuid": null,
53 "links": [
54 {
55 "href": "http://ironic.example.com:6385/v1/nodes/c9afd385-5d89-4ecb-9e1c-68194da6b474",
56 "rel": "self"
57 },
58 {
59 "href": "http://ironic.example.com:6385/nodes/c9afd385-5d89-4ecb-9e1c-68194da6b474",
60 "rel": "bookmark"
61 }
62 ],
63 "maintenance": false,
64 "name": "baz",
65 "power_state": null,
66 "provision_state": "enroll"
67 }
68 ]
69}
70`
71
72// NodeListDetailBody contains the canned body of a nodes.ListDetail response.
73const NodeListDetailBody = `
74 {
75 "nodes": [
76 {
77 "bios_interface": "no-bios",
78 "boot_interface": "pxe",
79 "chassis_uuid": null,
80 "clean_step": {},
81 "conductor_group": "",
82 "console_enabled": false,
83 "console_interface": "no-console",
84 "created_at": "2019-01-31T19:59:28+00:00",
85 "deploy_interface": "iscsi",
86 "deploy_step": {},
87 "driver": "ipmi",
88 "driver_info": {
89 "ipmi_port": "6230",
90 "ipmi_username": "admin",
91 "deploy_kernel": "http://172.22.0.1/images/tinyipa-stable-rocky.vmlinuz",
92 "ipmi_address": "192.168.122.1",
93 "deploy_ramdisk": "http://172.22.0.1/images/tinyipa-stable-rocky.gz",
94 "ipmi_password": "admin"
95
96 },
97 "driver_internal_info": {},
98 "extra": {},
99 "fault": null,
100 "inspect_interface": "no-inspect",
101 "inspection_finished_at": null,
102 "inspection_started_at": null,
103 "instance_info": {},
104 "instance_uuid": null,
105 "last_error": null,
106 "links": [
107 {
108 "href": "http://ironic.example.com:6385/v1/nodes/d2630783-6ec8-4836-b556-ab427c4b581e",
109 "rel": "self"
110 },
111 {
112 "href": "http://ironic.example.com:6385/nodes/d2630783-6ec8-4836-b556-ab427c4b581e",
113 "rel": "bookmark"
114 }
115 ],
116 "maintenance": false,
117 "maintenance_reason": null,
118 "management_interface": "ipmitool",
119 "name": "foo",
120 "network_interface": "flat",
121 "portgroups": [
122 {
123 "href": "http://ironic.example.com:6385/v1/nodes/d2630783-6ec8-4836-b556-ab427c4b581e/portgroups",
124 "rel": "self"
125 },
126 {
127 "href": "http://ironic.example.com:6385/nodes/d2630783-6ec8-4836-b556-ab427c4b581e/portgroups",
128 "rel": "bookmark"
129 }
130 ],
131 "ports": [
132 {
133 "href": "http://ironic.example.com:6385/v1/nodes/d2630783-6ec8-4836-b556-ab427c4b581e/ports",
134 "rel": "self"
135 },
136 {
137 "href": "http://ironic.example.com:6385/nodes/d2630783-6ec8-4836-b556-ab427c4b581e/ports",
138 "rel": "bookmark"
139 }
140 ],
141 "power_interface": "ipmitool",
142 "power_state": null,
143 "properties": {},
144 "provision_state": "enroll",
145 "provision_updated_at": null,
146 "raid_config": {},
147 "raid_interface": "no-raid",
148 "rescue_interface": "no-rescue",
149 "reservation": null,
150 "resource_class": null,
151 "states": [
152 {
153 "href": "http://ironic.example.com:6385/v1/nodes/d2630783-6ec8-4836-b556-ab427c4b581e/states",
154 "rel": "self"
155 },
156 {
157 "href": "http://ironic.example.com:6385/nodes/d2630783-6ec8-4836-b556-ab427c4b581e/states",
158 "rel": "bookmark"
159 }
160 ],
161 "storage_interface": "noop",
162 "target_power_state": null,
163 "target_provision_state": null,
164 "target_raid_config": {},
165 "traits": [],
166 "updated_at": null,
167 "uuid": "d2630783-6ec8-4836-b556-ab427c4b581e",
168 "vendor_interface": "ipmitool",
169 "volume": [
170 {
171 "href": "http://ironic.example.com:6385/v1/nodes/d2630783-6ec8-4836-b556-ab427c4b581e/volume",
172 "rel": "self"
173 },
174 {
175 "href": "http://ironic.example.com:6385/nodes/d2630783-6ec8-4836-b556-ab427c4b581e/volume",
176 "rel": "bookmark"
177 }
178 ]
179 },
180 {
181 "bios_interface": "no-bios",
182 "boot_interface": "pxe",
183 "chassis_uuid": null,
184 "clean_step": {},
185 "conductor_group": "",
186 "console_enabled": false,
187 "console_interface": "no-console",
188 "created_at": "2019-01-31T19:59:29+00:00",
189 "deploy_interface": "iscsi",
190 "deploy_step": {},
191 "driver": "ipmi",
192 "driver_info": {},
193 "driver_internal_info": {},
194 "extra": {},
195 "fault": null,
196 "inspect_interface": "no-inspect",
197 "inspection_finished_at": null,
198 "inspection_started_at": null,
199 "instance_info": {},
200 "instance_uuid": null,
201 "last_error": null,
202 "links": [
203 {
204 "href": "http://ironic.example.com:6385/v1/nodes/08c84581-58f5-4ea2-a0c6-dd2e5d2b3662",
205 "rel": "self"
206 },
207 {
208 "href": "http://ironic.example.com:6385/nodes/08c84581-58f5-4ea2-a0c6-dd2e5d2b3662",
209 "rel": "bookmark"
210 }
211 ],
212 "maintenance": false,
213 "maintenance_reason": null,
214 "management_interface": "ipmitool",
215 "name": "bar",
216 "network_interface": "flat",
217 "portgroups": [
218 {
219 "href": "http://ironic.example.com:6385/v1/nodes/08c84581-58f5-4ea2-a0c6-dd2e5d2b3662/portgroups",
220 "rel": "self"
221 },
222 {
223 "href": "http://ironic.example.com:6385/nodes/08c84581-58f5-4ea2-a0c6-dd2e5d2b3662/portgroups",
224 "rel": "bookmark"
225 }
226 ],
227 "ports": [
228 {
229 "href": "http://ironic.example.com:6385/v1/nodes/08c84581-58f5-4ea2-a0c6-dd2e5d2b3662/ports",
230 "rel": "self"
231 },
232 {
233 "href": "http://ironic.example.com:6385/nodes/08c84581-58f5-4ea2-a0c6-dd2e5d2b3662/ports",
234 "rel": "bookmark"
235 }
236 ],
237 "power_interface": "ipmitool",
238 "power_state": null,
239 "properties": {},
240 "provision_state": "enroll",
241 "provision_updated_at": null,
242 "raid_config": {},
243 "raid_interface": "no-raid",
244 "rescue_interface": "no-rescue",
245 "reservation": null,
246 "resource_class": null,
247 "states": [
248 {
249 "href": "http://ironic.example.com:6385/v1/nodes/08c84581-58f5-4ea2-a0c6-dd2e5d2b3662/states",
250 "rel": "self"
251 },
252 {
253 "href": "http://ironic.example.com:6385/nodes/08c84581-58f5-4ea2-a0c6-dd2e5d2b3662/states",
254 "rel": "bookmark"
255 }
256 ],
257 "storage_interface": "noop",
258 "target_power_state": null,
259 "target_provision_state": null,
260 "target_raid_config": {},
261 "traits": [],
262 "updated_at": null,
263 "uuid": "08c84581-58f5-4ea2-a0c6-dd2e5d2b3662",
264 "vendor_interface": "ipmitool",
265 "volume": [
266 {
267 "href": "http://ironic.example.com:6385/v1/nodes/08c84581-58f5-4ea2-a0c6-dd2e5d2b3662/volume",
268 "rel": "self"
269 },
270 {
271 "href": "http://ironic.example.com:6385/nodes/08c84581-58f5-4ea2-a0c6-dd2e5d2b3662/volume",
272 "rel": "bookmark"
273 }
274 ]
275 },
276 {
277 "bios_interface": "no-bios",
278 "boot_interface": "pxe",
279 "chassis_uuid": null,
280 "clean_step": {},
281 "conductor_group": "",
282 "console_enabled": false,
283 "console_interface": "no-console",
284 "created_at": "2019-01-31T19:59:30+00:00",
285 "deploy_interface": "iscsi",
286 "deploy_step": {},
287 "driver": "ipmi",
288 "driver_info": {},
289 "driver_internal_info": {},
290 "extra": {},
291 "fault": null,
292 "inspect_interface": "no-inspect",
293 "inspection_finished_at": null,
294 "inspection_started_at": null,
295 "instance_info": {},
296 "instance_uuid": null,
297 "last_error": null,
298 "links": [
299 {
300 "href": "http://ironic.example.com:6385/v1/nodes/c9afd385-5d89-4ecb-9e1c-68194da6b474",
301 "rel": "self"
302 },
303 {
304 "href": "http://ironic.example.com:6385/nodes/c9afd385-5d89-4ecb-9e1c-68194da6b474",
305 "rel": "bookmark"
306 }
307 ],
308 "maintenance": false,
309 "maintenance_reason": null,
310 "management_interface": "ipmitool",
311 "name": "baz",
312 "network_interface": "flat",
313 "portgroups": [
314 {
315 "href": "http://ironic.example.com:6385/v1/nodes/c9afd385-5d89-4ecb-9e1c-68194da6b474/portgroups",
316 "rel": "self"
317 },
318 {
319 "href": "http://ironic.example.com:6385/nodes/c9afd385-5d89-4ecb-9e1c-68194da6b474/portgroups",
320 "rel": "bookmark"
321 }
322 ],
323 "ports": [
324 {
325 "href": "http://ironic.example.com:6385/v1/nodes/c9afd385-5d89-4ecb-9e1c-68194da6b474/ports",
326 "rel": "self"
327 },
328 {
329 "href": "http://ironic.example.com:6385/nodes/c9afd385-5d89-4ecb-9e1c-68194da6b474/ports",
330 "rel": "bookmark"
331 }
332 ],
333 "power_interface": "ipmitool",
334 "power_state": null,
335 "properties": {},
336 "provision_state": "enroll",
337 "provision_updated_at": null,
338 "raid_config": {},
339 "raid_interface": "no-raid",
340 "rescue_interface": "no-rescue",
341 "reservation": null,
342 "resource_class": null,
343 "states": [
344 {
345 "href": "http://ironic.example.com:6385/v1/nodes/c9afd385-5d89-4ecb-9e1c-68194da6b474/states",
346 "rel": "self"
347 },
348 {
349 "href": "http://ironic.example.com:6385/nodes/c9afd385-5d89-4ecb-9e1c-68194da6b474/states",
350 "rel": "bookmark"
351 }
352 ],
353 "storage_interface": "noop",
354 "target_power_state": null,
355 "target_provision_state": null,
356 "target_raid_config": {},
357 "traits": [],
358 "updated_at": null,
359 "uuid": "c9afd385-5d89-4ecb-9e1c-68194da6b474",
360 "vendor_interface": "ipmitool",
361 "volume": [
362 {
363 "href": "http://ironic.example.com:6385/v1/nodes/c9afd385-5d89-4ecb-9e1c-68194da6b474/volume",
364 "rel": "self"
365 },
366 {
367 "href": "http://ironic.example.com:6385/nodes/c9afd385-5d89-4ecb-9e1c-68194da6b474/volume",
368 "rel": "bookmark"
369 }
370 ]
371 }
372 ]
373}
374`
375
376// SingleNodeBody is the canned body of a Get request on an existing node.
377const SingleNodeBody = `
378{
379 "bios_interface": "no-bios",
380 "boot_interface": "pxe",
381 "chassis_uuid": null,
382 "clean_step": {},
383 "conductor_group": "",
384 "console_enabled": false,
385 "console_interface": "no-console",
386 "created_at": "2019-01-31T19:59:28+00:00",
387 "deploy_interface": "iscsi",
388 "deploy_step": {},
389 "driver": "ipmi",
390 "driver_info": {
391 "ipmi_port": "6230",
392 "ipmi_username": "admin",
393 "deploy_kernel": "http://172.22.0.1/images/tinyipa-stable-rocky.vmlinuz",
394 "ipmi_address": "192.168.122.1",
395 "deploy_ramdisk": "http://172.22.0.1/images/tinyipa-stable-rocky.gz",
396 "ipmi_password": "admin"
397 },
398 "driver_internal_info": {},
399 "extra": {},
400 "fault": null,
401 "inspect_interface": "no-inspect",
402 "inspection_finished_at": null,
403 "inspection_started_at": null,
404 "instance_info": {},
405 "instance_uuid": null,
406 "last_error": null,
407 "links": [
408 {
409 "href": "http://ironic.example.com:6385/v1/nodes/d2630783-6ec8-4836-b556-ab427c4b581e",
410 "rel": "self"
411 },
412 {
413 "href": "http://ironic.example.com:6385/nodes/d2630783-6ec8-4836-b556-ab427c4b581e",
414 "rel": "bookmark"
415 }
416 ],
417 "maintenance": false,
418 "maintenance_reason": null,
419 "management_interface": "ipmitool",
420 "name": "foo",
421 "network_interface": "flat",
422 "portgroups": [
423 {
424 "href": "http://ironic.example.com:6385/v1/nodes/d2630783-6ec8-4836-b556-ab427c4b581e/portgroups",
425 "rel": "self"
426 },
427 {
428 "href": "http://ironic.example.com:6385/nodes/d2630783-6ec8-4836-b556-ab427c4b581e/portgroups",
429 "rel": "bookmark"
430 }
431 ],
432 "ports": [
433 {
434 "href": "http://ironic.example.com:6385/v1/nodes/d2630783-6ec8-4836-b556-ab427c4b581e/ports",
435 "rel": "self"
436 },
437 {
438 "href": "http://ironic.example.com:6385/nodes/d2630783-6ec8-4836-b556-ab427c4b581e/ports",
439 "rel": "bookmark"
440 }
441 ],
442 "power_interface": "ipmitool",
443 "power_state": null,
444 "properties": {},
445 "provision_state": "enroll",
446 "provision_updated_at": null,
447 "raid_config": {},
448 "raid_interface": "no-raid",
449 "rescue_interface": "no-rescue",
450 "reservation": null,
451 "resource_class": null,
452 "states": [
453 {
454 "href": "http://ironic.example.com:6385/v1/nodes/d2630783-6ec8-4836-b556-ab427c4b581e/states",
455 "rel": "self"
456 },
457 {
458 "href": "http://ironic.example.com:6385/nodes/d2630783-6ec8-4836-b556-ab427c4b581e/states",
459 "rel": "bookmark"
460 }
461 ],
462 "storage_interface": "noop",
463 "target_power_state": null,
464 "target_provision_state": null,
465 "target_raid_config": {},
466 "traits": [],
467 "updated_at": null,
468 "uuid": "d2630783-6ec8-4836-b556-ab427c4b581e",
469 "vendor_interface": "ipmitool",
470 "volume": [
471 {
472 "href": "http://ironic.example.com:6385/v1/nodes/d2630783-6ec8-4836-b556-ab427c4b581e/volume",
473 "rel": "self"
474 },
475 {
476 "href": "http://ironic.example.com:6385/nodes/d2630783-6ec8-4836-b556-ab427c4b581e/volume",
477 "rel": "bookmark"
478 }
479 ]
480}
481`
482
483const NodeValidationBody = `
484{
485 "bios": {
486 "reason": "Driver ipmi does not support bios (disabled or not implemented).",
487 "result": false
488 },
489 "boot": {
490 "reason": "Cannot validate image information for node a62b8495-52e2-407b-b3cb-62775d04c2b8 because one or more parameters are missing from its instance_info and insufficent information is present to boot from a remote volume. Missing are: ['ramdisk', 'kernel', 'image_source']",
491 "result": false
492 },
493 "console": {
494 "reason": "Driver ipmi does not support console (disabled or not implemented).",
495 "result": false
496 },
497 "deploy": {
498 "reason": "Cannot validate image information for node a62b8495-52e2-407b-b3cb-62775d04c2b8 because one or more parameters are missing from its instance_info and insufficent information is present to boot from a remote volume. Missing are: ['ramdisk', 'kernel', 'image_source']",
499 "result": false
500 },
501 "inspect": {
502 "reason": "Driver ipmi does not support inspect (disabled or not implemented).",
503 "result": false
504 },
505 "management": {
506 "result": true
507 },
508 "network": {
509 "result": true
510 },
511 "power": {
512 "result": true
513 },
514 "raid": {
515 "reason": "Driver ipmi does not support raid (disabled or not implemented).",
516 "result": false
517 },
518 "rescue": {
519 "reason": "Driver ipmi does not support rescue (disabled or not implemented).",
520 "result": false
521 },
522 "storage": {
523 "result": true
524 }
525}
526`
527
528const NodeBootDeviceBody = `
529{
530 "boot_device":"pxe",
531 "persistent":false
532}
533`
534
535const NodeSupportedBootDeviceBody = `
536{
537 "supported_boot_devices": [
538 "pxe",
539 "disk"
540 ]
541}
542`
543
544const NodeProvisionStateActiveBody = `
545{
546 "target": "active",
547 "configdrive": "http://127.0.0.1/images/test-node-config-drive.iso.gz"
548}
549`
550const NodeProvisionStateCleanBody = `
551{
552 "target": "clean",
553 "clean_steps": [
554 {
555 "interface": "deploy",
556 "step": "upgrade_firmware",
557 "args": {
558 "force": "True"
559 }
560 }
561 ]
562}
563`
564
565const NodeProvisionStateConfigDriveBody = `
566{
567 "target": "active",
568 "configdrive": {
569 "user_data": {
570 "ignition": {
571 "version": "2.2.0"
572 },
573 "systemd": {
574 "units": [
575 {
576 "enabled": true,
577 "name": "example.service"
578 }
579 ]
580 }
581 }
582 }
583}
584`
585
586var (
587 NodeFoo = nodes.Node{
588 UUID: "d2630783-6ec8-4836-b556-ab427c4b581e",
589 Name: "foo",
590 PowerState: "",
591 TargetPowerState: "",
592 ProvisionState: "enroll",
593 TargetProvisionState: "",
594 Maintenance: false,
595 MaintenanceReason: "",
596 Fault: "",
597 LastError: "",
598 Reservation: "",
599 Driver: "ipmi",
600 DriverInfo: map[string]interface{}{
601 "ipmi_port": "6230",
602 "ipmi_username": "admin",
603 "deploy_kernel": "http://172.22.0.1/images/tinyipa-stable-rocky.vmlinuz",
604 "ipmi_address": "192.168.122.1",
605 "deploy_ramdisk": "http://172.22.0.1/images/tinyipa-stable-rocky.gz",
606 "ipmi_password": "admin",
607 },
608 DriverInternalInfo: map[string]interface{}{},
609 Properties: map[string]interface{}{},
610 InstanceInfo: map[string]interface{}{},
611 InstanceUUID: "",
612 ChassisUUID: "",
613 Extra: map[string]interface{}{},
614 ConsoleEnabled: false,
615 RAIDConfig: map[string]interface{}{},
616 TargetRAIDConfig: map[string]interface{}{},
617 CleanStep: map[string]interface{}{},
618 DeployStep: map[string]interface{}{},
619 ResourceClass: "",
620 BootInterface: "pxe",
621 ConsoleInterface: "no-console",
622 DeployInterface: "iscsi",
623 InspectInterface: "no-inspect",
624 ManagementInterface: "ipmitool",
625 NetworkInterface: "flat",
626 PowerInterface: "ipmitool",
627 RAIDInterface: "no-raid",
628 RescueInterface: "no-rescue",
629 StorageInterface: "noop",
630 Traits: []string{},
631 VendorInterface: "ipmitool",
632 ConductorGroup: "",
633 Protected: false,
634 ProtectedReason: "",
635 }
636
637 NodeFooValidation = nodes.NodeValidation{
638 Boot: nodes.DriverValidation{
639 Result: false,
640 Reason: "Cannot validate image information for node a62b8495-52e2-407b-b3cb-62775d04c2b8 because one or more parameters are missing from its instance_info and insufficent information is present to boot from a remote volume. Missing are: ['ramdisk', 'kernel', 'image_source']",
641 },
642 Console: nodes.DriverValidation{
643 Result: false,
644 Reason: "Driver ipmi does not support console (disabled or not implemented).",
645 },
646 Deploy: nodes.DriverValidation{
647 Result: false,
648 Reason: "Cannot validate image information for node a62b8495-52e2-407b-b3cb-62775d04c2b8 because one or more parameters are missing from its instance_info and insufficent information is present to boot from a remote volume. Missing are: ['ramdisk', 'kernel', 'image_source']",
649 },
650 Inspect: nodes.DriverValidation{
651 Result: false,
652 Reason: "Driver ipmi does not support inspect (disabled or not implemented).",
653 },
654 Management: nodes.DriverValidation{
655 Result: true,
656 },
657 Network: nodes.DriverValidation{
658 Result: true,
659 },
660 Power: nodes.DriverValidation{
661 Result: true,
662 },
663 RAID: nodes.DriverValidation{
664 Result: false,
665 Reason: "Driver ipmi does not support raid (disabled or not implemented).",
666 },
667 Rescue: nodes.DriverValidation{
668 Result: false,
669 Reason: "Driver ipmi does not support rescue (disabled or not implemented).",
670 },
671 Storage: nodes.DriverValidation{
672 Result: true,
673 },
674 }
675
676 NodeBootDevice = nodes.BootDeviceOpts{
677 BootDevice: "pxe",
678 Persistent: false,
679 }
680
681 NodeSupportedBootDevice = []string{
682 "pxe",
683 "disk",
684 }
685
686 NodeBar = nodes.Node{
687 UUID: "08c84581-58f5-4ea2-a0c6-dd2e5d2b3662",
688 Name: "bar",
689 PowerState: "",
690 TargetPowerState: "",
691 ProvisionState: "enroll",
692 TargetProvisionState: "",
693 Maintenance: false,
694 MaintenanceReason: "",
695 Fault: "",
696 LastError: "",
697 Reservation: "",
698 Driver: "ipmi",
699 DriverInfo: map[string]interface{}{},
700 DriverInternalInfo: map[string]interface{}{},
701 Properties: map[string]interface{}{},
702 InstanceInfo: map[string]interface{}{},
703 InstanceUUID: "",
704 ChassisUUID: "",
705 Extra: map[string]interface{}{},
706 ConsoleEnabled: false,
707 RAIDConfig: map[string]interface{}{},
708 TargetRAIDConfig: map[string]interface{}{},
709 CleanStep: map[string]interface{}{},
710 DeployStep: map[string]interface{}{},
711 ResourceClass: "",
712 BootInterface: "pxe",
713 ConsoleInterface: "no-console",
714 DeployInterface: "iscsi",
715 InspectInterface: "no-inspect",
716 ManagementInterface: "ipmitool",
717 NetworkInterface: "flat",
718 PowerInterface: "ipmitool",
719 RAIDInterface: "no-raid",
720 RescueInterface: "no-rescue",
721 StorageInterface: "noop",
722 Traits: []string{},
723 VendorInterface: "ipmitool",
724 ConductorGroup: "",
725 Protected: false,
726 ProtectedReason: "",
727 }
728
729 NodeBaz = nodes.Node{
730 UUID: "c9afd385-5d89-4ecb-9e1c-68194da6b474",
731 Name: "baz",
732 PowerState: "",
733 TargetPowerState: "",
734 ProvisionState: "enroll",
735 TargetProvisionState: "",
736 Maintenance: false,
737 MaintenanceReason: "",
738 Fault: "",
739 LastError: "",
740 Reservation: "",
741 Driver: "ipmi",
742 DriverInfo: map[string]interface{}{},
743 DriverInternalInfo: map[string]interface{}{},
744 Properties: map[string]interface{}{},
745 InstanceInfo: map[string]interface{}{},
746 InstanceUUID: "",
747 ChassisUUID: "",
748 Extra: map[string]interface{}{},
749 ConsoleEnabled: false,
750 RAIDConfig: map[string]interface{}{},
751 TargetRAIDConfig: map[string]interface{}{},
752 CleanStep: map[string]interface{}{},
753 DeployStep: map[string]interface{}{},
754 ResourceClass: "",
755 BootInterface: "pxe",
756 ConsoleInterface: "no-console",
757 DeployInterface: "iscsi",
758 InspectInterface: "no-inspect",
759 ManagementInterface: "ipmitool",
760 NetworkInterface: "flat",
761 PowerInterface: "ipmitool",
762 RAIDInterface: "no-raid",
763 RescueInterface: "no-rescue",
764 StorageInterface: "noop",
765 Traits: []string{},
766 VendorInterface: "ipmitool",
767 ConductorGroup: "",
768 Protected: false,
769 ProtectedReason: "",
770 }
771
772 ConfigDriveMap = nodes.ConfigDrive{
773 UserData: map[string]interface{}{
774 "ignition": map[string]string{
775 "version": "2.2.0",
776 },
777 "systemd": map[string]interface{}{
778 "units": []map[string]interface{}{{
779 "name": "example.service",
780 "enabled": true,
781 },
782 },
783 },
784 },
785 }
786)
787
788// HandleNodeListSuccessfully sets up the test server to respond to a server List request.
789func HandleNodeListSuccessfully(t *testing.T) {
790 th.Mux.HandleFunc("/nodes", func(w http.ResponseWriter, r *http.Request) {
791 th.TestMethod(t, r, "GET")
792 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
793 w.Header().Add("Content-Type", "application/json")
794 r.ParseForm()
795
796 marker := r.Form.Get("marker")
797 switch marker {
798 case "":
799 fmt.Fprintf(w, NodeListBody)
800
801 case "9e5476bd-a4ec-4653-93d6-72c93aa682ba":
802 fmt.Fprintf(w, `{ "servers": [] }`)
803 default:
804 t.Fatalf("/nodes invoked with unexpected marker=[%s]", marker)
805 }
806 })
807}
808
809// HandleNodeListSuccessfully sets up the test server to respond to a server List request.
810func HandleNodeListDetailSuccessfully(t *testing.T) {
811 th.Mux.HandleFunc("/nodes/detail", func(w http.ResponseWriter, r *http.Request) {
812 th.TestMethod(t, r, "GET")
813 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
814 w.Header().Add("Content-Type", "application/json")
815 r.ParseForm()
816
817 fmt.Fprintf(w, NodeListDetailBody)
818 })
819}
820
821// HandleServerCreationSuccessfully sets up the test server to respond to a server creation request
822// with a given response.
823func HandleNodeCreationSuccessfully(t *testing.T, response string) {
824 th.Mux.HandleFunc("/nodes", func(w http.ResponseWriter, r *http.Request) {
825 th.TestMethod(t, r, "POST")
826 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
827 th.TestJSONRequest(t, r, `{
828 "boot_interface": "pxe",
829 "driver": "ipmi",
830 "driver_info": {
831 "deploy_kernel": "http://172.22.0.1/images/tinyipa-stable-rocky.vmlinuz",
832 "deploy_ramdisk": "http://172.22.0.1/images/tinyipa-stable-rocky.gz",
833 "ipmi_address": "192.168.122.1",
834 "ipmi_password": "admin",
835 "ipmi_port": "6230",
836 "ipmi_username": "admin"
837 },
838 "name": "foo"
839 }`)
840
841 w.WriteHeader(http.StatusAccepted)
842 w.Header().Add("Content-Type", "application/json")
843 fmt.Fprintf(w, response)
844 })
845}
846
847// HandleNodeDeletionSuccessfully sets up the test server to respond to a server deletion request.
848func HandleNodeDeletionSuccessfully(t *testing.T) {
849 th.Mux.HandleFunc("/nodes/asdfasdfasdf", func(w http.ResponseWriter, r *http.Request) {
850 th.TestMethod(t, r, "DELETE")
851 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
852
853 w.WriteHeader(http.StatusNoContent)
854 })
855}
856
857func HandleNodeGetSuccessfully(t *testing.T) {
858 th.Mux.HandleFunc("/nodes/1234asdf", func(w http.ResponseWriter, r *http.Request) {
859 th.TestMethod(t, r, "GET")
860 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
861 th.TestHeader(t, r, "Accept", "application/json")
862
863 fmt.Fprintf(w, SingleNodeBody)
864 })
865}
866
867func HandleNodeUpdateSuccessfully(t *testing.T, response string) {
868 th.Mux.HandleFunc("/nodes/1234asdf", func(w http.ResponseWriter, r *http.Request) {
869 th.TestMethod(t, r, "PATCH")
870 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
871 th.TestHeader(t, r, "Accept", "application/json")
872 th.TestHeader(t, r, "Content-Type", "application/json")
873 th.TestJSONRequest(t, r, `[{"op": "replace", "path": "/properties", "value": {"root_gb": 25}}]`)
874
875 fmt.Fprintf(w, response)
876 })
877}
878
879func HandleNodeValidateSuccessfully(t *testing.T) {
880 th.Mux.HandleFunc("/nodes/1234asdf/validate", func(w http.ResponseWriter, r *http.Request) {
881 th.TestMethod(t, r, "GET")
882 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
883 th.TestHeader(t, r, "Accept", "application/json")
884
885 fmt.Fprintf(w, NodeValidationBody)
886 })
887}
888
889// HandleInjectNMISuccessfully sets up the test server to respond to a node InjectNMI request
890func HandleInjectNMISuccessfully(t *testing.T) {
891 th.Mux.HandleFunc("/nodes/1234asdf/management/inject_nmi", func(w http.ResponseWriter, r *http.Request) {
892 th.TestMethod(t, r, "PUT")
893 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
894 th.TestJSONRequest(t, r, "{}")
895
896 w.WriteHeader(http.StatusNoContent)
897 })
898}
899
900// HandleSetBootDeviceSuccessfully sets up the test server to respond to a set boot device request for a node
901func HandleSetBootDeviceSuccessfully(t *testing.T) {
902 th.Mux.HandleFunc("/nodes/1234asdf/management/boot_device", func(w http.ResponseWriter, r *http.Request) {
903 th.TestMethod(t, r, "PUT")
904 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
905 th.TestJSONRequest(t, r, NodeBootDeviceBody)
906
907 w.WriteHeader(http.StatusNoContent)
908 })
909}
910
911// HandleGetBootDeviceSuccessfully sets up the test server to respond to a get boot device request for a node
912func HandleGetBootDeviceSuccessfully(t *testing.T) {
913 th.Mux.HandleFunc("/nodes/1234asdf/management/boot_device", func(w http.ResponseWriter, r *http.Request) {
914 th.TestMethod(t, r, "GET")
915 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
916 w.WriteHeader(http.StatusOK)
917 fmt.Fprintf(w, NodeBootDeviceBody)
918 })
919}
920
921// HandleGetBootDeviceSuccessfully sets up the test server to respond to a get boot device request for a node
922func HandleGetSupportedBootDeviceSuccessfully(t *testing.T) {
923 th.Mux.HandleFunc("/nodes/1234asdf/management/boot_device/supported", func(w http.ResponseWriter, r *http.Request) {
924 th.TestMethod(t, r, "GET")
925 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
926 w.WriteHeader(http.StatusOK)
927 fmt.Fprintf(w, NodeSupportedBootDeviceBody)
928 })
929}
930
931func HandleNodeChangeProvisionStateActive(t *testing.T) {
932 th.Mux.HandleFunc("/nodes/1234asdf/states/provision", func(w http.ResponseWriter, r *http.Request) {
933 th.TestMethod(t, r, "PUT")
934 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
935 th.TestJSONRequest(t, r, NodeProvisionStateActiveBody)
936 w.WriteHeader(http.StatusAccepted)
937 })
938}
939
940func HandleNodeChangeProvisionStateClean(t *testing.T) {
941 th.Mux.HandleFunc("/nodes/1234asdf/states/provision", func(w http.ResponseWriter, r *http.Request) {
942 th.TestMethod(t, r, "PUT")
943 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
944 th.TestJSONRequest(t, r, NodeProvisionStateCleanBody)
945 w.WriteHeader(http.StatusAccepted)
946 })
947}
948
949func HandleNodeChangeProvisionStateCleanWithConflict(t *testing.T) {
950 th.Mux.HandleFunc("/nodes/1234asdf/states/provision", func(w http.ResponseWriter, r *http.Request) {
951 th.TestMethod(t, r, "PUT")
952 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
953 th.TestJSONRequest(t, r, NodeProvisionStateCleanBody)
954 w.WriteHeader(http.StatusConflict)
955 })
956}
957
958func HandleNodeChangeProvisionStateConfigDrive(t *testing.T) {
959 th.Mux.HandleFunc("/nodes/1234asdf/states/provision", func(w http.ResponseWriter, r *http.Request) {
960 th.TestMethod(t, r, "PUT")
961 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
962 th.TestJSONRequest(t, r, NodeProvisionStateConfigDriveBody)
963 w.WriteHeader(http.StatusAccepted)
964 })
965}
966
967// HandleChangePowerStateSuccessfully sets up the test server to respond to a change power state request for a node
968func HandleChangePowerStateSuccessfully(t *testing.T) {
969 th.Mux.HandleFunc("/nodes/1234asdf/states/power", func(w http.ResponseWriter, r *http.Request) {
970 th.TestMethod(t, r, "PUT")
971 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
972 th.TestJSONRequest(t, r, `{
973 "target": "power on",
974 "timeout": 100
975 }`)
976
977 w.WriteHeader(http.StatusAccepted)
978 })
979}
980
981// HandleChangePowerStateWithConflict sets up the test server to respond to a change power state request for a node with a 409 error
982func HandleChangePowerStateWithConflict(t *testing.T) {
983 th.Mux.HandleFunc("/nodes/1234asdf/states/power", func(w http.ResponseWriter, r *http.Request) {
984 th.TestMethod(t, r, "PUT")
985 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
986 th.TestJSONRequest(t, r, `{
987 "target": "power on",
988 "timeout": 100
989 }`)
990
991 w.WriteHeader(http.StatusConflict)
992 })
993}
994
995func HandleSetRAIDConfig(t *testing.T) {
996 th.Mux.HandleFunc("/nodes/1234asdf/states/raid", func(w http.ResponseWriter, r *http.Request) {
997 th.TestMethod(t, r, "PUT")
998 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
999 th.TestJSONRequest(t, r, `
1000 {
1001 "logical_disks" : [
1002 {
1003 "size_gb" : 100,
1004 "is_root_volume" : true,
1005 "raid_level" : "1"
1006 }
1007 ]
1008 }
1009 `)
1010
1011 w.WriteHeader(http.StatusNoContent)
1012 })
1013}
1014
1015func HandleSetRAIDConfigMaxSize(t *testing.T) {
1016 th.Mux.HandleFunc("/nodes/1234asdf/states/raid", func(w http.ResponseWriter, r *http.Request) {
1017 th.TestMethod(t, r, "PUT")
1018 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
1019 th.TestJSONRequest(t, r, `
1020 {
1021 "logical_disks" : [
1022 {
1023 "size_gb" : "MAX",
1024 "is_root_volume" : true,
1025 "raid_level" : "1"
1026 }
1027 ]
1028 }
1029 `)
1030
1031 w.WriteHeader(http.StatusNoContent)
1032 })
1033}