blob: 877ea97a9a8af267077e3cf1395c9dd210fedef2 [file] [log] [blame]
Jamie Hannaford05d200d2015-02-20 14:49:05 +01001// +build acceptance db
2
3package v1
4
5import (
Jamie Hannaford99eced52015-03-02 15:24:22 +01006 "os"
Jamie Hannaford11108402015-02-23 10:31:41 +01007 "testing"
8
Krzysztof Szukiełojć24a29ce2017-05-07 14:24:02 +02009 "gerrit.mcp.mirantis.net/debian/gophercloud.git/acceptance/tools"
10 "gerrit.mcp.mirantis.net/debian/gophercloud.git/openstack/db/v1/instances"
11 "gerrit.mcp.mirantis.net/debian/gophercloud.git/pagination"
12 th "gerrit.mcp.mirantis.net/debian/gophercloud.git/testhelper"
Jamie Hannaford05d200d2015-02-20 14:49:05 +010013)
14
Jamie Hannaford99eced52015-03-02 15:24:22 +010015const envDSType = "DATASTORE_TYPE_ID"
16
Jamie Hannaford11108402015-02-23 10:31:41 +010017func TestRunner(t *testing.T) {
Jamie Hannaford05d200d2015-02-20 14:49:05 +010018 c := newContext(t)
19
20 // FLAVOR tests
21 c.listFlavors()
22 c.getFlavor()
23
24 // INSTANCE tests
Jamie Hannaford3c3c7842015-11-13 13:20:28 +010025 c.createInstance()
Jamie Hannaford05d200d2015-02-20 14:49:05 +010026 c.listInstances()
27 c.getInstance()
28 c.isRootEnabled()
29 c.enableRootUser()
30 c.isRootEnabled()
31 c.restartInstance()
Jamie Hannaford3c3c7842015-11-13 13:20:28 +010032 //c.resizeInstance()
33 //c.resizeVol()
Jamie Hannaford05d200d2015-02-20 14:49:05 +010034
35 // DATABASE tests
Jamie Hannaford11108402015-02-23 10:31:41 +010036 c.createDBs()
Jamie Hannaford05d200d2015-02-20 14:49:05 +010037 c.listDBs()
38
39 // USER tests
40 c.createUsers()
41 c.listUsers()
42
43 // TEARDOWN
44 c.deleteUsers()
45 c.deleteDBs()
Jamie Hannaford11108402015-02-23 10:31:41 +010046 c.deleteInstance()
Jamie Hannaford05d200d2015-02-20 14:49:05 +010047}
48
49func (c context) createInstance() {
Jamie Hannaford99eced52015-03-02 15:24:22 +010050 if os.Getenv(envDSType) == "" {
51 c.test.Fatalf("%s must be set as an environment var", envDSType)
52 }
53
54 opts := instances.CreateOpts{
Jamie Hannaford3c3c7842015-11-13 13:20:28 +010055 FlavorRef: "2",
56 Size: 5,
Jamie Hannaford05d200d2015-02-20 14:49:05 +010057 Name: tools.RandomString("gopher_db", 5),
Jamie Hannaford99eced52015-03-02 15:24:22 +010058 Datastore: &instances.DatastoreOpts{Type: os.Getenv(envDSType)},
Jamie Hannaford05d200d2015-02-20 14:49:05 +010059 }
60
61 instance, err := instances.Create(c.client, opts).Extract()
62 th.AssertNoErr(c.test, err)
63
Jamie Hannaford11108402015-02-23 10:31:41 +010064 c.Logf("Restarting %s. Waiting...", instance.ID)
65 c.WaitUntilActive(instance.ID)
Jamie Hannaford99eced52015-03-02 15:24:22 +010066 c.Logf("Created Instance %s", instance.ID)
Jamie Hannaford05d200d2015-02-20 14:49:05 +010067
68 c.instanceID = instance.ID
69}
70
71func (c context) listInstances() {
72 c.Logf("Listing instances")
73
74 err := instances.List(c.client).EachPage(func(page pagination.Page) (bool, error) {
75 instanceList, err := instances.ExtractInstances(page)
76 c.AssertNoErr(err)
77
Jamie Hannaford11108402015-02-23 10:31:41 +010078 for _, i := range instanceList {
Jamie Hannaford99eced52015-03-02 15:24:22 +010079 c.Logf("Instance: ID [%s] Name [%s] Status [%s] VolSize [%d] Datastore Type [%s]",
80 i.ID, i.Name, i.Status, i.Volume.Size, i.Datastore.Type)
Jamie Hannaford05d200d2015-02-20 14:49:05 +010081 }
82
83 return true, nil
84 })
85
Jamie Hannaford11108402015-02-23 10:31:41 +010086 c.AssertNoErr(err)
Jamie Hannaford05d200d2015-02-20 14:49:05 +010087}
88
89func (c context) getInstance() {
90 instance, err := instances.Get(c.client, c.instanceID).Extract()
91 c.AssertNoErr(err)
Jamie Hannaford99eced52015-03-02 15:24:22 +010092 c.Logf("Getting instance: %s", instance.ID)
Jamie Hannaford05d200d2015-02-20 14:49:05 +010093}
94
95func (c context) deleteInstance() {
96 err := instances.Delete(c.client, c.instanceID).ExtractErr()
97 c.AssertNoErr(err)
98 c.Logf("Deleted instance %s", c.instanceID)
99}
100
101func (c context) enableRootUser() {
Jamie Hannaford11108402015-02-23 10:31:41 +0100102 _, err := instances.EnableRootUser(c.client, c.instanceID).Extract()
Jamie Hannaford05d200d2015-02-20 14:49:05 +0100103 c.AssertNoErr(err)
104 c.Logf("Enabled root user on %s", c.instanceID)
105}
106
107func (c context) isRootEnabled() {
108 enabled, err := instances.IsRootEnabled(c.client, c.instanceID)
109 c.AssertNoErr(err)
Jamie Hannaford99eced52015-03-02 15:24:22 +0100110 c.Logf("Is root enabled? %d", enabled)
Jamie Hannaford05d200d2015-02-20 14:49:05 +0100111}
112
113func (c context) restartInstance() {
114 id := c.instanceID
Jamie Hannaford75e8cc42015-11-16 14:09:25 +0100115 err := instances.Restart(c.client, id).ExtractErr()
Jamie Hannaford05d200d2015-02-20 14:49:05 +0100116 c.AssertNoErr(err)
117 c.Logf("Restarting %s. Waiting...", id)
118 c.WaitUntilActive(id)
119 c.Logf("Restarted %s", id)
120}
121
122func (c context) resizeInstance() {
123 id := c.instanceID
Jamie Hannaford75e8cc42015-11-16 14:09:25 +0100124 err := instances.Resize(c.client, id, "3").ExtractErr()
Jamie Hannaford05d200d2015-02-20 14:49:05 +0100125 c.AssertNoErr(err)
126 c.Logf("Resizing %s. Waiting...", id)
127 c.WaitUntilActive(id)
128 c.Logf("Resized %s with flavorRef %s", id, "2")
129}
130
131func (c context) resizeVol() {
132 id := c.instanceID
Jamie Hannaford3c3c7842015-11-13 13:20:28 +0100133 err := instances.ResizeVolume(c.client, id, 4).ExtractErr()
Jamie Hannaford05d200d2015-02-20 14:49:05 +0100134 c.AssertNoErr(err)
135 c.Logf("Resizing volume of %s. Waiting...", id)
136 c.WaitUntilActive(id)
137 c.Logf("Resized the volume of %s to %d GB", id, 2)
138}