Jamie Hannaford | 6ee7d4a | 2015-02-09 17:26:49 +0100 | [diff] [blame] | 1 | package instances |
| 2 | |
| 3 | import ( |
Jamie Hannaford | 7274916 | 2015-10-14 12:14:32 +0200 | [diff] [blame] | 4 | "fmt" |
| 5 | |
Jamie Hannaford | e635b7d | 2015-02-18 14:11:46 +0100 | [diff] [blame] | 6 | "github.com/rackspace/gophercloud" |
Jamie Hannaford | 52dbcee | 2015-10-06 16:09:56 +0200 | [diff] [blame] | 7 | "github.com/rackspace/gophercloud/openstack/db/v1/datastores" |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 8 | "github.com/rackspace/gophercloud/openstack/db/v1/flavors" |
Jamie Hannaford | e635b7d | 2015-02-18 14:11:46 +0100 | [diff] [blame] | 9 | os "github.com/rackspace/gophercloud/openstack/db/v1/instances" |
Jamie Hannaford | 6ee7d4a | 2015-02-09 17:26:49 +0100 | [diff] [blame] | 10 | ) |
| 11 | |
Jamie Hannaford | e635b7d | 2015-02-18 14:11:46 +0100 | [diff] [blame] | 12 | const instance = ` |
Jamie Hannaford | 39d4ffb | 2015-02-10 13:19:44 +0100 | [diff] [blame] | 13 | { |
Jamie Hannaford | 7274916 | 2015-10-14 12:14:32 +0200 | [diff] [blame] | 14 | "created": "2014-02-13T21:47:13", |
| 15 | "datastore": { |
| 16 | "type": "mysql", |
| 17 | "version": "5.6" |
| 18 | }, |
| 19 | "flavor": { |
| 20 | "id": "1", |
Jamie Hannaford | 39d4ffb | 2015-02-10 13:19:44 +0100 | [diff] [blame] | 21 | "links": [ |
| 22 | { |
| 23 | "href": "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1", |
| 24 | "rel": "self" |
Jamie Hannaford | 7274916 | 2015-10-14 12:14:32 +0200 | [diff] [blame] | 25 | }, |
| 26 | { |
| 27 | "href": "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1", |
| 28 | "rel": "bookmark" |
Jamie Hannaford | 39d4ffb | 2015-02-10 13:19:44 +0100 | [diff] [blame] | 29 | } |
Jamie Hannaford | 7274916 | 2015-10-14 12:14:32 +0200 | [diff] [blame] | 30 | ] |
| 31 | }, |
| 32 | "links": [ |
| 33 | { |
| 34 | "href": "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1", |
| 35 | "rel": "self" |
Jamie Hannaford | 39d4ffb | 2015-02-10 13:19:44 +0100 | [diff] [blame] | 36 | } |
Jamie Hannaford | 7274916 | 2015-10-14 12:14:32 +0200 | [diff] [blame] | 37 | ], |
| 38 | "hostname": "e09ad9a3f73309469cf1f43d11e79549caf9acf2.rackspaceclouddb.com", |
| 39 | "id": "{instanceID}", |
| 40 | "name": "json_rack_instance", |
| 41 | "status": "BUILD", |
| 42 | "updated": "2014-02-13T21:47:13", |
| 43 | "volume": { |
| 44 | "size": 2 |
Jamie Hannaford | 39d4ffb | 2015-02-10 13:19:44 +0100 | [diff] [blame] | 45 | } |
| 46 | } |
| 47 | ` |
| 48 | |
Jamie Hannaford | e635b7d | 2015-02-18 14:11:46 +0100 | [diff] [blame] | 49 | var createReq = ` |
Jamie Hannaford | 6ee7d4a | 2015-02-09 17:26:49 +0100 | [diff] [blame] | 50 | { |
| 51 | "instance": { |
| 52 | "databases": [ |
| 53 | { |
| 54 | "character_set": "utf8", |
| 55 | "collate": "utf8_general_ci", |
| 56 | "name": "sampledb" |
| 57 | }, |
| 58 | { |
| 59 | "name": "nextround" |
| 60 | } |
| 61 | ], |
| 62 | "flavorRef": "1", |
| 63 | "name": "json_rack_instance", |
| 64 | "users": [ |
| 65 | { |
| 66 | "databases": [ |
| 67 | { |
| 68 | "name": "sampledb" |
| 69 | } |
| 70 | ], |
| 71 | "name": "demouser", |
| 72 | "password": "demopassword" |
| 73 | } |
| 74 | ], |
| 75 | "volume": { |
| 76 | "size": 2 |
| 77 | }, |
Jamie Hannaford | e635b7d | 2015-02-18 14:11:46 +0100 | [diff] [blame] | 78 | "restorePoint": { |
| 79 | "backupRef": "1234567890" |
| 80 | } |
Jamie Hannaford | 6ee7d4a | 2015-02-09 17:26:49 +0100 | [diff] [blame] | 81 | } |
| 82 | } |
Jamie Hannaford | e635b7d | 2015-02-18 14:11:46 +0100 | [diff] [blame] | 83 | ` |
Jamie Hannaford | 6ee7d4a | 2015-02-09 17:26:49 +0100 | [diff] [blame] | 84 | |
Jamie Hannaford | e635b7d | 2015-02-18 14:11:46 +0100 | [diff] [blame] | 85 | var createReplicaReq = ` |
Jamie Hannaford | 4ec6afe | 2015-02-16 16:52:49 +0100 | [diff] [blame] | 86 | { |
| 87 | "instance": { |
| 88 | "volume": { |
| 89 | "size": 1 |
| 90 | }, |
| 91 | "flavorRef": "9", |
| 92 | "name": "t2s1_ALT_GUEST", |
| 93 | "replica_of": "6bdca2fc-418e-40bd-a595-62abda61862d" |
| 94 | } |
| 95 | } |
Jamie Hannaford | e635b7d | 2015-02-18 14:11:46 +0100 | [diff] [blame] | 96 | ` |
Jamie Hannaford | 4ec6afe | 2015-02-16 16:52:49 +0100 | [diff] [blame] | 97 | |
Jamie Hannaford | e635b7d | 2015-02-18 14:11:46 +0100 | [diff] [blame] | 98 | var createReplicaResp = ` |
Jamie Hannaford | 4ec6afe | 2015-02-16 16:52:49 +0100 | [diff] [blame] | 99 | { |
| 100 | "instance": { |
| 101 | "status": "BUILD", |
| 102 | "updated": "2014-10-14T18:42:15", |
| 103 | "name": "t2s1_ALT_GUEST", |
| 104 | "links": [ |
| 105 | { |
| 106 | "href": "https://ord.databases.api.rackspacecloud.com/v1.0/5919009/instances/8367c312-7c40-4a66-aab1-5767478914fc", |
| 107 | "rel": "self" |
| 108 | }, |
| 109 | { |
| 110 | "href": "https://ord.databases.api.rackspacecloud.com/instances/8367c312-7c40-4a66-aab1-5767478914fc", |
| 111 | "rel": "bookmark" |
| 112 | } |
| 113 | ], |
| 114 | "created": "2014-10-14T18:42:15", |
| 115 | "id": "8367c312-7c40-4a66-aab1-5767478914fc", |
Jamie Hannaford | e635b7d | 2015-02-18 14:11:46 +0100 | [diff] [blame] | 116 | "volume": { |
| 117 | "size": 1 |
| 118 | }, |
| 119 | "flavor": { |
| 120 | "id": "9" |
| 121 | }, |
Jamie Hannaford | 4ec6afe | 2015-02-16 16:52:49 +0100 | [diff] [blame] | 122 | "datastore": { |
| 123 | "version": "5.6", |
| 124 | "type": "mysql" |
| 125 | }, |
Jamie Hannaford | e635b7d | 2015-02-18 14:11:46 +0100 | [diff] [blame] | 126 | "replica_of": { |
| 127 | "id": "6bdca2fc-418e-40bd-a595-62abda61862d" |
| 128 | } |
Jamie Hannaford | 4ec6afe | 2015-02-16 16:52:49 +0100 | [diff] [blame] | 129 | } |
| 130 | } |
Jamie Hannaford | e635b7d | 2015-02-18 14:11:46 +0100 | [diff] [blame] | 131 | ` |
Jamie Hannaford | 4ec6afe | 2015-02-16 16:52:49 +0100 | [diff] [blame] | 132 | |
Jamie Hannaford | e635b7d | 2015-02-18 14:11:46 +0100 | [diff] [blame] | 133 | var listReplicasResp = ` |
Jamie Hannaford | 4ec6afe | 2015-02-16 16:52:49 +0100 | [diff] [blame] | 134 | { |
Jamie Hannaford | e635b7d | 2015-02-18 14:11:46 +0100 | [diff] [blame] | 135 | "instances": [ |
| 136 | { |
| 137 | "status": "ACTIVE", |
| 138 | "name": "t1s1_ALT_GUEST", |
| 139 | "links": [ |
| 140 | { |
| 141 | "href": "https://ord.databases.api.rackspacecloud.com/v1.0/1234/instances/3c691f06-bf9a-4618-b7ec-2817ce0cf254", |
| 142 | "rel": "self" |
| 143 | }, |
| 144 | { |
| 145 | "href": "https://ord.databases.api.rackspacecloud.com/instances/3c691f06-bf9a-4618-b7ec-2817ce0cf254", |
| 146 | "rel": "bookmark" |
| 147 | } |
| 148 | ], |
| 149 | "ip": [ |
| 150 | "10.0.0.3" |
| 151 | ], |
| 152 | "id": "3c691f06-bf9a-4618-b7ec-2817ce0cf254", |
| 153 | "volume": { |
| 154 | "size": 1 |
| 155 | }, |
| 156 | "flavor": { |
| 157 | "id": "9" |
| 158 | }, |
| 159 | "datastore": { |
| 160 | "version": "5.6", |
| 161 | "type": "mysql" |
| 162 | }, |
| 163 | "replica_of": { |
| 164 | "id": "8b499b45-52d6-402d-b398-f9d8f279c69a" |
| 165 | } |
| 166 | } |
| 167 | ] |
Jamie Hannaford | 4ec6afe | 2015-02-16 16:52:49 +0100 | [diff] [blame] | 168 | } |
Jamie Hannaford | e635b7d | 2015-02-18 14:11:46 +0100 | [diff] [blame] | 169 | ` |
Jamie Hannaford | 4ec6afe | 2015-02-16 16:52:49 +0100 | [diff] [blame] | 170 | |
Jamie Hannaford | e635b7d | 2015-02-18 14:11:46 +0100 | [diff] [blame] | 171 | var getReplicaResp = ` |
Jamie Hannaford | 4ec6afe | 2015-02-16 16:52:49 +0100 | [diff] [blame] | 172 | { |
| 173 | "instance": { |
| 174 | "status": "ACTIVE", |
| 175 | "updated": "2014-09-26T19:15:57", |
| 176 | "name": "t1_ALT_GUEST", |
| 177 | "created": "2014-09-26T19:15:50", |
| 178 | "ip": [ |
| 179 | "10.0.0.2" |
| 180 | ], |
| 181 | "replicas": [ |
Jamie Hannaford | e635b7d | 2015-02-18 14:11:46 +0100 | [diff] [blame] | 182 | { |
| 183 | "id": "3c691f06-bf9a-4618-b7ec-2817ce0cf254" |
| 184 | } |
Jamie Hannaford | 4ec6afe | 2015-02-16 16:52:49 +0100 | [diff] [blame] | 185 | ], |
| 186 | "id": "8b499b45-52d6-402d-b398-f9d8f279c69a", |
| 187 | "volume": { |
| 188 | "used": 0.54, |
| 189 | "size": 1 |
| 190 | }, |
Jamie Hannaford | e635b7d | 2015-02-18 14:11:46 +0100 | [diff] [blame] | 191 | "flavor": { |
| 192 | "id": "9" |
| 193 | }, |
Jamie Hannaford | 4ec6afe | 2015-02-16 16:52:49 +0100 | [diff] [blame] | 194 | "datastore": { |
| 195 | "version": "5.6", |
| 196 | "type": "mysql" |
| 197 | } |
| 198 | } |
| 199 | } |
Jamie Hannaford | e635b7d | 2015-02-18 14:11:46 +0100 | [diff] [blame] | 200 | ` |
| 201 | |
| 202 | var detachReq = ` |
| 203 | { |
| 204 | "instance": { |
| 205 | "replica_of": "", |
| 206 | "slave_of": "" |
| 207 | } |
Jamie Hannaford | 4ec6afe | 2015-02-16 16:52:49 +0100 | [diff] [blame] | 208 | } |
Jamie Hannaford | e635b7d | 2015-02-18 14:11:46 +0100 | [diff] [blame] | 209 | ` |
Jamie Hannaford | 4ec6afe | 2015-02-16 16:52:49 +0100 | [diff] [blame] | 210 | |
Jamie Hannaford | e635b7d | 2015-02-18 14:11:46 +0100 | [diff] [blame] | 211 | var getConfigResp = ` |
Jamie Hannaford | 936a547 | 2015-02-10 14:38:28 +0100 | [diff] [blame] | 212 | { |
| 213 | "instance": { |
| 214 | "configuration": { |
| 215 | "basedir": "/usr", |
| 216 | "connect_timeout": "15", |
| 217 | "datadir": "/var/lib/mysql", |
| 218 | "default_storage_engine": "innodb", |
| 219 | "innodb_buffer_pool_instances": "1", |
| 220 | "innodb_buffer_pool_size": "175M", |
| 221 | "innodb_checksum_algorithm": "crc32", |
| 222 | "innodb_data_file_path": "ibdata1:10M:autoextend", |
| 223 | "innodb_file_per_table": "1", |
| 224 | "innodb_io_capacity": "200", |
| 225 | "innodb_log_file_size": "256M", |
| 226 | "innodb_log_files_in_group": "2", |
| 227 | "innodb_open_files": "8192", |
| 228 | "innodb_thread_concurrency": "0", |
| 229 | "join_buffer_size": "1M", |
| 230 | "key_buffer_size": "50M", |
| 231 | "local-infile": "0", |
| 232 | "log-error": "/var/log/mysql/mysqld.log", |
| 233 | "max_allowed_packet": "16M", |
| 234 | "max_connect_errors": "10000", |
| 235 | "max_connections": "40", |
| 236 | "max_heap_table_size": "16M", |
| 237 | "myisam-recover": "BACKUP", |
| 238 | "open_files_limit": "8192", |
| 239 | "performance_schema": "off", |
| 240 | "pid_file": "/var/run/mysqld/mysqld.pid", |
| 241 | "port": "3306", |
| 242 | "query_cache_limit": "1M", |
| 243 | "query_cache_size": "8M", |
| 244 | "query_cache_type": "1", |
| 245 | "read_buffer_size": "256K", |
| 246 | "read_rnd_buffer_size": "1M", |
| 247 | "server_id": "1", |
| 248 | "skip-external-locking": "1", |
| 249 | "skip_name_resolve": "1", |
| 250 | "sort_buffer_size": "256K", |
| 251 | "table_open_cache": "4096", |
| 252 | "thread_stack": "192K", |
| 253 | "tmp_table_size": "16M", |
| 254 | "tmpdir": "/var/tmp", |
| 255 | "user": "mysql", |
| 256 | "wait_timeout": "3600" |
| 257 | } |
| 258 | } |
| 259 | } |
Jamie Hannaford | e635b7d | 2015-02-18 14:11:46 +0100 | [diff] [blame] | 260 | ` |
Jamie Hannaford | f77fc10 | 2015-02-10 14:56:02 +0100 | [diff] [blame] | 261 | |
Jamie Hannaford | e635b7d | 2015-02-18 14:11:46 +0100 | [diff] [blame] | 262 | var associateReq = `{"instance": {"configuration": "{configGroupID}"}}` |
Jamie Hannaford | f77fc10 | 2015-02-10 14:56:02 +0100 | [diff] [blame] | 263 | |
Jamie Hannaford | e635b7d | 2015-02-18 14:11:46 +0100 | [diff] [blame] | 264 | var listBackupsResp = ` |
Jamie Hannaford | 2e81732 | 2015-02-16 15:29:17 +0100 | [diff] [blame] | 265 | { |
| 266 | "backups": [ |
| 267 | { |
| 268 | "status": "COMPLETED", |
| 269 | "updated": "2014-06-18T21:24:39", |
| 270 | "description": "Backup from Restored Instance", |
| 271 | "datastore": { |
| 272 | "version": "5.1", |
| 273 | "type": "MySQL", |
| 274 | "version_id": "20000000-0000-0000-0000-000000000002" |
| 275 | }, |
| 276 | "id": "87972694-4be2-40f5-83f8-501656e0032a", |
| 277 | "size": 0.141026, |
| 278 | "name": "restored_backup", |
| 279 | "created": "2014-06-18T21:23:35", |
| 280 | "instance_id": "29af2cd9-0674-48ab-b87a-b160f00208e6", |
| 281 | "parent_id": null, |
| 282 | "locationRef": "http://localhost/path/to/backup" |
| 283 | } |
| 284 | ] |
| 285 | } |
Jamie Hannaford | e635b7d | 2015-02-18 14:11:46 +0100 | [diff] [blame] | 286 | ` |
Jamie Hannaford | 4ec6afe | 2015-02-16 16:52:49 +0100 | [diff] [blame] | 287 | |
Jamie Hannaford | e635b7d | 2015-02-18 14:11:46 +0100 | [diff] [blame] | 288 | var ( |
Jamie Hannaford | 7274916 | 2015-10-14 12:14:32 +0200 | [diff] [blame] | 289 | createResp = fmt.Sprintf(`{"instance":%s}`, instance) |
| 290 | getResp = fmt.Sprintf(`{"instance":%s}`, instance) |
| 291 | associateResp = fmt.Sprintf(`{"instance":%s}`, instance) |
| 292 | listInstancesResp = fmt.Sprintf(`{"instances":[%s]}`, instance) |
Jamie Hannaford | e635b7d | 2015-02-18 14:11:46 +0100 | [diff] [blame] | 293 | ) |
Jamie Hannaford | 4ec6afe | 2015-02-16 16:52:49 +0100 | [diff] [blame] | 294 | |
Jamie Hannaford | 7274916 | 2015-10-14 12:14:32 +0200 | [diff] [blame] | 295 | var instanceID = "{instanceID}" |
| 296 | |
| 297 | var expectedInstance = &Instance{ |
| 298 | Created: "2014-02-13T21:47:13", |
| 299 | Updated: "2014-02-13T21:47:13", |
| 300 | Datastore: datastores.DatastorePartial{Type: "mysql", Version: "5.6"}, |
| 301 | Flavor: flavors.Flavor{ |
| 302 | ID: "1", |
| 303 | Links: []gophercloud.Link{ |
| 304 | gophercloud.Link{Href: "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1", Rel: "self"}, |
| 305 | gophercloud.Link{Href: "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1", Rel: "bookmark"}, |
| 306 | }, |
| 307 | }, |
| 308 | Hostname: "e09ad9a3f73309469cf1f43d11e79549caf9acf2.rackspaceclouddb.com", |
| 309 | ID: instanceID, |
| 310 | Links: []gophercloud.Link{ |
| 311 | gophercloud.Link{Href: "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1", Rel: "self"}, |
| 312 | }, |
| 313 | Name: "json_rack_instance", |
| 314 | Status: "BUILD", |
| 315 | Volume: os.Volume{Size: 2}, |
| 316 | } |
| 317 | |
Jamie Hannaford | e635b7d | 2015-02-18 14:11:46 +0100 | [diff] [blame] | 318 | var expectedReplica = &Instance{ |
| 319 | Status: "BUILD", |
| 320 | Updated: "2014-10-14T18:42:15", |
| 321 | Name: "t2s1_ALT_GUEST", |
| 322 | Links: []gophercloud.Link{ |
| 323 | gophercloud.Link{Rel: "self", Href: "https://ord.databases.api.rackspacecloud.com/v1.0/5919009/instances/8367c312-7c40-4a66-aab1-5767478914fc"}, |
| 324 | gophercloud.Link{Rel: "bookmark", Href: "https://ord.databases.api.rackspacecloud.com/instances/8367c312-7c40-4a66-aab1-5767478914fc"}, |
| 325 | }, |
| 326 | Created: "2014-10-14T18:42:15", |
| 327 | ID: "8367c312-7c40-4a66-aab1-5767478914fc", |
| 328 | Volume: os.Volume{Size: 1}, |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 329 | Flavor: flavors.Flavor{ID: "9"}, |
Jamie Hannaford | e635b7d | 2015-02-18 14:11:46 +0100 | [diff] [blame] | 330 | Datastore: datastores.DatastorePartial{Version: "5.6", Type: "mysql"}, |
| 331 | ReplicaOf: &Instance{ |
| 332 | ID: "6bdca2fc-418e-40bd-a595-62abda61862d", |
| 333 | }, |
Jamie Hannaford | 4ec6afe | 2015-02-16 16:52:49 +0100 | [diff] [blame] | 334 | } |