Compute Acceptance Test Changes (#33)

This commit makes more changes to the compute acceptance tests:

* Makes all reusable functions exportable so other APIs can use them.
* Centralizes client initialization and environment variable checks.
diff --git a/acceptance/openstack/compute/v2/secgroup_test.go b/acceptance/openstack/compute/v2/secgroup_test.go
index 8a2e7f7..9ec7ba4 100644
--- a/acceptance/openstack/compute/v2/secgroup_test.go
+++ b/acceptance/openstack/compute/v2/secgroup_test.go
@@ -5,13 +5,13 @@
 import (
 	"testing"
 
-	"github.com/gophercloud/gophercloud"
+	"github.com/gophercloud/gophercloud/acceptance/clients"
 	"github.com/gophercloud/gophercloud/acceptance/tools"
 	"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/secgroups"
 )
 
 func TestSecGroupsList(t *testing.T) {
-	client, err := newClient()
+	client, err := clients.NewComputeV2Client()
 	if err != nil {
 		t.Fatalf("Unable to create a compute client: %v", err)
 	}
@@ -27,34 +27,34 @@
 	}
 
 	for _, secgroup := range allSecGroups {
-		printSecurityGroup(t, &secgroup)
+		PrintSecurityGroup(t, &secgroup)
 	}
 }
 
 func TestSecGroupsCreate(t *testing.T) {
-	client, err := newClient()
+	client, err := clients.NewComputeV2Client()
 	if err != nil {
 		t.Fatalf("Unable to create a compute client: %v", err)
 	}
 
-	securityGroup, err := createSecurityGroup(t, client)
+	securityGroup, err := CreateSecurityGroup(t, client)
 	if err != nil {
 		t.Fatalf("Unable to create security group: %v", err)
 	}
-	defer deleteSecurityGroup(t, client, securityGroup)
+	defer DeleteSecurityGroup(t, client, securityGroup)
 }
 
 func TestSecGroupsUpdate(t *testing.T) {
-	client, err := newClient()
+	client, err := clients.NewComputeV2Client()
 	if err != nil {
 		t.Fatalf("Unable to create a compute client: %v", err)
 	}
 
-	securityGroup, err := createSecurityGroup(t, client)
+	securityGroup, err := CreateSecurityGroup(t, client)
 	if err != nil {
 		t.Fatalf("Unable to create security group: %v", err)
 	}
-	defer deleteSecurityGroup(t, client, securityGroup)
+	defer DeleteSecurityGroup(t, client, securityGroup)
 
 	updateOpts := secgroups.UpdateOpts{
 		Name:        tools.RandomString("secgroup_", 4),
@@ -69,22 +69,22 @@
 }
 
 func TestSecGroupsRuleCreate(t *testing.T) {
-	client, err := newClient()
+	client, err := clients.NewComputeV2Client()
 	if err != nil {
 		t.Fatalf("Unable to create a compute client: %v", err)
 	}
 
-	securityGroup, err := createSecurityGroup(t, client)
+	securityGroup, err := CreateSecurityGroup(t, client)
 	if err != nil {
 		t.Fatalf("Unable to create security group: %v", err)
 	}
-	defer deleteSecurityGroup(t, client, securityGroup)
+	defer DeleteSecurityGroup(t, client, securityGroup)
 
-	rule, err := createSecurityGroupRule(t, client, securityGroup.ID)
+	rule, err := CreateSecurityGroupRule(t, client, securityGroup.ID)
 	if err != nil {
 		t.Fatalf("Unable to create rule: %v", err)
 	}
-	defer deleteSecurityGroupRule(t, client, rule)
+	defer DeleteSecurityGroupRule(t, client, rule)
 }
 
 func TestSecGroupsAddGroupToServer(t *testing.T) {
@@ -92,37 +92,33 @@
 		t.Skip("Skipping test that requires server creation in short mode.")
 	}
 
-	client, err := newClient()
+	client, err := clients.NewComputeV2Client()
 	if err != nil {
 		t.Fatalf("Unable to create a compute client: %v", err)
 	}
 
-	choices, err := ComputeChoicesFromEnv()
+	choices, err := clients.AcceptanceTestChoicesFromEnv()
 	if err != nil {
 		t.Fatal(err)
 	}
 
-	server, err := createServer(t, client, choices)
+	server, err := CreateServer(t, client, choices)
 	if err != nil {
 		t.Fatalf("Unable to create server: %v", err)
 	}
+	defer DeleteServer(t, client, server)
 
-	if err = waitForStatus(client, server, "ACTIVE"); err != nil {
-		t.Fatalf("Unable to wait for server: %v", err)
-	}
-	defer deleteServer(t, client, server)
-
-	securityGroup, err := createSecurityGroup(t, client)
+	securityGroup, err := CreateSecurityGroup(t, client)
 	if err != nil {
 		t.Fatalf("Unable to create security group: %v", err)
 	}
-	defer deleteSecurityGroup(t, client, securityGroup)
+	defer DeleteSecurityGroup(t, client, securityGroup)
 
-	rule, err := createSecurityGroupRule(t, client, securityGroup.ID)
+	rule, err := CreateSecurityGroupRule(t, client, securityGroup.ID)
 	if err != nil {
 		t.Fatalf("Unable to create rule: %v", err)
 	}
-	defer deleteSecurityGroupRule(t, client, rule)
+	defer DeleteSecurityGroupRule(t, client, rule)
 
 	t.Logf("Adding group %s to server %s", securityGroup.ID, server.ID)
 	err = secgroups.AddServer(client, server.ID, securityGroup.Name).ExtractErr()
@@ -136,73 +132,3 @@
 		t.Fatalf("Unable to remove group %s from server %s: %s", securityGroup.ID, server.ID, err)
 	}
 }
-
-func createSecurityGroup(t *testing.T, client *gophercloud.ServiceClient) (secgroups.SecurityGroup, error) {
-	createOpts := secgroups.CreateOpts{
-		Name:        tools.RandomString("secgroup_", 5),
-		Description: "something",
-	}
-
-	securityGroup, err := secgroups.Create(client, createOpts).Extract()
-	if err != nil {
-		return *securityGroup, err
-	}
-
-	t.Logf("Created security group: %s", securityGroup.ID)
-	return *securityGroup, nil
-}
-
-func deleteSecurityGroup(t *testing.T, client *gophercloud.ServiceClient, securityGroup secgroups.SecurityGroup) {
-	err := secgroups.Delete(client, securityGroup.ID).ExtractErr()
-	if err != nil {
-		t.Fatalf("Unable to delete security group %s: %s", securityGroup.ID, err)
-	}
-
-	t.Logf("Deleted security group: %s", securityGroup.ID)
-}
-
-func createSecurityGroupRule(t *testing.T, client *gophercloud.ServiceClient, securityGroupID string) (secgroups.Rule, error) {
-	createOpts := secgroups.CreateRuleOpts{
-		ParentGroupID: securityGroupID,
-		FromPort:      tools.RandomInt(80, 89),
-		ToPort:        tools.RandomInt(90, 99),
-		IPProtocol:    "TCP",
-		CIDR:          "0.0.0.0/0",
-	}
-
-	rule, err := secgroups.CreateRule(client, createOpts).Extract()
-	if err != nil {
-		return *rule, err
-	}
-
-	t.Logf("Created security group rule: %s", rule.ID)
-	return *rule, nil
-}
-
-func deleteSecurityGroupRule(t *testing.T, client *gophercloud.ServiceClient, rule secgroups.Rule) {
-	err := secgroups.DeleteRule(client, rule.ID).ExtractErr()
-	if err != nil {
-		t.Fatalf("Unable to delete rule: %v", err)
-	}
-
-	t.Logf("Deleted security group rule: %s", rule.ID)
-}
-
-func printSecurityGroup(t *testing.T, securityGroup *secgroups.SecurityGroup) {
-	t.Logf("ID: %s", securityGroup.ID)
-	t.Logf("Name: %s", securityGroup.Name)
-	t.Logf("Description: %s", securityGroup.Description)
-	t.Logf("Tenant ID: %s", securityGroup.TenantID)
-	t.Logf("Rules:")
-
-	for _, rule := range securityGroup.Rules {
-		t.Logf("\tID: %s", rule.ID)
-		t.Logf("\tFrom Port: %d", rule.FromPort)
-		t.Logf("\tTo Port: %d", rule.ToPort)
-		t.Logf("\tIP Protocol: %s", rule.IPProtocol)
-		t.Logf("\tIP Range: %s", rule.IPRange.CIDR)
-		t.Logf("\tParent Group ID: %s", rule.ParentGroupID)
-		t.Logf("\tGroup Tenant ID: %s", rule.Group.TenantID)
-		t.Logf("\tGroup Name: %s", rule.Group.Name)
-	}
-}