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