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