blob: 25a47943c9b05f31ff7c62fef4a502f68b29fb31 [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 db "github.com/rackspace/gophercloud/openstack/db/v1/databases"
8 u "github.com/rackspace/gophercloud/openstack/db/v1/users"
9 "github.com/rackspace/gophercloud/pagination"
10)
11
12func (c context) createUsers() {
13 users := []string{
Jamie Hannaford11108402015-02-23 10:31:41 +010014 tools.RandomString("user_", 5),
15 tools.RandomString("user_", 5),
16 tools.RandomString("user_", 5),
Jamie Hannaford05d200d2015-02-20 14:49:05 +010017 }
18
Jamie Hannaford3c3c7842015-11-13 13:20:28 +010019 db1 := db.CreateOpts{Name: "db1"}
20 db2 := db.CreateOpts{Name: "db2"}
21 db3 := db.CreateOpts{Name: "db3"}
Jamie Hannaford05d200d2015-02-20 14:49:05 +010022
23 opts := u.BatchCreateOpts{
24 u.CreateOpts{
25 Name: users[0],
Jamie Hannaford11108402015-02-23 10:31:41 +010026 Password: tools.RandomString("", 5),
27 Databases: db.BatchCreateOpts{db1, db2, db3},
Jamie Hannaford05d200d2015-02-20 14:49:05 +010028 },
29 u.CreateOpts{
30 Name: users[1],
Jamie Hannaford11108402015-02-23 10:31:41 +010031 Password: tools.RandomString("", 5),
32 Databases: db.BatchCreateOpts{db1, db2},
Jamie Hannaford05d200d2015-02-20 14:49:05 +010033 },
34 u.CreateOpts{
35 Name: users[2],
Jamie Hannaford11108402015-02-23 10:31:41 +010036 Password: tools.RandomString("", 5),
37 Databases: db.BatchCreateOpts{db3},
Jamie Hannaford05d200d2015-02-20 14:49:05 +010038 },
39 }
40
41 err := u.Create(c.client, c.instanceID, opts).ExtractErr()
Jamie Hannaford11108402015-02-23 10:31:41 +010042 c.AssertNoErr(err)
Jamie Hannaford05d200d2015-02-20 14:49:05 +010043 c.Logf("Created three users on instance %s: %s, %s, %s", c.instanceID, users[0], users[1], users[2])
44 c.users = users
45}
46
47func (c context) listUsers() {
48 c.Logf("Listing databases on instance %s", c.instanceID)
49
Jamie Hannaford11108402015-02-23 10:31:41 +010050 err := db.List(c.client, c.instanceID).EachPage(func(page pagination.Page) (bool, error) {
Jamie Hannaford05d200d2015-02-20 14:49:05 +010051 dbList, err := db.ExtractDBs(page)
52 c.AssertNoErr(err)
53
54 for _, db := range dbList {
55 c.Logf("DB: %#v", db)
56 }
57
58 return true, nil
59 })
60
Jamie Hannaford11108402015-02-23 10:31:41 +010061 c.AssertNoErr(err)
Jamie Hannaford05d200d2015-02-20 14:49:05 +010062}
63
64func (c context) deleteUsers() {
65 for _, id := range c.DBIDs {
66 err := db.Delete(c.client, c.instanceID, id).ExtractErr()
Jamie Hannaford11108402015-02-23 10:31:41 +010067 c.AssertNoErr(err)
68 c.Logf("Deleted DB %s", id)
Jamie Hannaford05d200d2015-02-20 14:49:05 +010069 }
70}