blob: 55dc0a8960162f1551a17c08c33ae1e105f041ef [file] [log] [blame]
Jamie Hannaford6ee7d4a2015-02-09 17:26:49 +01001package instances
2
3import (
4 "fmt"
5 "net/http"
6 "testing"
7
8 th "github.com/rackspace/gophercloud/testhelper"
9 fake "github.com/rackspace/gophercloud/testhelper/client"
10)
11
Jamie Hannaford39d4ffb2015-02-10 13:19:44 +010012const singleInstanceJson = `
13{
14 "instance": {
15 "created": "2014-02-13T21:47:13",
16 "datastore": {
17 "type": "mysql",
18 "version": "5.6"
19 },
20 "flavor": {
21 "id": "1",
22 "links": [
23 {
24 "href": "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1",
25 "rel": "self"
26 },
27 {
28 "href": "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1",
29 "rel": "bookmark"
30 }
31 ]
32 },
33 "links": [
34 {
35 "href": "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1",
36 "rel": "self"
37 }
38 ],
39 "hostname": "e09ad9a3f73309469cf1f43d11e79549caf9acf2.rackspaceclouddb.com",
40 "id": "d4603f69-ec7e-4e9b-803f-600b9205576f",
41 "name": "json_rack_instance",
42 "status": "BUILD",
43 "updated": "2014-02-13T21:47:13",
44 "volume": {
45 "size": 2
46 }
47 }
48}
49`
50
Jamie Hannaford6ee7d4a2015-02-09 17:26:49 +010051func HandleCreateInstanceSuccessfully(t *testing.T) {
52 th.Mux.HandleFunc("/instances", func(w http.ResponseWriter, r *http.Request) {
53 th.TestMethod(t, r, "POST")
54 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
55
56 w.Header().Set("Content-Type", "application/json")
57 w.WriteHeader(http.StatusOK)
58
59 th.TestJSONRequest(t, r, `
60{
61 "instance": {
62 "databases": [
63 {
64 "character_set": "utf8",
65 "collate": "utf8_general_ci",
66 "name": "sampledb"
67 },
68 {
69 "name": "nextround"
70 }
71 ],
72 "flavorRef": "1",
73 "name": "json_rack_instance",
74 "users": [
75 {
76 "databases": [
77 {
78 "name": "sampledb"
79 }
80 ],
81 "name": "demouser",
82 "password": "demopassword"
83 }
84 ],
85 "volume": {
86 "size": 2
87 },
Jamie Hannaford302c0b62015-02-16 14:12:34 +010088 "restorePoint": {
89 "backupRef": "1234567890"
90 }
Jamie Hannaford6ee7d4a2015-02-09 17:26:49 +010091 }
92}
93`)
94
Jamie Hannaford39d4ffb2015-02-10 13:19:44 +010095 fmt.Fprintf(w, singleInstanceJson)
96 })
Jamie Hannaford6ee7d4a2015-02-09 17:26:49 +010097}
Jamie Hannaford39d4ffb2015-02-10 13:19:44 +010098
99func HandleGetInstanceSuccessfully(t *testing.T, id string) {
100 th.Mux.HandleFunc("/instances/"+id, func(w http.ResponseWriter, r *http.Request) {
101 th.TestMethod(t, r, "GET")
102 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
103
104 w.Header().Add("Content-Type", "application/json")
105
106 fmt.Fprintf(w, singleInstanceJson)
Jamie Hannaford6ee7d4a2015-02-09 17:26:49 +0100107 })
108}
Jamie Hannaford936a5472015-02-10 14:38:28 +0100109
110func HandleGetConfigSuccessfully(t *testing.T, id string) {
111 th.Mux.HandleFunc("/instances/"+id+"/configuration", func(w http.ResponseWriter, r *http.Request) {
112 th.TestMethod(t, r, "GET")
113 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
114
115 w.Header().Add("Content-Type", "application/json")
116
117 fmt.Fprintf(w, `
118{
119 "instance": {
120 "configuration": {
121 "basedir": "/usr",
122 "connect_timeout": "15",
123 "datadir": "/var/lib/mysql",
124 "default_storage_engine": "innodb",
125 "innodb_buffer_pool_instances": "1",
126 "innodb_buffer_pool_size": "175M",
127 "innodb_checksum_algorithm": "crc32",
128 "innodb_data_file_path": "ibdata1:10M:autoextend",
129 "innodb_file_per_table": "1",
130 "innodb_io_capacity": "200",
131 "innodb_log_file_size": "256M",
132 "innodb_log_files_in_group": "2",
133 "innodb_open_files": "8192",
134 "innodb_thread_concurrency": "0",
135 "join_buffer_size": "1M",
136 "key_buffer_size": "50M",
137 "local-infile": "0",
138 "log-error": "/var/log/mysql/mysqld.log",
139 "max_allowed_packet": "16M",
140 "max_connect_errors": "10000",
141 "max_connections": "40",
142 "max_heap_table_size": "16M",
143 "myisam-recover": "BACKUP",
144 "open_files_limit": "8192",
145 "performance_schema": "off",
146 "pid_file": "/var/run/mysqld/mysqld.pid",
147 "port": "3306",
148 "query_cache_limit": "1M",
149 "query_cache_size": "8M",
150 "query_cache_type": "1",
151 "read_buffer_size": "256K",
152 "read_rnd_buffer_size": "1M",
153 "server_id": "1",
154 "skip-external-locking": "1",
155 "skip_name_resolve": "1",
156 "sort_buffer_size": "256K",
157 "table_open_cache": "4096",
158 "thread_stack": "192K",
159 "tmp_table_size": "16M",
160 "tmpdir": "/var/tmp",
161 "user": "mysql",
162 "wait_timeout": "3600"
163 }
164 }
165}
166`)
167 })
168}
Jamie Hannafordf77fc102015-02-10 14:56:02 +0100169
170func HandleAssociateGroupSuccessfully(t *testing.T, id string) {
171 th.Mux.HandleFunc("/instances/"+id, func(w http.ResponseWriter, r *http.Request) {
172 th.TestMethod(t, r, "PUT")
173 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
174 th.TestJSONRequest(t, r, `{"instance": {"configuration": "{configGroupID}"}}`)
175
176 w.WriteHeader(http.StatusAccepted)
177 w.Header().Add("Content-Type", "application/json")
178
179 fmt.Fprintf(w, singleInstanceJson)
180 })
181}
Jamie Hannaford2e817322015-02-16 15:29:17 +0100182
183func HandleListBackupsSuccessfully(t *testing.T, id string) {
184 th.Mux.HandleFunc("/instances/"+id+"/backups", func(w http.ResponseWriter, r *http.Request) {
185 th.TestMethod(t, r, "GET")
186 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
187
188 w.Header().Add("Content-Type", "application/json")
189
190 fmt.Fprintf(w, `
191{
192 "backups": [
193 {
194 "status": "COMPLETED",
195 "updated": "2014-06-18T21:24:39",
196 "description": "Backup from Restored Instance",
197 "datastore": {
198 "version": "5.1",
199 "type": "MySQL",
200 "version_id": "20000000-0000-0000-0000-000000000002"
201 },
202 "id": "87972694-4be2-40f5-83f8-501656e0032a",
203 "size": 0.141026,
204 "name": "restored_backup",
205 "created": "2014-06-18T21:23:35",
206 "instance_id": "29af2cd9-0674-48ab-b87a-b160f00208e6",
207 "parent_id": null,
208 "locationRef": "http://localhost/path/to/backup"
209 }
210 ]
211}
212`)
213 })
214}