Server Group Acceptance Test Cleanup

The following changes were made to the servergroups acceptance tests:

* Renamed servers to servergroups in build tag
* Renamed tests so tests can selectively be run by substring.
* Modified test output.
* Printing all servergroups attributes.
diff --git a/acceptance/openstack/compute/v2/servergroup_test.go b/acceptance/openstack/compute/v2/servergroup_test.go
index 79f7c92..0ee47ea 100644
--- a/acceptance/openstack/compute/v2/servergroup_test.go
+++ b/acceptance/openstack/compute/v2/servergroup_test.go
@@ -1,9 +1,8 @@
-// +build acceptance compute servers
+// +build acceptance compute servergroups
 
 package v2
 
 import (
-	"fmt"
 	"testing"
 
 	"github.com/gophercloud/gophercloud"
@@ -11,43 +10,120 @@
 	"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/schedulerhints"
 	"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/servergroups"
 	"github.com/gophercloud/gophercloud/openstack/compute/v2/servers"
-	th "github.com/gophercloud/gophercloud/testhelper"
 )
 
-func createServerGroup(t *testing.T, computeClient *gophercloud.ServiceClient) (*servergroups.ServerGroup, error) {
-	sg, err := servergroups.Create(computeClient, &servergroups.CreateOpts{
+func TestServergroupsList(t *testing.T) {
+	client, err := newClient()
+	if err != nil {
+		t.Fatalf("Unable to create a compute client: %v", err)
+	}
+
+	allPages, err := servergroups.List(client).AllPages()
+	if err != nil {
+		t.Fatalf("Unable to list server groups: %v", err)
+	}
+
+	allServerGroups, err := servergroups.ExtractServerGroups(allPages)
+	if err != nil {
+		t.Fatalf("Unable to extract server groups: %v", err)
+	}
+
+	for _, serverGroup := range allServerGroups {
+		printServerGroup(t, &serverGroup)
+	}
+}
+
+func TestServergroupsCreate(t *testing.T) {
+	client, err := newClient()
+	if err != nil {
+		t.Fatalf("Unable to create a compute client: %v", err)
+	}
+
+	serverGroup, err := createServerGroup(t, client, "anti-affinity")
+	if err != nil {
+		t.Fatalf("Unable to create server group: %v", err)
+	}
+	defer deleteServerGroup(t, client, serverGroup)
+
+	serverGroup, err = servergroups.Get(client, serverGroup.ID).Extract()
+	if err != nil {
+		t.Fatalf("Unable to get server group: %v", err)
+	}
+
+	printServerGroup(t, serverGroup)
+}
+
+func TestServergroupsAffinityPolicy(t *testing.T) {
+	client, err := newClient()
+	if err != nil {
+		t.Fatalf("Unable to create a compute client: %v", err)
+	}
+
+	choices, err := ComputeChoicesFromEnv()
+	if err != nil {
+		t.Fatal(err)
+	}
+
+	serverGroup, err := createServerGroup(t, client, "affinity")
+	if err != nil {
+		t.Fatalf("Unable to create server group: %v", err)
+	}
+	defer deleteServerGroup(t, client, serverGroup)
+
+	firstServer, err := createServerInServerGroup(t, client, choices, serverGroup)
+	if err != nil {
+		t.Fatalf("Unable to create server: %v", err)
+	}
+
+	if err = waitForStatus(client, firstServer, "ACTIVE"); err != nil {
+		t.Fatalf("Unable to wait for server: %v", err)
+	}
+	defer deleteServer(t, client, firstServer)
+
+	firstServer, err = servers.Get(client, firstServer.ID).Extract()
+
+	secondServer, err := createServerInServerGroup(t, client, choices, serverGroup)
+	if err != nil {
+		t.Fatalf("Unable to create server: %v", err)
+	}
+
+	if err = waitForStatus(client, secondServer, "ACTIVE"); err != nil {
+		t.Fatalf("Unable to wait for server: %v", err)
+	}
+	defer deleteServer(t, client, secondServer)
+
+	secondServer, err = servers.Get(client, secondServer.ID).Extract()
+
+	if firstServer.HostID != secondServer.HostID {
+		t.Fatalf("%s and %s were not scheduled on the same host.", firstServer.ID, secondServer.ID)
+	}
+}
+
+func createServerGroup(t *testing.T, client *gophercloud.ServiceClient, policy string) (*servergroups.ServerGroup, error) {
+	sg, err := servergroups.Create(client, &servergroups.CreateOpts{
 		Name:     "test",
-		Policies: []string{"affinity"},
+		Policies: []string{policy},
 	}).Extract()
 
 	if err != nil {
 		t.Fatalf("Unable to create server group: %v", err)
 	}
 
-	t.Logf("Created server group: %v", sg.ID)
-	t.Logf("It has policies: %v", sg.Policies)
-
 	return sg, nil
 }
 
-func getServerGroup(t *testing.T, computeClient *gophercloud.ServiceClient, sgID string) error {
-	sg, err := servergroups.Get(computeClient, sgID).Extract()
-	if err != nil {
-		t.Fatalf("Unable to get server group: %v", err)
-	}
-
-	t.Logf("Got server group: %v", sg.Name)
-
-	return nil
-}
-
-func createServerInGroup(t *testing.T, computeClient *gophercloud.ServiceClient, choices *ComputeChoices, serverGroup *servergroups.ServerGroup) (*servers.Server, error) {
+func createServerInServerGroup(t *testing.T, client *gophercloud.ServiceClient, choices *ComputeChoices, serverGroup *servergroups.ServerGroup) (*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\n", name)
+	t.Logf("Attempting to create server: %s", name)
 
 	pwd := tools.MakeNewPassword("")
 
@@ -56,88 +132,38 @@
 		FlavorRef: choices.FlavorID,
 		ImageRef:  choices.ImageID,
 		AdminPass: pwd,
+		Networks: []servers.Network{
+			servers.Network{UUID: networkID},
+		},
 	}
-	server, err := servers.Create(computeClient, schedulerhints.CreateOptsExt{
+
+	schedulerHintsOpts := schedulerhints.CreateOptsExt{
 		serverCreateOpts,
 		schedulerhints.SchedulerHints{
 			Group: serverGroup.ID,
 		},
-	}).Extract()
+	}
+	server, err := servers.Create(client, schedulerHintsOpts).Extract()
 	if err != nil {
 		t.Fatalf("Unable to create server: %v", err)
 	}
 
-	th.AssertEquals(t, pwd, server.AdminPass)
-
 	return server, err
 }
 
-func verifySchedulerWorked(t *testing.T, firstServer, secondServer *servers.Server) error {
-	t.Logf("First server hostID: %v", firstServer.HostID)
-	t.Logf("Second server hostID: %v", secondServer.HostID)
-	if firstServer.HostID == secondServer.HostID {
-		return nil
+func deleteServerGroup(t *testing.T, client *gophercloud.ServiceClient, serverGroup *servergroups.ServerGroup) {
+	err := servergroups.Delete(client, serverGroup.ID).ExtractErr()
+	if err != nil {
+		t.Fatalf("Unable to delete server group %s: %v", serverGroup.ID, err)
 	}
 
-	return fmt.Errorf("%s and %s were not scheduled on the same host.", firstServer.ID, secondServer.ID)
+	t.Logf("Deleted server group %s", serverGroup.ID)
 }
 
-func TestServerGroups(t *testing.T) {
-	choices, err := ComputeChoicesFromEnv()
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	computeClient, err := newClient()
-	if err != nil {
-		t.Fatalf("Unable to create a compute client: %v", err)
-	}
-
-	sg, err := createServerGroup(t, computeClient)
-	if err != nil {
-		t.Fatalf("Unable to create server group: %v", err)
-	}
-	defer func() {
-		servergroups.Delete(computeClient, sg.ID)
-		t.Logf("Server Group deleted.")
-	}()
-
-	err = getServerGroup(t, computeClient, sg.ID)
-	if err != nil {
-		t.Fatalf("Unable to get server group: %v", err)
-	}
-
-	firstServer, err := createServerInGroup(t, computeClient, choices, sg)
-	if err != nil {
-		t.Fatalf("Unable to create server: %v", err)
-	}
-	defer func() {
-		servers.Delete(computeClient, firstServer.ID)
-		t.Logf("Server deleted.")
-	}()
-
-	if err = waitForStatus(computeClient, firstServer, "ACTIVE"); err != nil {
-		t.Fatalf("Unable to wait for server: %v", err)
-	}
-
-	firstServer, err = servers.Get(computeClient, firstServer.ID).Extract()
-
-	secondServer, err := createServerInGroup(t, computeClient, choices, sg)
-	if err != nil {
-		t.Fatalf("Unable to create server: %v", err)
-	}
-	defer func() {
-		servers.Delete(computeClient, secondServer.ID)
-		t.Logf("Server deleted.")
-	}()
-
-	if err = waitForStatus(computeClient, secondServer, "ACTIVE"); err != nil {
-		t.Fatalf("Unable to wait for server: %v", err)
-	}
-
-	secondServer, err = servers.Get(computeClient, secondServer.ID).Extract()
-
-	if err = verifySchedulerWorked(t, firstServer, secondServer); err != nil {
-		t.Fatalf("Scheduling did not work: %v", err)
-	}
+func printServerGroup(t *testing.T, serverGroup *servergroups.ServerGroup) {
+	t.Logf("ID: %s", serverGroup.ID)
+	t.Logf("Name: %s", serverGroup.Name)
+	t.Logf("Policies: %#v", serverGroup.Policies)
+	t.Logf("Members: %#v", serverGroup.Members)
+	t.Logf("Metadata: %#v", serverGroup.Metadata)
 }