blob: 35afe01a831ecb8db14794a738393cf9b0bbb4a9 [file] [log] [blame]
Jamie Hannaford936a5472015-02-10 14:38:28 +01001package instances
2
3import (
4 "testing"
5
Jamie Hannaford4ec6afe2015-02-16 16:52:49 +01006 "github.com/rackspace/gophercloud"
7 os "github.com/rackspace/gophercloud/openstack/db/v1/instances"
Jamie Hannaford2e817322015-02-16 15:29:17 +01008 "github.com/rackspace/gophercloud/pagination"
9 "github.com/rackspace/gophercloud/rackspace/db/v1/backups"
Jamie Hannaforda50d1352015-02-18 11:38:38 +010010 "github.com/rackspace/gophercloud/rackspace/db/v1/datastores"
Jamie Hannaford936a5472015-02-10 14:38:28 +010011 th "github.com/rackspace/gophercloud/testhelper"
12 fake "github.com/rackspace/gophercloud/testhelper/client"
13)
14
Jamie Hannaford4ec6afe2015-02-16 16:52:49 +010015var expectedReplica = &Instance{
16 Status: "BUILD",
17 Updated: "2014-10-14T18:42:15",
18 Name: "t2s1_ALT_GUEST",
19 Links: []gophercloud.Link{
20 gophercloud.Link{Rel: "self", Href: "https://ord.databases.api.rackspacecloud.com/v1.0/5919009/instances/8367c312-7c40-4a66-aab1-5767478914fc"},
21 gophercloud.Link{Rel: "bookmark", Href: "https://ord.databases.api.rackspacecloud.com/instances/8367c312-7c40-4a66-aab1-5767478914fc"},
22 },
23 Created: "2014-10-14T18:42:15",
24 ID: "8367c312-7c40-4a66-aab1-5767478914fc",
25 Volume: os.Volume{Size: 1},
26 Flavor: os.Flavor{ID: "9"},
Jamie Hannaforda50d1352015-02-18 11:38:38 +010027 Datastore: datastores.DatastorePartial{Version: "5.6", Type: "mysql"},
Jamie Hannaford4ec6afe2015-02-16 16:52:49 +010028 ReplicaOf: &Instance{
29 ID: "6bdca2fc-418e-40bd-a595-62abda61862d",
30 },
31}
32
Jamie Hannaford936a5472015-02-10 14:38:28 +010033func TestGetConfig(t *testing.T) {
34 th.SetupHTTP()
35 defer th.TeardownHTTP()
36
Jamie Hannafordf77fc102015-02-10 14:56:02 +010037 HandleGetConfigSuccessfully(t, instanceID)
Jamie Hannaford936a5472015-02-10 14:38:28 +010038
Jamie Hannafordf77fc102015-02-10 14:56:02 +010039 config, err := GetDefaultConfig(fake.ServiceClient(), instanceID).Extract()
Jamie Hannaford936a5472015-02-10 14:38:28 +010040
41 expected := map[string]string{
42 "basedir": "/usr",
43 "connect_timeout": "15",
44 "datadir": "/var/lib/mysql",
45 "default_storage_engine": "innodb",
46 "innodb_buffer_pool_instances": "1",
47 "innodb_buffer_pool_size": "175M",
48 "innodb_checksum_algorithm": "crc32",
49 "innodb_data_file_path": "ibdata1:10M:autoextend",
50 "innodb_file_per_table": "1",
51 "innodb_io_capacity": "200",
52 "innodb_log_file_size": "256M",
53 "innodb_log_files_in_group": "2",
54 "innodb_open_files": "8192",
55 "innodb_thread_concurrency": "0",
56 "join_buffer_size": "1M",
57 "key_buffer_size": "50M",
58 "local-infile": "0",
59 "log-error": "/var/log/mysql/mysqld.log",
60 "max_allowed_packet": "16M",
61 "max_connect_errors": "10000",
62 "max_connections": "40",
63 "max_heap_table_size": "16M",
64 "myisam-recover": "BACKUP",
65 "open_files_limit": "8192",
66 "performance_schema": "off",
67 "pid_file": "/var/run/mysqld/mysqld.pid",
68 "port": "3306",
69 "query_cache_limit": "1M",
70 "query_cache_size": "8M",
71 "query_cache_type": "1",
72 "read_buffer_size": "256K",
73 "read_rnd_buffer_size": "1M",
74 "server_id": "1",
75 "skip-external-locking": "1",
76 "skip_name_resolve": "1",
77 "sort_buffer_size": "256K",
78 "table_open_cache": "4096",
79 "thread_stack": "192K",
80 "tmp_table_size": "16M",
81 "tmpdir": "/var/tmp",
82 "user": "mysql",
83 "wait_timeout": "3600",
84 }
85
86 th.AssertNoErr(t, err)
87 th.AssertDeepEquals(t, expected, config)
88}
Jamie Hannafordf77fc102015-02-10 14:56:02 +010089
90func TestAssociateWithConfigGroup(t *testing.T) {
91 th.SetupHTTP()
92 defer th.TeardownHTTP()
93
94 HandleAssociateGroupSuccessfully(t, instanceID)
95
96 configGroupID := "{configGroupID}"
97 res := AssociateWithConfigGroup(fake.ServiceClient(), instanceID, configGroupID)
98 th.AssertNoErr(t, res.Err)
99}
Jamie Hannaford2e817322015-02-16 15:29:17 +0100100
101func TestListBackups(t *testing.T) {
102 th.SetupHTTP()
103 defer th.TeardownHTTP()
104
105 HandleListBackupsSuccessfully(t, instanceID)
106 count := 0
107
108 ListBackups(fake.ServiceClient(), instanceID).EachPage(func(page pagination.Page) (bool, error) {
109 count++
110 actual, err := backups.ExtractBackups(page)
111 th.AssertNoErr(t, err)
112
113 expected := []backups.Backup{
114 backups.Backup{
115 Created: "2014-06-18T21:23:35",
116 Description: "Backup from Restored Instance",
117 ID: "87972694-4be2-40f5-83f8-501656e0032a",
118 InstanceID: "29af2cd9-0674-48ab-b87a-b160f00208e6",
119 LocationRef: "http://localhost/path/to/backup",
120 Name: "restored_backup",
121 ParentID: "",
122 Size: 0.141026,
123 Status: "COMPLETED",
124 Updated: "2014-06-18T21:24:39",
Jamie Hannaforda50d1352015-02-18 11:38:38 +0100125 Datastore: datastores.DatastorePartial{Version: "5.1", Type: "MySQL", VersionID: "20000000-0000-0000-0000-000000000002"},
Jamie Hannaford2e817322015-02-16 15:29:17 +0100126 },
127 }
128
129 th.AssertDeepEquals(t, expected, actual)
130
131 return true, nil
132 })
133
134 if count != 1 {
135 t.Errorf("Expected 1 page, got %d", count)
136 }
137}
Jamie Hannaford4ec6afe2015-02-16 16:52:49 +0100138
139func TestCreateReplica(t *testing.T) {
140 th.SetupHTTP()
141 defer th.TeardownHTTP()
142
143 HandleCreateReplicaSuccessfully(t)
144
145 opts := CreateOpts{
146 Name: "t2s1_ALT_GUEST",
147 FlavorRef: "9",
148 Size: 1,
149 ReplicaOf: "6bdca2fc-418e-40bd-a595-62abda61862d",
150 }
151
152 replica, err := Create(fake.ServiceClient(), opts).Extract()
153 th.AssertNoErr(t, err)
154
155 th.AssertDeepEquals(t, expectedReplica, replica)
156}
157
158func TestListReplicas(t *testing.T) {
159 th.SetupHTTP()
160 defer th.TeardownHTTP()
161
162 HandleListReplicasSuccessfully(t)
163
164 pages := 0
165 err := List(fake.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) {
166 pages++
167
168 actual, err := ExtractInstances(page)
169 if err != nil {
170 return false, err
171 }
172
173 expected := []Instance{
174 Instance{
175 Status: "ACTIVE",
176 Name: "t1s1_ALT_GUEST",
177 Links: []gophercloud.Link{
178 gophercloud.Link{Rel: "self", Href: "https://ord.databases.api.rackspacecloud.com/v1.0/1234/instances/3c691f06-bf9a-4618-b7ec-2817ce0cf254"},
179 gophercloud.Link{Rel: "bookmark", Href: "https://ord.databases.api.rackspacecloud.com/instances/3c691f06-bf9a-4618-b7ec-2817ce0cf254"},
180 },
181 ID: "3c691f06-bf9a-4618-b7ec-2817ce0cf254",
182 IP: []string{"10.0.0.3"},
183 Volume: os.Volume{Size: 1},
184 Flavor: os.Flavor{ID: "9"},
Jamie Hannaforda50d1352015-02-18 11:38:38 +0100185 Datastore: datastores.DatastorePartial{Version: "5.6", Type: "mysql"},
Jamie Hannaford4ec6afe2015-02-16 16:52:49 +0100186 ReplicaOf: &Instance{
187 ID: "8b499b45-52d6-402d-b398-f9d8f279c69a",
188 },
189 },
190 }
191
192 th.CheckDeepEquals(t, expected, actual)
193
194 return true, nil
195 })
196
197 th.AssertNoErr(t, err)
198
199 if pages != 1 {
200 t.Errorf("Expected 1 page, saw %d", pages)
201 }
202}
203
204func TestGetReplica(t *testing.T) {
205 th.SetupHTTP()
206 defer th.TeardownHTTP()
207
208 HandleGetReplicaSuccessfully(t, instanceID)
209
210 replica, err := Get(fake.ServiceClient(), instanceID).Extract()
211 th.AssertNoErr(t, err)
212
213 expectedReplica := &Instance{
214 Status: "ACTIVE",
215 Updated: "2014-09-26T19:15:57",
216 Name: "t1_ALT_GUEST",
217 Created: "2014-09-26T19:15:50",
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 },
229 Flavor: os.Flavor{ID: "9"},
Jamie Hannaforda50d1352015-02-18 11:38:38 +0100230 Datastore: datastores.DatastorePartial{
Jamie Hannaford4ec6afe2015-02-16 16:52:49 +0100231 Version: "5.6",
232 Type: "mysql",
233 },
234 }
235
236 th.AssertDeepEquals(t, replica, expectedReplica)
237}
238
239func TestDetachReplica(t *testing.T) {
240 th.SetupHTTP()
241 defer th.TeardownHTTP()
242
243 HandleDetachReplicaSuccessfully(t, "{replicaID}")
244
245 err := DetachReplica(fake.ServiceClient(), "{replicaID}").ExtractErr()
246 th.AssertNoErr(t, err)
247}