blob: f6e1f03ddff06841749adcded0eda7900d1f8759 [file] [log] [blame]
Jamie Hannaford80c70672015-10-06 16:09:33 +02001// +build acceptance db rackspace
Jamie Hannaford05d200d2015-02-20 14:49:05 +01002
3package v1
4
5import (
Jamie Hannaford11108402015-02-23 10:31:41 +01006 "testing"
7
Jamie Hannaford99eced52015-03-02 15:24:22 +01008 "github.com/rackspace/gophercloud"
Jamie Hannaford05d200d2015-02-20 14:49:05 +01009 "github.com/rackspace/gophercloud/acceptance/tools"
10 "github.com/rackspace/gophercloud/pagination"
11 "github.com/rackspace/gophercloud/rackspace/db/v1/instances"
12 th "github.com/rackspace/gophercloud/testhelper"
13)
14
Jamie Hannaford11108402015-02-23 10:31:41 +010015func TestRunner(t *testing.T) {
Jamie Hannaford05d200d2015-02-20 14:49:05 +010016 c := newContext(t)
17
18 // FLAVOR tests
19 c.listFlavors()
20 c.getFlavor()
21
22 // INSTANCE tests
23 c.createInstance()
24 c.listInstances()
25 c.getInstance()
26 c.isRootEnabled()
27 c.enableRootUser()
28 c.isRootEnabled()
29 c.restartInstance()
30 c.resizeInstance()
31 c.resizeVol()
32 c.getDefaultConfig()
33
34 // REPLICA tests
35 c.createReplica()
36 c.detachReplica()
37
38 // BACKUP tests
39 c.createBackup()
40 c.getBackup()
41 c.listAllBackups()
42 c.listInstanceBackups()
43 c.deleteBackup()
44
45 // CONFIG GROUP tests
46 c.createConfigGrp()
47 c.getConfigGrp()
48 c.updateConfigGrp()
49 c.replaceConfigGrp()
50 c.associateInstanceWithConfigGrp()
51 c.listConfigGrpInstances()
Jamie Hannaford99eced52015-03-02 15:24:22 +010052 c.detachInstanceFromGrp()
Jamie Hannaford05d200d2015-02-20 14:49:05 +010053 c.deleteConfigGrp()
54
55 // DATABASE tests
Jamie Hannaford11108402015-02-23 10:31:41 +010056 c.createDBs()
Jamie Hannaford05d200d2015-02-20 14:49:05 +010057 c.listDBs()
58
59 // USER tests
60 c.createUsers()
61 c.listUsers()
62 c.changeUserPwd()
63 c.getUser()
64 c.updateUser()
65 c.listUserAccess()
66 c.revokeUserAccess()
67 c.grantUserAccess()
68
69 // TEARDOWN
70 c.deleteUsers()
71 c.deleteDBs()
Jamie Hannaford99eced52015-03-02 15:24:22 +010072 c.detachAndDeleteReplica()
Jamie Hannaford11108402015-02-23 10:31:41 +010073 c.deleteInstance()
Jamie Hannaford05d200d2015-02-20 14:49:05 +010074}
75
Jamie Hannaford99eced52015-03-02 15:24:22 +010076func (c *context) createInstance() {
Jamie Hannaford05d200d2015-02-20 14:49:05 +010077 opts := instances.CreateOpts{
78 FlavorRef: "1",
79 Size: 1,
80 Name: tools.RandomString("gopher_db", 5),
81 }
82
83 instance, err := instances.Create(c.client, opts).Extract()
84 th.AssertNoErr(c.test, err)
85
Jamie Hannaford99eced52015-03-02 15:24:22 +010086 c.Logf("Creating %s. Waiting...", instance.ID)
Jamie Hannaford11108402015-02-23 10:31:41 +010087 c.WaitUntilActive(instance.ID)
Jamie Hannaford99eced52015-03-02 15:24:22 +010088 c.Logf("Created instance %s", instance.ID)
Jamie Hannaford05d200d2015-02-20 14:49:05 +010089
90 c.instanceID = instance.ID
91}
92
Jamie Hannaford99eced52015-03-02 15:24:22 +010093func (c *context) listInstances() {
Jamie Hannaford05d200d2015-02-20 14:49:05 +010094 c.Logf("Listing instances")
95
96 err := instances.List(c.client).EachPage(func(page pagination.Page) (bool, error) {
97 instanceList, err := instances.ExtractInstances(page)
98 c.AssertNoErr(err)
99
Jamie Hannaford99eced52015-03-02 15:24:22 +0100100 for _, i := range instanceList {
101 c.Logf("Instance: ID [%s] Name [%s] Status [%s] VolSize [%d] Datastore Type [%s]",
102 i.ID, i.Name, i.Status, i.Volume.Size, i.Datastore.Type)
Jamie Hannaford05d200d2015-02-20 14:49:05 +0100103 }
104
105 return true, nil
106 })
107
Jamie Hannaford11108402015-02-23 10:31:41 +0100108 c.AssertNoErr(err)
Jamie Hannaford05d200d2015-02-20 14:49:05 +0100109}
110
Jamie Hannaford99eced52015-03-02 15:24:22 +0100111func (c *context) getInstance() {
Jamie Hannaford05d200d2015-02-20 14:49:05 +0100112 instance, err := instances.Get(c.client, c.instanceID).Extract()
113 c.AssertNoErr(err)
114 c.Logf("Getting instance: %#v", instance)
115}
116
Jamie Hannaford99eced52015-03-02 15:24:22 +0100117func (c *context) deleteInstance() {
Jamie Hannaford05d200d2015-02-20 14:49:05 +0100118 err := instances.Delete(c.client, c.instanceID).ExtractErr()
119 c.AssertNoErr(err)
120 c.Logf("Deleted instance %s", c.instanceID)
121}
122
Jamie Hannaford99eced52015-03-02 15:24:22 +0100123func (c *context) enableRootUser() {
Jamie Hannaford11108402015-02-23 10:31:41 +0100124 _, err := instances.EnableRootUser(c.client, c.instanceID).Extract()
Jamie Hannaford05d200d2015-02-20 14:49:05 +0100125 c.AssertNoErr(err)
126 c.Logf("Enabled root user on %s", c.instanceID)
127}
128
Jamie Hannaford99eced52015-03-02 15:24:22 +0100129func (c *context) isRootEnabled() {
Jamie Hannaford05d200d2015-02-20 14:49:05 +0100130 enabled, err := instances.IsRootEnabled(c.client, c.instanceID)
131 c.AssertNoErr(err)
132 c.Logf("Is root enabled? %s", enabled)
133}
134
Jamie Hannaford99eced52015-03-02 15:24:22 +0100135func (c *context) restartInstance() {
Jamie Hannaford05d200d2015-02-20 14:49:05 +0100136 id := c.instanceID
Jamie Hannaford11108402015-02-23 10:31:41 +0100137 err := instances.RestartService(c.client, id).ExtractErr()
Jamie Hannaford05d200d2015-02-20 14:49:05 +0100138 c.AssertNoErr(err)
139 c.Logf("Restarting %s. Waiting...", id)
140 c.WaitUntilActive(id)
141 c.Logf("Restarted %s", id)
142}
143
Jamie Hannaford99eced52015-03-02 15:24:22 +0100144func (c *context) resizeInstance() {
Jamie Hannaford05d200d2015-02-20 14:49:05 +0100145 id := c.instanceID
Jamie Hannaford11108402015-02-23 10:31:41 +0100146 err := instances.ResizeInstance(c.client, id, "2").ExtractErr()
Jamie Hannaford05d200d2015-02-20 14:49:05 +0100147 c.AssertNoErr(err)
148 c.Logf("Resizing %s. Waiting...", id)
149 c.WaitUntilActive(id)
150 c.Logf("Resized %s with flavorRef %s", id, "2")
151}
152
Jamie Hannaford99eced52015-03-02 15:24:22 +0100153func (c *context) resizeVol() {
Jamie Hannaford05d200d2015-02-20 14:49:05 +0100154 id := c.instanceID
Jamie Hannaford11108402015-02-23 10:31:41 +0100155 err := instances.ResizeVolume(c.client, id, 2).ExtractErr()
Jamie Hannaford05d200d2015-02-20 14:49:05 +0100156 c.AssertNoErr(err)
157 c.Logf("Resizing volume of %s. Waiting...", id)
158 c.WaitUntilActive(id)
159 c.Logf("Resized the volume of %s to %d GB", id, 2)
160}
161
Jamie Hannaford99eced52015-03-02 15:24:22 +0100162func (c *context) getDefaultConfig() {
Jamie Hannaford05d200d2015-02-20 14:49:05 +0100163 config, err := instances.GetDefaultConfig(c.client, c.instanceID).Extract()
164 c.Logf("Default config group for instance %s: %#v", c.instanceID, config)
165 c.AssertNoErr(err)
166}
Jamie Hannaford99eced52015-03-02 15:24:22 +0100167
168func (c *context) detachAndDeleteReplica() {
169 err := instances.DetachReplica(c.client, c.replicaID).ExtractErr()
170 c.AssertNoErr(err)
171 c.Logf("Detached replica %s from instance %s", c.replicaID, c.instanceID)
172
173 err = instances.Delete(c.client, c.replicaID).ExtractErr()
174 c.AssertNoErr(err)
175 c.Logf("Deleted replica %s", c.replicaID)
176
177 // Check that it's deleted
178 err = gophercloud.WaitFor(60, func() (bool, error) {
179 _, err := instances.Get(c.client, c.replicaID).Extract()
180 if casted, ok := err.(*gophercloud.UnexpectedResponseCodeError); ok && casted.Actual == 404 {
181 return true, nil
182 }
183 if err != nil {
184 return false, err
185 }
186 return false, nil
187 })
188}