Jamie Hannaford | 936a547 | 2015-02-10 14:38:28 +0100 | [diff] [blame] | 1 | package instances |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
Jamie Hannaford | 4ec6afe | 2015-02-16 16:52:49 +0100 | [diff] [blame] | 6 | "github.com/rackspace/gophercloud" |
| 7 | os "github.com/rackspace/gophercloud/openstack/db/v1/instances" |
Jamie Hannaford | 2e81732 | 2015-02-16 15:29:17 +0100 | [diff] [blame] | 8 | "github.com/rackspace/gophercloud/pagination" |
| 9 | "github.com/rackspace/gophercloud/rackspace/db/v1/backups" |
Jamie Hannaford | a50d135 | 2015-02-18 11:38:38 +0100 | [diff] [blame] | 10 | "github.com/rackspace/gophercloud/rackspace/db/v1/datastores" |
Jamie Hannaford | 936a547 | 2015-02-10 14:38:28 +0100 | [diff] [blame] | 11 | th "github.com/rackspace/gophercloud/testhelper" |
| 12 | fake "github.com/rackspace/gophercloud/testhelper/client" |
Jamie Hannaford | e635b7d | 2015-02-18 14:11:46 +0100 | [diff] [blame] | 13 | "github.com/rackspace/gophercloud/testhelper/fixture" |
Jamie Hannaford | 936a547 | 2015-02-10 14:38:28 +0100 | [diff] [blame] | 14 | ) |
| 15 | |
| 16 | func TestGetConfig(t *testing.T) { |
| 17 | th.SetupHTTP() |
| 18 | defer th.TeardownHTTP() |
Jamie Hannaford | e635b7d | 2015-02-18 14:11:46 +0100 | [diff] [blame] | 19 | fixture.SetupHandler(t, resURL+"/configuration", "GET", "", getConfigResp, 200) |
Jamie Hannaford | 936a547 | 2015-02-10 14:38:28 +0100 | [diff] [blame] | 20 | |
Jamie Hannaford | f77fc10 | 2015-02-10 14:56:02 +0100 | [diff] [blame] | 21 | config, err := GetDefaultConfig(fake.ServiceClient(), instanceID).Extract() |
Jamie Hannaford | 936a547 | 2015-02-10 14:38:28 +0100 | [diff] [blame] | 22 | |
| 23 | expected := map[string]string{ |
| 24 | "basedir": "/usr", |
| 25 | "connect_timeout": "15", |
| 26 | "datadir": "/var/lib/mysql", |
| 27 | "default_storage_engine": "innodb", |
| 28 | "innodb_buffer_pool_instances": "1", |
| 29 | "innodb_buffer_pool_size": "175M", |
| 30 | "innodb_checksum_algorithm": "crc32", |
| 31 | "innodb_data_file_path": "ibdata1:10M:autoextend", |
| 32 | "innodb_file_per_table": "1", |
| 33 | "innodb_io_capacity": "200", |
| 34 | "innodb_log_file_size": "256M", |
| 35 | "innodb_log_files_in_group": "2", |
| 36 | "innodb_open_files": "8192", |
| 37 | "innodb_thread_concurrency": "0", |
| 38 | "join_buffer_size": "1M", |
| 39 | "key_buffer_size": "50M", |
| 40 | "local-infile": "0", |
| 41 | "log-error": "/var/log/mysql/mysqld.log", |
| 42 | "max_allowed_packet": "16M", |
| 43 | "max_connect_errors": "10000", |
| 44 | "max_connections": "40", |
| 45 | "max_heap_table_size": "16M", |
| 46 | "myisam-recover": "BACKUP", |
| 47 | "open_files_limit": "8192", |
| 48 | "performance_schema": "off", |
| 49 | "pid_file": "/var/run/mysqld/mysqld.pid", |
| 50 | "port": "3306", |
| 51 | "query_cache_limit": "1M", |
| 52 | "query_cache_size": "8M", |
| 53 | "query_cache_type": "1", |
| 54 | "read_buffer_size": "256K", |
| 55 | "read_rnd_buffer_size": "1M", |
| 56 | "server_id": "1", |
| 57 | "skip-external-locking": "1", |
| 58 | "skip_name_resolve": "1", |
| 59 | "sort_buffer_size": "256K", |
| 60 | "table_open_cache": "4096", |
| 61 | "thread_stack": "192K", |
| 62 | "tmp_table_size": "16M", |
| 63 | "tmpdir": "/var/tmp", |
| 64 | "user": "mysql", |
| 65 | "wait_timeout": "3600", |
| 66 | } |
| 67 | |
| 68 | th.AssertNoErr(t, err) |
| 69 | th.AssertDeepEquals(t, expected, config) |
| 70 | } |
Jamie Hannaford | f77fc10 | 2015-02-10 14:56:02 +0100 | [diff] [blame] | 71 | |
| 72 | func TestAssociateWithConfigGroup(t *testing.T) { |
| 73 | th.SetupHTTP() |
| 74 | defer th.TeardownHTTP() |
Jamie Hannaford | e635b7d | 2015-02-18 14:11:46 +0100 | [diff] [blame] | 75 | fixture.SetupHandler(t, resURL, "PUT", associateReq, associateResp, 202) |
Jamie Hannaford | f77fc10 | 2015-02-10 14:56:02 +0100 | [diff] [blame] | 76 | |
Jamie Hannaford | e635b7d | 2015-02-18 14:11:46 +0100 | [diff] [blame] | 77 | res := AssociateWithConfigGroup(fake.ServiceClient(), instanceID, "{configGroupID}") |
Jamie Hannaford | f77fc10 | 2015-02-10 14:56:02 +0100 | [diff] [blame] | 78 | th.AssertNoErr(t, res.Err) |
| 79 | } |
Jamie Hannaford | 2e81732 | 2015-02-16 15:29:17 +0100 | [diff] [blame] | 80 | |
| 81 | func TestListBackups(t *testing.T) { |
| 82 | th.SetupHTTP() |
| 83 | defer th.TeardownHTTP() |
Jamie Hannaford | e635b7d | 2015-02-18 14:11:46 +0100 | [diff] [blame] | 84 | fixture.SetupHandler(t, resURL+"/backups", "GET", "", listBackupsResp, 200) |
Jamie Hannaford | 2e81732 | 2015-02-16 15:29:17 +0100 | [diff] [blame] | 85 | |
Jamie Hannaford | e635b7d | 2015-02-18 14:11:46 +0100 | [diff] [blame] | 86 | pages := 0 |
Jamie Hannaford | 2e81732 | 2015-02-16 15:29:17 +0100 | [diff] [blame] | 87 | |
Jamie Hannaford | e635b7d | 2015-02-18 14:11:46 +0100 | [diff] [blame] | 88 | err := ListBackups(fake.ServiceClient(), instanceID).EachPage(func(page pagination.Page) (bool, error) { |
| 89 | pages++ |
Jamie Hannaford | 2e81732 | 2015-02-16 15:29:17 +0100 | [diff] [blame] | 90 | actual, err := backups.ExtractBackups(page) |
| 91 | th.AssertNoErr(t, err) |
| 92 | |
| 93 | expected := []backups.Backup{ |
| 94 | backups.Backup{ |
| 95 | Created: "2014-06-18T21:23:35", |
| 96 | Description: "Backup from Restored Instance", |
| 97 | ID: "87972694-4be2-40f5-83f8-501656e0032a", |
| 98 | InstanceID: "29af2cd9-0674-48ab-b87a-b160f00208e6", |
| 99 | LocationRef: "http://localhost/path/to/backup", |
| 100 | Name: "restored_backup", |
| 101 | ParentID: "", |
| 102 | Size: 0.141026, |
| 103 | Status: "COMPLETED", |
| 104 | Updated: "2014-06-18T21:24:39", |
Jamie Hannaford | a50d135 | 2015-02-18 11:38:38 +0100 | [diff] [blame] | 105 | Datastore: datastores.DatastorePartial{Version: "5.1", Type: "MySQL", VersionID: "20000000-0000-0000-0000-000000000002"}, |
Jamie Hannaford | 2e81732 | 2015-02-16 15:29:17 +0100 | [diff] [blame] | 106 | }, |
| 107 | } |
| 108 | |
| 109 | th.AssertDeepEquals(t, expected, actual) |
Jamie Hannaford | 2e81732 | 2015-02-16 15:29:17 +0100 | [diff] [blame] | 110 | return true, nil |
| 111 | }) |
| 112 | |
Jamie Hannaford | e635b7d | 2015-02-18 14:11:46 +0100 | [diff] [blame] | 113 | th.AssertNoErr(t, err) |
| 114 | th.AssertEquals(t, 1, pages) |
Jamie Hannaford | 2e81732 | 2015-02-16 15:29:17 +0100 | [diff] [blame] | 115 | } |
Jamie Hannaford | 4ec6afe | 2015-02-16 16:52:49 +0100 | [diff] [blame] | 116 | |
| 117 | func TestCreateReplica(t *testing.T) { |
| 118 | th.SetupHTTP() |
| 119 | defer th.TeardownHTTP() |
Jamie Hannaford | e635b7d | 2015-02-18 14:11:46 +0100 | [diff] [blame] | 120 | fixture.SetupHandler(t, _rootURL, "POST", createReplicaReq, createReplicaResp, 200) |
Jamie Hannaford | 4ec6afe | 2015-02-16 16:52:49 +0100 | [diff] [blame] | 121 | |
| 122 | opts := CreateOpts{ |
| 123 | Name: "t2s1_ALT_GUEST", |
| 124 | FlavorRef: "9", |
| 125 | Size: 1, |
| 126 | ReplicaOf: "6bdca2fc-418e-40bd-a595-62abda61862d", |
| 127 | } |
| 128 | |
| 129 | replica, err := Create(fake.ServiceClient(), opts).Extract() |
| 130 | th.AssertNoErr(t, err) |
Jamie Hannaford | 4ec6afe | 2015-02-16 16:52:49 +0100 | [diff] [blame] | 131 | th.AssertDeepEquals(t, expectedReplica, replica) |
| 132 | } |
| 133 | |
| 134 | func TestListReplicas(t *testing.T) { |
| 135 | th.SetupHTTP() |
| 136 | defer th.TeardownHTTP() |
Jamie Hannaford | e635b7d | 2015-02-18 14:11:46 +0100 | [diff] [blame] | 137 | fixture.SetupHandler(t, _rootURL, "GET", "", listReplicasResp, 200) |
Jamie Hannaford | 4ec6afe | 2015-02-16 16:52:49 +0100 | [diff] [blame] | 138 | |
| 139 | pages := 0 |
| 140 | err := List(fake.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) { |
| 141 | pages++ |
| 142 | |
| 143 | actual, err := ExtractInstances(page) |
| 144 | if err != nil { |
| 145 | return false, err |
| 146 | } |
| 147 | |
| 148 | expected := []Instance{ |
| 149 | Instance{ |
| 150 | Status: "ACTIVE", |
| 151 | Name: "t1s1_ALT_GUEST", |
| 152 | Links: []gophercloud.Link{ |
| 153 | gophercloud.Link{Rel: "self", Href: "https://ord.databases.api.rackspacecloud.com/v1.0/1234/instances/3c691f06-bf9a-4618-b7ec-2817ce0cf254"}, |
| 154 | gophercloud.Link{Rel: "bookmark", Href: "https://ord.databases.api.rackspacecloud.com/instances/3c691f06-bf9a-4618-b7ec-2817ce0cf254"}, |
| 155 | }, |
| 156 | ID: "3c691f06-bf9a-4618-b7ec-2817ce0cf254", |
| 157 | IP: []string{"10.0.0.3"}, |
| 158 | Volume: os.Volume{Size: 1}, |
| 159 | Flavor: os.Flavor{ID: "9"}, |
Jamie Hannaford | a50d135 | 2015-02-18 11:38:38 +0100 | [diff] [blame] | 160 | Datastore: datastores.DatastorePartial{Version: "5.6", Type: "mysql"}, |
Jamie Hannaford | 4ec6afe | 2015-02-16 16:52:49 +0100 | [diff] [blame] | 161 | ReplicaOf: &Instance{ |
| 162 | ID: "8b499b45-52d6-402d-b398-f9d8f279c69a", |
| 163 | }, |
| 164 | }, |
| 165 | } |
| 166 | |
| 167 | th.CheckDeepEquals(t, expected, actual) |
| 168 | |
| 169 | return true, nil |
| 170 | }) |
| 171 | |
| 172 | th.AssertNoErr(t, err) |
Jamie Hannaford | e635b7d | 2015-02-18 14:11:46 +0100 | [diff] [blame] | 173 | th.AssertEquals(t, 1, pages) |
Jamie Hannaford | 4ec6afe | 2015-02-16 16:52:49 +0100 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | func TestGetReplica(t *testing.T) { |
| 177 | th.SetupHTTP() |
| 178 | defer th.TeardownHTTP() |
Jamie Hannaford | e635b7d | 2015-02-18 14:11:46 +0100 | [diff] [blame] | 179 | fixture.SetupHandler(t, resURL, "GET", "", getReplicaResp, 200) |
Jamie Hannaford | 4ec6afe | 2015-02-16 16:52:49 +0100 | [diff] [blame] | 180 | |
| 181 | replica, err := Get(fake.ServiceClient(), instanceID).Extract() |
| 182 | th.AssertNoErr(t, err) |
| 183 | |
| 184 | expectedReplica := &Instance{ |
| 185 | Status: "ACTIVE", |
| 186 | Updated: "2014-09-26T19:15:57", |
| 187 | Name: "t1_ALT_GUEST", |
| 188 | Created: "2014-09-26T19:15:50", |
| 189 | IP: []string{ |
| 190 | "10.0.0.2", |
| 191 | }, |
| 192 | Replicas: []Instance{ |
| 193 | Instance{ID: "3c691f06-bf9a-4618-b7ec-2817ce0cf254"}, |
| 194 | }, |
| 195 | ID: "8b499b45-52d6-402d-b398-f9d8f279c69a", |
| 196 | Volume: os.Volume{ |
| 197 | Used: 0.54, |
| 198 | Size: 1, |
| 199 | }, |
| 200 | Flavor: os.Flavor{ID: "9"}, |
Jamie Hannaford | a50d135 | 2015-02-18 11:38:38 +0100 | [diff] [blame] | 201 | Datastore: datastores.DatastorePartial{ |
Jamie Hannaford | 4ec6afe | 2015-02-16 16:52:49 +0100 | [diff] [blame] | 202 | Version: "5.6", |
| 203 | Type: "mysql", |
| 204 | }, |
| 205 | } |
| 206 | |
| 207 | th.AssertDeepEquals(t, replica, expectedReplica) |
| 208 | } |
| 209 | |
| 210 | func TestDetachReplica(t *testing.T) { |
| 211 | th.SetupHTTP() |
| 212 | defer th.TeardownHTTP() |
Jamie Hannaford | e635b7d | 2015-02-18 14:11:46 +0100 | [diff] [blame] | 213 | fixture.SetupHandler(t, resURL, "PATCH", detachReq, "", 202) |
Jamie Hannaford | 4ec6afe | 2015-02-16 16:52:49 +0100 | [diff] [blame] | 214 | |
Jamie Hannaford | e635b7d | 2015-02-18 14:11:46 +0100 | [diff] [blame] | 215 | err := DetachReplica(fake.ServiceClient(), instanceID).ExtractErr() |
Jamie Hannaford | 4ec6afe | 2015-02-16 16:52:49 +0100 | [diff] [blame] | 216 | th.AssertNoErr(t, err) |
| 217 | } |