blob: 4c3c0dd65e6b537a1bfc58c3f46625f458397ded [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
Eugene Yakubovichb3a4f332016-10-13 11:01:06 -070037func MockBeginDetachingResponse(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-begin_detaching": {}
47}
48 `)
49
50 w.Header().Add("Content-Type", "application/json")
51 w.WriteHeader(http.StatusAccepted)
52
53 fmt.Fprintf(w, `{}`)
54 })
55}
56
jrperritt9b7b9e62016-07-11 22:30:50 -050057func MockDetachResponse(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-detach": {}
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 MockReserveResponse(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-reserve": {}
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 MockUnreserveResponse(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-unreserve": {}
107}
108 `)
109
110 w.Header().Add("Content-Type", "application/json")
111 w.WriteHeader(http.StatusAccepted)
112
113 fmt.Fprintf(w, `{}`)
114 })
115}
116
117func MockInitializeConnectionResponse(t *testing.T) {
118 th.Mux.HandleFunc("/volumes/cd281d77-8217-4830-be95-9528227c105c/action",
119 func(w http.ResponseWriter, r *http.Request) {
120 th.TestMethod(t, r, "POST")
121 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
122 th.TestHeader(t, r, "Content-Type", "application/json")
123 th.TestHeader(t, r, "Accept", "application/json")
124 th.TestJSONRequest(t, r, `
125{
126 "os-initialize_connection":
127 {
128 "connector":
129 {
130 "ip":"127.0.0.1",
131 "host":"stack",
132 "initiator":"iqn.1994-05.com.redhat:17cf566367d2",
133 "multipath": false,
134 "platform": "x86_64",
135 "os_type": "linux2"
136 }
137 }
138}
139 `)
140
141 w.Header().Add("Content-Type", "application/json")
142 w.WriteHeader(http.StatusAccepted)
143
144 fmt.Fprintf(w, `{
145"connection_info": {
146 "data": {
147 "target_portals": [
148 "172.31.17.48:3260"
149 ],
150 "auth_method": "CHAP",
151 "auth_username": "5MLtcsTEmNN5jFVcT6ui",
152 "access_mode": "rw",
153 "target_lun": 0,
154 "volume_id": "cd281d77-8217-4830-be95-9528227c105c",
155 "target_luns": [
156 0
157 ],
158 "target_iqns": [
159 "iqn.2010-10.org.openstack:volume-cd281d77-8217-4830-be95-9528227c105c"
160 ],
161 "auth_password": "x854ZY5Re3aCkdNL",
162 "target_discovered": false,
163 "encrypted": false,
164 "qos_specs": null,
165 "target_iqn": "iqn.2010-10.org.openstack:volume-cd281d77-8217-4830-be95-9528227c105c",
166 "target_portal": "172.31.17.48:3260"
167 },
168 "driver_volume_type": "iscsi"
169 }
170 }`)
171 })
172}
173
174func MockTerminateConnectionResponse(t *testing.T) {
175 th.Mux.HandleFunc("/volumes/cd281d77-8217-4830-be95-9528227c105c/action",
176 func(w http.ResponseWriter, r *http.Request) {
177 th.TestMethod(t, r, "POST")
178 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
179 th.TestHeader(t, r, "Content-Type", "application/json")
180 th.TestHeader(t, r, "Accept", "application/json")
181 th.TestJSONRequest(t, r, `
182{
183 "os-terminate_connection":
184 {
185 "connector":
186 {
187 "ip":"127.0.0.1",
188 "host":"stack",
189 "initiator":"iqn.1994-05.com.redhat:17cf566367d2",
190 "multipath": true,
191 "platform": "x86_64",
192 "os_type": "linux2"
193 }
194 }
195}
196 `)
197
198 w.Header().Add("Content-Type", "application/json")
199 w.WriteHeader(http.StatusAccepted)
200
201 fmt.Fprintf(w, `{}`)
202 })
203}
Mario Luana4d49302016-09-02 11:37:24 -0400204
205func MockExtendSizeResponse(t *testing.T) {
206 th.Mux.HandleFunc("/volumes/cd281d77-8217-4830-be95-9528227c105c/action",
207 func(w http.ResponseWriter, r *http.Request) {
208 th.TestMethod(t, r, "POST")
209 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
210 th.TestHeader(t, r, "Content-Type", "application/json")
211 th.TestHeader(t, r, "Accept", "application/json")
212 th.TestJSONRequest(t, r, `
213{
214 "os-extend":
215 {
216 "new_size": 3
217 }
218}
219 `)
220
221 w.Header().Add("Content-Type", "application/json")
222 w.WriteHeader(http.StatusAccepted)
223
224 fmt.Fprintf(w, `{}`)
225 })
226}