blob: 34df0701a8640d85a5b532f100cf571202100f63 [file] [log] [blame]
jrperritt9b7b9e62016-07-11 22:30:50 -05001package testing
2
3import (
4 "fmt"
5 "net/http"
6 "testing"
7
8 th "github.com/gophercloud/gophercloud/testhelper"
9 fake "github.com/gophercloud/gophercloud/testhelper/client"
10)
11
12func MockAttachResponse(t *testing.T) {
13 th.Mux.HandleFunc("/volumes/cd281d77-8217-4830-be95-9528227c105c/action",
14 func(w http.ResponseWriter, r *http.Request) {
15 th.TestMethod(t, r, "POST")
16 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
17 th.TestHeader(t, r, "Content-Type", "application/json")
18 th.TestHeader(t, r, "Accept", "application/json")
19 th.TestJSONRequest(t, r, `
20{
21 "os-attach":
22 {
23 "mountpoint": "/mnt",
24 "mode": "rw",
25 "instance_uuid": "50902f4f-a974-46a0-85e9-7efc5e22dfdd"
26 }
27}
28 `)
29
30 w.Header().Add("Content-Type", "application/json")
31 w.WriteHeader(http.StatusAccepted)
32
33 fmt.Fprintf(w, `{}`)
34 })
35}
36
37func MockDetachResponse(t *testing.T) {
38 th.Mux.HandleFunc("/volumes/cd281d77-8217-4830-be95-9528227c105c/action",
39 func(w http.ResponseWriter, r *http.Request) {
40 th.TestMethod(t, r, "POST")
41 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
42 th.TestHeader(t, r, "Content-Type", "application/json")
43 th.TestHeader(t, r, "Accept", "application/json")
44 th.TestJSONRequest(t, r, `
45{
46 "os-detach": {}
47}
48 `)
49
50 w.Header().Add("Content-Type", "application/json")
51 w.WriteHeader(http.StatusAccepted)
52
53 fmt.Fprintf(w, `{}`)
54 })
55}
56
57func MockReserveResponse(t *testing.T) {
58 th.Mux.HandleFunc("/volumes/cd281d77-8217-4830-be95-9528227c105c/action",
59 func(w http.ResponseWriter, r *http.Request) {
60 th.TestMethod(t, r, "POST")
61 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
62 th.TestHeader(t, r, "Content-Type", "application/json")
63 th.TestHeader(t, r, "Accept", "application/json")
64 th.TestJSONRequest(t, r, `
65{
66 "os-reserve": {}
67}
68 `)
69
70 w.Header().Add("Content-Type", "application/json")
71 w.WriteHeader(http.StatusAccepted)
72
73 fmt.Fprintf(w, `{}`)
74 })
75}
76
77func MockUnreserveResponse(t *testing.T) {
78 th.Mux.HandleFunc("/volumes/cd281d77-8217-4830-be95-9528227c105c/action",
79 func(w http.ResponseWriter, r *http.Request) {
80 th.TestMethod(t, r, "POST")
81 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
82 th.TestHeader(t, r, "Content-Type", "application/json")
83 th.TestHeader(t, r, "Accept", "application/json")
84 th.TestJSONRequest(t, r, `
85{
86 "os-unreserve": {}
87}
88 `)
89
90 w.Header().Add("Content-Type", "application/json")
91 w.WriteHeader(http.StatusAccepted)
92
93 fmt.Fprintf(w, `{}`)
94 })
95}
96
97func MockInitializeConnectionResponse(t *testing.T) {
98 th.Mux.HandleFunc("/volumes/cd281d77-8217-4830-be95-9528227c105c/action",
99 func(w http.ResponseWriter, r *http.Request) {
100 th.TestMethod(t, r, "POST")
101 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
102 th.TestHeader(t, r, "Content-Type", "application/json")
103 th.TestHeader(t, r, "Accept", "application/json")
104 th.TestJSONRequest(t, r, `
105{
106 "os-initialize_connection":
107 {
108 "connector":
109 {
110 "ip":"127.0.0.1",
111 "host":"stack",
112 "initiator":"iqn.1994-05.com.redhat:17cf566367d2",
113 "multipath": false,
114 "platform": "x86_64",
115 "os_type": "linux2"
116 }
117 }
118}
119 `)
120
121 w.Header().Add("Content-Type", "application/json")
122 w.WriteHeader(http.StatusAccepted)
123
124 fmt.Fprintf(w, `{
125"connection_info": {
126 "data": {
127 "target_portals": [
128 "172.31.17.48:3260"
129 ],
130 "auth_method": "CHAP",
131 "auth_username": "5MLtcsTEmNN5jFVcT6ui",
132 "access_mode": "rw",
133 "target_lun": 0,
134 "volume_id": "cd281d77-8217-4830-be95-9528227c105c",
135 "target_luns": [
136 0
137 ],
138 "target_iqns": [
139 "iqn.2010-10.org.openstack:volume-cd281d77-8217-4830-be95-9528227c105c"
140 ],
141 "auth_password": "x854ZY5Re3aCkdNL",
142 "target_discovered": false,
143 "encrypted": false,
144 "qos_specs": null,
145 "target_iqn": "iqn.2010-10.org.openstack:volume-cd281d77-8217-4830-be95-9528227c105c",
146 "target_portal": "172.31.17.48:3260"
147 },
148 "driver_volume_type": "iscsi"
149 }
150 }`)
151 })
152}
153
154func MockTerminateConnectionResponse(t *testing.T) {
155 th.Mux.HandleFunc("/volumes/cd281d77-8217-4830-be95-9528227c105c/action",
156 func(w http.ResponseWriter, r *http.Request) {
157 th.TestMethod(t, r, "POST")
158 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
159 th.TestHeader(t, r, "Content-Type", "application/json")
160 th.TestHeader(t, r, "Accept", "application/json")
161 th.TestJSONRequest(t, r, `
162{
163 "os-terminate_connection":
164 {
165 "connector":
166 {
167 "ip":"127.0.0.1",
168 "host":"stack",
169 "initiator":"iqn.1994-05.com.redhat:17cf566367d2",
170 "multipath": true,
171 "platform": "x86_64",
172 "os_type": "linux2"
173 }
174 }
175}
176 `)
177
178 w.Header().Add("Content-Type", "application/json")
179 w.WriteHeader(http.StatusAccepted)
180
181 fmt.Fprintf(w, `{}`)
182 })
183}
Mario Luana4d49302016-09-02 11:37:24 -0400184
185func MockExtendSizeResponse(t *testing.T) {
186 th.Mux.HandleFunc("/volumes/cd281d77-8217-4830-be95-9528227c105c/action",
187 func(w http.ResponseWriter, r *http.Request) {
188 th.TestMethod(t, r, "POST")
189 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
190 th.TestHeader(t, r, "Content-Type", "application/json")
191 th.TestHeader(t, r, "Accept", "application/json")
192 th.TestJSONRequest(t, r, `
193{
194 "os-extend":
195 {
196 "new_size": 3
197 }
198}
199 `)
200
201 w.Header().Add("Content-Type", "application/json")
202 w.WriteHeader(http.StatusAccepted)
203
204 fmt.Fprintf(w, `{}`)
205 })
206}