fixes to get acceptance tests passing
diff --git a/acceptance/openstack/client_test.go b/acceptance/openstack/client_test.go
index 52c0cf5..6c0f9ee 100644
--- a/acceptance/openstack/client_test.go
+++ b/acceptance/openstack/client_test.go
@@ -30,7 +30,7 @@
t.Logf("Client successfully acquired a token: %v", client.TokenID)
// Find the storage service in the service catalog.
- storage, err := openstack.NewStorageV1(client, gophercloud.EndpointOpts{
+ storage, err := openstack.NewObjectStorageV1(client, gophercloud.EndpointOpts{
Region: os.Getenv("OS_REGION_NAME"),
})
if err != nil {
diff --git a/acceptance/openstack/compute/v2/servers_test.go b/acceptance/openstack/compute/v2/servers_test.go
index 3113aeb..2213e14 100644
--- a/acceptance/openstack/compute/v2/servers_test.go
+++ b/acceptance/openstack/compute/v2/servers_test.go
@@ -4,11 +4,15 @@
import (
"fmt"
+ "os"
"testing"
"github.com/rackspace/gophercloud"
"github.com/rackspace/gophercloud/acceptance/tools"
+ "github.com/rackspace/gophercloud/openstack"
"github.com/rackspace/gophercloud/openstack/compute/v2/servers"
+ "github.com/rackspace/gophercloud/openstack/networking/v2/networks"
+ "github.com/rackspace/gophercloud/openstack/utils"
"github.com/rackspace/gophercloud/pagination"
)
@@ -42,7 +46,49 @@
fmt.Printf("--------\n%d servers listed on %d pages.\n", count, pages)
}
+func networkingClient() (*gophercloud.ServiceClient, error) {
+ opts, err := utils.AuthOptions()
+ if err != nil {
+ return nil, err
+ }
+
+ provider, err := openstack.AuthenticatedClient(opts)
+ if err != nil {
+ return nil, err
+ }
+
+ return openstack.NewNetworkV2(provider, gophercloud.EndpointOpts{
+ Name: "neutron",
+ Region: os.Getenv("OS_REGION_NAME"),
+ })
+}
+
func createServer(t *testing.T, client *gophercloud.ServiceClient, choices *ComputeChoices) (*servers.Server, error) {
+ var network networks.Network
+
+ networkingClient, err := networkingClient()
+ if err != nil {
+ t.Fatalf("Unable to create a networking client: %v", err)
+ }
+
+ pager := networks.List(networkingClient, networks.ListOpts{Name: "public", Limit: 1})
+ pager.EachPage(func(page pagination.Page) (bool, error) {
+ networks, err := networks.ExtractNetworks(page)
+ if err != nil {
+ t.Errorf("Failed to extract networks: %v", err)
+ return false, err
+ }
+
+ if len(networks) == 0 {
+ t.Errorf("No networks to attach to server")
+ return false, err
+ }
+
+ network = networks[0]
+
+ return false, nil
+ })
+
name := tools.RandomString("ACPTTEST", 16)
t.Logf("Attempting to create server: %s\n", name)
@@ -50,6 +96,9 @@
Name: name,
FlavorRef: choices.FlavorID,
ImageRef: choices.ImageID,
+ Networks: []servers.Network{
+ servers.Network{UUID: network.ID},
+ },
}).Extract()
if err != nil {
t.Fatalf("Unable to create server: %v", err)
@@ -69,9 +118,6 @@
t.Fatalf("Unable to create a compute client: %v", err)
}
- name := tools.RandomString("ACPTTEST", 16)
- t.Logf("Attempting to create server: %s\n", name)
-
server, err := createServer(t, client, choices)
if err != nil {
t.Fatalf("Unable to create server: %v", err)
@@ -157,7 +203,7 @@
}
randomPassword := tools.MakeNewPassword(server.AdminPass)
- res = servers.ChangeAdminPassword(client, server.ID, randomPassword)
+ res := servers.ChangeAdminPassword(client, server.ID, randomPassword)
if res.Err != nil {
t.Fatal(err)
}
@@ -194,7 +240,7 @@
t.Fatal(err)
}
- res = servers.Reboot(client, server.ID, "aldhjflaskhjf")
+ res := servers.Reboot(client, server.ID, "aldhjflaskhjf")
if res.Err == nil {
t.Fatal("Expected the SDK to provide an ArgumentError here")
}
@@ -271,7 +317,7 @@
t.Logf("Attempting to resize server [%s]", server.ID)
if res := servers.Resize(client, server.ID, choices.FlavorIDResize); res.Err != nil {
- t.Fatal(err)
+ t.Fatal(res.Err)
}
if err := waitForStatus(client, server, "VERIFY_RESIZE"); err != nil {
diff --git a/acceptance/openstack/networking/v2/extensions/security_test.go b/acceptance/openstack/networking/v2/extensions/security_test.go
index 16ecca4..fc9227f 100644
--- a/acceptance/openstack/networking/v2/extensions/security_test.go
+++ b/acceptance/openstack/networking/v2/extensions/security_test.go
@@ -21,6 +21,9 @@
// create security group
groupID := createSecGroup(t)
+ // delete security group
+ defer deleteSecGroup(t, groupID)
+
// list security group
listSecGroups(t)
@@ -30,14 +33,11 @@
// create port with security group
networkID, portID := createPort(t, groupID)
- // delete port
- deletePort(t, portID)
-
- // delete security group
- deleteSecGroup(t, groupID)
-
// teardown
- deleteNetwork(t, networkID)
+ defer deleteNetwork(t, networkID)
+
+ // delete port
+ defer deletePort(t, portID)
}
func TestSecurityGroupRules(t *testing.T) {
@@ -47,6 +47,8 @@
// create security group
groupID := createSecGroup(t)
+ defer deleteSecGroup(t, groupID)
+
// create security group rule
ruleID := createSecRule(t, groupID)
diff --git a/acceptance/openstack/objectstorage/v1/accounts_test.go b/acceptance/openstack/objectstorage/v1/accounts_test.go
index 6768927..b55f2a6 100644
--- a/acceptance/openstack/objectstorage/v1/accounts_test.go
+++ b/acceptance/openstack/objectstorage/v1/accounts_test.go
@@ -7,46 +7,32 @@
"testing"
"github.com/rackspace/gophercloud/openstack/objectstorage/v1/accounts"
+ th "github.com/rackspace/gophercloud/testhelper"
)
func TestAccounts(t *testing.T) {
// Create a provider client for making the HTTP requests.
// See common.go in this directory for more information.
client, err := newClient()
- if err != nil {
- t.Error(err)
- return
- }
+ th.AssertNoErr(t, err)
// Update an account's metadata.
- err = accounts.Update(client, accounts.UpdateOpts{
- Metadata: metadata,
- })
- if err != nil {
- t.Error(err)
- return
- }
+ res = accounts.Update(client, accounts.UpdateOpts{Metadata: metadata})
+ th.AssertNoErr(t, res.Err)
+
// Defer the deletion of the metadata set above.
defer func() {
tempMap := make(map[string]string)
for k := range metadata {
tempMap[k] = ""
}
- err = accounts.Update(client, accounts.UpdateOpts{
- Metadata: tempMap,
- })
- if err != nil {
- t.Error(err)
- return
- }
+ res = accounts.Update(client, accounts.UpdateOpts{Metadata: tempMap})
+ th.AssertNoErr(t, res.Err)
}()
// Retrieve account metadata.
- gr, err := accounts.Get(client, accounts.GetOpts{})
- if err != nil {
- t.Error(err)
- return
- }
+ res := accounts.Get(client, accounts.GetOpts{})
+ th.AssertNoErr(res.Err)
// Extract the custom metadata from the 'Get' response.
am := accounts.ExtractMetadata(gr)
for k := range metadata {
diff --git a/acceptance/openstack/objectstorage/v1/common.go b/acceptance/openstack/objectstorage/v1/common.go
index 08065a4..4e2f9b5 100644
--- a/acceptance/openstack/objectstorage/v1/common.go
+++ b/acceptance/openstack/objectstorage/v1/common.go
@@ -3,26 +3,24 @@
package v1
import (
+ "os"
+
"github.com/rackspace/gophercloud"
"github.com/rackspace/gophercloud/openstack"
"github.com/rackspace/gophercloud/openstack/utils"
- "os"
+ th "github.com/rackspace/gophercloud/testhelper"
)
var metadata = map[string]string{"gopher": "cloud"}
func newClient() (*gophercloud.ServiceClient, error) {
ao, err := utils.AuthOptions()
- if err != nil {
- return nil, err
- }
+ th.AssertNoErr(t, err)
client, err := openstack.AuthenticatedClient(ao)
- if err != nil {
- return nil, err
- }
+ th.AssertNoErr(t, err)
- return openstack.NewStorageV1(client, gophercloud.EndpointOpts{
+ return openstack.NewObjectStorageV1(client, gophercloud.EndpointOpts{
Region: os.Getenv("OS_REGION_NAME"),
- })
+ }), nil
}
diff --git a/acceptance/openstack/objectstorage/v1/containers_test.go b/acceptance/openstack/objectstorage/v1/containers_test.go
index b541307..b2c91c5 100644
--- a/acceptance/openstack/objectstorage/v1/containers_test.go
+++ b/acceptance/openstack/objectstorage/v1/containers_test.go
@@ -9,6 +9,7 @@
"github.com/rackspace/gophercloud/acceptance/tools"
"github.com/rackspace/gophercloud/openstack/objectstorage/v1/containers"
"github.com/rackspace/gophercloud/pagination"
+ th "github.com/rackspace/gophercloud/testhelper"
)
// numContainers is the number of containers to create for testing.
@@ -17,9 +18,7 @@
func TestContainers(t *testing.T) {
// Create a new client to execute the HTTP requests. See common.go for newClient body.
client, err := newClient()
- if err != nil {
- t.Error(err)
- }
+ th.AssertNoErr(err)
// Create a slice of random container names.
cNames := make([]string, numContainers)
@@ -29,18 +28,14 @@
// Create numContainers containers.
for i := 0; i < len(cNames); i++ {
- _, err := containers.Create(client, cNames[i], nil).ExtractHeaders()
- if err != nil {
- t.Error(err)
- }
+ res := containers.Create(client, cNames[i], nil)
+ th.AssertNoErr(res.Err)
}
// Delete the numContainers containers after function completion.
defer func() {
for i := 0; i < len(cNames); i++ {
- _, err = containers.Delete(client, cNames[i]).ExtractHeaders()
- if err != nil {
- t.Error(err)
- }
+ res = containers.Delete(client, cNames[i])
+ th.AssertNoErr(res.Err)
}
}()
@@ -48,9 +43,8 @@
// the 'prefix' parameter is used.
err = containers.List(client, &containers.ListOpts{Full: true, Prefix: "gophercloud-test-container-"}).EachPage(func(page pagination.Page) (bool, error) {
containerList, err := containers.ExtractInfo(page)
- if err != nil {
- t.Error(err)
- }
+ th.AssertNoErr(err)
+
for _, n := range containerList {
t.Logf("Container: Name [%s] Count [%d] Bytes [%d]",
n.Name, n.Count, n.Bytes)
@@ -58,48 +52,36 @@
return true, nil
})
- if err != nil {
- t.Error(err)
- }
+ th.AssertNoErr(err)
// List the info for the numContainer containers that were created.
err = containers.List(client, &containers.ListOpts{Full: false, Prefix: "gophercloud-test-container-"}).EachPage(func(page pagination.Page) (bool, error) {
containerList, err := containers.ExtractNames(page)
- if err != nil {
- return false, err
- }
+ th.AssertNoErr(err)
for _, n := range containerList {
t.Logf("Container: Name [%s]", n)
}
return true, nil
})
- if err != nil {
- t.Error(err)
- }
+ th.AssertNoErr(err)
// Update one of the numContainer container metadata.
- _, err = containers.Update(client, cNames[0], &containers.UpdateOpts{Metadata: metadata}).ExtractHeaders()
- if err != nil {
- t.Error(err)
- }
+ res = containers.Update(client, cNames[0], &containers.UpdateOpts{Metadata: metadata})
+ th.AssertNoErr(res.Err)
// After the tests are done, delete the metadata that was set.
defer func() {
tempMap := make(map[string]string)
for k := range metadata {
tempMap[k] = ""
}
- _, err = containers.Update(client, cNames[0], &containers.UpdateOpts{Metadata: tempMap}).ExtractHeaders()
- if err != nil {
- t.Error(err)
- }
+ res = containers.Update(client, cNames[0], &containers.UpdateOpts{Metadata: tempMap})
+ th.AssertNoErr(res.Err)
}()
// Retrieve a container's metadata.
cm, err := containers.Get(client, cNames[0]).ExtractMetadata()
- if err != nil {
- t.Error(err)
- }
+ th.AssertNoErr(err)
for k := range metadata {
if cm[k] != metadata[strings.Title(k)] {
t.Errorf("Expected custom metadata with key: %s", k)
diff --git a/acceptance/openstack/objectstorage/v1/objects_test.go b/acceptance/openstack/objectstorage/v1/objects_test.go
index 5a63a4c..1454063 100644
--- a/acceptance/openstack/objectstorage/v1/objects_test.go
+++ b/acceptance/openstack/objectstorage/v1/objects_test.go
@@ -11,6 +11,7 @@
"github.com/rackspace/gophercloud/openstack/objectstorage/v1/containers"
"github.com/rackspace/gophercloud/openstack/objectstorage/v1/objects"
"github.com/rackspace/gophercloud/pagination"
+ th "github.com/rackspace/gophercloud/testhelper"
)
// numObjects is the number of objects to create for testing.
@@ -20,10 +21,7 @@
// Create a provider client for executing the HTTP request.
// See common.go for more information.
client, err := newClient()
- if err != nil {
- t.Error(err)
- return
- }
+ th.AssertNoErr(err)
// Make a slice of length numObjects to hold the random object names.
oNames := make([]string, numObjects)
@@ -33,51 +31,38 @@
// Create a container to hold the test objects.
cName := tools.RandomString("test-container-", 8)
- _, err = containers.Create(client, cName, nil).ExtractHeaders()
- if err != nil {
- t.Error(err)
- return
- }
+ res = containers.Create(client, cName, nil)
+ th.AssertNoErr(res.Err)
+
// Defer deletion of the container until after testing.
defer func() {
- _, err = containers.Delete(client, cName).ExtractHeaders()
- if err != nil {
- t.Error(err)
- return
- }
+ res = containers.Delete(client, cName)
+ th.AssertNoErr(res.Err)
}()
// Create a slice of buffers to hold the test object content.
oContents := make([]*bytes.Buffer, numObjects)
for i := 0; i < numObjects; i++ {
oContents[i] = bytes.NewBuffer([]byte(tools.RandomString("", 10)))
- _, err = objects.Create(client, cName, oNames[i], oContents[i], nil).ExtractHeaders()
- if err != nil {
- t.Error(err)
- return
- }
+ res = objects.Create(client, cName, oNames[i], oContents[i], nil)
+ th.AssertNoErr(res.Err)
}
// Delete the objects after testing.
defer func() {
for i := 0; i < numObjects; i++ {
- _, err = objects.Delete(client, cName, oNames[i], nil).ExtractHeaders()
+ res = objects.Delete(client, cName, oNames[i], nil)
}
}()
ons := make([]string, 0, len(oNames))
err = objects.List(client, cName, &objects.ListOpts{Full: false, Prefix: "test-object-"}).EachPage(func(page pagination.Page) (bool, error) {
names, err := objects.ExtractNames(page)
- if err != nil {
- return false, err
- }
+ th.AssertNoErr(err)
ons = append(ons, names...)
return true, nil
})
- if err != nil {
- t.Error(err)
- return
- }
+ th.AssertNoErr(err)
if len(ons) != len(oNames) {
t.Errorf("Expected %d names and got %d", len(oNames), len(ons))
return
@@ -86,42 +71,30 @@
ois := make([]objects.Object, 0, len(oNames))
err = objects.List(client, cName, &objects.ListOpts{Full: true, Prefix: "test-object-"}).EachPage(func(page pagination.Page) (bool, error) {
info, err := objects.ExtractInfo(page)
- if err != nil {
- return false, nil
- }
+ th.AssertNoErr(err)
ois = append(ois, info...)
return true, nil
})
- if err != nil {
- t.Error(err)
- return
- }
+ th.AssertNoErr(err)
if len(ois) != len(oNames) {
t.Errorf("Expected %d containers and got %d", len(oNames), len(ois))
return
}
// Copy the contents of one object to another.
- _, err = objects.Copy(client, cName, oNames[0], &objects.CopyOpts{Destination: cName + "/" + oNames[1]}).ExtractHeaders()
- if err != nil {
- t.Error(err)
- return
- }
+ res = objects.Copy(client, cName, oNames[0], &objects.CopyOpts{Destination: cName + "/" + oNames[1]})
+ th.AssertNoErr(res.Err)
// Download one of the objects that was created above.
o1Content, err := objects.Download(client, cName, oNames[0], nil).ExtractContent()
- if err != nil {
- t.Error(err)
- return
- }
+ th.AssertNoErr(err)
+
// Download the another object that was create above.
o2Content, err := objects.Download(client, cName, oNames[1], nil).ExtractContent()
- if err != nil {
- t.Error(err)
- return
- }
+ th.AssertNoErr(err)
+
// Compare the two object's contents to test that the copy worked.
if string(o2Content) != string(o1Content) {
t.Errorf("Copy failed. Expected\n%s\nand got\n%s", string(o1Content), string(o2Content))
@@ -129,30 +102,22 @@
}
// Update an object's metadata.
- _, err = objects.Update(client, cName, oNames[0], &objects.UpdateOpts{Metadata: metadata}).ExtractHeaders()
- if err != nil {
- t.Error(err)
- return
- }
+ res = objects.Update(client, cName, oNames[0], &objects.UpdateOpts{Metadata: metadata})
+ th.AssertNoErr(res.Err)
+
// Delete the object's metadata after testing.
defer func() {
tempMap := make(map[string]string)
for k := range metadata {
tempMap[k] = ""
}
- _, err = objects.Update(client, cName, oNames[0], &objects.UpdateOpts{Metadata: tempMap}).ExtractHeaders()
- if err != nil {
- t.Error(err)
- return
- }
+ res = objects.Update(client, cName, oNames[0], &objects.UpdateOpts{Metadata: tempMap})
+ th.AssertNoErr(res.Err)
}()
// Retrieve an object's metadata.
om, err := objects.Get(client, cName, oNames[0], nil).ExtractMetadata()
- if err != nil {
- t.Error(err)
- return
- }
+ th.AssertNoErr(err)
for k := range metadata {
if om[k] != metadata[strings.Title(k)] {
t.Errorf("Expected custom metadata with key: %s", k)
diff --git a/openstack/compute/v2/servers/requests.go b/openstack/compute/v2/servers/requests.go
index 9207474..a997484 100644
--- a/openstack/compute/v2/servers/requests.go
+++ b/openstack/compute/v2/servers/requests.go
@@ -165,6 +165,7 @@
securityGroups[i] = map[string]interface{}{"name": groupName}
}
}
+
if len(opts.Networks) > 0 {
networks := make([]map[string]interface{}, len(opts.Networks))
for i, net := range opts.Networks {
@@ -179,6 +180,7 @@
networks[i]["fixed_ip"] = net.FixedIP
}
}
+ server["networks"] = networks
}
return map[string]interface{}{"server": server}