blob: b5540e3bb0093fab157bafe1836e152315b76ff4 [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 Hannaford05d200d2015-02-20 14:49:05 +01008 "github.com/rackspace/gophercloud/acceptance/tools"
9 "github.com/rackspace/gophercloud/pagination"
10 "github.com/rackspace/gophercloud/rackspace/db/v1/instances"
11 th "github.com/rackspace/gophercloud/testhelper"
12)
13
Jamie Hannaford11108402015-02-23 10:31:41 +010014func TestRunner(t *testing.T) {
Jamie Hannaford05d200d2015-02-20 14:49:05 +010015 c := newContext(t)
16
17 // FLAVOR tests
18 c.listFlavors()
19 c.getFlavor()
20
21 // INSTANCE tests
22 c.createInstance()
23 c.listInstances()
24 c.getInstance()
25 c.isRootEnabled()
26 c.enableRootUser()
27 c.isRootEnabled()
28 c.restartInstance()
29 c.resizeInstance()
30 c.resizeVol()
31 c.getDefaultConfig()
32
33 // REPLICA tests
34 c.createReplica()
35 c.detachReplica()
36
37 // BACKUP tests
38 c.createBackup()
39 c.getBackup()
40 c.listAllBackups()
41 c.listInstanceBackups()
42 c.deleteBackup()
43
44 // CONFIG GROUP tests
45 c.createConfigGrp()
46 c.getConfigGrp()
47 c.updateConfigGrp()
48 c.replaceConfigGrp()
49 c.associateInstanceWithConfigGrp()
50 c.listConfigGrpInstances()
Jamie Hannaford99eced52015-03-02 15:24:22 +010051 c.detachInstanceFromGrp()
Jamie Hannaford05d200d2015-02-20 14:49:05 +010052 c.deleteConfigGrp()
53
54 // DATABASE tests
Jamie Hannaford11108402015-02-23 10:31:41 +010055 c.createDBs()
Jamie Hannaford05d200d2015-02-20 14:49:05 +010056 c.listDBs()
57
58 // USER tests
59 c.createUsers()
60 c.listUsers()
61 c.changeUserPwd()
62 c.getUser()
63 c.updateUser()
64 c.listUserAccess()
65 c.revokeUserAccess()
66 c.grantUserAccess()
67
68 // TEARDOWN
69 c.deleteUsers()
70 c.deleteDBs()
Jamie Hannafordd2b755f2015-10-07 14:01:57 +020071
72 c.restartInstance()
73 c.WaitUntilActive(c.instanceID)
74
75 c.deleteInstance(c.replicaID)
76 c.deleteInstance(c.instanceID)
Jamie Hannaford05d200d2015-02-20 14:49:05 +010077}
78
Jamie Hannaford99eced52015-03-02 15:24:22 +010079func (c *context) createInstance() {
Jamie Hannaford05d200d2015-02-20 14:49:05 +010080 opts := instances.CreateOpts{
81 FlavorRef: "1",
82 Size: 1,
83 Name: tools.RandomString("gopher_db", 5),
84 }
85
86 instance, err := instances.Create(c.client, opts).Extract()
87 th.AssertNoErr(c.test, err)
88
Jamie Hannaford99eced52015-03-02 15:24:22 +010089 c.Logf("Creating %s. Waiting...", instance.ID)
Jamie Hannaford11108402015-02-23 10:31:41 +010090 c.WaitUntilActive(instance.ID)
Jamie Hannaford99eced52015-03-02 15:24:22 +010091 c.Logf("Created instance %s", instance.ID)
Jamie Hannaford05d200d2015-02-20 14:49:05 +010092
93 c.instanceID = instance.ID
94}
95
Jamie Hannaford99eced52015-03-02 15:24:22 +010096func (c *context) listInstances() {
Jamie Hannaford05d200d2015-02-20 14:49:05 +010097 c.Logf("Listing instances")
98
Jamie Hannaford3c3c7842015-11-13 13:20:28 +010099 err := instances.List(c.client, nil).EachPage(func(page pagination.Page) (bool, error) {
Jamie Hannaford05d200d2015-02-20 14:49:05 +0100100 instanceList, err := instances.ExtractInstances(page)
101 c.AssertNoErr(err)
102
Jamie Hannaford99eced52015-03-02 15:24:22 +0100103 for _, i := range instanceList {
104 c.Logf("Instance: ID [%s] Name [%s] Status [%s] VolSize [%d] Datastore Type [%s]",
105 i.ID, i.Name, i.Status, i.Volume.Size, i.Datastore.Type)
Jamie Hannaford05d200d2015-02-20 14:49:05 +0100106 }
107
108 return true, nil
109 })
110
Jamie Hannaford11108402015-02-23 10:31:41 +0100111 c.AssertNoErr(err)
Jamie Hannaford05d200d2015-02-20 14:49:05 +0100112}
113
Jamie Hannaford99eced52015-03-02 15:24:22 +0100114func (c *context) getInstance() {
Jamie Hannaford05d200d2015-02-20 14:49:05 +0100115 instance, err := instances.Get(c.client, c.instanceID).Extract()
116 c.AssertNoErr(err)
117 c.Logf("Getting instance: %#v", instance)
118}
119
Jamie Hannafordd2b755f2015-10-07 14:01:57 +0200120func (c *context) deleteInstance(id string) {
121 err := instances.Delete(c.client, id).ExtractErr()
Jamie Hannaford05d200d2015-02-20 14:49:05 +0100122 c.AssertNoErr(err)
Jamie Hannafordd2b755f2015-10-07 14:01:57 +0200123 c.Logf("Deleted instance %s", id)
Jamie Hannaford05d200d2015-02-20 14:49:05 +0100124}
125
Jamie Hannaford99eced52015-03-02 15:24:22 +0100126func (c *context) enableRootUser() {
Jamie Hannaford11108402015-02-23 10:31:41 +0100127 _, err := instances.EnableRootUser(c.client, c.instanceID).Extract()
Jamie Hannaford05d200d2015-02-20 14:49:05 +0100128 c.AssertNoErr(err)
129 c.Logf("Enabled root user on %s", c.instanceID)
130}
131
Jamie Hannaford99eced52015-03-02 15:24:22 +0100132func (c *context) isRootEnabled() {
Jamie Hannaford05d200d2015-02-20 14:49:05 +0100133 enabled, err := instances.IsRootEnabled(c.client, c.instanceID)
134 c.AssertNoErr(err)
135 c.Logf("Is root enabled? %s", enabled)
136}
137
Jamie Hannaford99eced52015-03-02 15:24:22 +0100138func (c *context) restartInstance() {
Jamie Hannaford05d200d2015-02-20 14:49:05 +0100139 id := c.instanceID
Jamie Hannaford75e8cc42015-11-16 14:09:25 +0100140 err := instances.Restart(c.client, id).ExtractErr()
Jamie Hannaford05d200d2015-02-20 14:49:05 +0100141 c.AssertNoErr(err)
142 c.Logf("Restarting %s. Waiting...", id)
143 c.WaitUntilActive(id)
144 c.Logf("Restarted %s", id)
145}
146
Jamie Hannaford99eced52015-03-02 15:24:22 +0100147func (c *context) resizeInstance() {
Jamie Hannaford05d200d2015-02-20 14:49:05 +0100148 id := c.instanceID
Jamie Hannaford75e8cc42015-11-16 14:09:25 +0100149 err := instances.Resize(c.client, id, "2").ExtractErr()
Jamie Hannaford05d200d2015-02-20 14:49:05 +0100150 c.AssertNoErr(err)
151 c.Logf("Resizing %s. Waiting...", id)
152 c.WaitUntilActive(id)
153 c.Logf("Resized %s with flavorRef %s", id, "2")
154}
155
Jamie Hannaford99eced52015-03-02 15:24:22 +0100156func (c *context) resizeVol() {
Jamie Hannaford05d200d2015-02-20 14:49:05 +0100157 id := c.instanceID
Jamie Hannaford11108402015-02-23 10:31:41 +0100158 err := instances.ResizeVolume(c.client, id, 2).ExtractErr()
Jamie Hannaford05d200d2015-02-20 14:49:05 +0100159 c.AssertNoErr(err)
160 c.Logf("Resizing volume of %s. Waiting...", id)
161 c.WaitUntilActive(id)
162 c.Logf("Resized the volume of %s to %d GB", id, 2)
163}
164
Jamie Hannaford99eced52015-03-02 15:24:22 +0100165func (c *context) getDefaultConfig() {
Jamie Hannaford05d200d2015-02-20 14:49:05 +0100166 config, err := instances.GetDefaultConfig(c.client, c.instanceID).Extract()
167 c.Logf("Default config group for instance %s: %#v", c.instanceID, config)
168 c.AssertNoErr(err)
169}