github.com/vnpaycloud-console/gophercloud/v2@v2.0.5/openstack/baremetal/v1/drivers/testing/fixtures_test.go (about) 1 package testing 2 3 import ( 4 "fmt" 5 "net/http" 6 "testing" 7 8 "github.com/vnpaycloud-console/gophercloud/v2/openstack/baremetal/v1/drivers" 9 th "github.com/vnpaycloud-console/gophercloud/v2/testhelper" 10 "github.com/vnpaycloud-console/gophercloud/v2/testhelper/client" 11 ) 12 13 // ListDriversBody contains the canned body of a drivers.ListDrivers response, without details. 14 const ListDriversBody = ` 15 { 16 "drivers": [ 17 { 18 "hosts": [ 19 "897ab1dad809" 20 ], 21 "links": [ 22 { 23 "href": "http://127.0.0.1:6385/v1/drivers/agent_ipmitool", 24 "rel": "self" 25 }, 26 { 27 "href": "http://127.0.0.1:6385/drivers/agent_ipmitool", 28 "rel": "bookmark" 29 } 30 ], 31 "name": "agent_ipmitool", 32 "properties": [ 33 { 34 "href": "http://127.0.0.1:6385/v1/drivers/agent_ipmitool/properties", 35 "rel": "self" 36 }, 37 { 38 "href": "http://127.0.0.1:6385/drivers/agent_ipmitool/properties", 39 "rel": "bookmark" 40 } 41 ], 42 "type": "classic" 43 }, 44 { 45 "hosts": [ 46 "897ab1dad809" 47 ], 48 "links": [ 49 { 50 "href": "http://127.0.0.1:6385/v1/drivers/fake", 51 "rel": "self" 52 }, 53 { 54 "href": "http://127.0.0.1:6385/drivers/fake", 55 "rel": "bookmark" 56 } 57 ], 58 "name": "fake", 59 "properties": [ 60 { 61 "href": "http://127.0.0.1:6385/v1/drivers/fake/properties", 62 "rel": "self" 63 }, 64 { 65 "href": "http://127.0.0.1:6385/drivers/fake/properties", 66 "rel": "bookmark" 67 } 68 ], 69 "type": "classic" 70 }, 71 { 72 "hosts": [ 73 "897ab1dad809" 74 ], 75 "links": [ 76 { 77 "href": "http://127.0.0.1:6385/v1/drivers/ipmi", 78 "rel": "self" 79 }, 80 { 81 "href": "http://127.0.0.1:6385/drivers/ipmi", 82 "rel": "bookmark" 83 } 84 ], 85 "name": "ipmi", 86 "properties": [ 87 { 88 "href": "http://127.0.0.1:6385/v1/drivers/ipmi/properties", 89 "rel": "self" 90 }, 91 { 92 "href": "http://127.0.0.1:6385/drivers/ipmi/properties", 93 "rel": "bookmark" 94 } 95 ], 96 "type": "dynamic" 97 } 98 ] 99 } 100 ` 101 const SingleDriverDetails = ` 102 { 103 "default_bios_interface": "no-bios", 104 "default_boot_interface": "pxe", 105 "default_console_interface": "no-console", 106 "default_deploy_interface": "iscsi", 107 "default_firmware_interface": "no-firmware", 108 "default_inspect_interface": "no-inspect", 109 "default_management_interface": "ipmitool", 110 "default_network_interface": "flat", 111 "default_power_interface": "ipmitool", 112 "default_raid_interface": "no-raid", 113 "default_rescue_interface": "no-rescue", 114 "default_storage_interface": "noop", 115 "default_vendor_interface": "no-vendor", 116 "enabled_bios_interfaces": [ 117 "no-bios" 118 ], 119 "enabled_boot_interfaces": [ 120 "pxe" 121 ], 122 "enabled_console_interfaces": [ 123 "no-console" 124 ], 125 "enabled_deploy_interfaces": [ 126 "iscsi", 127 "direct" 128 ], 129 "enabled_firmware_interfaces": [ 130 "no-firmware" 131 ], 132 "enabled_inspect_interfaces": [ 133 "no-inspect" 134 ], 135 "enabled_management_interfaces": [ 136 "ipmitool" 137 ], 138 "enabled_network_interfaces": [ 139 "flat", 140 "noop" 141 ], 142 "enabled_power_interfaces": [ 143 "ipmitool" 144 ], 145 "enabled_raid_interfaces": [ 146 "no-raid", 147 "agent" 148 ], 149 "enabled_rescue_interfaces": [ 150 "no-rescue" 151 ], 152 "enabled_storage_interfaces": [ 153 "noop" 154 ], 155 "enabled_vendor_interfaces": [ 156 "no-vendor" 157 ], 158 "hosts": [ 159 "897ab1dad809" 160 ], 161 "links": [ 162 { 163 "href": "http://127.0.0.1:6385/v1/drivers/ipmi", 164 "rel": "self" 165 }, 166 { 167 "href": "http://127.0.0.1:6385/drivers/ipmi", 168 "rel": "bookmark" 169 } 170 ], 171 "name": "ipmi", 172 "properties": [ 173 { 174 "href": "http://127.0.0.1:6385/v1/drivers/ipmi/properties", 175 "rel": "self" 176 }, 177 { 178 "href": "http://127.0.0.1:6385/drivers/ipmi/properties", 179 "rel": "bookmark" 180 } 181 ], 182 "type": "dynamic" 183 } 184 ` 185 186 const SingleDriverProperties = ` 187 { 188 "deploy_forces_oob_reboot": "Whether Ironic should force a reboot of the Node via the out-of-band channel after deployment is complete. Provides compatibility with older deploy ramdisks. Defaults to False. Optional.", 189 "deploy_kernel": "UUID (from Glance) of the deployment kernel. Required.", 190 "deploy_ramdisk": "UUID (from Glance) of the ramdisk that is mounted at boot time. Required.", 191 "image_http_proxy": "URL of a proxy server for HTTP connections. Optional.", 192 "image_https_proxy": "URL of a proxy server for HTTPS connections. Optional.", 193 "image_no_proxy": "A comma-separated list of host names, IP addresses and domain names (with optional :port) that will be excluded from proxying. To denote a domain name, use a dot to prefix the domain name. This value will be ignored if ` + "``image_http_proxy`` and ``image_https_proxy``" + ` are not specified. Optional.", 194 "ipmi_address": "IP address or hostname of the node. Required.", 195 "ipmi_bridging": "bridging_type; default is \"no\". One of \"single\", \"dual\", \"no\". Optional.", 196 "ipmi_disable_boot_timeout": "By default ironic will send a raw IPMI command to disable the 60 second timeout for booting. Setting this option to False will NOT send that command; default value is True. Optional.", 197 "ipmi_force_boot_device": "Whether Ironic should specify the boot device to the BMC each time the server is turned on, eg. because the BMC is not capable of remembering the selected boot device across power cycles; default value is False. Optional.", 198 "ipmi_local_address": "local IPMB address for bridged requests. Used only if ipmi_bridging is set to \"single\" or \"dual\". Optional.", 199 "ipmi_password": "password. Optional.", 200 "ipmi_port": "remote IPMI RMCP port. Optional.", 201 "ipmi_priv_level": "privilege level; default is ADMINISTRATOR. One of ADMINISTRATOR, CALLBACK, OPERATOR, USER. Optional.", 202 "ipmi_protocol_version": "the version of the IPMI protocol; default is \"2.0\". One of \"1.5\", \"2.0\". Optional.", 203 "ipmi_target_address": "destination address for bridged request. Required only if ipmi_bridging is set to \"single\" or \"dual\".", 204 "ipmi_target_channel": "destination channel for bridged request. Required only if ipmi_bridging is set to \"single\" or \"dual\".", 205 "ipmi_terminal_port": "node's UDP port to connect to. Only required for console access.", 206 "ipmi_transit_address": "transit address for bridged request. Required only if ipmi_bridging is set to \"dual\".", 207 "ipmi_transit_channel": "transit channel for bridged request. Required only if ipmi_bridging is set to \"dual\".", 208 "ipmi_username": "username; default is NULL user. Optional." 209 } 210 ` 211 212 const SingleDriverDiskProperties = ` 213 { 214 "controller": "Controller to use for this logical disk. If not specified, the driver will choose a suitable RAID controller on the bare metal node. Optional.", 215 "disk_type": "The type of disk preferred. Valid values are 'hdd' and 'ssd'. If this is not specified, disk type will not be a selection criterion for choosing backing physical disks. Optional.", 216 "interface_type": "The interface type of disk. Valid values are 'sata', 'scsi' and 'sas'. If this is not specified, interface type will not be a selection criterion for choosing backing physical disks. Optional.", 217 "is_root_volume": "Specifies whether this disk is a root volume. By default, this is False. Optional.", 218 "number_of_physical_disks": "Number of physical disks to use for this logical disk. By default, the driver uses the minimum number of disks required for that RAID level. Optional.", 219 "physical_disks": "The physical disks to use for this logical disk. If not specified, the driver will choose suitable physical disks to use. Optional.", 220 "raid_level": "RAID level for the logical disk. Valid values are 'JBOD', '0', '1', '2', '5', '6', '1+0', '5+0' and '6+0'. Required.", 221 "share_physical_disks": "Specifies whether other logical disks can share physical disks with this logical disk. By default, this is False. Optional.", 222 "size_gb": "Size in GiB (Integer) for the logical disk. Use 'MAX' as size_gb if this logical disk is supposed to use the rest of the space available. Required.", 223 "volume_name": "Name of the volume to be created. If this is not specified, it will be auto-generated. Optional." 224 } 225 ` 226 227 var ( 228 DriverAgentIpmitool = drivers.Driver{ 229 Name: "agent_ipmitool", 230 Type: "classic", 231 Hosts: []string{"897ab1dad809"}, 232 Links: []any{ 233 map[string]any{ 234 "href": "http://127.0.0.1:6385/v1/drivers/agent_ipmitool", 235 "rel": "self", 236 }, 237 map[string]any{ 238 "href": "http://127.0.0.1:6385/drivers/agent_ipmitool", 239 "rel": "bookmark", 240 }, 241 }, 242 Properties: []any{ 243 map[string]any{ 244 "href": "http://127.0.0.1:6385/v1/drivers/agent_ipmitool/properties", 245 "rel": "self", 246 }, 247 map[string]any{ 248 "href": "http://127.0.0.1:6385/drivers/agent_ipmitool/properties", 249 "rel": "bookmark", 250 }, 251 }, 252 } 253 254 DriverFake = drivers.Driver{ 255 Name: "fake", 256 Type: "classic", 257 Hosts: []string{"897ab1dad809"}, 258 Links: []any{ 259 map[string]any{ 260 "href": "http://127.0.0.1:6385/v1/drivers/fake", 261 "rel": "self", 262 }, 263 map[string]any{ 264 "href": "http://127.0.0.1:6385/drivers/fake", 265 "rel": "bookmark", 266 }, 267 }, 268 Properties: []any{ 269 map[string]any{ 270 "href": "http://127.0.0.1:6385/v1/drivers/fake/properties", 271 "rel": "self", 272 }, 273 map[string]any{ 274 "href": "http://127.0.0.1:6385/drivers/fake/properties", 275 "rel": "bookmark", 276 }, 277 }, 278 } 279 280 DriverIpmi = drivers.Driver{ 281 Name: "ipmi", 282 Type: "dynamic", 283 Hosts: []string{"897ab1dad809"}, 284 DefaultBiosInterface: "no-bios", 285 DefaultBootInterface: "pxe", 286 DefaultConsoleInterface: "no-console", 287 DefaultDeployInterface: "iscsi", 288 DefaultFirmwareInterface: "no-firmware", 289 DefaultInspectInterface: "no-inspect", 290 DefaultManagementInterface: "ipmitool", 291 DefaultNetworkInterface: "flat", 292 DefaultPowerInterface: "ipmitool", 293 DefaultRaidInterface: "no-raid", 294 DefaultRescueInterface: "no-rescue", 295 DefaultStorageInterface: "noop", 296 DefaultVendorInterface: "no-vendor", 297 EnabledBiosInterfaces: []string{"no-bios"}, 298 EnabledBootInterfaces: []string{"pxe"}, 299 EnabledConsoleInterface: []string{"no-console"}, 300 EnabledDeployInterfaces: []string{"iscsi", "direct"}, 301 EnabledFirmwareInterfaces: []string{"no-firmware"}, 302 EnabledInspectInterfaces: []string{"no-inspect"}, 303 EnabledManagementInterfaces: []string{"ipmitool"}, 304 EnabledNetworkInterfaces: []string{"flat", "noop"}, 305 EnabledPowerInterfaces: []string{"ipmitool"}, 306 EnabledRescueInterfaces: []string{"no-rescue"}, 307 EnabledRaidInterfaces: []string{"no-raid", "agent"}, 308 EnabledStorageInterfaces: []string{"noop"}, 309 EnabledVendorInterfaces: []string{"no-vendor"}, 310 Links: []any{ 311 map[string]any{ 312 "href": "http://127.0.0.1:6385/v1/drivers/ipmi", 313 "rel": "self", 314 }, 315 map[string]any{ 316 "href": "http://127.0.0.1:6385/drivers/ipmi", 317 "rel": "bookmark", 318 }, 319 }, 320 Properties: []any{ 321 map[string]any{ 322 "href": "http://127.0.0.1:6385/v1/drivers/ipmi/properties", 323 "rel": "self", 324 }, 325 map[string]any{ 326 "href": "http://127.0.0.1:6385/drivers/ipmi/properties", 327 "rel": "bookmark", 328 }, 329 }, 330 } 331 332 DriverIpmiToolProperties = drivers.DriverProperties{ 333 "deploy_forces_oob_reboot": "Whether Ironic should force a reboot of the Node via the out-of-band channel after deployment is complete. Provides compatibility with older deploy ramdisks. Defaults to False. Optional.", 334 "deploy_kernel": "UUID (from Glance) of the deployment kernel. Required.", 335 "deploy_ramdisk": "UUID (from Glance) of the ramdisk that is mounted at boot time. Required.", 336 "image_http_proxy": "URL of a proxy server for HTTP connections. Optional.", 337 "image_https_proxy": "URL of a proxy server for HTTPS connections. Optional.", 338 "image_no_proxy": "A comma-separated list of host names, IP addresses and domain names (with optional :port) that will be excluded from proxying. To denote a domain name, use a dot to prefix the domain name. This value will be ignored if ``image_http_proxy`` and ``image_https_proxy`` are not specified. Optional.", 339 "ipmi_address": "IP address or hostname of the node. Required.", 340 "ipmi_bridging": "bridging_type; default is \"no\". One of \"single\", \"dual\", \"no\". Optional.", 341 "ipmi_disable_boot_timeout": "By default ironic will send a raw IPMI command to disable the 60 second timeout for booting. Setting this option to False will NOT send that command; default value is True. Optional.", 342 "ipmi_force_boot_device": "Whether Ironic should specify the boot device to the BMC each time the server is turned on, eg. because the BMC is not capable of remembering the selected boot device across power cycles; default value is False. Optional.", 343 "ipmi_local_address": "local IPMB address for bridged requests. Used only if ipmi_bridging is set to \"single\" or \"dual\". Optional.", 344 "ipmi_password": "password. Optional.", 345 "ipmi_port": "remote IPMI RMCP port. Optional.", 346 "ipmi_priv_level": "privilege level; default is ADMINISTRATOR. One of ADMINISTRATOR, CALLBACK, OPERATOR, USER. Optional.", 347 "ipmi_protocol_version": "the version of the IPMI protocol; default is \"2.0\". One of \"1.5\", \"2.0\". Optional.", 348 "ipmi_target_address": "destination address for bridged request. Required only if ipmi_bridging is set to \"single\" or \"dual\".", 349 "ipmi_target_channel": "destination channel for bridged request. Required only if ipmi_bridging is set to \"single\" or \"dual\".", 350 "ipmi_terminal_port": "node's UDP port to connect to. Only required for console access.", 351 "ipmi_transit_address": "transit address for bridged request. Required only if ipmi_bridging is set to \"dual\".", 352 "ipmi_transit_channel": "transit channel for bridged request. Required only if ipmi_bridging is set to \"dual\".", 353 "ipmi_username": "username; default is NULL user. Optional.", 354 } 355 356 DriverIpmiToolDisk = drivers.DiskProperties{ 357 "controller": "Controller to use for this logical disk. If not specified, the driver will choose a suitable RAID controller on the bare metal node. Optional.", 358 "disk_type": "The type of disk preferred. Valid values are 'hdd' and 'ssd'. If this is not specified, disk type will not be a selection criterion for choosing backing physical disks. Optional.", 359 "interface_type": "The interface type of disk. Valid values are 'sata', 'scsi' and 'sas'. If this is not specified, interface type will not be a selection criterion for choosing backing physical disks. Optional.", 360 "is_root_volume": "Specifies whether this disk is a root volume. By default, this is False. Optional.", 361 "number_of_physical_disks": "Number of physical disks to use for this logical disk. By default, the driver uses the minimum number of disks required for that RAID level. Optional.", 362 "physical_disks": "The physical disks to use for this logical disk. If not specified, the driver will choose suitable physical disks to use. Optional.", 363 "raid_level": "RAID level for the logical disk. Valid values are 'JBOD', '0', '1', '2', '5', '6', '1+0', '5+0' and '6+0'. Required.", 364 "share_physical_disks": "Specifies whether other logical disks can share physical disks with this logical disk. By default, this is False. Optional.", 365 "size_gb": "Size in GiB (Integer) for the logical disk. Use 'MAX' as size_gb if this logical disk is supposed to use the rest of the space available. Required.", 366 "volume_name": "Name of the volume to be created. If this is not specified, it will be auto-generated. Optional.", 367 } 368 ) 369 370 // HandleListDriversSuccessfully sets up the test server to respond to a drivers ListDrivers request. 371 func HandleListDriversSuccessfully(t *testing.T) { 372 th.Mux.HandleFunc("/drivers", func(w http.ResponseWriter, r *http.Request) { 373 th.TestMethod(t, r, "GET") 374 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 375 w.Header().Add("Content-Type", "application/json") 376 if err := r.ParseForm(); err != nil { 377 t.Errorf("Failed to parse request form %v", err) 378 } 379 380 fmt.Fprint(w, ListDriversBody) 381 }) 382 } 383 384 // HandleGetDriverDetailsSuccessfully sets up the test server to respond to a drivers GetDriverDetails request. 385 func HandleGetDriverDetailsSuccessfully(t *testing.T) { 386 th.Mux.HandleFunc("/drivers/ipmi", func(w http.ResponseWriter, r *http.Request) { 387 th.TestMethod(t, r, "GET") 388 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 389 th.TestHeader(t, r, "Accept", "application/json") 390 391 fmt.Fprint(w, SingleDriverDetails) 392 }) 393 } 394 395 // HandleGetDriverPropertiesSuccessfully sets up the test server to respond to a drivers GetDriverProperties request. 396 func HandleGetDriverPropertiesSuccessfully(t *testing.T) { 397 th.Mux.HandleFunc("/drivers/agent_ipmitool/properties", func(w http.ResponseWriter, r *http.Request) { 398 th.TestMethod(t, r, "GET") 399 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 400 th.TestHeader(t, r, "Accept", "application/json") 401 402 fmt.Fprint(w, SingleDriverProperties) 403 }) 404 } 405 406 // HandleGetDriverDiskPropertiesSuccessfully sets up the test server to respond to a drivers GetDriverDiskProperties request. 407 func HandleGetDriverDiskPropertiesSuccessfully(t *testing.T) { 408 th.Mux.HandleFunc("/drivers/agent_ipmitool/raid/logical_disk_properties", func(w http.ResponseWriter, r *http.Request) { 409 th.TestMethod(t, r, "GET") 410 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 411 th.TestHeader(t, r, "Accept", "application/json") 412 413 fmt.Fprint(w, SingleDriverDiskProperties) 414 }) 415 }