blob: 6ccb80e8560ccc3815f44892ef86350c83c3f16c [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
Jamie Hannaford99eced52015-03-02 15:24:22 +010011func (c *context) createDBs() {
Jamie Hannaford05d200d2015-02-20 14:49:05 +010012 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()
Jamie Hannaford05d200d2015-02-20 14:49:05 +010025 c.Logf("Created three databases on instance %s: %s, %s, %s", c.instanceID, dbs[0], dbs[1], dbs[2])
Jamie Hannaford11108402015-02-23 10:31:41 +010026 c.AssertNoErr(err)
27
Jamie Hannaford05d200d2015-02-20 14:49:05 +010028 c.DBIDs = dbs
29}
30
Jamie Hannaford99eced52015-03-02 15:24:22 +010031func (c *context) listDBs() {
Jamie Hannaford05d200d2015-02-20 14:49:05 +010032 c.Logf("Listing databases on instance %s", c.instanceID)
33
Jamie Hannaford11108402015-02-23 10:31:41 +010034 err := db.List(c.client, c.instanceID).EachPage(func(page pagination.Page) (bool, error) {
Jamie Hannaford05d200d2015-02-20 14:49:05 +010035 dbList, err := db.ExtractDBs(page)
36 c.AssertNoErr(err)
37
38 for _, db := range dbList {
39 c.Logf("DB: %#v", db)
40 }
41
42 return true, nil
43 })
44
Jamie Hannaford11108402015-02-23 10:31:41 +010045 c.AssertNoErr(err)
Jamie Hannaford05d200d2015-02-20 14:49:05 +010046}
47
Jamie Hannaford99eced52015-03-02 15:24:22 +010048func (c *context) deleteDBs() {
Jamie Hannaford05d200d2015-02-20 14:49:05 +010049 for _, id := range c.DBIDs {
50 err := db.Delete(c.client, c.instanceID, id).ExtractErr()
Jamie Hannaford11108402015-02-23 10:31:41 +010051 c.AssertNoErr(err)
52 c.Logf("Deleted DB %s", id)
Jamie Hannaford05d200d2015-02-20 14:49:05 +010053 }
54}