blob: 75040304b5a60f48799d49fc0ec516cddf31a062 [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/drivers"
9 th "gerrit.mcp.mirantis.net/debian/gophercloud.git/testhelper"
10 "gerrit.mcp.mirantis.net/debian/gophercloud.git/testhelper/client"
11)
12
13// ListDriversBody contains the canned body of a drivers.ListDrivers response, without details.
14const 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`
101const 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_inspect_interface": "no-inspect",
108 "default_management_interface": "ipmitool",
109 "default_network_interface": "flat",
110 "default_power_interface": "ipmitool",
111 "default_raid_interface": "no-raid",
112 "default_rescue_interface": "no-rescue",
113 "default_storage_interface": "noop",
114 "default_vendor_interface": "no-vendor",
115 "enabled_bios_interfaces": [
116 "no-bios"
117 ],
118 "enabled_boot_interfaces": [
119 "pxe"
120 ],
121 "enabled_console_interfaces": [
122 "no-console"
123 ],
124 "enabled_deploy_interfaces": [
125 "iscsi",
126 "direct"
127 ],
128 "enabled_inspect_interfaces": [
129 "no-inspect"
130 ],
131 "enabled_management_interfaces": [
132 "ipmitool"
133 ],
134 "enabled_network_interfaces": [
135 "flat",
136 "noop"
137 ],
138 "enabled_power_interfaces": [
139 "ipmitool"
140 ],
141 "enabled_raid_interfaces": [
142 "no-raid",
143 "agent"
144 ],
145 "enabled_rescue_interfaces": [
146 "no-rescue"
147 ],
148 "enabled_storage_interfaces": [
149 "noop"
150 ],
151 "enabled_vendor_interfaces": [
152 "no-vendor"
153 ],
154 "hosts": [
155 "897ab1dad809"
156 ],
157 "links": [
158 {
159 "href": "http://127.0.0.1:6385/v1/drivers/ipmi",
160 "rel": "self"
161 },
162 {
163 "href": "http://127.0.0.1:6385/drivers/ipmi",
164 "rel": "bookmark"
165 }
166 ],
167 "name": "ipmi",
168 "properties": [
169 {
170 "href": "http://127.0.0.1:6385/v1/drivers/ipmi/properties",
171 "rel": "self"
172 },
173 {
174 "href": "http://127.0.0.1:6385/drivers/ipmi/properties",
175 "rel": "bookmark"
176 }
177 ],
178 "type": "dynamic"
179}
180`
181
182const SingleDriverProperties = `
183{
184 "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.",
185 "deploy_kernel": "UUID (from Glance) of the deployment kernel. Required.",
186 "deploy_ramdisk": "UUID (from Glance) of the ramdisk that is mounted at boot time. Required.",
187 "image_http_proxy": "URL of a proxy server for HTTP connections. Optional.",
188 "image_https_proxy": "URL of a proxy server for HTTPS connections. Optional.",
189 "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.",
190 "ipmi_address": "IP address or hostname of the node. Required.",
191 "ipmi_bridging": "bridging_type; default is \"no\". One of \"single\", \"dual\", \"no\". Optional.",
192 "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.",
193 "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.",
194 "ipmi_local_address": "local IPMB address for bridged requests. Used only if ipmi_bridging is set to \"single\" or \"dual\". Optional.",
195 "ipmi_password": "password. Optional.",
196 "ipmi_port": "remote IPMI RMCP port. Optional.",
197 "ipmi_priv_level": "privilege level; default is ADMINISTRATOR. One of ADMINISTRATOR, CALLBACK, OPERATOR, USER. Optional.",
198 "ipmi_protocol_version": "the version of the IPMI protocol; default is \"2.0\". One of \"1.5\", \"2.0\". Optional.",
199 "ipmi_target_address": "destination address for bridged request. Required only if ipmi_bridging is set to \"single\" or \"dual\".",
200 "ipmi_target_channel": "destination channel for bridged request. Required only if ipmi_bridging is set to \"single\" or \"dual\".",
201 "ipmi_terminal_port": "node's UDP port to connect to. Only required for console access.",
202 "ipmi_transit_address": "transit address for bridged request. Required only if ipmi_bridging is set to \"dual\".",
203 "ipmi_transit_channel": "transit channel for bridged request. Required only if ipmi_bridging is set to \"dual\".",
204 "ipmi_username": "username; default is NULL user. Optional."
205}
206`
207
208const SingleDriverDiskProperties = `
209{
210 "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.",
211 "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.",
212 "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.",
213 "is_root_volume": "Specifies whether this disk is a root volume. By default, this is False. Optional.",
214 "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.",
215 "physical_disks": "The physical disks to use for this logical disk. If not specified, the driver will choose suitable physical disks to use. Optional.",
216 "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.",
217 "share_physical_disks": "Specifies whether other logical disks can share physical disks with this logical disk. By default, this is False. Optional.",
218 "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.",
219 "volume_name": "Name of the volume to be created. If this is not specified, it will be auto-generated. Optional."
220}
221`
222
223var (
224 DriverAgentIpmitool = drivers.Driver{
225 Name: "agent_ipmitool",
226 Type: "classic",
227 Hosts: []string{"897ab1dad809"},
228 Links: []interface{}{
229 map[string]interface{}{
230 "href": "http://127.0.0.1:6385/v1/drivers/agent_ipmitool",
231 "rel": "self",
232 },
233 map[string]interface{}{
234 "href": "http://127.0.0.1:6385/drivers/agent_ipmitool",
235 "rel": "bookmark",
236 },
237 },
238 Properties: []interface{}{
239 map[string]interface{}{
240 "href": "http://127.0.0.1:6385/v1/drivers/agent_ipmitool/properties",
241 "rel": "self",
242 },
243 map[string]interface{}{
244 "href": "http://127.0.0.1:6385/drivers/agent_ipmitool/properties",
245 "rel": "bookmark",
246 },
247 },
248 }
249
250 DriverFake = drivers.Driver{
251 Name: "fake",
252 Type: "classic",
253 Hosts: []string{"897ab1dad809"},
254 Links: []interface{}{
255 map[string]interface{}{
256 "href": "http://127.0.0.1:6385/v1/drivers/fake",
257 "rel": "self",
258 },
259 map[string]interface{}{
260 "href": "http://127.0.0.1:6385/drivers/fake",
261 "rel": "bookmark",
262 },
263 },
264 Properties: []interface{}{
265 map[string]interface{}{
266 "href": "http://127.0.0.1:6385/v1/drivers/fake/properties",
267 "rel": "self",
268 },
269 map[string]interface{}{
270 "href": "http://127.0.0.1:6385/drivers/fake/properties",
271 "rel": "bookmark",
272 },
273 },
274 }
275
276 DriverIpmi = drivers.Driver{
277 Name: "ipmi",
278 Type: "dynamic",
279 Hosts: []string{"897ab1dad809"},
280 DefaultBiosInterface: "no-bios",
281 DefaultBootInterface: "pxe",
282 DefaultConsoleInterface: "no-console",
283 DefaultDeployInterface: "iscsi",
284 DefaultInspectInterface: "no-inspect",
285 DefaultManagementInterface: "ipmitool",
286 DefaultNetworkInterface: "flat",
287 DefaultPowerInterface: "ipmitool",
288 DefaultRaidInterface: "no-raid",
289 DefaultRescueInterface: "no-rescue",
290 DefaultStorageInterface: "noop",
291 DefaultVendorInterface: "no-vendor",
292 EnabledBiosInterfaces: []string{"no-bios"},
293 EnabledBootInterfaces: []string{"pxe"},
294 EnabledConsoleInterface: []string{"no-console"},
295 EnabledDeployInterfaces: []string{"iscsi", "direct"},
296 EnabledInspectInterfaces: []string{"no-inspect"},
297 EnabledManagementInterfaces: []string{"ipmitool"},
298 EnabledNetworkInterfaces: []string{"flat", "noop"},
299 EnabledPowerInterfaces: []string{"ipmitool"},
300 EnabledRescueInterfaces: []string{"no-rescue"},
301 EnabledRaidInterfaces: []string{"no-raid", "agent"},
302 EnabledStorageInterfaces: []string{"noop"},
303 EnabledVendorInterfaces: []string{"no-vendor"},
304 Links: []interface{}{
305 map[string]interface{}{
306 "href": "http://127.0.0.1:6385/v1/drivers/ipmi",
307 "rel": "self",
308 },
309 map[string]interface{}{
310 "href": "http://127.0.0.1:6385/drivers/ipmi",
311 "rel": "bookmark",
312 },
313 },
314 Properties: []interface{}{
315 map[string]interface{}{
316 "href": "http://127.0.0.1:6385/v1/drivers/ipmi/properties",
317 "rel": "self",
318 },
319 map[string]interface{}{
320 "href": "http://127.0.0.1:6385/drivers/ipmi/properties",
321 "rel": "bookmark",
322 },
323 },
324 }
325
326 DriverIpmiToolProperties = drivers.DriverProperties{
327 "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.",
328 "deploy_kernel": "UUID (from Glance) of the deployment kernel. Required.",
329 "deploy_ramdisk": "UUID (from Glance) of the ramdisk that is mounted at boot time. Required.",
330 "image_http_proxy": "URL of a proxy server for HTTP connections. Optional.",
331 "image_https_proxy": "URL of a proxy server for HTTPS connections. Optional.",
332 "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.",
333 "ipmi_address": "IP address or hostname of the node. Required.",
334 "ipmi_bridging": "bridging_type; default is \"no\". One of \"single\", \"dual\", \"no\". Optional.",
335 "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.",
336 "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.",
337 "ipmi_local_address": "local IPMB address for bridged requests. Used only if ipmi_bridging is set to \"single\" or \"dual\". Optional.",
338 "ipmi_password": "password. Optional.",
339 "ipmi_port": "remote IPMI RMCP port. Optional.",
340 "ipmi_priv_level": "privilege level; default is ADMINISTRATOR. One of ADMINISTRATOR, CALLBACK, OPERATOR, USER. Optional.",
341 "ipmi_protocol_version": "the version of the IPMI protocol; default is \"2.0\". One of \"1.5\", \"2.0\". Optional.",
342 "ipmi_target_address": "destination address for bridged request. Required only if ipmi_bridging is set to \"single\" or \"dual\".",
343 "ipmi_target_channel": "destination channel for bridged request. Required only if ipmi_bridging is set to \"single\" or \"dual\".",
344 "ipmi_terminal_port": "node's UDP port to connect to. Only required for console access.",
345 "ipmi_transit_address": "transit address for bridged request. Required only if ipmi_bridging is set to \"dual\".",
346 "ipmi_transit_channel": "transit channel for bridged request. Required only if ipmi_bridging is set to \"dual\".",
347 "ipmi_username": "username; default is NULL user. Optional.",
348 }
349
350 DriverIpmiToolDisk = drivers.DiskProperties{
351 "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.",
352 "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.",
353 "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.",
354 "is_root_volume": "Specifies whether this disk is a root volume. By default, this is False. Optional.",
355 "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.",
356 "physical_disks": "The physical disks to use for this logical disk. If not specified, the driver will choose suitable physical disks to use. Optional.",
357 "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.",
358 "share_physical_disks": "Specifies whether other logical disks can share physical disks with this logical disk. By default, this is False. Optional.",
359 "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.",
360 "volume_name": "Name of the volume to be created. If this is not specified, it will be auto-generated. Optional.",
361 }
362)
363
364// HandleListDriversSuccessfully sets up the test server to respond to a drivers ListDrivers request.
365func HandleListDriversSuccessfully(t *testing.T) {
366 th.Mux.HandleFunc("/drivers", func(w http.ResponseWriter, r *http.Request) {
367 th.TestMethod(t, r, "GET")
368 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
369 w.Header().Add("Content-Type", "application/json")
370 r.ParseForm()
371
372 fmt.Fprintf(w, ListDriversBody)
373 })
374}
375
376// HandleGetDriverDetailsSuccessfully sets up the test server to respond to a drivers GetDriverDetails request.
377func HandleGetDriverDetailsSuccessfully(t *testing.T) {
378 th.Mux.HandleFunc("/drivers/ipmi", func(w http.ResponseWriter, r *http.Request) {
379 th.TestMethod(t, r, "GET")
380 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
381 th.TestHeader(t, r, "Accept", "application/json")
382
383 fmt.Fprintf(w, SingleDriverDetails)
384 })
385}
386
387// HandleGetDriverPropertiesSuccessfully sets up the test server to respond to a drivers GetDriverProperties request.
388func HandleGetDriverPropertiesSuccessfully(t *testing.T) {
389 th.Mux.HandleFunc("/drivers/agent_ipmitool/properties", func(w http.ResponseWriter, r *http.Request) {
390 th.TestMethod(t, r, "GET")
391 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
392 th.TestHeader(t, r, "Accept", "application/json")
393
394 fmt.Fprintf(w, SingleDriverProperties)
395 })
396}
397
398// HandleGetDriverDiskPropertiesSuccessfully sets up the test server to respond to a drivers GetDriverDiskProperties request.
399func HandleGetDriverDiskPropertiesSuccessfully(t *testing.T) {
400 th.Mux.HandleFunc("/drivers/agent_ipmitool/raid/logical_disk_properties", func(w http.ResponseWriter, r *http.Request) {
401 th.TestMethod(t, r, "GET")
402 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
403 th.TestHeader(t, r, "Accept", "application/json")
404
405 fmt.Fprintf(w, SingleDriverDiskProperties)
406 })
407}