Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame^] | 1 | // +build acceptance db |
| 2 | |
| 3 | package v1 |
| 4 | |
| 5 | import ( |
| 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 | |
| 12 | func (c context) createUsers() { |
| 13 | users := []string{ |
| 14 | tools.RandomString("user_"), |
| 15 | tools.RandomString("user_"), |
| 16 | tools.RandomString("user_"), |
| 17 | } |
| 18 | |
| 19 | db1 := db.CreateOpt{Name: c.DBIDs[0]} |
| 20 | db2 := db.CreateOpt{Name: c.DBIDs[1]} |
| 21 | db3 := db.CreateOpt{Name: c.DBIDs[2]} |
| 22 | |
| 23 | opts := u.BatchCreateOpts{ |
| 24 | u.CreateOpts{ |
| 25 | Name: users[0], |
| 26 | Password: tools.RandomString(), |
| 27 | databases: db.BatchCreateOpts{db1, db2, db3}, |
| 28 | }, |
| 29 | u.CreateOpts{ |
| 30 | Name: users[1], |
| 31 | Password: tools.RandomString(), |
| 32 | databases: db.BatchCreateOpts{db1, db2}, |
| 33 | }, |
| 34 | u.CreateOpts{ |
| 35 | Name: users[2], |
| 36 | Password: tools.RandomString(), |
| 37 | databases: db.BatchCreateOpts{db3}, |
| 38 | }, |
| 39 | } |
| 40 | |
| 41 | err := u.Create(c.client, c.instanceID, opts).ExtractErr() |
| 42 | c.Logf("Created three users on instance %s: %s, %s, %s", c.instanceID, users[0], users[1], users[2]) |
| 43 | c.users = users |
| 44 | } |
| 45 | |
| 46 | func (c context) listUsers() { |
| 47 | c.Logf("Listing databases on instance %s", c.instanceID) |
| 48 | |
| 49 | err := dbs.List(c.client, c.instanceID).EachPage(func(page pagination.Page) (bool, error) { |
| 50 | dbList, err := db.ExtractDBs(page) |
| 51 | c.AssertNoErr(err) |
| 52 | |
| 53 | for _, db := range dbList { |
| 54 | c.Logf("DB: %#v", db) |
| 55 | } |
| 56 | |
| 57 | return true, nil |
| 58 | }) |
| 59 | |
| 60 | c.CheckNoErr(err) |
| 61 | } |
| 62 | |
| 63 | func (c context) deleteUsers() { |
| 64 | for _, id := range c.DBIDs { |
| 65 | err := db.Delete(c.client, c.instanceID, id).ExtractErr() |
| 66 | c.CheckNoErr(err) |
| 67 | t.Logf("Deleted DB %s", id) |
| 68 | } |
| 69 | } |