blob: 39e561882c548d4ee05d7578371bbf6b21be5840 [file] [log] [blame]
Ildar Svetlov8edb1e82018-03-27 17:32:09 +04001package testing
2
3import (
4 "fmt"
5 "math"
6 "net/http"
7 "testing"
8
9 "gerrit.mcp.mirantis.net/debian/gophercloud.git/openstack/blockstorage/extensions/schedulerstats"
10 "gerrit.mcp.mirantis.net/debian/gophercloud.git/testhelper"
11 "gerrit.mcp.mirantis.net/debian/gophercloud.git/testhelper/client"
12)
13
14const StoragePoolsListBody = `
15{
16 "pools": [
17 {
18 "name": "rbd:cinder.volumes.ssd@cinder.volumes.ssd#cinder.volumes.ssd"
19 },
20 {
21 "name": "rbd:cinder.volumes.hdd@cinder.volumes#cinder.volumes.hdd"
22 }
23 ]
24}
25`
26
27const StoragePoolsListBodyDetail = `
28{
29 "pools": [
30 {
31 "capabilities": {
32 "driver_version": "1.2.0",
33 "filter_function": null,
34 "free_capacity_gb": 64765,
35 "goodness_function": null,
36 "multiattach": false,
37 "reserved_percentage": 0,
38 "storage_protocol": "ceph",
39 "timestamp": "2016-11-24T10:33:51.248360",
40 "total_capacity_gb": 787947.93,
41 "vendor_name": "Open Source",
42 "volume_backend_name": "cinder.volumes.ssd"
43 },
44 "name": "rbd:cinder.volumes.ssd@cinder.volumes.ssd#cinder.volumes.ssd"
45 },
46 {
47 "capabilities": {
48 "driver_version": "1.2.0",
49 "filter_function": null,
50 "free_capacity_gb": "unknown",
51 "goodness_function": null,
52 "multiattach": false,
53 "reserved_percentage": 0,
54 "storage_protocol": "ceph",
55 "timestamp": "2016-11-24T10:33:43.138628",
56 "total_capacity_gb": "infinite",
57 "vendor_name": "Open Source",
58 "volume_backend_name": "cinder.volumes.hdd"
59 },
60 "name": "rbd:cinder.volumes.hdd@cinder.volumes.hdd#cinder.volumes.hdd"
61 }
62 ]
63}
64`
65
66var (
67 StoragePoolFake1 = schedulerstats.StoragePool{
68 Name: "rbd:cinder.volumes.ssd@cinder.volumes.ssd#cinder.volumes.ssd",
69 Capabilities: schedulerstats.Capabilities{
70 DriverVersion: "1.2.0",
71 FreeCapacityGB: 64765,
72 StorageProtocol: "ceph",
73 TotalCapacityGB: 787947.93,
74 VendorName: "Open Source",
75 VolumeBackendName: "cinder.volumes.ssd",
76 },
77 }
78
79 StoragePoolFake2 = schedulerstats.StoragePool{
80 Name: "rbd:cinder.volumes.hdd@cinder.volumes.hdd#cinder.volumes.hdd",
81 Capabilities: schedulerstats.Capabilities{
82 DriverVersion: "1.2.0",
83 FreeCapacityGB: 0.0,
84 StorageProtocol: "ceph",
85 TotalCapacityGB: math.Inf(1),
86 VendorName: "Open Source",
87 VolumeBackendName: "cinder.volumes.hdd",
88 },
89 }
90)
91
92func HandleStoragePoolsListSuccessfully(t *testing.T) {
93 testhelper.Mux.HandleFunc("/scheduler-stats/get_pools", func(w http.ResponseWriter, r *http.Request) {
94 testhelper.TestMethod(t, r, "GET")
95 testhelper.TestHeader(t, r, "X-Auth-Token", client.TokenID)
96
97 w.Header().Add("Content-Type", "application/json")
98
99 r.ParseForm()
100 if r.FormValue("detail") == "true" {
101 fmt.Fprintf(w, StoragePoolsListBodyDetail)
102 } else {
103 fmt.Fprintf(w, StoragePoolsListBody)
104 }
105 })
106}