Sync baremetal openstack with upstream
Change-Id: I125fc08e2cc4433aeaa470de48823dd4434c2030
Related-PROD: PROD-33018
diff --git a/openstack/baremetal/v1/nodes/testing/doc.go b/openstack/baremetal/v1/nodes/testing/doc.go
new file mode 100644
index 0000000..df83778
--- /dev/null
+++ b/openstack/baremetal/v1/nodes/testing/doc.go
@@ -0,0 +1,2 @@
+// nodes unit tests
+package testing
diff --git a/openstack/baremetal/v1/nodes/testing/fixtures.go b/openstack/baremetal/v1/nodes/testing/fixtures.go
new file mode 100644
index 0000000..c073329
--- /dev/null
+++ b/openstack/baremetal/v1/nodes/testing/fixtures.go
@@ -0,0 +1,1033 @@
+package testing
+
+import (
+ "fmt"
+ "net/http"
+ "testing"
+
+ "gerrit.mcp.mirantis.net/debian/gophercloud.git/openstack/baremetal/v1/nodes"
+ th "gerrit.mcp.mirantis.net/debian/gophercloud.git/testhelper"
+ "gerrit.mcp.mirantis.net/debian/gophercloud.git/testhelper/client"
+)
+
+// NodeListBody contains the canned body of a nodes.List response, without detail.
+const NodeListBody = `
+ {
+ "nodes": [
+ {
+ "instance_uuid": null,
+ "links": [
+ {
+ "href": "http://ironic.example.com:6385/v1/nodes/d2630783-6ec8-4836-b556-ab427c4b581e",
+ "rel": "self"
+ },
+ {
+ "href": "http://ironic.example.com:6385/nodes/d2630783-6ec8-4836-b556-ab427c4b581e",
+ "rel": "bookmark"
+ }
+ ],
+ "maintenance": false,
+ "name": "foo",
+ "power_state": null,
+ "provision_state": "enroll"
+ },
+ {
+ "instance_uuid": null,
+ "links": [
+ {
+ "href": "http://ironic.example.com:6385/v1/nodes/08c84581-58f5-4ea2-a0c6-dd2e5d2b3662",
+ "rel": "self"
+ },
+ {
+ "href": "http://ironic.example.com:6385/nodes/08c84581-58f5-4ea2-a0c6-dd2e5d2b3662",
+ "rel": "bookmark"
+ }
+ ],
+ "maintenance": false,
+ "name": "bar",
+ "power_state": null,
+ "provision_state": "enroll"
+ },
+ {
+ "instance_uuid": null,
+ "links": [
+ {
+ "href": "http://ironic.example.com:6385/v1/nodes/c9afd385-5d89-4ecb-9e1c-68194da6b474",
+ "rel": "self"
+ },
+ {
+ "href": "http://ironic.example.com:6385/nodes/c9afd385-5d89-4ecb-9e1c-68194da6b474",
+ "rel": "bookmark"
+ }
+ ],
+ "maintenance": false,
+ "name": "baz",
+ "power_state": null,
+ "provision_state": "enroll"
+ }
+ ]
+}
+`
+
+// NodeListDetailBody contains the canned body of a nodes.ListDetail response.
+const NodeListDetailBody = `
+ {
+ "nodes": [
+ {
+ "bios_interface": "no-bios",
+ "boot_interface": "pxe",
+ "chassis_uuid": null,
+ "clean_step": {},
+ "conductor_group": "",
+ "console_enabled": false,
+ "console_interface": "no-console",
+ "created_at": "2019-01-31T19:59:28+00:00",
+ "deploy_interface": "iscsi",
+ "deploy_step": {},
+ "driver": "ipmi",
+ "driver_info": {
+ "ipmi_port": "6230",
+ "ipmi_username": "admin",
+ "deploy_kernel": "http://172.22.0.1/images/tinyipa-stable-rocky.vmlinuz",
+ "ipmi_address": "192.168.122.1",
+ "deploy_ramdisk": "http://172.22.0.1/images/tinyipa-stable-rocky.gz",
+ "ipmi_password": "admin"
+
+ },
+ "driver_internal_info": {},
+ "extra": {},
+ "fault": null,
+ "inspect_interface": "no-inspect",
+ "inspection_finished_at": null,
+ "inspection_started_at": null,
+ "instance_info": {},
+ "instance_uuid": null,
+ "last_error": null,
+ "links": [
+ {
+ "href": "http://ironic.example.com:6385/v1/nodes/d2630783-6ec8-4836-b556-ab427c4b581e",
+ "rel": "self"
+ },
+ {
+ "href": "http://ironic.example.com:6385/nodes/d2630783-6ec8-4836-b556-ab427c4b581e",
+ "rel": "bookmark"
+ }
+ ],
+ "maintenance": false,
+ "maintenance_reason": null,
+ "management_interface": "ipmitool",
+ "name": "foo",
+ "network_interface": "flat",
+ "portgroups": [
+ {
+ "href": "http://ironic.example.com:6385/v1/nodes/d2630783-6ec8-4836-b556-ab427c4b581e/portgroups",
+ "rel": "self"
+ },
+ {
+ "href": "http://ironic.example.com:6385/nodes/d2630783-6ec8-4836-b556-ab427c4b581e/portgroups",
+ "rel": "bookmark"
+ }
+ ],
+ "ports": [
+ {
+ "href": "http://ironic.example.com:6385/v1/nodes/d2630783-6ec8-4836-b556-ab427c4b581e/ports",
+ "rel": "self"
+ },
+ {
+ "href": "http://ironic.example.com:6385/nodes/d2630783-6ec8-4836-b556-ab427c4b581e/ports",
+ "rel": "bookmark"
+ }
+ ],
+ "power_interface": "ipmitool",
+ "power_state": null,
+ "properties": {},
+ "provision_state": "enroll",
+ "provision_updated_at": null,
+ "raid_config": {},
+ "raid_interface": "no-raid",
+ "rescue_interface": "no-rescue",
+ "reservation": null,
+ "resource_class": null,
+ "states": [
+ {
+ "href": "http://ironic.example.com:6385/v1/nodes/d2630783-6ec8-4836-b556-ab427c4b581e/states",
+ "rel": "self"
+ },
+ {
+ "href": "http://ironic.example.com:6385/nodes/d2630783-6ec8-4836-b556-ab427c4b581e/states",
+ "rel": "bookmark"
+ }
+ ],
+ "storage_interface": "noop",
+ "target_power_state": null,
+ "target_provision_state": null,
+ "target_raid_config": {},
+ "traits": [],
+ "updated_at": null,
+ "uuid": "d2630783-6ec8-4836-b556-ab427c4b581e",
+ "vendor_interface": "ipmitool",
+ "volume": [
+ {
+ "href": "http://ironic.example.com:6385/v1/nodes/d2630783-6ec8-4836-b556-ab427c4b581e/volume",
+ "rel": "self"
+ },
+ {
+ "href": "http://ironic.example.com:6385/nodes/d2630783-6ec8-4836-b556-ab427c4b581e/volume",
+ "rel": "bookmark"
+ }
+ ]
+ },
+ {
+ "bios_interface": "no-bios",
+ "boot_interface": "pxe",
+ "chassis_uuid": null,
+ "clean_step": {},
+ "conductor_group": "",
+ "console_enabled": false,
+ "console_interface": "no-console",
+ "created_at": "2019-01-31T19:59:29+00:00",
+ "deploy_interface": "iscsi",
+ "deploy_step": {},
+ "driver": "ipmi",
+ "driver_info": {},
+ "driver_internal_info": {},
+ "extra": {},
+ "fault": null,
+ "inspect_interface": "no-inspect",
+ "inspection_finished_at": null,
+ "inspection_started_at": null,
+ "instance_info": {},
+ "instance_uuid": null,
+ "last_error": null,
+ "links": [
+ {
+ "href": "http://ironic.example.com:6385/v1/nodes/08c84581-58f5-4ea2-a0c6-dd2e5d2b3662",
+ "rel": "self"
+ },
+ {
+ "href": "http://ironic.example.com:6385/nodes/08c84581-58f5-4ea2-a0c6-dd2e5d2b3662",
+ "rel": "bookmark"
+ }
+ ],
+ "maintenance": false,
+ "maintenance_reason": null,
+ "management_interface": "ipmitool",
+ "name": "bar",
+ "network_interface": "flat",
+ "portgroups": [
+ {
+ "href": "http://ironic.example.com:6385/v1/nodes/08c84581-58f5-4ea2-a0c6-dd2e5d2b3662/portgroups",
+ "rel": "self"
+ },
+ {
+ "href": "http://ironic.example.com:6385/nodes/08c84581-58f5-4ea2-a0c6-dd2e5d2b3662/portgroups",
+ "rel": "bookmark"
+ }
+ ],
+ "ports": [
+ {
+ "href": "http://ironic.example.com:6385/v1/nodes/08c84581-58f5-4ea2-a0c6-dd2e5d2b3662/ports",
+ "rel": "self"
+ },
+ {
+ "href": "http://ironic.example.com:6385/nodes/08c84581-58f5-4ea2-a0c6-dd2e5d2b3662/ports",
+ "rel": "bookmark"
+ }
+ ],
+ "power_interface": "ipmitool",
+ "power_state": null,
+ "properties": {},
+ "provision_state": "enroll",
+ "provision_updated_at": null,
+ "raid_config": {},
+ "raid_interface": "no-raid",
+ "rescue_interface": "no-rescue",
+ "reservation": null,
+ "resource_class": null,
+ "states": [
+ {
+ "href": "http://ironic.example.com:6385/v1/nodes/08c84581-58f5-4ea2-a0c6-dd2e5d2b3662/states",
+ "rel": "self"
+ },
+ {
+ "href": "http://ironic.example.com:6385/nodes/08c84581-58f5-4ea2-a0c6-dd2e5d2b3662/states",
+ "rel": "bookmark"
+ }
+ ],
+ "storage_interface": "noop",
+ "target_power_state": null,
+ "target_provision_state": null,
+ "target_raid_config": {},
+ "traits": [],
+ "updated_at": null,
+ "uuid": "08c84581-58f5-4ea2-a0c6-dd2e5d2b3662",
+ "vendor_interface": "ipmitool",
+ "volume": [
+ {
+ "href": "http://ironic.example.com:6385/v1/nodes/08c84581-58f5-4ea2-a0c6-dd2e5d2b3662/volume",
+ "rel": "self"
+ },
+ {
+ "href": "http://ironic.example.com:6385/nodes/08c84581-58f5-4ea2-a0c6-dd2e5d2b3662/volume",
+ "rel": "bookmark"
+ }
+ ]
+ },
+ {
+ "bios_interface": "no-bios",
+ "boot_interface": "pxe",
+ "chassis_uuid": null,
+ "clean_step": {},
+ "conductor_group": "",
+ "console_enabled": false,
+ "console_interface": "no-console",
+ "created_at": "2019-01-31T19:59:30+00:00",
+ "deploy_interface": "iscsi",
+ "deploy_step": {},
+ "driver": "ipmi",
+ "driver_info": {},
+ "driver_internal_info": {},
+ "extra": {},
+ "fault": null,
+ "inspect_interface": "no-inspect",
+ "inspection_finished_at": null,
+ "inspection_started_at": null,
+ "instance_info": {},
+ "instance_uuid": null,
+ "last_error": null,
+ "links": [
+ {
+ "href": "http://ironic.example.com:6385/v1/nodes/c9afd385-5d89-4ecb-9e1c-68194da6b474",
+ "rel": "self"
+ },
+ {
+ "href": "http://ironic.example.com:6385/nodes/c9afd385-5d89-4ecb-9e1c-68194da6b474",
+ "rel": "bookmark"
+ }
+ ],
+ "maintenance": false,
+ "maintenance_reason": null,
+ "management_interface": "ipmitool",
+ "name": "baz",
+ "network_interface": "flat",
+ "portgroups": [
+ {
+ "href": "http://ironic.example.com:6385/v1/nodes/c9afd385-5d89-4ecb-9e1c-68194da6b474/portgroups",
+ "rel": "self"
+ },
+ {
+ "href": "http://ironic.example.com:6385/nodes/c9afd385-5d89-4ecb-9e1c-68194da6b474/portgroups",
+ "rel": "bookmark"
+ }
+ ],
+ "ports": [
+ {
+ "href": "http://ironic.example.com:6385/v1/nodes/c9afd385-5d89-4ecb-9e1c-68194da6b474/ports",
+ "rel": "self"
+ },
+ {
+ "href": "http://ironic.example.com:6385/nodes/c9afd385-5d89-4ecb-9e1c-68194da6b474/ports",
+ "rel": "bookmark"
+ }
+ ],
+ "power_interface": "ipmitool",
+ "power_state": null,
+ "properties": {},
+ "provision_state": "enroll",
+ "provision_updated_at": null,
+ "raid_config": {},
+ "raid_interface": "no-raid",
+ "rescue_interface": "no-rescue",
+ "reservation": null,
+ "resource_class": null,
+ "states": [
+ {
+ "href": "http://ironic.example.com:6385/v1/nodes/c9afd385-5d89-4ecb-9e1c-68194da6b474/states",
+ "rel": "self"
+ },
+ {
+ "href": "http://ironic.example.com:6385/nodes/c9afd385-5d89-4ecb-9e1c-68194da6b474/states",
+ "rel": "bookmark"
+ }
+ ],
+ "storage_interface": "noop",
+ "target_power_state": null,
+ "target_provision_state": null,
+ "target_raid_config": {},
+ "traits": [],
+ "updated_at": null,
+ "uuid": "c9afd385-5d89-4ecb-9e1c-68194da6b474",
+ "vendor_interface": "ipmitool",
+ "volume": [
+ {
+ "href": "http://ironic.example.com:6385/v1/nodes/c9afd385-5d89-4ecb-9e1c-68194da6b474/volume",
+ "rel": "self"
+ },
+ {
+ "href": "http://ironic.example.com:6385/nodes/c9afd385-5d89-4ecb-9e1c-68194da6b474/volume",
+ "rel": "bookmark"
+ }
+ ]
+ }
+ ]
+}
+`
+
+// SingleNodeBody is the canned body of a Get request on an existing node.
+const SingleNodeBody = `
+{
+ "bios_interface": "no-bios",
+ "boot_interface": "pxe",
+ "chassis_uuid": null,
+ "clean_step": {},
+ "conductor_group": "",
+ "console_enabled": false,
+ "console_interface": "no-console",
+ "created_at": "2019-01-31T19:59:28+00:00",
+ "deploy_interface": "iscsi",
+ "deploy_step": {},
+ "driver": "ipmi",
+ "driver_info": {
+ "ipmi_port": "6230",
+ "ipmi_username": "admin",
+ "deploy_kernel": "http://172.22.0.1/images/tinyipa-stable-rocky.vmlinuz",
+ "ipmi_address": "192.168.122.1",
+ "deploy_ramdisk": "http://172.22.0.1/images/tinyipa-stable-rocky.gz",
+ "ipmi_password": "admin"
+ },
+ "driver_internal_info": {},
+ "extra": {},
+ "fault": null,
+ "inspect_interface": "no-inspect",
+ "inspection_finished_at": null,
+ "inspection_started_at": null,
+ "instance_info": {},
+ "instance_uuid": null,
+ "last_error": null,
+ "links": [
+ {
+ "href": "http://ironic.example.com:6385/v1/nodes/d2630783-6ec8-4836-b556-ab427c4b581e",
+ "rel": "self"
+ },
+ {
+ "href": "http://ironic.example.com:6385/nodes/d2630783-6ec8-4836-b556-ab427c4b581e",
+ "rel": "bookmark"
+ }
+ ],
+ "maintenance": false,
+ "maintenance_reason": null,
+ "management_interface": "ipmitool",
+ "name": "foo",
+ "network_interface": "flat",
+ "portgroups": [
+ {
+ "href": "http://ironic.example.com:6385/v1/nodes/d2630783-6ec8-4836-b556-ab427c4b581e/portgroups",
+ "rel": "self"
+ },
+ {
+ "href": "http://ironic.example.com:6385/nodes/d2630783-6ec8-4836-b556-ab427c4b581e/portgroups",
+ "rel": "bookmark"
+ }
+ ],
+ "ports": [
+ {
+ "href": "http://ironic.example.com:6385/v1/nodes/d2630783-6ec8-4836-b556-ab427c4b581e/ports",
+ "rel": "self"
+ },
+ {
+ "href": "http://ironic.example.com:6385/nodes/d2630783-6ec8-4836-b556-ab427c4b581e/ports",
+ "rel": "bookmark"
+ }
+ ],
+ "power_interface": "ipmitool",
+ "power_state": null,
+ "properties": {},
+ "provision_state": "enroll",
+ "provision_updated_at": null,
+ "raid_config": {},
+ "raid_interface": "no-raid",
+ "rescue_interface": "no-rescue",
+ "reservation": null,
+ "resource_class": null,
+ "states": [
+ {
+ "href": "http://ironic.example.com:6385/v1/nodes/d2630783-6ec8-4836-b556-ab427c4b581e/states",
+ "rel": "self"
+ },
+ {
+ "href": "http://ironic.example.com:6385/nodes/d2630783-6ec8-4836-b556-ab427c4b581e/states",
+ "rel": "bookmark"
+ }
+ ],
+ "storage_interface": "noop",
+ "target_power_state": null,
+ "target_provision_state": null,
+ "target_raid_config": {},
+ "traits": [],
+ "updated_at": null,
+ "uuid": "d2630783-6ec8-4836-b556-ab427c4b581e",
+ "vendor_interface": "ipmitool",
+ "volume": [
+ {
+ "href": "http://ironic.example.com:6385/v1/nodes/d2630783-6ec8-4836-b556-ab427c4b581e/volume",
+ "rel": "self"
+ },
+ {
+ "href": "http://ironic.example.com:6385/nodes/d2630783-6ec8-4836-b556-ab427c4b581e/volume",
+ "rel": "bookmark"
+ }
+ ]
+}
+`
+
+const NodeValidationBody = `
+{
+ "bios": {
+ "reason": "Driver ipmi does not support bios (disabled or not implemented).",
+ "result": false
+ },
+ "boot": {
+ "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']",
+ "result": false
+ },
+ "console": {
+ "reason": "Driver ipmi does not support console (disabled or not implemented).",
+ "result": false
+ },
+ "deploy": {
+ "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']",
+ "result": false
+ },
+ "inspect": {
+ "reason": "Driver ipmi does not support inspect (disabled or not implemented).",
+ "result": false
+ },
+ "management": {
+ "result": true
+ },
+ "network": {
+ "result": true
+ },
+ "power": {
+ "result": true
+ },
+ "raid": {
+ "reason": "Driver ipmi does not support raid (disabled or not implemented).",
+ "result": false
+ },
+ "rescue": {
+ "reason": "Driver ipmi does not support rescue (disabled or not implemented).",
+ "result": false
+ },
+ "storage": {
+ "result": true
+ }
+}
+`
+
+const NodeBootDeviceBody = `
+{
+ "boot_device":"pxe",
+ "persistent":false
+}
+`
+
+const NodeSupportedBootDeviceBody = `
+{
+ "supported_boot_devices": [
+ "pxe",
+ "disk"
+ ]
+}
+`
+
+const NodeProvisionStateActiveBody = `
+{
+ "target": "active",
+ "configdrive": "http://127.0.0.1/images/test-node-config-drive.iso.gz"
+}
+`
+const NodeProvisionStateCleanBody = `
+{
+ "target": "clean",
+ "clean_steps": [
+ {
+ "interface": "deploy",
+ "step": "upgrade_firmware",
+ "args": {
+ "force": "True"
+ }
+ }
+ ]
+}
+`
+
+const NodeProvisionStateConfigDriveBody = `
+{
+ "target": "active",
+ "configdrive": {
+ "user_data": {
+ "ignition": {
+ "version": "2.2.0"
+ },
+ "systemd": {
+ "units": [
+ {
+ "enabled": true,
+ "name": "example.service"
+ }
+ ]
+ }
+ }
+ }
+}
+`
+
+var (
+ NodeFoo = nodes.Node{
+ UUID: "d2630783-6ec8-4836-b556-ab427c4b581e",
+ Name: "foo",
+ PowerState: "",
+ TargetPowerState: "",
+ ProvisionState: "enroll",
+ TargetProvisionState: "",
+ Maintenance: false,
+ MaintenanceReason: "",
+ Fault: "",
+ LastError: "",
+ Reservation: "",
+ Driver: "ipmi",
+ DriverInfo: map[string]interface{}{
+ "ipmi_port": "6230",
+ "ipmi_username": "admin",
+ "deploy_kernel": "http://172.22.0.1/images/tinyipa-stable-rocky.vmlinuz",
+ "ipmi_address": "192.168.122.1",
+ "deploy_ramdisk": "http://172.22.0.1/images/tinyipa-stable-rocky.gz",
+ "ipmi_password": "admin",
+ },
+ DriverInternalInfo: map[string]interface{}{},
+ Properties: map[string]interface{}{},
+ InstanceInfo: map[string]interface{}{},
+ InstanceUUID: "",
+ ChassisUUID: "",
+ Extra: map[string]interface{}{},
+ ConsoleEnabled: false,
+ RAIDConfig: map[string]interface{}{},
+ TargetRAIDConfig: map[string]interface{}{},
+ CleanStep: map[string]interface{}{},
+ DeployStep: map[string]interface{}{},
+ ResourceClass: "",
+ BootInterface: "pxe",
+ ConsoleInterface: "no-console",
+ DeployInterface: "iscsi",
+ InspectInterface: "no-inspect",
+ ManagementInterface: "ipmitool",
+ NetworkInterface: "flat",
+ PowerInterface: "ipmitool",
+ RAIDInterface: "no-raid",
+ RescueInterface: "no-rescue",
+ StorageInterface: "noop",
+ Traits: []string{},
+ VendorInterface: "ipmitool",
+ ConductorGroup: "",
+ Protected: false,
+ ProtectedReason: "",
+ }
+
+ NodeFooValidation = nodes.NodeValidation{
+ Boot: nodes.DriverValidation{
+ Result: false,
+ 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']",
+ },
+ Console: nodes.DriverValidation{
+ Result: false,
+ Reason: "Driver ipmi does not support console (disabled or not implemented).",
+ },
+ Deploy: nodes.DriverValidation{
+ Result: false,
+ 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']",
+ },
+ Inspect: nodes.DriverValidation{
+ Result: false,
+ Reason: "Driver ipmi does not support inspect (disabled or not implemented).",
+ },
+ Management: nodes.DriverValidation{
+ Result: true,
+ },
+ Network: nodes.DriverValidation{
+ Result: true,
+ },
+ Power: nodes.DriverValidation{
+ Result: true,
+ },
+ RAID: nodes.DriverValidation{
+ Result: false,
+ Reason: "Driver ipmi does not support raid (disabled or not implemented).",
+ },
+ Rescue: nodes.DriverValidation{
+ Result: false,
+ Reason: "Driver ipmi does not support rescue (disabled or not implemented).",
+ },
+ Storage: nodes.DriverValidation{
+ Result: true,
+ },
+ }
+
+ NodeBootDevice = nodes.BootDeviceOpts{
+ BootDevice: "pxe",
+ Persistent: false,
+ }
+
+ NodeSupportedBootDevice = []string{
+ "pxe",
+ "disk",
+ }
+
+ NodeBar = nodes.Node{
+ UUID: "08c84581-58f5-4ea2-a0c6-dd2e5d2b3662",
+ Name: "bar",
+ PowerState: "",
+ TargetPowerState: "",
+ ProvisionState: "enroll",
+ TargetProvisionState: "",
+ Maintenance: false,
+ MaintenanceReason: "",
+ Fault: "",
+ LastError: "",
+ Reservation: "",
+ Driver: "ipmi",
+ DriverInfo: map[string]interface{}{},
+ DriverInternalInfo: map[string]interface{}{},
+ Properties: map[string]interface{}{},
+ InstanceInfo: map[string]interface{}{},
+ InstanceUUID: "",
+ ChassisUUID: "",
+ Extra: map[string]interface{}{},
+ ConsoleEnabled: false,
+ RAIDConfig: map[string]interface{}{},
+ TargetRAIDConfig: map[string]interface{}{},
+ CleanStep: map[string]interface{}{},
+ DeployStep: map[string]interface{}{},
+ ResourceClass: "",
+ BootInterface: "pxe",
+ ConsoleInterface: "no-console",
+ DeployInterface: "iscsi",
+ InspectInterface: "no-inspect",
+ ManagementInterface: "ipmitool",
+ NetworkInterface: "flat",
+ PowerInterface: "ipmitool",
+ RAIDInterface: "no-raid",
+ RescueInterface: "no-rescue",
+ StorageInterface: "noop",
+ Traits: []string{},
+ VendorInterface: "ipmitool",
+ ConductorGroup: "",
+ Protected: false,
+ ProtectedReason: "",
+ }
+
+ NodeBaz = nodes.Node{
+ UUID: "c9afd385-5d89-4ecb-9e1c-68194da6b474",
+ Name: "baz",
+ PowerState: "",
+ TargetPowerState: "",
+ ProvisionState: "enroll",
+ TargetProvisionState: "",
+ Maintenance: false,
+ MaintenanceReason: "",
+ Fault: "",
+ LastError: "",
+ Reservation: "",
+ Driver: "ipmi",
+ DriverInfo: map[string]interface{}{},
+ DriverInternalInfo: map[string]interface{}{},
+ Properties: map[string]interface{}{},
+ InstanceInfo: map[string]interface{}{},
+ InstanceUUID: "",
+ ChassisUUID: "",
+ Extra: map[string]interface{}{},
+ ConsoleEnabled: false,
+ RAIDConfig: map[string]interface{}{},
+ TargetRAIDConfig: map[string]interface{}{},
+ CleanStep: map[string]interface{}{},
+ DeployStep: map[string]interface{}{},
+ ResourceClass: "",
+ BootInterface: "pxe",
+ ConsoleInterface: "no-console",
+ DeployInterface: "iscsi",
+ InspectInterface: "no-inspect",
+ ManagementInterface: "ipmitool",
+ NetworkInterface: "flat",
+ PowerInterface: "ipmitool",
+ RAIDInterface: "no-raid",
+ RescueInterface: "no-rescue",
+ StorageInterface: "noop",
+ Traits: []string{},
+ VendorInterface: "ipmitool",
+ ConductorGroup: "",
+ Protected: false,
+ ProtectedReason: "",
+ }
+
+ ConfigDriveMap = nodes.ConfigDrive{
+ UserData: map[string]interface{}{
+ "ignition": map[string]string{
+ "version": "2.2.0",
+ },
+ "systemd": map[string]interface{}{
+ "units": []map[string]interface{}{{
+ "name": "example.service",
+ "enabled": true,
+ },
+ },
+ },
+ },
+ }
+)
+
+// HandleNodeListSuccessfully sets up the test server to respond to a server List request.
+func HandleNodeListSuccessfully(t *testing.T) {
+ th.Mux.HandleFunc("/nodes", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "GET")
+ th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
+ w.Header().Add("Content-Type", "application/json")
+ r.ParseForm()
+
+ marker := r.Form.Get("marker")
+ switch marker {
+ case "":
+ fmt.Fprintf(w, NodeListBody)
+
+ case "9e5476bd-a4ec-4653-93d6-72c93aa682ba":
+ fmt.Fprintf(w, `{ "servers": [] }`)
+ default:
+ t.Fatalf("/nodes invoked with unexpected marker=[%s]", marker)
+ }
+ })
+}
+
+// HandleNodeListSuccessfully sets up the test server to respond to a server List request.
+func HandleNodeListDetailSuccessfully(t *testing.T) {
+ th.Mux.HandleFunc("/nodes/detail", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "GET")
+ th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
+ w.Header().Add("Content-Type", "application/json")
+ r.ParseForm()
+
+ fmt.Fprintf(w, NodeListDetailBody)
+ })
+}
+
+// HandleServerCreationSuccessfully sets up the test server to respond to a server creation request
+// with a given response.
+func HandleNodeCreationSuccessfully(t *testing.T, response string) {
+ th.Mux.HandleFunc("/nodes", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "POST")
+ th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
+ th.TestJSONRequest(t, r, `{
+ "boot_interface": "pxe",
+ "driver": "ipmi",
+ "driver_info": {
+ "deploy_kernel": "http://172.22.0.1/images/tinyipa-stable-rocky.vmlinuz",
+ "deploy_ramdisk": "http://172.22.0.1/images/tinyipa-stable-rocky.gz",
+ "ipmi_address": "192.168.122.1",
+ "ipmi_password": "admin",
+ "ipmi_port": "6230",
+ "ipmi_username": "admin"
+ },
+ "name": "foo"
+ }`)
+
+ w.WriteHeader(http.StatusAccepted)
+ w.Header().Add("Content-Type", "application/json")
+ fmt.Fprintf(w, response)
+ })
+}
+
+// HandleNodeDeletionSuccessfully sets up the test server to respond to a server deletion request.
+func HandleNodeDeletionSuccessfully(t *testing.T) {
+ th.Mux.HandleFunc("/nodes/asdfasdfasdf", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "DELETE")
+ th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
+
+ w.WriteHeader(http.StatusNoContent)
+ })
+}
+
+func HandleNodeGetSuccessfully(t *testing.T) {
+ th.Mux.HandleFunc("/nodes/1234asdf", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "GET")
+ th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
+ th.TestHeader(t, r, "Accept", "application/json")
+
+ fmt.Fprintf(w, SingleNodeBody)
+ })
+}
+
+func HandleNodeUpdateSuccessfully(t *testing.T, response string) {
+ th.Mux.HandleFunc("/nodes/1234asdf", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "PATCH")
+ th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
+ th.TestHeader(t, r, "Accept", "application/json")
+ th.TestHeader(t, r, "Content-Type", "application/json")
+ th.TestJSONRequest(t, r, `[{"op": "replace", "path": "/properties", "value": {"root_gb": 25}}]`)
+
+ fmt.Fprintf(w, response)
+ })
+}
+
+func HandleNodeValidateSuccessfully(t *testing.T) {
+ th.Mux.HandleFunc("/nodes/1234asdf/validate", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "GET")
+ th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
+ th.TestHeader(t, r, "Accept", "application/json")
+
+ fmt.Fprintf(w, NodeValidationBody)
+ })
+}
+
+// HandleInjectNMISuccessfully sets up the test server to respond to a node InjectNMI request
+func HandleInjectNMISuccessfully(t *testing.T) {
+ th.Mux.HandleFunc("/nodes/1234asdf/management/inject_nmi", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "PUT")
+ th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
+ th.TestJSONRequest(t, r, "{}")
+
+ w.WriteHeader(http.StatusNoContent)
+ })
+}
+
+// HandleSetBootDeviceSuccessfully sets up the test server to respond to a set boot device request for a node
+func HandleSetBootDeviceSuccessfully(t *testing.T) {
+ th.Mux.HandleFunc("/nodes/1234asdf/management/boot_device", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "PUT")
+ th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
+ th.TestJSONRequest(t, r, NodeBootDeviceBody)
+
+ w.WriteHeader(http.StatusNoContent)
+ })
+}
+
+// HandleGetBootDeviceSuccessfully sets up the test server to respond to a get boot device request for a node
+func HandleGetBootDeviceSuccessfully(t *testing.T) {
+ th.Mux.HandleFunc("/nodes/1234asdf/management/boot_device", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "GET")
+ th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
+ w.WriteHeader(http.StatusOK)
+ fmt.Fprintf(w, NodeBootDeviceBody)
+ })
+}
+
+// HandleGetBootDeviceSuccessfully sets up the test server to respond to a get boot device request for a node
+func HandleGetSupportedBootDeviceSuccessfully(t *testing.T) {
+ th.Mux.HandleFunc("/nodes/1234asdf/management/boot_device/supported", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "GET")
+ th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
+ w.WriteHeader(http.StatusOK)
+ fmt.Fprintf(w, NodeSupportedBootDeviceBody)
+ })
+}
+
+func HandleNodeChangeProvisionStateActive(t *testing.T) {
+ th.Mux.HandleFunc("/nodes/1234asdf/states/provision", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "PUT")
+ th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
+ th.TestJSONRequest(t, r, NodeProvisionStateActiveBody)
+ w.WriteHeader(http.StatusAccepted)
+ })
+}
+
+func HandleNodeChangeProvisionStateClean(t *testing.T) {
+ th.Mux.HandleFunc("/nodes/1234asdf/states/provision", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "PUT")
+ th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
+ th.TestJSONRequest(t, r, NodeProvisionStateCleanBody)
+ w.WriteHeader(http.StatusAccepted)
+ })
+}
+
+func HandleNodeChangeProvisionStateCleanWithConflict(t *testing.T) {
+ th.Mux.HandleFunc("/nodes/1234asdf/states/provision", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "PUT")
+ th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
+ th.TestJSONRequest(t, r, NodeProvisionStateCleanBody)
+ w.WriteHeader(http.StatusConflict)
+ })
+}
+
+func HandleNodeChangeProvisionStateConfigDrive(t *testing.T) {
+ th.Mux.HandleFunc("/nodes/1234asdf/states/provision", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "PUT")
+ th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
+ th.TestJSONRequest(t, r, NodeProvisionStateConfigDriveBody)
+ w.WriteHeader(http.StatusAccepted)
+ })
+}
+
+// HandleChangePowerStateSuccessfully sets up the test server to respond to a change power state request for a node
+func HandleChangePowerStateSuccessfully(t *testing.T) {
+ th.Mux.HandleFunc("/nodes/1234asdf/states/power", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "PUT")
+ th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
+ th.TestJSONRequest(t, r, `{
+ "target": "power on",
+ "timeout": 100
+ }`)
+
+ w.WriteHeader(http.StatusAccepted)
+ })
+}
+
+// HandleChangePowerStateWithConflict sets up the test server to respond to a change power state request for a node with a 409 error
+func HandleChangePowerStateWithConflict(t *testing.T) {
+ th.Mux.HandleFunc("/nodes/1234asdf/states/power", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "PUT")
+ th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
+ th.TestJSONRequest(t, r, `{
+ "target": "power on",
+ "timeout": 100
+ }`)
+
+ w.WriteHeader(http.StatusConflict)
+ })
+}
+
+func HandleSetRAIDConfig(t *testing.T) {
+ th.Mux.HandleFunc("/nodes/1234asdf/states/raid", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "PUT")
+ th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
+ th.TestJSONRequest(t, r, `
+ {
+ "logical_disks" : [
+ {
+ "size_gb" : 100,
+ "is_root_volume" : true,
+ "raid_level" : "1"
+ }
+ ]
+ }
+ `)
+
+ w.WriteHeader(http.StatusNoContent)
+ })
+}
+
+func HandleSetRAIDConfigMaxSize(t *testing.T) {
+ th.Mux.HandleFunc("/nodes/1234asdf/states/raid", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "PUT")
+ th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
+ th.TestJSONRequest(t, r, `
+ {
+ "logical_disks" : [
+ {
+ "size_gb" : "MAX",
+ "is_root_volume" : true,
+ "raid_level" : "1"
+ }
+ ]
+ }
+ `)
+
+ w.WriteHeader(http.StatusNoContent)
+ })
+}
diff --git a/openstack/baremetal/v1/nodes/testing/requests_test.go b/openstack/baremetal/v1/nodes/testing/requests_test.go
new file mode 100644
index 0000000..aa1ac58
--- /dev/null
+++ b/openstack/baremetal/v1/nodes/testing/requests_test.go
@@ -0,0 +1,432 @@
+package testing
+
+import (
+ "testing"
+
+ "gerrit.mcp.mirantis.net/debian/gophercloud.git"
+ "gerrit.mcp.mirantis.net/debian/gophercloud.git/openstack/baremetal/v1/nodes"
+ "gerrit.mcp.mirantis.net/debian/gophercloud.git/pagination"
+ th "gerrit.mcp.mirantis.net/debian/gophercloud.git/testhelper"
+ "gerrit.mcp.mirantis.net/debian/gophercloud.git/testhelper/client"
+)
+
+func TestListDetailNodes(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ HandleNodeListDetailSuccessfully(t)
+
+ pages := 0
+ err := nodes.ListDetail(client.ServiceClient(), nodes.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) {
+ pages++
+
+ actual, err := nodes.ExtractNodes(page)
+ if err != nil {
+ return false, err
+ }
+
+ if len(actual) != 3 {
+ t.Fatalf("Expected 3 nodes, got %d", len(actual))
+ }
+ th.CheckDeepEquals(t, NodeFoo, actual[0])
+ th.CheckDeepEquals(t, NodeBar, actual[1])
+ th.CheckDeepEquals(t, NodeBaz, actual[2])
+
+ return true, nil
+ })
+
+ th.AssertNoErr(t, err)
+
+ if pages != 1 {
+ t.Errorf("Expected 1 page, saw %d", pages)
+ }
+}
+
+func TestListNodes(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ HandleNodeListSuccessfully(t)
+
+ pages := 0
+ err := nodes.List(client.ServiceClient(), nodes.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) {
+ pages++
+
+ actual, err := nodes.ExtractNodes(page)
+ if err != nil {
+ return false, err
+ }
+
+ if len(actual) != 3 {
+ t.Fatalf("Expected 3 nodes, got %d", len(actual))
+ }
+ th.AssertEquals(t, "foo", actual[0].Name)
+ th.AssertEquals(t, "bar", actual[1].Name)
+ th.AssertEquals(t, "baz", actual[2].Name)
+
+ return true, nil
+ })
+
+ th.AssertNoErr(t, err)
+
+ if pages != 1 {
+ t.Errorf("Expected 1 page, saw %d", pages)
+ }
+}
+
+func TestListOpts(t *testing.T) {
+ // Detail cannot take Fields
+ opts := nodes.ListOpts{
+ Fields: []string{"name", "uuid"},
+ }
+
+ _, err := opts.ToNodeListDetailQuery()
+ th.AssertEquals(t, err.Error(), "fields is not a valid option when getting a detailed listing of nodes")
+
+ // Regular ListOpts can
+ query, err := opts.ToNodeListQuery()
+ th.AssertEquals(t, query, "?fields=name&fields=uuid")
+ th.AssertNoErr(t, err)
+}
+
+func TestCreateNode(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ HandleNodeCreationSuccessfully(t, SingleNodeBody)
+
+ actual, err := nodes.Create(client.ServiceClient(), nodes.CreateOpts{
+ Name: "foo",
+ Driver: "ipmi",
+ BootInterface: "pxe",
+ DriverInfo: map[string]interface{}{
+ "ipmi_port": "6230",
+ "ipmi_username": "admin",
+ "deploy_kernel": "http://172.22.0.1/images/tinyipa-stable-rocky.vmlinuz",
+ "ipmi_address": "192.168.122.1",
+ "deploy_ramdisk": "http://172.22.0.1/images/tinyipa-stable-rocky.gz",
+ "ipmi_password": "admin",
+ },
+ }).Extract()
+ th.AssertNoErr(t, err)
+
+ th.CheckDeepEquals(t, NodeFoo, *actual)
+}
+
+func TestDeleteNode(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ HandleNodeDeletionSuccessfully(t)
+
+ res := nodes.Delete(client.ServiceClient(), "asdfasdfasdf")
+ th.AssertNoErr(t, res.Err)
+}
+
+func TestGetNode(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ HandleNodeGetSuccessfully(t)
+
+ c := client.ServiceClient()
+ actual, err := nodes.Get(c, "1234asdf").Extract()
+ if err != nil {
+ t.Fatalf("Unexpected Get error: %v", err)
+ }
+
+ th.CheckDeepEquals(t, NodeFoo, *actual)
+}
+
+func TestUpdateNode(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ HandleNodeUpdateSuccessfully(t, SingleNodeBody)
+
+ c := client.ServiceClient()
+ actual, err := nodes.Update(c, "1234asdf", nodes.UpdateOpts{
+ nodes.UpdateOperation{
+ Op: nodes.ReplaceOp,
+ Path: "/properties",
+ Value: map[string]interface{}{
+ "root_gb": 25,
+ },
+ },
+ }).Extract()
+ if err != nil {
+ t.Fatalf("Unexpected Update error: %v", err)
+ }
+
+ th.CheckDeepEquals(t, NodeFoo, *actual)
+}
+
+func TestUpdateRequiredOp(t *testing.T) {
+ c := client.ServiceClient()
+ _, err := nodes.Update(c, "1234asdf", nodes.UpdateOpts{
+ nodes.UpdateOperation{
+ Path: "/driver",
+ Value: "new-driver",
+ },
+ }).Extract()
+
+ if _, ok := err.(gophercloud.ErrMissingInput); !ok {
+ t.Fatal("ErrMissingInput was expected to occur")
+ }
+
+}
+
+func TestUpdateRequiredPath(t *testing.T) {
+ c := client.ServiceClient()
+ _, err := nodes.Update(c, "1234asdf", nodes.UpdateOpts{
+ nodes.UpdateOperation{
+ Op: nodes.ReplaceOp,
+ Value: "new-driver",
+ },
+ }).Extract()
+
+ if _, ok := err.(gophercloud.ErrMissingInput); !ok {
+ t.Fatal("ErrMissingInput was expected to occur")
+ }
+}
+
+func TestValidateNode(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ HandleNodeValidateSuccessfully(t)
+
+ c := client.ServiceClient()
+ actual, err := nodes.Validate(c, "1234asdf").Extract()
+ th.AssertNoErr(t, err)
+ th.CheckDeepEquals(t, NodeFooValidation, *actual)
+}
+
+func TestInjectNMI(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ HandleInjectNMISuccessfully(t)
+
+ c := client.ServiceClient()
+ err := nodes.InjectNMI(c, "1234asdf").ExtractErr()
+ th.AssertNoErr(t, err)
+}
+
+func TestSetBootDevice(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ HandleSetBootDeviceSuccessfully(t)
+
+ c := client.ServiceClient()
+ err := nodes.SetBootDevice(c, "1234asdf", nodes.BootDeviceOpts{
+ BootDevice: "pxe",
+ Persistent: false,
+ }).ExtractErr()
+ th.AssertNoErr(t, err)
+}
+
+func TestGetBootDevice(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ HandleGetBootDeviceSuccessfully(t)
+
+ c := client.ServiceClient()
+ bootDevice, err := nodes.GetBootDevice(c, "1234asdf").Extract()
+ th.AssertNoErr(t, err)
+ th.CheckDeepEquals(t, NodeBootDevice, *bootDevice)
+}
+
+func TestGetSupportedBootDevices(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ HandleGetSupportedBootDeviceSuccessfully(t)
+
+ c := client.ServiceClient()
+ bootDevices, err := nodes.GetSupportedBootDevices(c, "1234asdf").Extract()
+ th.AssertNoErr(t, err)
+ th.CheckDeepEquals(t, NodeSupportedBootDevice, bootDevices)
+}
+
+func TestNodeChangeProvisionStateActive(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ HandleNodeChangeProvisionStateActive(t)
+
+ c := client.ServiceClient()
+ err := nodes.ChangeProvisionState(c, "1234asdf", nodes.ProvisionStateOpts{
+ Target: nodes.TargetActive,
+ ConfigDrive: "http://127.0.0.1/images/test-node-config-drive.iso.gz",
+ }).ExtractErr()
+
+ th.AssertNoErr(t, err)
+}
+
+func TestHandleNodeChangeProvisionStateConfigDrive(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+
+ HandleNodeChangeProvisionStateConfigDrive(t)
+
+ c := client.ServiceClient()
+
+ err := nodes.ChangeProvisionState(c, "1234asdf", nodes.ProvisionStateOpts{
+ Target: nodes.TargetActive,
+ ConfigDrive: ConfigDriveMap,
+ }).ExtractErr()
+
+ th.AssertNoErr(t, err)
+}
+
+func TestNodeChangeProvisionStateClean(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ HandleNodeChangeProvisionStateClean(t)
+
+ c := client.ServiceClient()
+ err := nodes.ChangeProvisionState(c, "1234asdf", nodes.ProvisionStateOpts{
+ Target: nodes.TargetClean,
+ CleanSteps: []nodes.CleanStep{
+ {
+ Interface: "deploy",
+ Step: "upgrade_firmware",
+ Args: map[string]interface{}{
+ "force": "True",
+ },
+ },
+ },
+ }).ExtractErr()
+
+ th.AssertNoErr(t, err)
+}
+
+func TestNodeChangeProvisionStateCleanWithConflict(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ HandleNodeChangeProvisionStateCleanWithConflict(t)
+
+ c := client.ServiceClient()
+ err := nodes.ChangeProvisionState(c, "1234asdf", nodes.ProvisionStateOpts{
+ Target: nodes.TargetClean,
+ CleanSteps: []nodes.CleanStep{
+ {
+ Interface: "deploy",
+ Step: "upgrade_firmware",
+ Args: map[string]interface{}{
+ "force": "True",
+ },
+ },
+ },
+ }).ExtractErr()
+
+ if _, ok := err.(gophercloud.ErrDefault409); !ok {
+ t.Fatal("ErrDefault409 was expected to occur")
+ }
+}
+
+func TestCleanStepRequiresInterface(t *testing.T) {
+ c := client.ServiceClient()
+ err := nodes.ChangeProvisionState(c, "1234asdf", nodes.ProvisionStateOpts{
+ Target: nodes.TargetClean,
+ CleanSteps: []nodes.CleanStep{
+ {
+ Step: "upgrade_firmware",
+ Args: map[string]interface{}{
+ "force": "True",
+ },
+ },
+ },
+ }).ExtractErr()
+
+ if _, ok := err.(gophercloud.ErrMissingInput); !ok {
+ t.Fatal("ErrMissingInput was expected to occur")
+ }
+}
+
+func TestCleanStepRequiresStep(t *testing.T) {
+ c := client.ServiceClient()
+ err := nodes.ChangeProvisionState(c, "1234asdf", nodes.ProvisionStateOpts{
+ Target: nodes.TargetClean,
+ CleanSteps: []nodes.CleanStep{
+ {
+ Interface: "deploy",
+ Args: map[string]interface{}{
+ "force": "True",
+ },
+ },
+ },
+ }).ExtractErr()
+
+ if _, ok := err.(gophercloud.ErrMissingInput); !ok {
+ t.Fatal("ErrMissingInput was expected to occur")
+ }
+}
+
+func TestChangePowerState(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ HandleChangePowerStateSuccessfully(t)
+
+ opts := nodes.PowerStateOpts{
+ Target: nodes.PowerOn,
+ Timeout: 100,
+ }
+
+ c := client.ServiceClient()
+ err := nodes.ChangePowerState(c, "1234asdf", opts).ExtractErr()
+ th.AssertNoErr(t, err)
+}
+
+func TestChangePowerStateWithConflict(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ HandleChangePowerStateWithConflict(t)
+
+ opts := nodes.PowerStateOpts{
+ Target: nodes.PowerOn,
+ Timeout: 100,
+ }
+
+ c := client.ServiceClient()
+ err := nodes.ChangePowerState(c, "1234asdf", opts).ExtractErr()
+ if _, ok := err.(gophercloud.ErrDefault409); !ok {
+ t.Fatal("ErrDefault409 was expected to occur")
+ }
+}
+
+func TestSetRAIDConfig(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ HandleSetRAIDConfig(t)
+
+ sizeGB := 100
+ isRootVolume := true
+
+ config := nodes.RAIDConfigOpts{
+ LogicalDisks: []nodes.LogicalDisk{
+ {
+ SizeGB: &sizeGB,
+ IsRootVolume: &isRootVolume,
+ RAIDLevel: nodes.RAID1,
+ },
+ },
+ }
+
+ c := client.ServiceClient()
+ err := nodes.SetRAIDConfig(c, "1234asdf", config).ExtractErr()
+ th.AssertNoErr(t, err)
+}
+
+// Without specifying a size, we need to send a string: "MAX"
+func TestSetRAIDConfigMaxSize(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ HandleSetRAIDConfigMaxSize(t)
+
+ isRootVolume := true
+
+ config := nodes.RAIDConfigOpts{
+ LogicalDisks: []nodes.LogicalDisk{
+ {
+ IsRootVolume: &isRootVolume,
+ RAIDLevel: nodes.RAID1,
+ },
+ },
+ }
+
+ c := client.ServiceClient()
+ err := nodes.SetRAIDConfig(c, "1234asdf", config).ExtractErr()
+ th.AssertNoErr(t, err)
+}