blob: 24678cbf165328eda5f9e64b54083abbdfce4059 [file] [log] [blame]
Jamie Hannaford05d200d2015-02-20 14:49:05 +01001// +build acceptance db
2
3package v1
4
5import (
6 "github.com/rackspace/gophercloud/acceptance/tools"
7 "github.com/rackspace/gophercloud/openstack/db/v1/instances"
8 "github.com/rackspace/gophercloud/pagination"
9 th "github.com/rackspace/gophercloud/testhelper"
10)
11
12func TestRunner(t *testingT) {
13 c := newContext(t)
14
15 // FLAVOR tests
16 c.listFlavors()
17 c.getFlavor()
18
19 // INSTANCE tests
20 c.createInstance()
21 c.listInstances()
22 c.getInstance()
23 c.isRootEnabled()
24 c.enableRootUser()
25 c.isRootEnabled()
26 c.restartInstance()
27 c.resizeInstance()
28 c.resizeVol()
29
30 // DATABASE tests
31 c.createDB()
32 c.listDBs()
33
34 // USER tests
35 c.createUsers()
36 c.listUsers()
37
38 // TEARDOWN
39 c.deleteUsers()
40 c.deleteDBs()
41 c.deleteInstance(id)
42}
43
44func (c context) createInstance() {
45 opts := instances.CreateOpts{
46 FlavorRef: "1",
47 Size: 1,
48 Name: tools.RandomString("gopher_db", 5),
49 }
50
51 instance, err := instances.Create(c.client, opts).Extract()
52 th.AssertNoErr(c.test, err)
53
54 c.Logf("Restarting %s. Waiting...", id)
55 c.WaitUntilActive(id)
56 c.Logf("Created DB %#v", instance)
57
58 c.instanceID = instance.ID
59}
60
61func (c context) listInstances() {
62 c.Logf("Listing instances")
63
64 err := instances.List(c.client).EachPage(func(page pagination.Page) (bool, error) {
65 instanceList, err := instances.ExtractInstances(page)
66 c.AssertNoErr(err)
67
68 for _, n := range networkList {
69 c.Logf("Instance: %#v", instance)
70 }
71
72 return true, nil
73 })
74
75 c.CheckNoErr(err)
76}
77
78func (c context) getInstance() {
79 instance, err := instances.Get(c.client, c.instanceID).Extract()
80 c.AssertNoErr(err)
81 c.Logf("Getting instance: %#v", instance)
82}
83
84func (c context) deleteInstance() {
85 err := instances.Delete(c.client, c.instanceID).ExtractErr()
86 c.AssertNoErr(err)
87 c.Logf("Deleted instance %s", c.instanceID)
88}
89
90func (c context) enableRootUser() {
91 err := instances.EnableRootUser(c.client, c.instanceID).ExtractErr()
92 c.AssertNoErr(err)
93 c.Logf("Enabled root user on %s", c.instanceID)
94}
95
96func (c context) isRootEnabled() {
97 enabled, err := instances.IsRootEnabled(c.client, c.instanceID)
98 c.AssertNoErr(err)
99 c.Logf("Is root enabled? %s", enabled)
100}
101
102func (c context) restartInstance() {
103 id := c.instanceID
104 err := instances.Restart(c.client, id).ExtractErr()
105 c.AssertNoErr(err)
106 c.Logf("Restarting %s. Waiting...", id)
107 c.WaitUntilActive(id)
108 c.Logf("Restarted %s", id)
109}
110
111func (c context) resizeInstance() {
112 id := c.instanceID
113 err := instances.Resize(c.client, id, "2").ExtractErr()
114 c.AssertNoErr(err)
115 c.Logf("Resizing %s. Waiting...", id)
116 c.WaitUntilActive(id)
117 c.Logf("Resized %s with flavorRef %s", id, "2")
118}
119
120func (c context) resizeVol() {
121 id := c.instanceID
122 err := instances.ResizeVol(c.client, id, 2).ExtractErr()
123 c.AssertNoErr(err)
124 c.Logf("Resizing volume of %s. Waiting...", id)
125 c.WaitUntilActive(id)
126 c.Logf("Resized the volume of %s to %d GB", id, 2)
127}