Server Acceptance Test Cleanup

The following changes were made to the servers acceptance tests:

* Renamed tests so tests can selectively be run by substring.
* Reading all returned pages at once.
* Modified test output.
* Printing all server attributes in output.
* Consistently place and log server deletion.
* Fixed occurrences of wrong error variable being reported.
* Removed invalid resize error.
* Implemented RebootOpts in order to test server reboot.
diff --git a/acceptance/openstack/compute/v2/servers_test.go b/acceptance/openstack/compute/v2/servers_test.go
index 4c4fb42..34a3fd2 100644
--- a/acceptance/openstack/compute/v2/servers_test.go
+++ b/acceptance/openstack/compute/v2/servers_test.go
@@ -3,178 +3,93 @@
 package v2
 
 import (
-	"os"
 	"testing"
 
 	"github.com/gophercloud/gophercloud"
 	"github.com/gophercloud/gophercloud/acceptance/tools"
-	"github.com/gophercloud/gophercloud/openstack"
 	"github.com/gophercloud/gophercloud/openstack/compute/v2/servers"
-	"github.com/gophercloud/gophercloud/openstack/networking/v2/networks"
-	"github.com/gophercloud/gophercloud/pagination"
 	th "github.com/gophercloud/gophercloud/testhelper"
 )
 
-func TestListServers(t *testing.T) {
+func TestServersList(t *testing.T) {
 	client, err := newClient()
 	if err != nil {
 		t.Fatalf("Unable to create a compute client: %v", err)
 	}
 
-	t.Logf("ID\tRegion\tName\tStatus\tIPv4\tIPv6")
+	allPages, err := servers.List(client, servers.ListOpts{}).AllPages()
+	if err != nil {
+		t.Fatalf("Unable to retrieve servers: %v", err)
+	}
 
-	pager := servers.List(client, servers.ListOpts{})
-	count, pages := 0, 0
-	pager.EachPage(func(page pagination.Page) (bool, error) {
-		pages++
-		t.Logf("---")
+	allServers, err := servers.ExtractServers(allPages)
+	if err != nil {
+		t.Fatalf("Unable to extract servers: %v", err)
+	}
 
-		servers, err := servers.ExtractServers(page)
-		if err != nil {
-			return false, err
-		}
-
-		for _, s := range servers {
-			t.Logf("%s\t%s\t%s\t%s\t%s\t\n", s.ID, s.Name, s.Status, s.AccessIPv4, s.AccessIPv6)
-			count++
-		}
-
-		return true, nil
-	})
-
-	t.Logf("--------\n%d servers listed on %d pages.\n", count, pages)
+	for _, server := range allServers {
+		printServer(t, &server)
+	}
 }
 
-func networkingClient() (*gophercloud.ServiceClient, error) {
-	opts, err := openstack.AuthOptionsFromEnv()
+func TestServersCreateDestroy(t *testing.T) {
+	client, err := newClient()
 	if err != nil {
-		return nil, err
+		t.Fatalf("Unable to create a compute client: %v", err)
 	}
 
-	provider, err := openstack.AuthenticatedClient(opts)
-	if err != nil {
-		return nil, err
-	}
-
-	return openstack.NewNetworkV2(provider, gophercloud.EndpointOpts{
-		Region: os.Getenv("OS_REGION_NAME"),
-	})
-}
-
-func createServer(t *testing.T, client *gophercloud.ServiceClient, choices *ComputeChoices) (*servers.Server, error) {
-	if testing.Short() {
-		t.Skip("Skipping test that requires server creation in short mode.")
-	}
-
-	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:  choices.NetworkName,
-		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.Fatalf("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)
-
-	pwd := tools.MakeNewPassword("")
-
-	server, err := servers.Create(client, servers.CreateOpts{
-		Name:      name,
-		FlavorRef: choices.FlavorID,
-		ImageRef:  choices.ImageID,
-		Networks: []servers.Network{
-			servers.Network{UUID: network.ID},
-		},
-		AdminPass: pwd,
-		Personality: servers.Personality{
-			&servers.File{
-				Path:     "/etc/test",
-				Contents: []byte("hello world"),
-			},
-		},
-	}).Extract()
-	if err != nil {
-		t.Fatalf("Unable to create server: %v", err)
-	}
-
-	th.AssertEquals(t, pwd, server.AdminPass)
-
-	return server, err
-}
-
-func TestCreateDestroyServer(t *testing.T) {
 	choices, err := ComputeChoicesFromEnv()
 	if err != nil {
 		t.Fatal(err)
 	}
 
-	client, err := newClient()
-	if err != nil {
-		t.Fatalf("Unable to create a compute client: %v", err)
-	}
-
 	server, err := createServer(t, client, choices)
 	if err != nil {
 		t.Fatalf("Unable to create server: %v", err)
 	}
-	defer func() {
-		servers.Delete(client, server.ID)
-		t.Logf("Server deleted.")
-	}()
 
 	if err = waitForStatus(client, server, "ACTIVE"); err != nil {
 		t.Fatalf("Unable to wait for server: %v", err)
 	}
+	defer deleteServer(t, client, server)
 
-	pager := servers.ListAddresses(client, server.ID)
-	pager.EachPage(func(page pagination.Page) (bool, error) {
-		networks, err := servers.ExtractAddresses(page)
-		if err != nil {
-			return false, err
-		}
+	newServer, err := servers.Get(client, server.ID).Extract()
+	if err != nil {
+		t.Errorf("Unable to retrieve server: %v", err)
+	}
+	printServer(t, newServer)
 
-		for n, a := range networks {
-			t.Logf("%s: %+v\n", n, a)
-		}
-		return true, nil
-	})
+	allAddressPages, err := servers.ListAddresses(client, server.ID).AllPages()
+	if err != nil {
+		t.Errorf("Unable to list server addresses: %v", err)
+	}
 
-	pager = servers.ListAddressesByNetwork(client, server.ID, choices.NetworkName)
-	pager.EachPage(func(page pagination.Page) (bool, error) {
-		addresses, err := servers.ExtractNetworkAddresses(page)
-		if err != nil {
-			return false, err
-		}
+	allAddresses, err := servers.ExtractAddresses(allAddressPages)
+	if err != nil {
+		t.Errorf("Unable to extract server addresses: %v", err)
+	}
 
-		for _, a := range addresses {
-			t.Logf("%+v\n", a)
-		}
-		return true, nil
-	})
+	for network, address := range allAddresses {
+		t.Logf("Addresses on %s: %+v", network, address)
+	}
+
+	allNetworkAddressPages, err := servers.ListAddressesByNetwork(client, server.ID, choices.NetworkName).AllPages()
+	if err != nil {
+		t.Errorf("Unable to list server addresses: %v", err)
+	}
+
+	allNetworkAddresses, err := servers.ExtractNetworkAddresses(allNetworkAddressPages)
+	if err != nil {
+		t.Errorf("Unable to extract server addresses: %v", err)
+	}
+
+	t.Logf("Addresses on %s:", choices.NetworkName)
+	for _, address := range allNetworkAddresses {
+		t.Logf("%+v", address)
+	}
 }
 
-func TestUpdateServer(t *testing.T) {
+func TestServersUpdate(t *testing.T) {
 	client, err := newClient()
 	if err != nil {
 		t.Fatalf("Unable to create a compute client: %v", err)
@@ -189,11 +104,11 @@
 	if err != nil {
 		t.Fatal(err)
 	}
-	defer servers.Delete(client, server.ID)
 
 	if err = waitForStatus(client, server, "ACTIVE"); err != nil {
 		t.Fatal(err)
 	}
+	defer deleteServer(t, client, server)
 
 	alternateName := tools.RandomString("ACPTTEST", 16)
 	for alternateName == server.Name {
@@ -202,7 +117,11 @@
 
 	t.Logf("Attempting to rename the server to %s.", alternateName)
 
-	updated, err := servers.Update(client, server.ID, servers.UpdateOpts{Name: alternateName}).Extract()
+	updateOpts := servers.UpdateOpts{
+		Name: alternateName,
+	}
+
+	updated, err := servers.Update(client, server.ID, updateOpts).Extract()
 	if err != nil {
 		t.Fatalf("Unable to rename server: %v", err)
 	}
@@ -221,7 +140,73 @@
 	})
 }
 
-func TestActionChangeAdminPassword(t *testing.T) {
+func TestServersMetadata(t *testing.T) {
+	t.Parallel()
+
+	choices, err := ComputeChoicesFromEnv()
+	if err != nil {
+		t.Fatal(err)
+	}
+
+	client, err := newClient()
+	if err != nil {
+		t.Fatalf("Unable to create a compute client: %v", err)
+	}
+
+	server, err := createServer(t, client, choices)
+	if err != nil {
+		t.Fatal(err)
+	}
+
+	if err = waitForStatus(client, server, "ACTIVE"); err != nil {
+		t.Fatal(err)
+	}
+	defer deleteServer(t, client, server)
+
+	metadata, err := servers.UpdateMetadata(client, server.ID, servers.MetadataOpts{
+		"foo":  "bar",
+		"this": "that",
+	}).Extract()
+	if err != nil {
+		t.Fatalf("Unable to update metadata: %v", err)
+	}
+	t.Logf("UpdateMetadata result: %+v\n", metadata)
+
+	err = servers.DeleteMetadatum(client, server.ID, "foo").ExtractErr()
+	if err != nil {
+		t.Fatalf("Unable to delete metadatum: %v", err)
+	}
+
+	metadata, err = servers.CreateMetadatum(client, server.ID, servers.MetadatumOpts{
+		"foo": "baz",
+	}).Extract()
+	if err != nil {
+		t.Fatalf("Unable to create metadatum: %v", err)
+	}
+	t.Logf("CreateMetadatum result: %+v\n", metadata)
+
+	metadata, err = servers.Metadatum(client, server.ID, "foo").Extract()
+	if err != nil {
+		t.Fatalf("Unable to get metadatum: %v", err)
+	}
+	t.Logf("Metadatum result: %+v\n", metadata)
+	th.AssertEquals(t, "baz", metadata["foo"])
+
+	metadata, err = servers.Metadata(client, server.ID).Extract()
+	if err != nil {
+		t.Fatalf("Unable to get metadata: %v", err)
+	}
+	t.Logf("Metadata result: %+v\n", metadata)
+
+	metadata, err = servers.ResetMetadata(client, server.ID, servers.MetadataOpts{}).Extract()
+	if err != nil {
+		t.Fatalf("Unable to reset metadata: %v", err)
+	}
+	t.Logf("ResetMetadata result: %+v\n", metadata)
+	th.AssertDeepEquals(t, map[string]string{}, metadata)
+}
+
+func TestServersActionChangeAdminPassword(t *testing.T) {
 	t.Parallel()
 
 	client, err := newClient()
@@ -238,16 +223,16 @@
 	if err != nil {
 		t.Fatal(err)
 	}
-	defer servers.Delete(client, server.ID)
 
 	if err = waitForStatus(client, server, "ACTIVE"); err != nil {
 		t.Fatal(err)
 	}
+	defer deleteServer(t, client, server)
 
 	randomPassword := tools.MakeNewPassword(server.AdminPass)
 	res := servers.ChangeAdminPassword(client, server.ID, randomPassword)
 	if res.Err != nil {
-		t.Fatal(err)
+		t.Fatal(res.Err)
 	}
 
 	if err = waitForStatus(client, server, "PASSWORD"); err != nil {
@@ -259,7 +244,7 @@
 	}
 }
 
-func TestActionReboot(t *testing.T) {
+func TestServersActionReboot(t *testing.T) {
 	t.Parallel()
 
 	client, err := newClient()
@@ -276,21 +261,20 @@
 	if err != nil {
 		t.Fatal(err)
 	}
-	defer servers.Delete(client, server.ID)
 
 	if err = waitForStatus(client, server, "ACTIVE"); err != nil {
 		t.Fatal(err)
 	}
+	defer deleteServer(t, client, server)
 
-	res := servers.Reboot(client, server.ID, "aldhjflaskhjf")
-	if res.Err == nil {
-		t.Fatal("Expected the SDK to provide an ArgumentError here")
+	rebootOpts := &servers.RebootOpts{
+		Type: servers.SoftReboot,
 	}
 
 	t.Logf("Attempting reboot of server %s", server.ID)
-	res = servers.Reboot(client, server.ID, servers.OSReboot)
+	res := servers.Reboot(client, server.ID, rebootOpts)
 	if res.Err != nil {
-		t.Fatalf("Unable to reboot server: %v", err)
+		t.Fatalf("Unable to reboot server: %v", res.Err)
 	}
 
 	if err = waitForStatus(client, server, "REBOOT"); err != nil {
@@ -302,7 +286,7 @@
 	}
 }
 
-func TestActionRebuild(t *testing.T) {
+func TestServersActionRebuild(t *testing.T) {
 	t.Parallel()
 
 	client, err := newClient()
@@ -319,11 +303,11 @@
 	if err != nil {
 		t.Fatal(err)
 	}
-	defer servers.Delete(client, server.ID)
 
 	if err = waitForStatus(client, server, "ACTIVE"); err != nil {
 		t.Fatal(err)
 	}
+	defer deleteServer(t, client, server)
 
 	t.Logf("Attempting to rebuild server %s", server.ID)
 
@@ -351,13 +335,118 @@
 	}
 }
 
-func resizeServer(t *testing.T, client *gophercloud.ServiceClient, server *servers.Server, choices *ComputeChoices) {
-	if err := waitForStatus(client, server, "ACTIVE"); err != nil {
+func TestServersActionResizeConfirm(t *testing.T) {
+	t.Parallel()
+
+	choices, err := ComputeChoicesFromEnv()
+	if err != nil {
 		t.Fatal(err)
 	}
 
-	t.Logf("Attempting to resize server [%s]", server.ID)
+	client, err := newClient()
+	if err != nil {
+		t.Fatalf("Unable to create a compute client: %v", err)
+	}
 
+	server, err := createServer(t, client, choices)
+	if err != nil {
+		t.Fatal(err)
+	}
+
+	if err = waitForStatus(client, server, "ACTIVE"); err != nil {
+		t.Fatal(err)
+	}
+	defer deleteServer(t, client, server)
+
+	t.Logf("Attempting to resize server %s", server.ID)
+	resizeServer(t, client, server, choices)
+
+	t.Logf("Attempting to confirm resize for server %s", server.ID)
+	if res := servers.ConfirmResize(client, server.ID); res.Err != nil {
+		t.Fatal(res.Err)
+	}
+
+	if err = waitForStatus(client, server, "ACTIVE"); err != nil {
+		t.Fatal(err)
+	}
+}
+
+func TestServersActionResizeRevert(t *testing.T) {
+	t.Parallel()
+
+	choices, err := ComputeChoicesFromEnv()
+	if err != nil {
+		t.Fatal(err)
+	}
+
+	client, err := newClient()
+	if err != nil {
+		t.Fatalf("Unable to create a compute client: %v", err)
+	}
+
+	server, err := createServer(t, client, choices)
+	if err != nil {
+		t.Fatal(err)
+	}
+
+	if err = waitForStatus(client, server, "ACTIVE"); err != nil {
+		t.Fatal(err)
+	}
+	defer deleteServer(t, client, server)
+
+	t.Logf("Attempting to resize server %s", server.ID)
+	resizeServer(t, client, server, choices)
+
+	t.Logf("Attempting to revert resize for server %s", server.ID)
+	if res := servers.RevertResize(client, server.ID); res.Err != nil {
+		t.Fatal(res.Err)
+	}
+
+	if err = waitForStatus(client, server, "ACTIVE"); err != nil {
+		t.Fatal(err)
+	}
+}
+
+func createServer(t *testing.T, client *gophercloud.ServiceClient, choices *ComputeChoices) (*servers.Server, error) {
+	if testing.Short() {
+		t.Skip("Skipping test that requires server creation in short mode.")
+	}
+
+	networkID, err := getNetworkIDFromTenantNetworks(t, client, choices.NetworkName)
+	if err != nil {
+		t.Fatalf("Failed to obtain network ID: %v", err)
+	}
+
+	name := tools.RandomString("ACPTTEST", 16)
+	t.Logf("Attempting to create server: %s", name)
+
+	pwd := tools.MakeNewPassword("")
+
+	server, err := servers.Create(client, servers.CreateOpts{
+		Name:      name,
+		FlavorRef: choices.FlavorID,
+		ImageRef:  choices.ImageID,
+		AdminPass: pwd,
+		Networks: []servers.Network{
+			servers.Network{UUID: networkID},
+		},
+		Personality: servers.Personality{
+			&servers.File{
+				Path:     "/etc/test",
+				Contents: []byte("hello world"),
+			},
+		},
+	}).Extract()
+	if err != nil {
+		t.Fatalf("Unable to create server: %v", err)
+	}
+
+	th.AssertEquals(t, pwd, server.AdminPass)
+
+	return server, err
+}
+
+func resizeServer(t *testing.T, client *gophercloud.ServiceClient, server *servers.Server, choices *ComputeChoices) {
 	opts := &servers.ResizeOpts{
 		FlavorRef: choices.FlavorIDResize,
 	}
@@ -370,115 +459,33 @@
 	}
 }
 
-func TestActionResizeConfirm(t *testing.T) {
-	t.Parallel()
-
-	choices, err := ComputeChoicesFromEnv()
+func deleteServer(t *testing.T, client *gophercloud.ServiceClient, server *servers.Server) {
+	err := servers.Delete(client, server.ID).ExtractErr()
 	if err != nil {
-		t.Fatal(err)
+		t.Fatalf("Unable to delete server %s: %s", server.ID, err)
 	}
 
-	client, err := newClient()
-	if err != nil {
-		t.Fatalf("Unable to create a compute client: %v", err)
-	}
-
-	server, err := createServer(t, client, choices)
-	if err != nil {
-		t.Fatal(err)
-	}
-	defer servers.Delete(client, server.ID)
-	resizeServer(t, client, server, choices)
-
-	t.Logf("Attempting to confirm resize for server %s", server.ID)
-
-	if res := servers.ConfirmResize(client, server.ID); res.Err != nil {
-		t.Fatal(err)
-	}
-
-	if err = waitForStatus(client, server, "ACTIVE"); err != nil {
-		t.Fatal(err)
-	}
+	t.Logf("Deleted server: %s", server.ID)
 }
 
-func TestActionResizeRevert(t *testing.T) {
-	t.Parallel()
-
-	choices, err := ComputeChoicesFromEnv()
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	client, err := newClient()
-	if err != nil {
-		t.Fatalf("Unable to create a compute client: %v", err)
-	}
-
-	server, err := createServer(t, client, choices)
-	if err != nil {
-		t.Fatal(err)
-	}
-	defer servers.Delete(client, server.ID)
-	resizeServer(t, client, server, choices)
-
-	t.Logf("Attempting to revert resize for server %s", server.ID)
-
-	if res := servers.RevertResize(client, server.ID); res.Err != nil {
-		t.Fatal(err)
-	}
-
-	if err = waitForStatus(client, server, "ACTIVE"); err != nil {
-		t.Fatal(err)
-	}
-}
-
-func TestServerMetadata(t *testing.T) {
-	t.Parallel()
-
-	choices, err := ComputeChoicesFromEnv()
-	th.AssertNoErr(t, err)
-
-	client, err := newClient()
-	if err != nil {
-		t.Fatalf("Unable to create a compute client: %v", err)
-	}
-
-	server, err := createServer(t, client, choices)
-	if err != nil {
-		t.Fatal(err)
-	}
-	defer servers.Delete(client, server.ID)
-	if err = waitForStatus(client, server, "ACTIVE"); err != nil {
-		t.Fatal(err)
-	}
-
-	metadata, err := servers.UpdateMetadata(client, server.ID, servers.MetadataOpts{
-		"foo":  "bar",
-		"this": "that",
-	}).Extract()
-	th.AssertNoErr(t, err)
-	t.Logf("UpdateMetadata result: %+v\n", metadata)
-
-	err = servers.DeleteMetadatum(client, server.ID, "foo").ExtractErr()
-	th.AssertNoErr(t, err)
-
-	metadata, err = servers.CreateMetadatum(client, server.ID, servers.MetadatumOpts{
-		"foo": "baz",
-	}).Extract()
-	th.AssertNoErr(t, err)
-	t.Logf("CreateMetadatum result: %+v\n", metadata)
-
-	metadata, err = servers.Metadatum(client, server.ID, "foo").Extract()
-	th.AssertNoErr(t, err)
-	t.Logf("Metadatum result: %+v\n", metadata)
-	th.AssertEquals(t, "baz", metadata["foo"])
-
-	metadata, err = servers.Metadata(client, server.ID).Extract()
-	th.AssertNoErr(t, err)
-	t.Logf("Metadata result: %+v\n", metadata)
-
-	metadata, err = servers.ResetMetadata(client, server.ID, servers.MetadataOpts{}).Extract()
-	th.AssertNoErr(t, err)
-	t.Logf("ResetMetadata result: %+v\n", metadata)
-	th.AssertDeepEquals(t, map[string]string{}, metadata)
+func printServer(t *testing.T, server *servers.Server) {
+	t.Logf("ID: %s", server.ID)
+	t.Logf("TenantID: %s", server.TenantID)
+	t.Logf("UserID: %s", server.UserID)
+	t.Logf("Name: %s", server.Name)
+	t.Logf("Updated: %s", server.Updated)
+	t.Logf("Created: %s", server.Created)
+	t.Logf("HostID: %s", server.HostID)
+	t.Logf("Status: %s", server.Status)
+	t.Logf("Progress: %d", server.Progress)
+	t.Logf("AccessIPv4: %s", server.AccessIPv4)
+	t.Logf("AccessIPv6: %s", server.AccessIPv6)
+	t.Logf("Image: %s", server.Image)
+	t.Logf("Flavor: %s", server.Flavor)
+	t.Logf("Addresses: %#v", server.Addresses)
+	t.Logf("Metadata: %#v", server.Metadata)
+	t.Logf("Links: %#v", server.Links)
+	t.Logf("KeyName: %s", server.KeyName)
+	t.Logf("AdminPass: %s", server.AdminPass)
+	t.Logf("SecurityGroups: %#v", server.SecurityGroups)
 }