Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.

Commit 99eced5

Browse files
author
Jamie Hannaford
committed
Finalize Rackspace acceptance tests and fix various things
1 parent 42a5c6f commit 99eced5

File tree

17 files changed

+202
-79
lines changed

17 files changed

+202
-79
lines changed

acceptance/openstack/db/v1/common.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ func newContext(t *testing.T) context {
4343
}
4444

4545
func (c context) Logf(msg string, args ...interface{}) {
46-
c.test.Logf(msg, args)
46+
if len(args) > 0 {
47+
c.test.Logf(msg, args...)
48+
} else {
49+
c.test.Log(msg)
50+
}
4751
}
4852

4953
func (c context) AssertNoErr(err error) {

acceptance/openstack/db/v1/flavor_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func (c context) listFlavors() {
1515
c.AssertNoErr(err)
1616

1717
for _, f := range flavorList {
18-
c.Logf("Flavor: %#v", f)
18+
c.Logf("Flavor: ID [%s] Name [%s] RAM [%d]", f.ID, f.Name, f.RAM)
1919
}
2020

2121
return true, nil

acceptance/openstack/db/v1/instance_test.go

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@
33
package v1
44

55
import (
6+
"os"
67
"testing"
78

89
"github.com/rackspace/gophercloud/acceptance/tools"
910
"github.com/rackspace/gophercloud/openstack/db/v1/instances"
1011
"github.com/rackspace/gophercloud/pagination"
11-
rackspaceInst "github.com/rackspace/gophercloud/rackspace/db/v1/instances"
1212
th "github.com/rackspace/gophercloud/testhelper"
1313
)
1414

15+
const envDSType = "DATASTORE_TYPE_ID"
16+
1517
func TestRunner(t *testing.T) {
1618
c := newContext(t)
1719

@@ -20,7 +22,9 @@ func TestRunner(t *testing.T) {
2022
c.getFlavor()
2123

2224
// INSTANCE tests
23-
c.createInstance()
25+
//c.createInstance()
26+
c.instanceID = "dbf901f4-fe23-48b7-8c1d-ee60ec85a660"
27+
2428
c.listInstances()
2529
c.getInstance()
2630
c.isRootEnabled()
@@ -45,19 +49,23 @@ func TestRunner(t *testing.T) {
4549
}
4650

4751
func (c context) createInstance() {
48-
opts := rackspaceInst.CreateOpts{
52+
if os.Getenv(envDSType) == "" {
53+
c.test.Fatalf("%s must be set as an environment var", envDSType)
54+
}
55+
56+
opts := instances.CreateOpts{
4957
FlavorRef: "1",
5058
Size: 1,
5159
Name: tools.RandomString("gopher_db", 5),
52-
Datastore: &rackspaceInst.DatastoreOpts{Version: "5.6", Type: "MySQL"},
60+
Datastore: &instances.DatastoreOpts{Type: os.Getenv(envDSType)},
5361
}
5462

5563
instance, err := instances.Create(c.client, opts).Extract()
5664
th.AssertNoErr(c.test, err)
5765

5866
c.Logf("Restarting %s. Waiting...", instance.ID)
5967
c.WaitUntilActive(instance.ID)
60-
c.Logf("Created DB %#v", instance)
68+
c.Logf("Created Instance %s", instance.ID)
6169

6270
c.instanceID = instance.ID
6371
}
@@ -70,7 +78,8 @@ func (c context) listInstances() {
7078
c.AssertNoErr(err)
7179

7280
for _, i := range instanceList {
73-
c.Logf("Instance: %#v", i)
81+
c.Logf("Instance: ID [%s] Name [%s] Status [%s] VolSize [%d] Datastore Type [%s]",
82+
i.ID, i.Name, i.Status, i.Volume.Size, i.Datastore.Type)
7483
}
7584

7685
return true, nil
@@ -82,7 +91,7 @@ func (c context) listInstances() {
8291
func (c context) getInstance() {
8392
instance, err := instances.Get(c.client, c.instanceID).Extract()
8493
c.AssertNoErr(err)
85-
c.Logf("Getting instance: %#v", instance)
94+
c.Logf("Getting instance: %s", instance.ID)
8695
}
8796

8897
func (c context) deleteInstance() {
@@ -100,7 +109,7 @@ func (c context) enableRootUser() {
100109
func (c context) isRootEnabled() {
101110
enabled, err := instances.IsRootEnabled(c.client, c.instanceID)
102111
c.AssertNoErr(err)
103-
c.Logf("Is root enabled? %s", enabled)
112+
c.Logf("Is root enabled? %d", enabled)
104113
}
105114

106115
func (c context) restartInstance() {

acceptance/rackspace/db/v1/backup_test.go

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
package v1
44

55
import (
6+
"github.com/rackspace/gophercloud"
67
"github.com/rackspace/gophercloud/acceptance/tools"
78
"github.com/rackspace/gophercloud/pagination"
89

910
"github.com/rackspace/gophercloud/rackspace/db/v1/backups"
1011
"github.com/rackspace/gophercloud/rackspace/db/v1/instances"
1112
)
1213

13-
func (c context) createBackup() {
14+
func (c *context) createBackup() {
1415
opts := backups.CreateOpts{
1516
Name: tools.RandomString("backup_", 5),
1617
InstanceID: c.instanceID,
@@ -21,16 +22,28 @@ func (c context) createBackup() {
2122
c.Logf("Created backup %#v", backup)
2223
c.AssertNoErr(err)
2324

25+
err = gophercloud.WaitFor(60, func() (bool, error) {
26+
b, err := backups.Get(c.client, backup.ID).Extract()
27+
if err != nil {
28+
return false, err
29+
}
30+
if b.Status == "COMPLETED" {
31+
return true, nil
32+
}
33+
return false, nil
34+
})
35+
c.AssertNoErr(err)
36+
2437
c.backupID = backup.ID
2538
}
2639

27-
func (c context) getBackup() {
40+
func (c *context) getBackup() {
2841
backup, err := backups.Get(c.client, c.backupID).Extract()
2942
c.AssertNoErr(err)
3043
c.Logf("Getting backup %s", backup.ID)
3144
}
3245

33-
func (c context) listAllBackups() {
46+
func (c *context) listAllBackups() {
3447
c.Logf("Listing backups")
3548

3649
err := backups.List(c.client, nil).EachPage(func(page pagination.Page) (bool, error) {
@@ -47,7 +60,7 @@ func (c context) listAllBackups() {
4760
c.AssertNoErr(err)
4861
}
4962

50-
func (c context) listInstanceBackups() {
63+
func (c *context) listInstanceBackups() {
5164
c.Logf("Listing backups for instance %s", c.instanceID)
5265

5366
err := instances.ListBackups(c.client, c.instanceID).EachPage(func(page pagination.Page) (bool, error) {
@@ -64,7 +77,7 @@ func (c context) listInstanceBackups() {
6477
c.AssertNoErr(err)
6578
}
6679

67-
func (c context) deleteBackup() {
80+
func (c *context) deleteBackup() {
6881
err := backups.Delete(c.client, c.backupID).ExtractErr()
6982
c.AssertNoErr(err)
7083
c.Logf("Deleted backup %s", c.backupID)

acceptance/rackspace/db/v1/common.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,25 @@
33
package v1
44

55
import (
6-
"os"
76
"testing"
87

98
"github.com/rackspace/gophercloud"
10-
"github.com/rackspace/gophercloud/openstack"
9+
"github.com/rackspace/gophercloud/acceptance/tools"
1110
"github.com/rackspace/gophercloud/rackspace"
1211
"github.com/rackspace/gophercloud/rackspace/db/v1/instances"
1312
th "github.com/rackspace/gophercloud/testhelper"
1413
)
1514

1615
func newClient(t *testing.T) *gophercloud.ServiceClient {
17-
ao, err := openstack.AuthOptionsFromEnv()
16+
opts, err := rackspace.AuthOptionsFromEnv()
1817
th.AssertNoErr(t, err)
18+
opts = tools.OnlyRS(opts)
1919

20-
client, err := openstack.AuthenticatedClient(ao)
20+
client, err := rackspace.AuthenticatedClient(opts)
2121
th.AssertNoErr(t, err)
2222

2323
c, err := rackspace.NewDBV1(client, gophercloud.EndpointOpts{
24-
Region: os.Getenv("RS_REGION_NAME"),
24+
Region: "IAD",
2525
})
2626
th.AssertNoErr(t, err)
2727

@@ -47,7 +47,11 @@ func newContext(t *testing.T) context {
4747
}
4848

4949
func (c context) Logf(msg string, args ...interface{}) {
50-
c.test.Logf(msg, args)
50+
if len(args) > 0 {
51+
c.test.Logf(msg, args...)
52+
} else {
53+
c.test.Log(msg)
54+
}
5155
}
5256

5357
func (c context) AssertNoErr(err error) {

acceptance/rackspace/db/v1/config_group_test.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/rackspace/gophercloud/rackspace/db/v1/instances"
1010
)
1111

12-
func (c context) createConfigGrp() {
12+
func (c *context) createConfigGrp() {
1313
opts := config.CreateOpts{
1414
Name: tools.RandomString("config_", 5),
1515
Values: map[string]interface{}{
@@ -26,13 +26,13 @@ func (c context) createConfigGrp() {
2626
c.configGroupID = cg.ID
2727
}
2828

29-
func (c context) getConfigGrp() {
29+
func (c *context) getConfigGrp() {
3030
cg, err := config.Get(c.client, c.configGroupID).Extract()
3131
c.Logf("Getting config group: %#v", cg)
3232
c.AssertNoErr(err)
3333
}
3434

35-
func (c context) updateConfigGrp() {
35+
func (c *context) updateConfigGrp() {
3636
opts := config.UpdateOpts{
3737
Name: tools.RandomString("new_name_", 5),
3838
Values: map[string]interface{}{
@@ -44,7 +44,7 @@ func (c context) updateConfigGrp() {
4444
c.AssertNoErr(err)
4545
}
4646

47-
func (c context) replaceConfigGrp() {
47+
func (c *context) replaceConfigGrp() {
4848
opts := config.UpdateOpts{
4949
Values: map[string]interface{}{
5050
"expire_logs_days": 7,
@@ -56,13 +56,13 @@ func (c context) replaceConfigGrp() {
5656
c.AssertNoErr(err)
5757
}
5858

59-
func (c context) associateInstanceWithConfigGrp() {
59+
func (c *context) associateInstanceWithConfigGrp() {
6060
err := instances.AssociateWithConfigGroup(c.client, c.instanceID, c.configGroupID).ExtractErr()
6161
c.Logf("Associated instance %s with config group %s", c.instanceID, c.configGroupID)
6262
c.AssertNoErr(err)
6363
}
6464

65-
func (c context) listConfigGrpInstances() {
65+
func (c *context) listConfigGrpInstances() {
6666
c.Logf("Listing all instances associated with config group %s", c.configGroupID)
6767

6868
err := config.ListInstances(c.client, c.configGroupID).EachPage(func(page pagination.Page) (bool, error) {
@@ -79,8 +79,14 @@ func (c context) listConfigGrpInstances() {
7979
c.AssertNoErr(err)
8080
}
8181

82-
func (c context) deleteConfigGrp() {
82+
func (c *context) deleteConfigGrp() {
8383
err := config.Delete(c.client, c.configGroupID).ExtractErr()
8484
c.Logf("Deleted config group %s", c.configGroupID)
8585
c.AssertNoErr(err)
8686
}
87+
88+
func (c *context) detachInstanceFromGrp() {
89+
err := instances.DetachFromConfigGroup(c.client, c.instanceID).ExtractErr()
90+
c.Logf("Detached instance %s from config groups", c.instanceID)
91+
c.AssertNoErr(err)
92+
}

acceptance/rackspace/db/v1/database_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"github.com/rackspace/gophercloud/pagination"
99
)
1010

11-
func (c context) createDBs() {
11+
func (c *context) createDBs() {
1212
dbs := []string{
1313
tools.RandomString("db_", 5),
1414
tools.RandomString("db_", 5),
@@ -28,7 +28,7 @@ func (c context) createDBs() {
2828
c.DBIDs = dbs
2929
}
3030

31-
func (c context) listDBs() {
31+
func (c *context) listDBs() {
3232
c.Logf("Listing databases on instance %s", c.instanceID)
3333

3434
err := db.List(c.client, c.instanceID).EachPage(func(page pagination.Page) (bool, error) {
@@ -45,7 +45,7 @@ func (c context) listDBs() {
4545
c.AssertNoErr(err)
4646
}
4747

48-
func (c context) deleteDBs() {
48+
func (c *context) deleteDBs() {
4949
for _, id := range c.DBIDs {
5050
err := db.Delete(c.client, c.instanceID, id).ExtractErr()
5151
c.AssertNoErr(err)

acceptance/rackspace/db/v1/flavor_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func (c context) listFlavors() {
1616
c.AssertNoErr(err)
1717

1818
for _, f := range flavorList {
19-
c.Logf("Flavor: %#v", f)
19+
c.Logf("Flavor: ID [%s] Name [%s] RAM [%d]", f.ID, f.Name, f.RAM)
2020
}
2121

2222
return true, nil
@@ -26,7 +26,7 @@ func (c context) listFlavors() {
2626
}
2727

2828
func (c context) getFlavor() {
29-
flavor, err := flavors.Get(c.client, 1).Extract()
29+
flavor, err := flavors.Get(c.client, "1").Extract()
3030
c.Logf("Getting flavor %s", flavor.ID)
3131
c.AssertNoErr(err)
3232
}

0 commit comments

Comments
 (0)