First crack at acceptance tests
diff --git a/acceptance/rackspace/db/v1/backup_test.go b/acceptance/rackspace/db/v1/backup_test.go
new file mode 100644
index 0000000..677b3b3
--- /dev/null
+++ b/acceptance/rackspace/db/v1/backup_test.go
@@ -0,0 +1,65 @@
+// +build acceptance db
+
+package v1
+
+import "github.com/rackspace/gophercloud/pagination"
+
+func (c context) createBackup() {
+ opts := backups.CreateOpts{
+ Name: tools.PrefixString("backup_", 5),
+ InstanceID: c.instanceID,
+ }
+
+ backup, err := backups.Create(c.client, opts)
+
+ c.Logf("Created backup %#v", backup)
+ c.AssertNoErr(t, err)
+
+ c.backupID = backup.ID
+}
+
+func (c context) getBackup() {
+ backup, err := backups.Get(c.client, c.backupID).Extract()
+ c.AssertNoErr(err)
+ c.Logf("Getting backup %s", backup.ID)
+}
+
+func (c context) listAllBackups() {
+ c.Logf("Listing backups")
+
+ err := backups.List(c.client).EachPage(func(page pagination.Page) (bool, error) {
+ backupList, err := backups.ExtractBackups(page)
+ c.AssertNoErr(err)
+
+ for _, b := range backupList {
+ c.Logf("Backup: %#v", b)
+ }
+
+ return true, nil
+ })
+
+ c.CheckNoErr(err)
+}
+
+func (c context) listInstanceBackups() {
+ c.Logf("Listing backups for instance %s", c.instanceID)
+
+ err := instances.ListBackups(c.client).EachPage(func(page pagination.Page) (bool, error) {
+ backupList, err := backups.ExtractBackups(page)
+ c.AssertNoErr(err)
+
+ for _, b := range backupList {
+ c.Logf("Backup: %#v", b)
+ }
+
+ return true, nil
+ })
+
+ c.CheckNoErr(err)
+}
+
+func (c context) deleteBackup() {
+ err := backups.Delete(c.client, c.backupID).ExtractErr()
+ c.AssertNoErr(err)
+ c.Logf("Deleted backup %s", c.backupID)
+}
diff --git a/acceptance/rackspace/db/v1/common.go b/acceptance/rackspace/db/v1/common.go
new file mode 100644
index 0000000..2fa977f
--- /dev/null
+++ b/acceptance/rackspace/db/v1/common.go
@@ -0,0 +1,66 @@
+// +build acceptance db
+
+package v1
+
+import (
+ "os"
+ "testing"
+
+ "github.com/rackspace/gophercloud"
+ "github.com/rackspace/gophercloud/openstack"
+ "github.com/rackspace/gophercloud/rackspace"
+ th "github.com/rackspace/gophercloud/testhelper"
+)
+
+func newClient(t *testing.T) *gophercloud.ServiceClient {
+ ao, err := openstack.AuthOptionsFromEnv()
+ th.AssertNoErr(t, err)
+
+ client, err := openstack.AuthenticatedClient(ao)
+ th.AssertNoErr(t, err)
+
+ c, err := rackspace.NewDBV1(client, gophercloud.EndpointOpts{
+ Region: os.Getenv("RS_REGION_NAME"),
+ })
+ th.AssertNoErr(t, err)
+
+ return c
+}
+
+type context struct {
+ test *testing.T
+ client *gophercloud.ServiceClient
+ instanceID string
+ DBIDs []string
+ replicaID string
+ backupID string
+ configGroupID string
+}
+
+func newContext(t *testing.T) context {
+ return context{
+ test: t,
+ client: newClient(t),
+ }
+}
+
+func (c context) Logf(msg string, args ...interface{}) {
+ c.test.Logf(msg, args)
+}
+
+func (c context) AssertNoErr(err error) {
+ th.AssertNoErr(c.test, err)
+}
+
+func (c context) WaitUntilActive(id string) {
+ err := gophercloud.WaitFor(60, func() (bool, error) {
+ inst, err := instances.Get(c.client, id).Extract()
+ if err != nil {
+ return false, err
+ }
+ if inst.Status == "ACTIVE" {
+ return true, nil
+ }
+ return false, nil
+ })
+}
diff --git a/acceptance/rackspace/db/v1/config_group_test.go b/acceptance/rackspace/db/v1/config_group_test.go
new file mode 100644
index 0000000..3d269c4
--- /dev/null
+++ b/acceptance/rackspace/db/v1/config_group_test.go
@@ -0,0 +1,84 @@
+// +build acceptance db
+
+package v1
+
+import (
+ config "github.com/rackspace/gophercloud/openstack/db/v1/configurations"
+ "github.com/rackspace/gophercloud/pagination"
+)
+
+func (c context) createConfigGrp() {
+ opts := config.CreateOpts{
+ Name: tools.PrefixString("config_", 5),
+ Values: map[string]interface{}{
+ "connect_timeout": 300,
+ "join_buffer_size": 900000,
+ },
+ }
+
+ cg, err := config.Create(c.client, opts)
+
+ c.AssertNoErr(err)
+ c.Logf("Created config group %#v", cg)
+
+ c.configGroupID = cg.ID
+}
+
+func (c context) getConfigGrp() {
+ cg, err := config.Get(c.client, c.configGroupID)
+ c.Logf("Getting config group: %#v", cg)
+ c.AssertNoErr(err)
+}
+
+func (c context) updateConfigGrp() {
+ opts := config.UpdateOpts{
+ Name: tools.PrefixString("new_name_", 5),
+ Values: map[string]interface{}{
+ "connect_timeout": 250,
+ },
+ }
+ err := config.Update(c.client, c.configGroupID, opts).ExtractErr()
+ c.Logf("Updated config group %s", c.configGroupID)
+ c.AssertNoErr(err)
+}
+
+func (c context) replaceConfigGrp() {
+ opts := config.UpdateOpts{
+ Values: map[string]interface{}{
+ "expire_logs_days": 7,
+ },
+ }
+
+ err := config.Replace(c.client, c.configGroupID, opts).ExtractErr()
+ c.Logf("Replaced values for config group %s", c.configGroupID)
+ c.AssertNoErr(err)
+}
+
+func (c context) associateInstanceWithConfigGrp() {
+ err := config.AssociateWithConfigGroup(c.client, c.instanceID, c.configGroupID).ExtractErr()
+ c.Logf("Associated instance %s with config group %s", c.instanceID, c.configGroupID)
+ c.AssertNoErr(err)
+}
+
+func (c context) listConfigGrpInstances() {
+ c.Logf("Listing all instances associated with config group %s", c.configGroupID)
+
+ err := config.ListInstances(c.client, c.configGroupID).EachPage(func(page pagination.Page) (bool, error) {
+ instanceList, err := instances.ExtractInstances(page)
+ c.AssertNoErr(err)
+
+ for _, n := range networkList {
+ c.Logf("Instance: %#v", instance)
+ }
+
+ return true, nil
+ })
+
+ c.CheckNoErr(err)
+}
+
+func (c context) deleteConfigGrp() {
+ err := config.Delete(c.client, c.configGroupID).ExtractErr()
+ c.Logf("Deleted config group %s", c.configGroupID)
+ c.AssertNoErr(err)
+}
diff --git a/acceptance/rackspace/db/v1/database_test.go b/acceptance/rackspace/db/v1/database_test.go
new file mode 100644
index 0000000..e2d41cf
--- /dev/null
+++ b/acceptance/rackspace/db/v1/database_test.go
@@ -0,0 +1,52 @@
+// +build acceptance db
+
+package v1
+
+import (
+ "github.com/rackspace/gophercloud/acceptance/tools"
+ db "github.com/rackspace/gophercloud/openstack/db/v1/databases"
+ "github.com/rackspace/gophercloud/pagination"
+)
+
+func (c context) createDBs() {
+ dbs := []string{
+ tools.RandomString("db_"),
+ tools.RandomString("db_"),
+ tools.RandomString("db_"),
+ }
+
+ opts := db.BatchCreateOpts{
+ db.CreateOpts{Name: dbs[0]},
+ db.CreateOpts{Name: dbs[1]},
+ db.CreateOpts{Name: dbs[2]},
+ }
+
+ res := db.Create(c.client, c.instanceID, opts)
+ c.Logf("Created three databases on instance %s: %s, %s, %s", c.instanceID, dbs[0], dbs[1], dbs[2])
+ c.DBIDs = dbs
+}
+
+func (c context) listDBs() {
+ c.Logf("Listing databases on instance %s", c.instanceID)
+
+ err := dbs.List(c.client, c.instanceID).EachPage(func(page pagination.Page) (bool, error) {
+ dbList, err := db.ExtractDBs(page)
+ c.AssertNoErr(err)
+
+ for _, db := range dbList {
+ c.Logf("DB: %#v", db)
+ }
+
+ return true, nil
+ })
+
+ c.CheckNoErr(err)
+}
+
+func (c context) deleteDBs() {
+ for _, id := range c.DBIDs {
+ err := db.Delete(c.client, c.instanceID, id).ExtractErr()
+ c.CheckNoErr(err)
+ t.Logf("Deleted DB %s", id)
+ }
+}
diff --git a/acceptance/rackspace/db/v1/flavor_test.go b/acceptance/rackspace/db/v1/flavor_test.go
new file mode 100644
index 0000000..e121f68
--- /dev/null
+++ b/acceptance/rackspace/db/v1/flavor_test.go
@@ -0,0 +1,31 @@
+// +build acceptance db
+
+package v1
+
+import (
+ "github.com/rackspace/gophercloud/pagination"
+ "github.com/rackspace/gophercloud/rackspace/db/v1/flavors"
+)
+
+func (c context) listFlavors() {
+ c.Logf("Listing flavors")
+
+ err := flavors.List(c.client, c.instanceID).EachPage(func(page pagination.Page) (bool, error) {
+ flavorList, err := db.ExtractFlavors(page)
+ c.AssertNoErr(err)
+
+ for _, f := range flavorList {
+ c.Logf("Flavor: %#v", f)
+ }
+
+ return true, nil
+ })
+
+ c.CheckNoErr(err)
+}
+
+func (c context) getFlavor() {
+ flavor, err := flavors.Get(c.client, "1").Extract()
+ c.Logf("Getting flavor %s", flavor.ID)
+ c.CheckNoErr(err)
+}
diff --git a/acceptance/rackspace/db/v1/instance_test.go b/acceptance/rackspace/db/v1/instance_test.go
new file mode 100644
index 0000000..eb745e2
--- /dev/null
+++ b/acceptance/rackspace/db/v1/instance_test.go
@@ -0,0 +1,160 @@
+// +build acceptance db
+
+package v1
+
+import (
+ "github.com/rackspace/gophercloud/acceptance/tools"
+ "github.com/rackspace/gophercloud/pagination"
+ "github.com/rackspace/gophercloud/rackspace/db/v1/instances"
+ th "github.com/rackspace/gophercloud/testhelper"
+)
+
+func TestRunner(t *testingT) {
+ c := newContext(t)
+
+ // FLAVOR tests
+ c.listFlavors()
+ c.getFlavor()
+
+ // INSTANCE tests
+ c.createInstance()
+ c.listInstances()
+ c.getInstance()
+ c.isRootEnabled()
+ c.enableRootUser()
+ c.isRootEnabled()
+ c.restartInstance()
+ c.resizeInstance()
+ c.resizeVol()
+ c.getDefaultConfig()
+
+ // REPLICA tests
+ c.createReplica()
+ c.detachReplica()
+
+ // BACKUP tests
+ c.createBackup()
+ c.getBackup()
+ c.listAllBackups()
+ c.listInstanceBackups()
+ c.deleteBackup()
+
+ // CONFIG GROUP tests
+ c.createConfigGrp()
+ c.getConfigGrp()
+ c.updateConfigGrp()
+ c.replaceConfigGrp()
+ c.associateInstanceWithConfigGrp()
+ c.listConfigGrpInstances()
+ c.deleteConfigGrp()
+
+ // DATABASE tests
+ c.createDB()
+ c.listDBs()
+
+ // USER tests
+ c.createUsers()
+ c.listUsers()
+ c.changeUserPwd()
+ c.getUser()
+ c.updateUser()
+ c.listUserAccess()
+ c.revokeUserAccess()
+ c.grantUserAccess()
+
+ // TEARDOWN
+ c.deleteUsers()
+ c.deleteDBs()
+ c.deleteInstance(id)
+}
+
+func (c context) createInstance() {
+ opts := instances.CreateOpts{
+ FlavorRef: "1",
+ Size: 1,
+ Name: tools.RandomString("gopher_db", 5),
+ }
+
+ instance, err := instances.Create(c.client, opts).Extract()
+ th.AssertNoErr(c.test, err)
+
+ c.Logf("Restarting %s. Waiting...", id)
+ c.WaitUntilActive(id)
+ c.Logf("Created DB %#v", instance)
+
+ c.instanceID = instance.ID
+}
+
+func (c context) listInstances() {
+ c.Logf("Listing instances")
+
+ err := instances.List(c.client).EachPage(func(page pagination.Page) (bool, error) {
+ instanceList, err := instances.ExtractInstances(page)
+ c.AssertNoErr(err)
+
+ for _, n := range networkList {
+ c.Logf("Instance: %#v", instance)
+ }
+
+ return true, nil
+ })
+
+ c.CheckNoErr(err)
+}
+
+func (c context) getInstance() {
+ instance, err := instances.Get(c.client, c.instanceID).Extract()
+ c.AssertNoErr(err)
+ c.Logf("Getting instance: %#v", instance)
+}
+
+func (c context) deleteInstance() {
+ err := instances.Delete(c.client, c.instanceID).ExtractErr()
+ c.AssertNoErr(err)
+ c.Logf("Deleted instance %s", c.instanceID)
+}
+
+func (c context) enableRootUser() {
+ err := instances.EnableRootUser(c.client, c.instanceID).ExtractErr()
+ c.AssertNoErr(err)
+ c.Logf("Enabled root user on %s", c.instanceID)
+}
+
+func (c context) isRootEnabled() {
+ enabled, err := instances.IsRootEnabled(c.client, c.instanceID)
+ c.AssertNoErr(err)
+ c.Logf("Is root enabled? %s", enabled)
+}
+
+func (c context) restartInstance() {
+ id := c.instanceID
+ err := instances.Restart(c.client, id).ExtractErr()
+ c.AssertNoErr(err)
+ c.Logf("Restarting %s. Waiting...", id)
+ c.WaitUntilActive(id)
+ c.Logf("Restarted %s", id)
+}
+
+func (c context) resizeInstance() {
+ id := c.instanceID
+ err := instances.Resize(c.client, id, "2").ExtractErr()
+ c.AssertNoErr(err)
+ c.Logf("Resizing %s. Waiting...", id)
+ c.WaitUntilActive(id)
+ c.Logf("Resized %s with flavorRef %s", id, "2")
+}
+
+func (c context) resizeVol() {
+ id := c.instanceID
+ err := instances.ResizeVol(c.client, id, 2).ExtractErr()
+ c.AssertNoErr(err)
+ c.Logf("Resizing volume of %s. Waiting...", id)
+ c.WaitUntilActive(id)
+ c.Logf("Resized the volume of %s to %d GB", id, 2)
+}
+
+func (c context) getDefaultConfig() {
+ config, err := instances.GetDefaultConfig(c.client, c.instanceID).Extract()
+ c.Logf("Default config group for instance %s: %#v", c.instanceID, config)
+ c.AssertNoErr(err)
+}
diff --git a/acceptance/rackspace/db/v1/pkg.go b/acceptance/rackspace/db/v1/pkg.go
new file mode 100644
index 0000000..b7b1f99
--- /dev/null
+++ b/acceptance/rackspace/db/v1/pkg.go
@@ -0,0 +1 @@
+package v1
diff --git a/acceptance/rackspace/db/v1/replica_test.go b/acceptance/rackspace/db/v1/replica_test.go
new file mode 100644
index 0000000..96eaf19
--- /dev/null
+++ b/acceptance/rackspace/db/v1/replica_test.go
@@ -0,0 +1,34 @@
+// +build acceptance db
+
+package v1
+
+import (
+ "github.com/rackspace/gophercloud/acceptance/tools"
+ "github.com/rackspace/gophercloud/rackspace/db/v1/instances"
+ th "github.com/rackspace/gophercloud/testhelper"
+)
+
+func (c context) createReplica() {
+ repl, err := instances.Create(c.client, opts).Extract()
+
+ opts := instances.CreateOpts{
+ FlavorRef: "1",
+ Size: 1,
+ Name: tools.RandomString("gopher_db", 5),
+ ReplicaOf: c.instanceID,
+ }
+
+ instance, err := instances.Create(c.client, opts).Extract()
+ th.AssertNoErr(c.test, err)
+
+ c.Logf("Creating replica of %s. Waiting...", c.instanceID)
+ c.WaitUntilActive(id)
+ c.Logf("Created replica %#v", repl)
+
+ c.replicaID = repl.ID
+}
+
+func (c context) detachReplica() {
+ err := instances.DetachReplica(c.client, c.replicaID).ExtractErr()
+ c.Logf("Detached replica %s", c.replicaID)
+}
diff --git a/acceptance/rackspace/db/v1/user_test.go b/acceptance/rackspace/db/v1/user_test.go
new file mode 100644
index 0000000..9bf00dd
--- /dev/null
+++ b/acceptance/rackspace/db/v1/user_test.go
@@ -0,0 +1,122 @@
+// +build acceptance db
+
+package v1
+
+import (
+ "github.com/rackspace/gophercloud/acceptance/tools"
+ "github.com/rackspace/gophercloud/openstack/identity/v2/users"
+ "github.com/rackspace/gophercloud/pagination"
+ db "github.com/rackspace/gophercloud/rackspace/db/v1/databases"
+ u "github.com/rackspace/gophercloud/rackspace/db/v1/users"
+)
+
+func (c context) createUsers() {
+ users := []string{
+ tools.RandomString("user_"),
+ tools.RandomString("user_"),
+ tools.RandomString("user_"),
+ }
+
+ db1 := db.CreateOpt{Name: c.DBIDs[0]}
+ db2 := db.CreateOpt{Name: c.DBIDs[1]}
+ db3 := db.CreateOpt{Name: c.DBIDs[2]}
+
+ opts := u.BatchCreateOpts{
+ u.CreateOpts{
+ Name: users[0],
+ Password: tools.RandomString(),
+ databases: db.BatchCreateOpts{db1, db2, db3},
+ },
+ u.CreateOpts{
+ Name: users[1],
+ Password: tools.RandomString(),
+ databases: db.BatchCreateOpts{db1, db2},
+ },
+ u.CreateOpts{
+ Name: users[2],
+ Password: tools.RandomString(),
+ databases: db.BatchCreateOpts{db3},
+ },
+ }
+
+ err := u.Create(c.client, c.instanceID, opts).ExtractErr()
+ c.Logf("Created three users on instance %s: %s, %s, %s", c.instanceID, users[0], users[1], users[2])
+ c.users = users
+}
+
+func (c context) listUsers() {
+ c.Logf("Listing users on instance %s", c.instanceID)
+
+ err := users.List(c.client, c.instanceID).EachPage(func(page pagination.Page) (bool, error) {
+ uList, err := u.ExtractUsers(page)
+ c.AssertNoErr(err)
+
+ for _, u := range uList {
+ c.Logf("User: %#v", u)
+ }
+
+ return true, nil
+ })
+
+ c.CheckNoErr(err)
+}
+
+func (c context) deleteUsers() {
+ for _, id := range c.users {
+ err := u.Delete(c.client, c.instanceID, id).ExtractErr()
+ c.CheckNoErr(err)
+ t.Logf("Deleted user %s", id)
+ }
+}
+
+func (c context) changeUserPwd() {
+ opts := u.BatchCreateOpts{}
+
+ for _, id := range c.users[:1] {
+ opts = append(opts, u.CreateOpts{Password: tools.PrefixString("", 5)})
+ }
+
+ err := u.UpdatePassword(c.client, c.instanceID, opts).ExtractErr()
+ c.Logf("Updated 2 users' passwords")
+ c.AssertNoErr(err)
+}
+
+func (c context) getUser() {
+ user, err := u.Get(c.client, c.instanceID, c.users[0]).Extract()
+ c.Logf("Getting user %s", user)
+ c.AssertNoErr(err)
+}
+
+func (c context) updateUser() {
+ opts := u.CreateOpts{Name: tools.PrefixString("new_name_", 5)}
+ user, err := u.Update(c.client, c.instanceID, c.users[0], opts).Extract()
+ c.Logf("Updated user %s", user)
+ c.AssertNoErr(err)
+}
+
+func (c context) listUserAccess() {
+ err := u.ListAccess(c.client, c.instanceId, c.users[0]).EachPage(func(page pagination.Page) (bool, error) {
+ dbList, err := db.ExtractDBs(page)
+ c.AssertNoErr(err)
+
+ for _, db := range dbList {
+ c.Logf("User %s has access to DB: %#v", db)
+ }
+
+ return true, nil
+ })
+
+ c.CheckNoErr(err)
+}
+
+func (c context) grantUserAccess() {
+ userID, dbID := c.users[0], c.DBIDS[0]
+ err := u.GrantUserAccess(c.client, c.instanceID, userID, dbID)
+ c.Logf("Granted access for user %s to DB %s", userID, dbID)
+}
+
+func (c context) revokeUserAccess() {
+ userID, dbID := c.users[0], c.DBIDS[0]
+ err := u.RevokeUserAccess(c.client, c.instanceID, userID, dbID)
+ c.Logf("Revoked access for user %s to DB %s", userID, dbID)
+}