blob: cecd9c92f81d6ff15de1258ff22a35cd815e05df [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 "github.com/rackspace/gophercloud/pagination"
9)
10
11func (c context) createDBs() {
12 dbs := []string{
Jamie Hannaford11108402015-02-23 10:31:41 +010013 tools.RandomString("db_", 5),
14 tools.RandomString("db_", 5),
15 tools.RandomString("db_", 5),
Jamie Hannaford05d200d2015-02-20 14:49:05 +010016 }
17
18 opts := db.BatchCreateOpts{
19 db.CreateOpts{Name: dbs[0]},
20 db.CreateOpts{Name: dbs[1]},
21 db.CreateOpts{Name: dbs[2]},
22 }
23
Jamie Hannaford11108402015-02-23 10:31:41 +010024 err := db.Create(c.client, c.instanceID, opts).ExtractErr()
25 c.AssertNoErr(err)
Jamie Hannaford05d200d2015-02-20 14:49:05 +010026 c.Logf("Created three databases on instance %s: %s, %s, %s", c.instanceID, dbs[0], dbs[1], dbs[2])
27 c.DBIDs = dbs
28}
29
30func (c context) listDBs() {
31 c.Logf("Listing databases on instance %s", c.instanceID)
32
Jamie Hannaford11108402015-02-23 10:31:41 +010033 err := db.List(c.client, c.instanceID).EachPage(func(page pagination.Page) (bool, error) {
Jamie Hannaford05d200d2015-02-20 14:49:05 +010034 dbList, err := db.ExtractDBs(page)
35 c.AssertNoErr(err)
36
37 for _, db := range dbList {
38 c.Logf("DB: %#v", db)
39 }
40
41 return true, nil
42 })
43
Jamie Hannaford11108402015-02-23 10:31:41 +010044 c.AssertNoErr(err)
Jamie Hannaford05d200d2015-02-20 14:49:05 +010045}
46
47func (c context) deleteDBs() {
48 for _, id := range c.DBIDs {
49 err := db.Delete(c.client, c.instanceID, id).ExtractErr()
Jamie Hannaford11108402015-02-23 10:31:41 +010050 c.AssertNoErr(err)
51 c.Logf("Deleted DB %s", id)
Jamie Hannaford05d200d2015-02-20 14:49:05 +010052 }
53}