Jamie Hannaford | 6ee7d4a | 2015-02-09 17:26:49 +0100 | [diff] [blame] | 1 | package instances |
| 2 | |
| 3 | import ( |
| 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 Hannaford | 39d4ffb | 2015-02-10 13:19:44 +0100 | [diff] [blame] | 12 | const 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 Hannaford | 6ee7d4a | 2015-02-09 17:26:49 +0100 | [diff] [blame] | 51 | func 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 Hannaford | 302c0b6 | 2015-02-16 14:12:34 +0100 | [diff] [blame] | 88 | "restorePoint": { |
| 89 | "backupRef": "1234567890" |
| 90 | } |
Jamie Hannaford | 6ee7d4a | 2015-02-09 17:26:49 +0100 | [diff] [blame] | 91 | } |
| 92 | } |
| 93 | `) |
| 94 | |
Jamie Hannaford | 39d4ffb | 2015-02-10 13:19:44 +0100 | [diff] [blame] | 95 | fmt.Fprintf(w, singleInstanceJson) |
| 96 | }) |
Jamie Hannaford | 6ee7d4a | 2015-02-09 17:26:49 +0100 | [diff] [blame] | 97 | } |
Jamie Hannaford | 39d4ffb | 2015-02-10 13:19:44 +0100 | [diff] [blame] | 98 | |
Jamie Hannaford | 4ec6afe | 2015-02-16 16:52:49 +0100 | [diff] [blame^] | 99 | func HandleCreateReplicaSuccessfully(t *testing.T) { |
| 100 | th.Mux.HandleFunc("/instances", func(w http.ResponseWriter, r *http.Request) { |
| 101 | th.TestMethod(t, r, "POST") |
| 102 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 103 | th.TestJSONRequest(t, r, ` |
| 104 | { |
| 105 | "instance": { |
| 106 | "volume": { |
| 107 | "size": 1 |
| 108 | }, |
| 109 | "flavorRef": "9", |
| 110 | "name": "t2s1_ALT_GUEST", |
| 111 | "replica_of": "6bdca2fc-418e-40bd-a595-62abda61862d" |
| 112 | } |
| 113 | } |
| 114 | `) |
| 115 | |
| 116 | w.Header().Set("Content-Type", "application/json") |
| 117 | w.WriteHeader(http.StatusOK) |
| 118 | |
| 119 | fmt.Fprintf(w, ` |
| 120 | { |
| 121 | "instance": { |
| 122 | "status": "BUILD", |
| 123 | "updated": "2014-10-14T18:42:15", |
| 124 | "name": "t2s1_ALT_GUEST", |
| 125 | "links": [ |
| 126 | { |
| 127 | "href": "https://ord.databases.api.rackspacecloud.com/v1.0/5919009/instances/8367c312-7c40-4a66-aab1-5767478914fc", |
| 128 | "rel": "self" |
| 129 | }, |
| 130 | { |
| 131 | "href": "https://ord.databases.api.rackspacecloud.com/instances/8367c312-7c40-4a66-aab1-5767478914fc", |
| 132 | "rel": "bookmark" |
| 133 | } |
| 134 | ], |
| 135 | "created": "2014-10-14T18:42:15", |
| 136 | "id": "8367c312-7c40-4a66-aab1-5767478914fc", |
| 137 | "volume": {"size": 1}, |
| 138 | "flavor": {"id": "9"}, |
| 139 | "datastore": { |
| 140 | "version": "5.6", |
| 141 | "type": "mysql" |
| 142 | }, |
| 143 | "replica_of": {"id": "6bdca2fc-418e-40bd-a595-62abda61862d"} |
| 144 | } |
| 145 | } |
| 146 | `) |
| 147 | }) |
| 148 | } |
| 149 | |
| 150 | func HandleListReplicasSuccessfully(t *testing.T) { |
| 151 | th.Mux.HandleFunc("/instances", func(w http.ResponseWriter, r *http.Request) { |
| 152 | th.TestMethod(t, r, "GET") |
| 153 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 154 | |
| 155 | w.Header().Add("Content-Type", "application/json") |
| 156 | |
| 157 | fmt.Fprintf(w, ` |
| 158 | { |
| 159 | "instances": [ |
| 160 | { |
| 161 | "status": "ACTIVE", |
| 162 | "name": "t1s1_ALT_GUEST", |
| 163 | "links": [ |
| 164 | { |
| 165 | "href": "https://ord.databases.api.rackspacecloud.com/v1.0/1234/instances/3c691f06-bf9a-4618-b7ec-2817ce0cf254", |
| 166 | "rel": "self" |
| 167 | }, |
| 168 | { |
| 169 | "href": "https://ord.databases.api.rackspacecloud.com/instances/3c691f06-bf9a-4618-b7ec-2817ce0cf254", |
| 170 | "rel": "bookmark" |
| 171 | } |
| 172 | ], |
| 173 | "ip": [ |
| 174 | "10.0.0.3" |
| 175 | ], |
| 176 | "id": "3c691f06-bf9a-4618-b7ec-2817ce0cf254", |
| 177 | "volume": { |
| 178 | "size": 1 |
| 179 | }, |
| 180 | "flavor": { |
| 181 | "id": "9" |
| 182 | }, |
| 183 | "datastore": { |
| 184 | "version": "5.6", |
| 185 | "type": "mysql" |
| 186 | }, |
| 187 | "replica_of": { |
| 188 | "id": "8b499b45-52d6-402d-b398-f9d8f279c69a" |
| 189 | } |
| 190 | } |
| 191 | ] |
| 192 | } |
| 193 | `) |
| 194 | }) |
| 195 | } |
| 196 | |
Jamie Hannaford | 39d4ffb | 2015-02-10 13:19:44 +0100 | [diff] [blame] | 197 | func HandleGetInstanceSuccessfully(t *testing.T, id string) { |
| 198 | th.Mux.HandleFunc("/instances/"+id, func(w http.ResponseWriter, r *http.Request) { |
| 199 | th.TestMethod(t, r, "GET") |
| 200 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 201 | |
| 202 | w.Header().Add("Content-Type", "application/json") |
| 203 | |
| 204 | fmt.Fprintf(w, singleInstanceJson) |
Jamie Hannaford | 6ee7d4a | 2015-02-09 17:26:49 +0100 | [diff] [blame] | 205 | }) |
| 206 | } |
Jamie Hannaford | 936a547 | 2015-02-10 14:38:28 +0100 | [diff] [blame] | 207 | |
Jamie Hannaford | 4ec6afe | 2015-02-16 16:52:49 +0100 | [diff] [blame^] | 208 | func HandleGetReplicaSuccessfully(t *testing.T, id string) { |
| 209 | th.Mux.HandleFunc("/instances/"+id, func(w http.ResponseWriter, r *http.Request) { |
| 210 | th.TestMethod(t, r, "GET") |
| 211 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 212 | |
| 213 | w.Header().Add("Content-Type", "application/json") |
| 214 | |
| 215 | fmt.Fprintf(w, ` |
| 216 | { |
| 217 | "instance": { |
| 218 | "status": "ACTIVE", |
| 219 | "updated": "2014-09-26T19:15:57", |
| 220 | "name": "t1_ALT_GUEST", |
| 221 | "created": "2014-09-26T19:15:50", |
| 222 | "ip": [ |
| 223 | "10.0.0.2" |
| 224 | ], |
| 225 | "replicas": [ |
| 226 | {"id": "3c691f06-bf9a-4618-b7ec-2817ce0cf254"} |
| 227 | ], |
| 228 | "id": "8b499b45-52d6-402d-b398-f9d8f279c69a", |
| 229 | "volume": { |
| 230 | "used": 0.54, |
| 231 | "size": 1 |
| 232 | }, |
| 233 | "flavor": {"id": "9"}, |
| 234 | "datastore": { |
| 235 | "version": "5.6", |
| 236 | "type": "mysql" |
| 237 | } |
| 238 | } |
| 239 | } |
| 240 | `) |
| 241 | }) |
| 242 | } |
| 243 | |
Jamie Hannaford | 936a547 | 2015-02-10 14:38:28 +0100 | [diff] [blame] | 244 | func HandleGetConfigSuccessfully(t *testing.T, id string) { |
| 245 | th.Mux.HandleFunc("/instances/"+id+"/configuration", func(w http.ResponseWriter, r *http.Request) { |
| 246 | th.TestMethod(t, r, "GET") |
| 247 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 248 | |
| 249 | w.Header().Add("Content-Type", "application/json") |
| 250 | |
| 251 | fmt.Fprintf(w, ` |
| 252 | { |
| 253 | "instance": { |
| 254 | "configuration": { |
| 255 | "basedir": "/usr", |
| 256 | "connect_timeout": "15", |
| 257 | "datadir": "/var/lib/mysql", |
| 258 | "default_storage_engine": "innodb", |
| 259 | "innodb_buffer_pool_instances": "1", |
| 260 | "innodb_buffer_pool_size": "175M", |
| 261 | "innodb_checksum_algorithm": "crc32", |
| 262 | "innodb_data_file_path": "ibdata1:10M:autoextend", |
| 263 | "innodb_file_per_table": "1", |
| 264 | "innodb_io_capacity": "200", |
| 265 | "innodb_log_file_size": "256M", |
| 266 | "innodb_log_files_in_group": "2", |
| 267 | "innodb_open_files": "8192", |
| 268 | "innodb_thread_concurrency": "0", |
| 269 | "join_buffer_size": "1M", |
| 270 | "key_buffer_size": "50M", |
| 271 | "local-infile": "0", |
| 272 | "log-error": "/var/log/mysql/mysqld.log", |
| 273 | "max_allowed_packet": "16M", |
| 274 | "max_connect_errors": "10000", |
| 275 | "max_connections": "40", |
| 276 | "max_heap_table_size": "16M", |
| 277 | "myisam-recover": "BACKUP", |
| 278 | "open_files_limit": "8192", |
| 279 | "performance_schema": "off", |
| 280 | "pid_file": "/var/run/mysqld/mysqld.pid", |
| 281 | "port": "3306", |
| 282 | "query_cache_limit": "1M", |
| 283 | "query_cache_size": "8M", |
| 284 | "query_cache_type": "1", |
| 285 | "read_buffer_size": "256K", |
| 286 | "read_rnd_buffer_size": "1M", |
| 287 | "server_id": "1", |
| 288 | "skip-external-locking": "1", |
| 289 | "skip_name_resolve": "1", |
| 290 | "sort_buffer_size": "256K", |
| 291 | "table_open_cache": "4096", |
| 292 | "thread_stack": "192K", |
| 293 | "tmp_table_size": "16M", |
| 294 | "tmpdir": "/var/tmp", |
| 295 | "user": "mysql", |
| 296 | "wait_timeout": "3600" |
| 297 | } |
| 298 | } |
| 299 | } |
| 300 | `) |
| 301 | }) |
| 302 | } |
Jamie Hannaford | f77fc10 | 2015-02-10 14:56:02 +0100 | [diff] [blame] | 303 | |
| 304 | func HandleAssociateGroupSuccessfully(t *testing.T, id string) { |
| 305 | th.Mux.HandleFunc("/instances/"+id, func(w http.ResponseWriter, r *http.Request) { |
| 306 | th.TestMethod(t, r, "PUT") |
| 307 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 308 | th.TestJSONRequest(t, r, `{"instance": {"configuration": "{configGroupID}"}}`) |
| 309 | |
| 310 | w.WriteHeader(http.StatusAccepted) |
| 311 | w.Header().Add("Content-Type", "application/json") |
| 312 | |
| 313 | fmt.Fprintf(w, singleInstanceJson) |
| 314 | }) |
| 315 | } |
Jamie Hannaford | 2e81732 | 2015-02-16 15:29:17 +0100 | [diff] [blame] | 316 | |
| 317 | func HandleListBackupsSuccessfully(t *testing.T, id string) { |
| 318 | th.Mux.HandleFunc("/instances/"+id+"/backups", func(w http.ResponseWriter, r *http.Request) { |
| 319 | th.TestMethod(t, r, "GET") |
| 320 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 321 | |
| 322 | w.Header().Add("Content-Type", "application/json") |
| 323 | |
| 324 | fmt.Fprintf(w, ` |
| 325 | { |
| 326 | "backups": [ |
| 327 | { |
| 328 | "status": "COMPLETED", |
| 329 | "updated": "2014-06-18T21:24:39", |
| 330 | "description": "Backup from Restored Instance", |
| 331 | "datastore": { |
| 332 | "version": "5.1", |
| 333 | "type": "MySQL", |
| 334 | "version_id": "20000000-0000-0000-0000-000000000002" |
| 335 | }, |
| 336 | "id": "87972694-4be2-40f5-83f8-501656e0032a", |
| 337 | "size": 0.141026, |
| 338 | "name": "restored_backup", |
| 339 | "created": "2014-06-18T21:23:35", |
| 340 | "instance_id": "29af2cd9-0674-48ab-b87a-b160f00208e6", |
| 341 | "parent_id": null, |
| 342 | "locationRef": "http://localhost/path/to/backup" |
| 343 | } |
| 344 | ] |
| 345 | } |
| 346 | `) |
| 347 | }) |
| 348 | } |
Jamie Hannaford | 4ec6afe | 2015-02-16 16:52:49 +0100 | [diff] [blame^] | 349 | |
| 350 | func HandleDetachReplicaSuccessfully(t *testing.T, id string) { |
| 351 | th.Mux.HandleFunc("/instances/"+id, func(w http.ResponseWriter, r *http.Request) { |
| 352 | th.TestMethod(t, r, "PATCH") |
| 353 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 354 | |
| 355 | th.TestJSONRequest(t, r, ` |
| 356 | { |
| 357 | "instance": { |
| 358 | "replica_of": "", |
| 359 | "slave_of": "" |
| 360 | } |
| 361 | } |
| 362 | `) |
| 363 | |
| 364 | w.Header().Add("Content-Type", "application/json") |
| 365 | w.WriteHeader(http.StatusAccepted) |
| 366 | }) |
| 367 | } |