blob: 92d7bedb7233f8130bd572007a915e376c830e2b [file] [log] [blame]
Keith Byrnebda48592016-03-23 11:37:08 +00001// +build fixtures
2
Jamie Hannaford6ee7d4a2015-02-09 17:26:49 +01003package instances
4
5import (
Jamie Hannaford72749162015-10-14 12:14:32 +02006 "fmt"
Jamie Hannaforde65ad952015-11-16 14:05:11 +01007 "time"
Jamie Hannaford72749162015-10-14 12:14:32 +02008
Jamie Hannaforde635b7d2015-02-18 14:11:46 +01009 "github.com/rackspace/gophercloud"
Jamie Hannaford52dbcee2015-10-06 16:09:56 +020010 "github.com/rackspace/gophercloud/openstack/db/v1/datastores"
Jamie Hannaford11108402015-02-23 10:31:41 +010011 "github.com/rackspace/gophercloud/openstack/db/v1/flavors"
Jamie Hannaforde635b7d2015-02-18 14:11:46 +010012 os "github.com/rackspace/gophercloud/openstack/db/v1/instances"
Jamie Hannaford6ee7d4a2015-02-09 17:26:49 +010013)
14
Jamie Hannaforde65ad952015-11-16 14:05:11 +010015var (
16 timestamp = "2015-11-12T14:22:42Z"
17 timeVal, _ = time.Parse(time.RFC3339, timestamp)
18)
19
20var instance = `
Jamie Hannaford39d4ffb2015-02-10 13:19:44 +010021{
Jamie Hannaforde65ad952015-11-16 14:05:11 +010022 "created": "` + timestamp + `",
Jamie Hannaford72749162015-10-14 12:14:32 +020023 "datastore": {
24 "type": "mysql",
25 "version": "5.6"
26 },
27 "flavor": {
28 "id": "1",
Jamie Hannaford39d4ffb2015-02-10 13:19:44 +010029 "links": [
30 {
31 "href": "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1",
32 "rel": "self"
Jamie Hannaford72749162015-10-14 12:14:32 +020033 },
34 {
35 "href": "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1",
36 "rel": "bookmark"
Jamie Hannaford39d4ffb2015-02-10 13:19:44 +010037 }
Jamie Hannaford72749162015-10-14 12:14:32 +020038 ]
39 },
40 "links": [
41 {
42 "href": "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1",
43 "rel": "self"
Jamie Hannaford39d4ffb2015-02-10 13:19:44 +010044 }
Jamie Hannaford72749162015-10-14 12:14:32 +020045 ],
46 "hostname": "e09ad9a3f73309469cf1f43d11e79549caf9acf2.rackspaceclouddb.com",
47 "id": "{instanceID}",
48 "name": "json_rack_instance",
49 "status": "BUILD",
Jamie Hannaforde65ad952015-11-16 14:05:11 +010050 "updated": "` + timestamp + `",
Jamie Hannaford72749162015-10-14 12:14:32 +020051 "volume": {
52 "size": 2
Jamie Hannaford39d4ffb2015-02-10 13:19:44 +010053 }
54}
55`
56
Jamie Hannaforde635b7d2015-02-18 14:11:46 +010057var createReq = `
Jamie Hannaford6ee7d4a2015-02-09 17:26:49 +010058{
59 "instance": {
60 "databases": [
61 {
62 "character_set": "utf8",
63 "collate": "utf8_general_ci",
64 "name": "sampledb"
65 },
66 {
67 "name": "nextround"
68 }
69 ],
70 "flavorRef": "1",
71 "name": "json_rack_instance",
72 "users": [
73 {
74 "databases": [
75 {
76 "name": "sampledb"
77 }
78 ],
79 "name": "demouser",
80 "password": "demopassword"
81 }
82 ],
83 "volume": {
84 "size": 2
85 },
Jamie Hannaforde635b7d2015-02-18 14:11:46 +010086 "restorePoint": {
87 "backupRef": "1234567890"
88 }
Jamie Hannaford6ee7d4a2015-02-09 17:26:49 +010089 }
90}
Jamie Hannaforde635b7d2015-02-18 14:11:46 +010091`
Jamie Hannaford6ee7d4a2015-02-09 17:26:49 +010092
Jamie Hannaforde635b7d2015-02-18 14:11:46 +010093var createReplicaReq = `
Jamie Hannaford4ec6afe2015-02-16 16:52:49 +010094{
95 "instance": {
96 "volume": {
97 "size": 1
98 },
99 "flavorRef": "9",
100 "name": "t2s1_ALT_GUEST",
101 "replica_of": "6bdca2fc-418e-40bd-a595-62abda61862d"
102 }
103}
Jamie Hannaforde635b7d2015-02-18 14:11:46 +0100104`
Jamie Hannaford4ec6afe2015-02-16 16:52:49 +0100105
Jamie Hannaforde635b7d2015-02-18 14:11:46 +0100106var createReplicaResp = `
Jamie Hannaford4ec6afe2015-02-16 16:52:49 +0100107{
108 "instance": {
109 "status": "BUILD",
Jamie Hannaforde65ad952015-11-16 14:05:11 +0100110 "updated": "` + timestamp + `",
Jamie Hannaford4ec6afe2015-02-16 16:52:49 +0100111 "name": "t2s1_ALT_GUEST",
112 "links": [
113 {
114 "href": "https://ord.databases.api.rackspacecloud.com/v1.0/5919009/instances/8367c312-7c40-4a66-aab1-5767478914fc",
115 "rel": "self"
116 },
117 {
118 "href": "https://ord.databases.api.rackspacecloud.com/instances/8367c312-7c40-4a66-aab1-5767478914fc",
119 "rel": "bookmark"
120 }
121 ],
Jamie Hannaforde65ad952015-11-16 14:05:11 +0100122 "created": "` + timestamp + `",
Jamie Hannaford4ec6afe2015-02-16 16:52:49 +0100123 "id": "8367c312-7c40-4a66-aab1-5767478914fc",
Jamie Hannaforde635b7d2015-02-18 14:11:46 +0100124 "volume": {
125 "size": 1
126 },
127 "flavor": {
128 "id": "9"
129 },
Jamie Hannaford4ec6afe2015-02-16 16:52:49 +0100130 "datastore": {
131 "version": "5.6",
132 "type": "mysql"
133 },
Jamie Hannaforde635b7d2015-02-18 14:11:46 +0100134 "replica_of": {
135 "id": "6bdca2fc-418e-40bd-a595-62abda61862d"
136 }
Jamie Hannaford4ec6afe2015-02-16 16:52:49 +0100137 }
138}
Jamie Hannaforde635b7d2015-02-18 14:11:46 +0100139`
Jamie Hannaford4ec6afe2015-02-16 16:52:49 +0100140
Jamie Hannaforde635b7d2015-02-18 14:11:46 +0100141var listReplicasResp = `
Jamie Hannaford4ec6afe2015-02-16 16:52:49 +0100142{
Jamie Hannaforde635b7d2015-02-18 14:11:46 +0100143 "instances": [
144 {
145 "status": "ACTIVE",
146 "name": "t1s1_ALT_GUEST",
147 "links": [
148 {
149 "href": "https://ord.databases.api.rackspacecloud.com/v1.0/1234/instances/3c691f06-bf9a-4618-b7ec-2817ce0cf254",
150 "rel": "self"
151 },
152 {
153 "href": "https://ord.databases.api.rackspacecloud.com/instances/3c691f06-bf9a-4618-b7ec-2817ce0cf254",
154 "rel": "bookmark"
155 }
156 ],
157 "ip": [
158 "10.0.0.3"
159 ],
160 "id": "3c691f06-bf9a-4618-b7ec-2817ce0cf254",
161 "volume": {
162 "size": 1
163 },
164 "flavor": {
165 "id": "9"
166 },
167 "datastore": {
168 "version": "5.6",
169 "type": "mysql"
170 },
171 "replica_of": {
172 "id": "8b499b45-52d6-402d-b398-f9d8f279c69a"
173 }
174 }
175 ]
Jamie Hannaford4ec6afe2015-02-16 16:52:49 +0100176}
Jamie Hannaforde635b7d2015-02-18 14:11:46 +0100177`
Jamie Hannaford4ec6afe2015-02-16 16:52:49 +0100178
Jamie Hannaforde635b7d2015-02-18 14:11:46 +0100179var getReplicaResp = `
Jamie Hannaford4ec6afe2015-02-16 16:52:49 +0100180{
181 "instance": {
182 "status": "ACTIVE",
Jamie Hannaforde65ad952015-11-16 14:05:11 +0100183 "updated": "` + timestamp + `",
Jamie Hannaford4ec6afe2015-02-16 16:52:49 +0100184 "name": "t1_ALT_GUEST",
Jamie Hannaforde65ad952015-11-16 14:05:11 +0100185 "created": "` + timestamp + `",
Jamie Hannaford4ec6afe2015-02-16 16:52:49 +0100186 "ip": [
187 "10.0.0.2"
188 ],
189 "replicas": [
Jamie Hannaforde635b7d2015-02-18 14:11:46 +0100190 {
191 "id": "3c691f06-bf9a-4618-b7ec-2817ce0cf254"
192 }
Jamie Hannaford4ec6afe2015-02-16 16:52:49 +0100193 ],
194 "id": "8b499b45-52d6-402d-b398-f9d8f279c69a",
195 "volume": {
196 "used": 0.54,
197 "size": 1
198 },
Jamie Hannaforde635b7d2015-02-18 14:11:46 +0100199 "flavor": {
200 "id": "9"
201 },
Jamie Hannaford4ec6afe2015-02-16 16:52:49 +0100202 "datastore": {
203 "version": "5.6",
204 "type": "mysql"
205 }
206 }
207}
Jamie Hannaforde635b7d2015-02-18 14:11:46 +0100208`
209
210var detachReq = `
211{
212 "instance": {
213 "replica_of": "",
214 "slave_of": ""
215 }
Jamie Hannaford4ec6afe2015-02-16 16:52:49 +0100216}
Jamie Hannaforde635b7d2015-02-18 14:11:46 +0100217`
Jamie Hannaford4ec6afe2015-02-16 16:52:49 +0100218
Jamie Hannaforde635b7d2015-02-18 14:11:46 +0100219var getConfigResp = `
Jamie Hannaford936a5472015-02-10 14:38:28 +0100220{
221 "instance": {
222 "configuration": {
223 "basedir": "/usr",
224 "connect_timeout": "15",
225 "datadir": "/var/lib/mysql",
226 "default_storage_engine": "innodb",
227 "innodb_buffer_pool_instances": "1",
228 "innodb_buffer_pool_size": "175M",
229 "innodb_checksum_algorithm": "crc32",
230 "innodb_data_file_path": "ibdata1:10M:autoextend",
231 "innodb_file_per_table": "1",
232 "innodb_io_capacity": "200",
233 "innodb_log_file_size": "256M",
234 "innodb_log_files_in_group": "2",
235 "innodb_open_files": "8192",
236 "innodb_thread_concurrency": "0",
237 "join_buffer_size": "1M",
238 "key_buffer_size": "50M",
239 "local-infile": "0",
240 "log-error": "/var/log/mysql/mysqld.log",
241 "max_allowed_packet": "16M",
242 "max_connect_errors": "10000",
243 "max_connections": "40",
244 "max_heap_table_size": "16M",
245 "myisam-recover": "BACKUP",
246 "open_files_limit": "8192",
247 "performance_schema": "off",
248 "pid_file": "/var/run/mysqld/mysqld.pid",
249 "port": "3306",
250 "query_cache_limit": "1M",
251 "query_cache_size": "8M",
252 "query_cache_type": "1",
253 "read_buffer_size": "256K",
254 "read_rnd_buffer_size": "1M",
255 "server_id": "1",
256 "skip-external-locking": "1",
257 "skip_name_resolve": "1",
258 "sort_buffer_size": "256K",
259 "table_open_cache": "4096",
260 "thread_stack": "192K",
261 "tmp_table_size": "16M",
262 "tmpdir": "/var/tmp",
263 "user": "mysql",
264 "wait_timeout": "3600"
265 }
266 }
267}
Jamie Hannaforde635b7d2015-02-18 14:11:46 +0100268`
Jamie Hannafordf77fc102015-02-10 14:56:02 +0100269
Jamie Hannaforde635b7d2015-02-18 14:11:46 +0100270var associateReq = `{"instance": {"configuration": "{configGroupID}"}}`
Jamie Hannafordf77fc102015-02-10 14:56:02 +0100271
Jamie Hannaforde635b7d2015-02-18 14:11:46 +0100272var listBackupsResp = `
Jamie Hannaford2e817322015-02-16 15:29:17 +0100273{
274 "backups": [
275 {
276 "status": "COMPLETED",
Jamie Hannaforde65ad952015-11-16 14:05:11 +0100277 "updated": "` + timestamp + `",
Jamie Hannaford2e817322015-02-16 15:29:17 +0100278 "description": "Backup from Restored Instance",
279 "datastore": {
280 "version": "5.1",
281 "type": "MySQL",
282 "version_id": "20000000-0000-0000-0000-000000000002"
283 },
284 "id": "87972694-4be2-40f5-83f8-501656e0032a",
285 "size": 0.141026,
286 "name": "restored_backup",
Jamie Hannaforde65ad952015-11-16 14:05:11 +0100287 "created": "` + timestamp + `",
Jamie Hannaford2e817322015-02-16 15:29:17 +0100288 "instance_id": "29af2cd9-0674-48ab-b87a-b160f00208e6",
289 "parent_id": null,
290 "locationRef": "http://localhost/path/to/backup"
291 }
292 ]
293}
Jamie Hannaforde635b7d2015-02-18 14:11:46 +0100294`
Jamie Hannaford4ec6afe2015-02-16 16:52:49 +0100295
Jamie Hannaforde635b7d2015-02-18 14:11:46 +0100296var (
Jamie Hannaford72749162015-10-14 12:14:32 +0200297 createResp = fmt.Sprintf(`{"instance":%s}`, instance)
298 getResp = fmt.Sprintf(`{"instance":%s}`, instance)
299 associateResp = fmt.Sprintf(`{"instance":%s}`, instance)
300 listInstancesResp = fmt.Sprintf(`{"instances":[%s]}`, instance)
Jamie Hannaforde635b7d2015-02-18 14:11:46 +0100301)
Jamie Hannaford4ec6afe2015-02-16 16:52:49 +0100302
Jamie Hannaford72749162015-10-14 12:14:32 +0200303var instanceID = "{instanceID}"
304
305var expectedInstance = &Instance{
Jamie Hannaforde65ad952015-11-16 14:05:11 +0100306 Created: timeVal,
307 Updated: timeVal,
Jamie Hannaford72749162015-10-14 12:14:32 +0200308 Datastore: datastores.DatastorePartial{Type: "mysql", Version: "5.6"},
309 Flavor: flavors.Flavor{
310 ID: "1",
311 Links: []gophercloud.Link{
312 gophercloud.Link{Href: "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1", Rel: "self"},
313 gophercloud.Link{Href: "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1", Rel: "bookmark"},
314 },
315 },
316 Hostname: "e09ad9a3f73309469cf1f43d11e79549caf9acf2.rackspaceclouddb.com",
317 ID: instanceID,
318 Links: []gophercloud.Link{
319 gophercloud.Link{Href: "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1", Rel: "self"},
320 },
321 Name: "json_rack_instance",
322 Status: "BUILD",
323 Volume: os.Volume{Size: 2},
324}
325
Jamie Hannaforde635b7d2015-02-18 14:11:46 +0100326var expectedReplica = &Instance{
327 Status: "BUILD",
Jamie Hannaforde65ad952015-11-16 14:05:11 +0100328 Updated: timeVal,
Jamie Hannaforde635b7d2015-02-18 14:11:46 +0100329 Name: "t2s1_ALT_GUEST",
330 Links: []gophercloud.Link{
331 gophercloud.Link{Rel: "self", Href: "https://ord.databases.api.rackspacecloud.com/v1.0/5919009/instances/8367c312-7c40-4a66-aab1-5767478914fc"},
332 gophercloud.Link{Rel: "bookmark", Href: "https://ord.databases.api.rackspacecloud.com/instances/8367c312-7c40-4a66-aab1-5767478914fc"},
333 },
Jamie Hannaforde65ad952015-11-16 14:05:11 +0100334 Created: timeVal,
Jamie Hannaforde635b7d2015-02-18 14:11:46 +0100335 ID: "8367c312-7c40-4a66-aab1-5767478914fc",
336 Volume: os.Volume{Size: 1},
Jamie Hannaford11108402015-02-23 10:31:41 +0100337 Flavor: flavors.Flavor{ID: "9"},
Jamie Hannaforde635b7d2015-02-18 14:11:46 +0100338 Datastore: datastores.DatastorePartial{Version: "5.6", Type: "mysql"},
339 ReplicaOf: &Instance{
340 ID: "6bdca2fc-418e-40bd-a595-62abda61862d",
341 },
Jamie Hannaford4ec6afe2015-02-16 16:52:49 +0100342}