blob: 1961f1f852f72348a8cf687d3a7cbdabca210aa1 [file] [log] [blame]
Jamie Hannaford05d200d2015-02-20 14:49:05 +01001// +build acceptance db
2
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/openstack/db/v1/instances"
10 "github.com/rackspace/gophercloud/pagination"
Jamie Hannaford11108402015-02-23 10:31:41 +010011 rackspaceInst "github.com/rackspace/gophercloud/rackspace/db/v1/instances"
Jamie Hannaford05d200d2015-02-20 14:49:05 +010012 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
33 // DATABASE tests
Jamie Hannaford11108402015-02-23 10:31:41 +010034 c.createDBs()
Jamie Hannaford05d200d2015-02-20 14:49:05 +010035 c.listDBs()
36
37 // USER tests
38 c.createUsers()
39 c.listUsers()
40
41 // TEARDOWN
42 c.deleteUsers()
43 c.deleteDBs()
Jamie Hannaford11108402015-02-23 10:31:41 +010044 c.deleteInstance()
Jamie Hannaford05d200d2015-02-20 14:49:05 +010045}
46
47func (c context) createInstance() {
Jamie Hannaford11108402015-02-23 10:31:41 +010048 opts := rackspaceInst.CreateOpts{
Jamie Hannaford05d200d2015-02-20 14:49:05 +010049 FlavorRef: "1",
50 Size: 1,
51 Name: tools.RandomString("gopher_db", 5),
Jamie Hannaford11108402015-02-23 10:31:41 +010052 Datastore: &rackspaceInst.DatastoreOpts{Version: "5.6", Type: "MySQL"},
Jamie Hannaford05d200d2015-02-20 14:49:05 +010053 }
54
55 instance, err := instances.Create(c.client, opts).Extract()
56 th.AssertNoErr(c.test, err)
57
Jamie Hannaford11108402015-02-23 10:31:41 +010058 c.Logf("Restarting %s. Waiting...", instance.ID)
59 c.WaitUntilActive(instance.ID)
Jamie Hannaford05d200d2015-02-20 14:49:05 +010060 c.Logf("Created DB %#v", instance)
61
62 c.instanceID = instance.ID
63}
64
65func (c context) listInstances() {
66 c.Logf("Listing instances")
67
68 err := instances.List(c.client).EachPage(func(page pagination.Page) (bool, error) {
69 instanceList, err := instances.ExtractInstances(page)
70 c.AssertNoErr(err)
71
Jamie Hannaford11108402015-02-23 10:31:41 +010072 for _, i := range instanceList {
73 c.Logf("Instance: %#v", i)
Jamie Hannaford05d200d2015-02-20 14:49:05 +010074 }
75
76 return true, nil
77 })
78
Jamie Hannaford11108402015-02-23 10:31:41 +010079 c.AssertNoErr(err)
Jamie Hannaford05d200d2015-02-20 14:49:05 +010080}
81
82func (c context) getInstance() {
83 instance, err := instances.Get(c.client, c.instanceID).Extract()
84 c.AssertNoErr(err)
85 c.Logf("Getting instance: %#v", instance)
86}
87
88func (c context) deleteInstance() {
89 err := instances.Delete(c.client, c.instanceID).ExtractErr()
90 c.AssertNoErr(err)
91 c.Logf("Deleted instance %s", c.instanceID)
92}
93
94func (c context) enableRootUser() {
Jamie Hannaford11108402015-02-23 10:31:41 +010095 _, err := instances.EnableRootUser(c.client, c.instanceID).Extract()
Jamie Hannaford05d200d2015-02-20 14:49:05 +010096 c.AssertNoErr(err)
97 c.Logf("Enabled root user on %s", c.instanceID)
98}
99
100func (c context) isRootEnabled() {
101 enabled, err := instances.IsRootEnabled(c.client, c.instanceID)
102 c.AssertNoErr(err)
103 c.Logf("Is root enabled? %s", enabled)
104}
105
106func (c context) restartInstance() {
107 id := c.instanceID
Jamie Hannaford11108402015-02-23 10:31:41 +0100108 err := instances.RestartService(c.client, id).ExtractErr()
Jamie Hannaford05d200d2015-02-20 14:49:05 +0100109 c.AssertNoErr(err)
110 c.Logf("Restarting %s. Waiting...", id)
111 c.WaitUntilActive(id)
112 c.Logf("Restarted %s", id)
113}
114
115func (c context) resizeInstance() {
116 id := c.instanceID
Jamie Hannaford11108402015-02-23 10:31:41 +0100117 err := instances.ResizeInstance(c.client, id, "2").ExtractErr()
Jamie Hannaford05d200d2015-02-20 14:49:05 +0100118 c.AssertNoErr(err)
119 c.Logf("Resizing %s. Waiting...", id)
120 c.WaitUntilActive(id)
121 c.Logf("Resized %s with flavorRef %s", id, "2")
122}
123
124func (c context) resizeVol() {
125 id := c.instanceID
Jamie Hannaford11108402015-02-23 10:31:41 +0100126 err := instances.ResizeVolume(c.client, id, 2).ExtractErr()
Jamie Hannaford05d200d2015-02-20 14:49:05 +0100127 c.AssertNoErr(err)
128 c.Logf("Resizing volume of %s. Waiting...", id)
129 c.WaitUntilActive(id)
130 c.Logf("Resized the volume of %s to %d GB", id, 2)
131}