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