Acceptance Test Updates (#218)
* compute: don't pass choices
* blockstorage: don't pass choices
* DumpResource Function
This function prints a resource in JSON format but retains the actual
field name rather than using the name specified in the JSON tag.
* New DumpResource
This version just converts the resource into JSON. The original is
being left in git history for posterity.
* Renaming DumpResource to PrintResource
* Removing all print functions in favor of PrintResource
* Rebase reconcilliation
diff --git a/acceptance/openstack/compute/v2/bootfromvolume_test.go b/acceptance/openstack/compute/v2/bootfromvolume_test.go
index 54719d0..2ba8888 100644
--- a/acceptance/openstack/compute/v2/bootfromvolume_test.go
+++ b/acceptance/openstack/compute/v2/bootfromvolume_test.go
@@ -7,6 +7,7 @@
"github.com/gophercloud/gophercloud/acceptance/clients"
blockstorage "github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/v2"
+ "github.com/gophercloud/gophercloud/acceptance/tools"
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/bootfromvolume"
)
@@ -35,13 +36,13 @@
},
}
- server, err := CreateBootableVolumeServer(t, client, blockDevices, choices)
+ server, err := CreateBootableVolumeServer(t, client, blockDevices)
if err != nil {
t.Fatalf("Unable to create server: %v", err)
}
defer DeleteServer(t, client, server)
- PrintServer(t, server)
+ tools.PrintResource(t, server)
}
func TestBootFromNewVolume(t *testing.T) {
@@ -69,13 +70,13 @@
},
}
- server, err := CreateBootableVolumeServer(t, client, blockDevices, choices)
+ server, err := CreateBootableVolumeServer(t, client, blockDevices)
if err != nil {
t.Fatalf("Unable to create server: %v", err)
}
defer DeleteServer(t, client, server)
- PrintServer(t, server)
+ tools.PrintResource(t, server)
}
func TestBootFromExistingVolume(t *testing.T) {
@@ -93,12 +94,7 @@
t.Fatalf("Unable to create a block storage client: %v", err)
}
- choices, err := clients.AcceptanceTestChoicesFromEnv()
- if err != nil {
- t.Fatal(err)
- }
-
- volume, err := blockstorage.CreateVolumeFromImage(t, blockStorageClient, choices)
+ volume, err := blockstorage.CreateVolumeFromImage(t, blockStorageClient)
if err != nil {
t.Fatal(err)
}
@@ -112,13 +108,13 @@
},
}
- server, err := CreateBootableVolumeServer(t, computeClient, blockDevices, choices)
+ server, err := CreateBootableVolumeServer(t, computeClient, blockDevices)
if err != nil {
t.Fatalf("Unable to create server: %v", err)
}
defer DeleteServer(t, computeClient, server)
- PrintServer(t, server)
+ tools.PrintResource(t, server)
}
func TestBootFromMultiEphemeralServer(t *testing.T) {
@@ -163,13 +159,13 @@
},
}
- server, err := CreateMultiEphemeralServer(t, client, blockDevices, choices)
+ server, err := CreateMultiEphemeralServer(t, client, blockDevices)
if err != nil {
t.Fatalf("Unable to create server: %v", err)
}
defer DeleteServer(t, client, server)
- PrintServer(t, server)
+ tools.PrintResource(t, server)
}
func TestAttachNewVolume(t *testing.T) {
@@ -204,13 +200,13 @@
},
}
- server, err := CreateBootableVolumeServer(t, client, blockDevices, choices)
+ server, err := CreateBootableVolumeServer(t, client, blockDevices)
if err != nil {
t.Fatalf("Unable to create server: %v", err)
}
defer DeleteServer(t, client, server)
- PrintServer(t, server)
+ tools.PrintResource(t, server)
}
func TestAttachExistingVolume(t *testing.T) {
@@ -255,11 +251,11 @@
},
}
- server, err := CreateBootableVolumeServer(t, computeClient, blockDevices, choices)
+ server, err := CreateBootableVolumeServer(t, computeClient, blockDevices)
if err != nil {
t.Fatalf("Unable to create server: %v", err)
}
defer DeleteServer(t, computeClient, server)
- PrintServer(t, server)
+ tools.PrintResource(t, server)
}
diff --git a/acceptance/openstack/compute/v2/compute.go b/acceptance/openstack/compute/v2/compute.go
index 97d61f6..1f3dc16 100644
--- a/acceptance/openstack/compute/v2/compute.go
+++ b/acceptance/openstack/compute/v2/compute.go
@@ -23,8 +23,6 @@
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/servergroups"
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/tenantnetworks"
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/volumeattach"
- "github.com/gophercloud/gophercloud/openstack/compute/v2/flavors"
- "github.com/gophercloud/gophercloud/openstack/compute/v2/images"
"github.com/gophercloud/gophercloud/openstack/compute/v2/servers"
"golang.org/x/crypto/ssh"
@@ -67,13 +65,18 @@
// CreateBootableVolumeServer works like CreateServer but is configured with
// one or more block devices defined by passing in []bootfromvolume.BlockDevice.
// An error will be returned if a server was unable to be created.
-func CreateBootableVolumeServer(t *testing.T, client *gophercloud.ServiceClient, blockDevices []bootfromvolume.BlockDevice, choices *clients.AcceptanceTestChoices) (*servers.Server, error) {
+func CreateBootableVolumeServer(t *testing.T, client *gophercloud.ServiceClient, blockDevices []bootfromvolume.BlockDevice) (*servers.Server, error) {
if testing.Short() {
t.Skip("Skipping test that requires server creation in short mode.")
}
var server *servers.Server
+ choices, err := clients.AcceptanceTestChoicesFromEnv()
+ if err != nil {
+ t.Fatal(err)
+ }
+
networkID, err := GetNetworkIDFromTenantNetworks(t, client, choices.NetworkName)
if err != nil {
return server, err
@@ -135,7 +138,12 @@
// CreateFloatingIP will allocate a floating IP.
// An error will be returend if one was unable to be allocated.
-func CreateFloatingIP(t *testing.T, client *gophercloud.ServiceClient, choices *clients.AcceptanceTestChoices) (*floatingips.FloatingIP, error) {
+func CreateFloatingIP(t *testing.T, client *gophercloud.ServiceClient) (*floatingips.FloatingIP, error) {
+ choices, err := clients.AcceptanceTestChoicesFromEnv()
+ if err != nil {
+ t.Fatal(err)
+ }
+
createOpts := floatingips.CreateOpts{
Pool: choices.FloatingIPPoolName,
}
@@ -189,13 +197,18 @@
// These block devices act like block devices when booting from a volume but
// are actually local ephemeral disks.
// An error will be returned if a server was unable to be created.
-func CreateMultiEphemeralServer(t *testing.T, client *gophercloud.ServiceClient, blockDevices []bootfromvolume.BlockDevice, choices *clients.AcceptanceTestChoices) (*servers.Server, error) {
+func CreateMultiEphemeralServer(t *testing.T, client *gophercloud.ServiceClient, blockDevices []bootfromvolume.BlockDevice) (*servers.Server, error) {
if testing.Short() {
t.Skip("Skipping test that requires server creation in short mode.")
}
var server *servers.Server
+ choices, err := clients.AcceptanceTestChoicesFromEnv()
+ if err != nil {
+ t.Fatal(err)
+ }
+
networkID, err := GetNetworkIDFromTenantNetworks(t, client, choices.NetworkName)
if err != nil {
return server, err
@@ -274,13 +287,18 @@
// The image will be the value of the OS_IMAGE_ID environment variable.
// The instance will be launched on the network specified in OS_NETWORK_NAME.
// An error will be returned if the instance was unable to be created.
-func CreateServer(t *testing.T, client *gophercloud.ServiceClient, choices *clients.AcceptanceTestChoices) (*servers.Server, error) {
+func CreateServer(t *testing.T, client *gophercloud.ServiceClient) (*servers.Server, error) {
if testing.Short() {
t.Skip("Skipping test that requires server creation in short mode.")
}
var server *servers.Server
+ choices, err := clients.AcceptanceTestChoicesFromEnv()
+ if err != nil {
+ t.Fatal(err)
+ }
+
networkID, err := GetNetworkIDFromTenantNetworks(t, client, choices.NetworkName)
if err != nil {
return server, err
@@ -325,13 +343,18 @@
// The image is intentionally missing to trigger an error.
// The instance will be launched on the network specified in OS_NETWORK_NAME.
// An error will be returned if the instance was unable to be created.
-func CreateServerWithoutImageRef(t *testing.T, client *gophercloud.ServiceClient, choices *clients.AcceptanceTestChoices) (*servers.Server, error) {
+func CreateServerWithoutImageRef(t *testing.T, client *gophercloud.ServiceClient) (*servers.Server, error) {
if testing.Short() {
t.Skip("Skipping test that requires server creation in short mode.")
}
var server *servers.Server
+ choices, err := clients.AcceptanceTestChoicesFromEnv()
+ if err != nil {
+ t.Fatal(err)
+ }
+
networkID, err := GetNetworkIDFromTenantNetworks(t, client, choices.NetworkName)
if err != nil {
return server, err
@@ -384,13 +407,18 @@
// CreateServerInServerGroup works like CreateServer but places the instance in
// a specified Server Group.
-func CreateServerInServerGroup(t *testing.T, client *gophercloud.ServiceClient, choices *clients.AcceptanceTestChoices, serverGroup *servergroups.ServerGroup) (*servers.Server, error) {
+func CreateServerInServerGroup(t *testing.T, client *gophercloud.ServiceClient, serverGroup *servergroups.ServerGroup) (*servers.Server, error) {
if testing.Short() {
t.Skip("Skipping test that requires server creation in short mode.")
}
var server *servers.Server
+ choices, err := clients.AcceptanceTestChoicesFromEnv()
+ if err != nil {
+ t.Fatal(err)
+ }
+
networkID, err := GetNetworkIDFromTenantNetworks(t, client, choices.NetworkName)
if err != nil {
return server, err
@@ -427,13 +455,18 @@
// CreateServerWithPublicKey works the same as CreateServer, but additionally
// configures the server with a specified Key Pair name.
-func CreateServerWithPublicKey(t *testing.T, client *gophercloud.ServiceClient, choices *clients.AcceptanceTestChoices, keyPairName string) (*servers.Server, error) {
+func CreateServerWithPublicKey(t *testing.T, client *gophercloud.ServiceClient, keyPairName string) (*servers.Server, error) {
if testing.Short() {
t.Skip("Skipping test that requires server creation in short mode.")
}
var server *servers.Server
+ choices, err := clients.AcceptanceTestChoicesFromEnv()
+ if err != nil {
+ t.Fatal(err)
+ }
+
networkID, err := GetNetworkIDFromTenantNetworks(t, client, choices.NetworkName)
if err != nil {
return server, err
@@ -673,7 +706,12 @@
// ResizeServer performs a resize action on an instance. An error will be
// returned if the instance failed to resize.
// The new flavor that the instance will be resized to is specified in OS_FLAVOR_ID_RESIZE.
-func ResizeServer(t *testing.T, client *gophercloud.ServiceClient, server *servers.Server, choices *clients.AcceptanceTestChoices) error {
+func ResizeServer(t *testing.T, client *gophercloud.ServiceClient, server *servers.Server) error {
+ choices, err := clients.AcceptanceTestChoicesFromEnv()
+ if err != nil {
+ t.Fatal(err)
+ }
+
opts := &servers.ResizeOpts{
FlavorRef: choices.FlavorIDResize,
}
@@ -711,7 +749,7 @@
}
//Convenience method to fill an QuotaSet-UpdateOpts-struct from a QuotaSet-struct
-func FillUpdateOptsFromQuotaSet(src quotasets.QuotaSet,dest *quotasets.UpdateOpts) {
+func FillUpdateOptsFromQuotaSet(src quotasets.QuotaSet, dest *quotasets.UpdateOpts) {
dest.FixedIps = &src.FixedIps
dest.FloatingIps = &src.FloatingIps
dest.InjectedFileContentBytes = &src.InjectedFileContentBytes
@@ -727,171 +765,3 @@
dest.ServerGroupMembers = &src.ServerGroupMembers
dest.MetadataItems = &src.MetadataItems
}
-
-// PrintServer will print an instance and all of its attributes.
-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)
-}
-
-// PrintDefaultRule will print a default security group rule and all of its attributes.
-func PrintDefaultRule(t *testing.T, defaultRule *dsr.DefaultRule) {
- t.Logf("\tID: %s", defaultRule.ID)
- t.Logf("\tFrom Port: %d", defaultRule.FromPort)
- t.Logf("\tTo Port: %d", defaultRule.ToPort)
- t.Logf("\tIP Protocol: %s", defaultRule.IPProtocol)
- t.Logf("\tIP Range: %s", defaultRule.IPRange.CIDR)
- t.Logf("\tParent Group ID: %s", defaultRule.ParentGroupID)
- t.Logf("\tGroup Tenant ID: %s", defaultRule.Group.TenantID)
- t.Logf("\tGroup Name: %s", defaultRule.Group.Name)
-}
-
-// PrintFlavor will print a flavor and all of its attributes.
-func PrintFlavor(t *testing.T, flavor *flavors.Flavor) {
- t.Logf("ID: %s", flavor.ID)
- t.Logf("Name: %s", flavor.Name)
- t.Logf("RAM: %d", flavor.RAM)
- t.Logf("Disk: %d", flavor.Disk)
- t.Logf("Swap: %d", flavor.Swap)
- t.Logf("RxTxFactor: %f", flavor.RxTxFactor)
-}
-
-// PrintFloatingIP will print a floating IP and all of its attributes.
-func PrintFloatingIP(t *testing.T, floatingIP *floatingips.FloatingIP) {
- t.Logf("ID: %s", floatingIP.ID)
- t.Logf("Fixed IP: %s", floatingIP.FixedIP)
- t.Logf("Instance ID: %s", floatingIP.InstanceID)
- t.Logf("IP: %s", floatingIP.IP)
- t.Logf("Pool: %s", floatingIP.Pool)
-}
-
-// PrintImage will print an image and all of its attributes.
-func PrintImage(t *testing.T, image images.Image) {
- t.Logf("ID: %s", image.ID)
- t.Logf("Name: %s", image.Name)
- t.Logf("MinDisk: %d", image.MinDisk)
- t.Logf("MinRAM: %d", image.MinRAM)
- t.Logf("Status: %s", image.Status)
- t.Logf("Progress: %d", image.Progress)
- t.Logf("Metadata: %#v", image.Metadata)
- t.Logf("Created: %s", image.Created)
- t.Logf("Updated: %s", image.Updated)
-}
-
-// PrintKeyPair will print keypair and all of its attributes.
-func PrintKeyPair(t *testing.T, keypair *keypairs.KeyPair) {
- t.Logf("Name: %s", keypair.Name)
- t.Logf("Fingerprint: %s", keypair.Fingerprint)
- t.Logf("Public Key: %s", keypair.PublicKey)
- t.Logf("Private Key: %s", keypair.PrivateKey)
- t.Logf("UserID: %s", keypair.UserID)
-}
-
-// PrintNetwork will print an os-networks based network and all of its attributes.
-func PrintNetwork(t *testing.T, network *networks.Network) {
- t.Logf("Bridge: %s", network.Bridge)
- t.Logf("BridgeInterface: %s", network.BridgeInterface)
- t.Logf("Broadcast: %s", network.Broadcast)
- t.Logf("CIDR: %s", network.CIDR)
- t.Logf("CIDRv6: %s", network.CIDRv6)
- t.Logf("CreatedAt: %v", network.CreatedAt)
- t.Logf("Deleted: %t", network.Deleted)
- t.Logf("DeletedAt: %v", network.DeletedAt)
- t.Logf("DHCPStart: %s", network.DHCPStart)
- t.Logf("DNS1: %s", network.DNS1)
- t.Logf("DNS2: %s", network.DNS2)
- t.Logf("Gateway: %s", network.Gateway)
- t.Logf("Gatewayv6: %s", network.Gatewayv6)
- t.Logf("Host: %s", network.Host)
- t.Logf("ID: %s", network.ID)
- t.Logf("Injected: %t", network.Injected)
- t.Logf("Label: %s", network.Label)
- t.Logf("MultiHost: %t", network.MultiHost)
- t.Logf("Netmask: %s", network.Netmask)
- t.Logf("Netmaskv6: %s", network.Netmaskv6)
- t.Logf("Priority: %d", network.Priority)
- t.Logf("ProjectID: %s", network.ProjectID)
- t.Logf("RXTXBase: %d", network.RXTXBase)
- t.Logf("UpdatedAt: %v", network.UpdatedAt)
- t.Logf("VLAN: %d", network.VLAN)
- t.Logf("VPNPrivateAddress: %s", network.VPNPrivateAddress)
- t.Logf("VPNPublicAddress: %s", network.VPNPublicAddress)
- t.Logf("VPNPublicPort: %d", network.VPNPublicPort)
-}
-
-// PrintQuotaSet will print a quota set and all of its attributes.
-func PrintQuotaSet(t *testing.T, quotaSet *quotasets.QuotaSet) {
- t.Logf("instances: %d\n", quotaSet.Instances)
- t.Logf("cores: %d\n", quotaSet.Cores)
- t.Logf("ram: %d\n", quotaSet.Ram)
- t.Logf("key_pairs: %d\n", quotaSet.KeyPairs)
- t.Logf("metadata_items: %d\n", quotaSet.MetadataItems)
- t.Logf("security_groups: %d\n", quotaSet.SecurityGroups)
- t.Logf("security_group_rules: %d\n", quotaSet.SecurityGroupRules)
- t.Logf("fixed_ips: %d\n", quotaSet.FixedIps)
- t.Logf("floating_ips: %d\n", quotaSet.FloatingIps)
- t.Logf("injected_file_content_bytes: %d\n", quotaSet.InjectedFileContentBytes)
- t.Logf("injected_file_path_bytes: %d\n", quotaSet.InjectedFilePathBytes)
- t.Logf("injected_files: %d\n", quotaSet.InjectedFiles)
-}
-
-// PrintSecurityGroup will print a security group and all of its attributes and rules.
-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)
- }
-}
-
-// PrintServerGroup will print a server group and all of its attributes.
-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)
-}
-
-// PrintTenantNetwork will print an os-tenant-networks based network and all of its attributes.
-func PrintTenantNetwork(t *testing.T, network *tenantnetworks.Network) {
- t.Logf("ID: %s", network.ID)
- t.Logf("Name: %s", network.Name)
- t.Logf("CIDR: %s", network.CIDR)
-}
-
-// PrintVolumeAttachment will print a volume attachment and all of its attributes.
-func PrintVolumeAttachment(t *testing.T, volumeAttachment *volumeattach.VolumeAttachment) {
- t.Logf("ID: %s", volumeAttachment.ID)
- t.Logf("Device: %s", volumeAttachment.Device)
- t.Logf("VolumeID: %s", volumeAttachment.VolumeID)
- t.Logf("ServerID: %s", volumeAttachment.ServerID)
-}
diff --git a/acceptance/openstack/compute/v2/defsecrules_test.go b/acceptance/openstack/compute/v2/defsecrules_test.go
index ca221be..16c43f4 100644
--- a/acceptance/openstack/compute/v2/defsecrules_test.go
+++ b/acceptance/openstack/compute/v2/defsecrules_test.go
@@ -6,6 +6,7 @@
"testing"
"github.com/gophercloud/gophercloud/acceptance/clients"
+ "github.com/gophercloud/gophercloud/acceptance/tools"
dsr "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/defsecrules"
)
@@ -26,7 +27,7 @@
}
for _, defaultRule := range allDefaultRules {
- PrintDefaultRule(t, &defaultRule)
+ tools.PrintResource(t, defaultRule)
}
}
@@ -42,7 +43,7 @@
}
defer DeleteDefaultRule(t, client, defaultRule)
- PrintDefaultRule(t, &defaultRule)
+ tools.PrintResource(t, defaultRule)
}
func TestDefSecRulesGet(t *testing.T) {
@@ -62,5 +63,5 @@
t.Fatalf("Unable to get default rule %s: %v", defaultRule.ID, err)
}
- PrintDefaultRule(t, newDefaultRule)
+ tools.PrintResource(t, newDefaultRule)
}
diff --git a/acceptance/openstack/compute/v2/extension_test.go b/acceptance/openstack/compute/v2/extension_test.go
index 5de715d..5b2cf4a 100644
--- a/acceptance/openstack/compute/v2/extension_test.go
+++ b/acceptance/openstack/compute/v2/extension_test.go
@@ -6,7 +6,7 @@
"testing"
"github.com/gophercloud/gophercloud/acceptance/clients"
- "github.com/gophercloud/gophercloud/acceptance/openstack"
+ "github.com/gophercloud/gophercloud/acceptance/tools"
"github.com/gophercloud/gophercloud/openstack/common/extensions"
)
@@ -27,7 +27,7 @@
}
for _, extension := range allExtensions {
- openstack.PrintExtension(t, &extension)
+ tools.PrintResource(t, extension)
}
}
@@ -42,5 +42,5 @@
t.Fatalf("Unable to get extension os-admin-actions: %v", err)
}
- openstack.PrintExtension(t, extension)
+ tools.PrintResource(t, extension)
}
diff --git a/acceptance/openstack/compute/v2/flavors_test.go b/acceptance/openstack/compute/v2/flavors_test.go
index 6f6490e..ee698cc 100644
--- a/acceptance/openstack/compute/v2/flavors_test.go
+++ b/acceptance/openstack/compute/v2/flavors_test.go
@@ -6,6 +6,7 @@
"testing"
"github.com/gophercloud/gophercloud/acceptance/clients"
+ "github.com/gophercloud/gophercloud/acceptance/tools"
"github.com/gophercloud/gophercloud/openstack/compute/v2/flavors"
)
@@ -26,7 +27,7 @@
}
for _, flavor := range allFlavors {
- PrintFlavor(t, &flavor)
+ tools.PrintResource(t, flavor)
}
}
@@ -36,7 +37,7 @@
t.Fatalf("Unable to create a compute client: %v", err)
}
- choices, err :=clients.AcceptanceTestChoicesFromEnv()
+ choices, err := clients.AcceptanceTestChoicesFromEnv()
if err != nil {
t.Fatal(err)
}
@@ -46,5 +47,5 @@
t.Fatalf("Unable to get flavor information: %v", err)
}
- PrintFlavor(t, flavor)
+ tools.PrintResource(t, flavor)
}
diff --git a/acceptance/openstack/compute/v2/floatingip_test.go b/acceptance/openstack/compute/v2/floatingip_test.go
index 001dc9f..26b7bfe 100644
--- a/acceptance/openstack/compute/v2/floatingip_test.go
+++ b/acceptance/openstack/compute/v2/floatingip_test.go
@@ -6,6 +6,7 @@
"testing"
"github.com/gophercloud/gophercloud/acceptance/clients"
+ "github.com/gophercloud/gophercloud/acceptance/tools"
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/floatingips"
"github.com/gophercloud/gophercloud/openstack/compute/v2/servers"
)
@@ -27,7 +28,7 @@
}
for _, floatingIP := range allFloatingIPs {
- PrintFloatingIP(t, &floatingIP)
+ tools.PrintResource(t, floatingIP)
}
}
@@ -37,18 +38,13 @@
t.Fatalf("Unable to create a compute client: %v", err)
}
- choices, err := clients.AcceptanceTestChoicesFromEnv()
- if err != nil {
- t.Fatal(err)
- }
-
- floatingIP, err := CreateFloatingIP(t, client, choices)
+ floatingIP, err := CreateFloatingIP(t, client)
if err != nil {
t.Fatalf("Unable to create floating IP: %v", err)
}
defer DeleteFloatingIP(t, client, floatingIP)
- PrintFloatingIP(t, floatingIP)
+ tools.PrintResource(t, floatingIP)
}
func TestFloatingIPsAssociate(t *testing.T) {
@@ -61,24 +57,19 @@
t.Fatalf("Unable to create a compute client: %v", err)
}
- choices, err := clients.AcceptanceTestChoicesFromEnv()
- if err != nil {
- t.Fatal(err)
- }
-
- server, err := CreateServer(t, client, choices)
+ server, err := CreateServer(t, client)
if err != nil {
t.Fatalf("Unable to create server: %v", err)
}
defer DeleteServer(t, client, server)
- floatingIP, err := CreateFloatingIP(t, client, choices)
+ floatingIP, err := CreateFloatingIP(t, client)
if err != nil {
t.Fatalf("Unable to create floating IP: %v", err)
}
defer DeleteFloatingIP(t, client, floatingIP)
- PrintFloatingIP(t, floatingIP)
+ tools.PrintResource(t, floatingIP)
err = AssociateFloatingIP(t, client, floatingIP, server)
if err != nil {
@@ -93,7 +84,7 @@
t.Logf("Floating IP %s is associated with Fixed IP %s", floatingIP.IP, newFloatingIP.FixedIP)
- PrintFloatingIP(t, newFloatingIP)
+ tools.PrintResource(t, newFloatingIP)
}
func TestFloatingIPsFixedIPAssociate(t *testing.T) {
@@ -111,7 +102,7 @@
t.Fatal(err)
}
- server, err := CreateServer(t, client, choices)
+ server, err := CreateServer(t, client)
if err != nil {
t.Fatalf("Unable to create server: %v", err)
}
@@ -122,13 +113,13 @@
t.Fatalf("Unable to get server %s: %v", server.ID, err)
}
- floatingIP, err := CreateFloatingIP(t, client, choices)
+ floatingIP, err := CreateFloatingIP(t, client)
if err != nil {
t.Fatalf("Unable to create floating IP: %v", err)
}
defer DeleteFloatingIP(t, client, floatingIP)
- PrintFloatingIP(t, floatingIP)
+ tools.PrintResource(t, floatingIP)
var fixedIP string
for _, networkAddresses := range newServer.Addresses[choices.NetworkName].([]interface{}) {
@@ -153,5 +144,5 @@
t.Logf("Floating IP %s is associated with Fixed IP %s", floatingIP.IP, newFloatingIP.FixedIP)
- PrintFloatingIP(t, newFloatingIP)
+ tools.PrintResource(t, newFloatingIP)
}
diff --git a/acceptance/openstack/compute/v2/images_test.go b/acceptance/openstack/compute/v2/images_test.go
index 53291dd..a34ce3e 100644
--- a/acceptance/openstack/compute/v2/images_test.go
+++ b/acceptance/openstack/compute/v2/images_test.go
@@ -6,6 +6,7 @@
"testing"
"github.com/gophercloud/gophercloud/acceptance/clients"
+ "github.com/gophercloud/gophercloud/acceptance/tools"
"github.com/gophercloud/gophercloud/openstack/compute/v2/images"
)
@@ -26,7 +27,7 @@
}
for _, image := range allImages {
- PrintImage(t, image)
+ tools.PrintResource(t, image)
}
}
@@ -46,5 +47,5 @@
t.Fatalf("Unable to get image information: %v", err)
}
- PrintImage(t, *image)
+ tools.PrintResource(t, image)
}
diff --git a/acceptance/openstack/compute/v2/keypairs_test.go b/acceptance/openstack/compute/v2/keypairs_test.go
index 3c6abb4..c4b91ec 100644
--- a/acceptance/openstack/compute/v2/keypairs_test.go
+++ b/acceptance/openstack/compute/v2/keypairs_test.go
@@ -6,6 +6,7 @@
"testing"
"github.com/gophercloud/gophercloud/acceptance/clients"
+ "github.com/gophercloud/gophercloud/acceptance/tools"
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/keypairs"
"github.com/gophercloud/gophercloud/openstack/compute/v2/servers"
)
@@ -29,7 +30,7 @@
}
for _, keypair := range allKeys {
- PrintKeyPair(t, &keypair)
+ tools.PrintResource(t, keypair)
}
}
@@ -45,7 +46,7 @@
}
defer DeleteKeyPair(t, client, keyPair)
- PrintKeyPair(t, keyPair)
+ tools.PrintResource(t, keyPair)
}
func TestKeypairsImportPublicKey(t *testing.T) {
@@ -65,7 +66,7 @@
}
defer DeleteKeyPair(t, client, keyPair)
- PrintKeyPair(t, keyPair)
+ tools.PrintResource(t, keyPair)
}
func TestKeypairsServerCreateWithKey(t *testing.T) {
@@ -78,11 +79,6 @@
t.Fatalf("Unable to create a compute client: %v", err)
}
- choices, err := clients.AcceptanceTestChoicesFromEnv()
- if err != nil {
- t.Fatal(err)
- }
-
publicKey, err := createKey()
if err != nil {
t.Fatalf("Unable to create public key: %s", err)
@@ -94,7 +90,7 @@
}
defer DeleteKeyPair(t, client, keyPair)
- server, err := CreateServerWithPublicKey(t, client, choices, keyPair.Name)
+ server, err := CreateServerWithPublicKey(t, client, keyPair.Name)
if err != nil {
t.Fatalf("Unable to create server: %s", err)
}
diff --git a/acceptance/openstack/compute/v2/network_test.go b/acceptance/openstack/compute/v2/network_test.go
index 38a6d54..7451518 100644
--- a/acceptance/openstack/compute/v2/network_test.go
+++ b/acceptance/openstack/compute/v2/network_test.go
@@ -6,6 +6,7 @@
"testing"
"github.com/gophercloud/gophercloud/acceptance/clients"
+ "github.com/gophercloud/gophercloud/acceptance/tools"
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/networks"
)
@@ -26,7 +27,7 @@
}
for _, network := range allNetworks {
- PrintNetwork(t, &network)
+ tools.PrintResource(t, network)
}
}
@@ -51,5 +52,5 @@
t.Fatalf("Unable to get network %s: %v", networkID, err)
}
- PrintNetwork(t, network)
+ tools.PrintResource(t, network)
}
diff --git a/acceptance/openstack/compute/v2/quotaset_test.go b/acceptance/openstack/compute/v2/quotaset_test.go
index 2fb7c99..e0c4bae 100644
--- a/acceptance/openstack/compute/v2/quotaset_test.go
+++ b/acceptance/openstack/compute/v2/quotaset_test.go
@@ -8,6 +8,7 @@
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/acceptance/clients"
+ "github.com/gophercloud/gophercloud/acceptance/tools"
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/quotasets"
"github.com/gophercloud/gophercloud/openstack/identity/v2/tenants"
th "github.com/gophercloud/gophercloud/testhelper"
@@ -35,7 +36,7 @@
t.Fatal(err)
}
- PrintQuotaSet(t, quotaSet)
+ tools.PrintResource(t, quotaSet)
}
func getTenantID(t *testing.T, client *gophercloud.ServiceClient) (string, error) {
@@ -182,4 +183,4 @@
}`
FillUpdateOptsFromQuotaSet(UpdatedQuotas,op)
th.AssertJSONEquals(t,expected,op)
-}
\ No newline at end of file
+}
diff --git a/acceptance/openstack/compute/v2/secgroup_test.go b/acceptance/openstack/compute/v2/secgroup_test.go
index 9ec7ba4..c0d0230 100644
--- a/acceptance/openstack/compute/v2/secgroup_test.go
+++ b/acceptance/openstack/compute/v2/secgroup_test.go
@@ -27,7 +27,7 @@
}
for _, secgroup := range allSecGroups {
- PrintSecurityGroup(t, &secgroup)
+ tools.PrintResource(t, secgroup)
}
}
@@ -85,6 +85,14 @@
t.Fatalf("Unable to create rule: %v", err)
}
defer DeleteSecurityGroupRule(t, client, rule)
+
+ newSecurityGroup, err := secgroups.Get(client, securityGroup.ID).Extract()
+ if err != nil {
+ t.Fatalf("Unable to obtain security group: %v", err)
+ }
+
+ tools.PrintResource(t, newSecurityGroup)
+
}
func TestSecGroupsAddGroupToServer(t *testing.T) {
@@ -97,12 +105,7 @@
t.Fatalf("Unable to create a compute client: %v", err)
}
- choices, err := clients.AcceptanceTestChoicesFromEnv()
- if err != nil {
- t.Fatal(err)
- }
-
- server, err := CreateServer(t, client, choices)
+ server, err := CreateServer(t, client)
if err != nil {
t.Fatalf("Unable to create server: %v", err)
}
diff --git a/acceptance/openstack/compute/v2/servergroup_test.go b/acceptance/openstack/compute/v2/servergroup_test.go
index 5921014..ac1915f 100644
--- a/acceptance/openstack/compute/v2/servergroup_test.go
+++ b/acceptance/openstack/compute/v2/servergroup_test.go
@@ -6,6 +6,7 @@
"testing"
"github.com/gophercloud/gophercloud/acceptance/clients"
+ "github.com/gophercloud/gophercloud/acceptance/tools"
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/servergroups"
"github.com/gophercloud/gophercloud/openstack/compute/v2/servers"
)
@@ -27,7 +28,7 @@
}
for _, serverGroup := range allServerGroups {
- PrintServerGroup(t, &serverGroup)
+ tools.PrintResource(t, serverGroup)
}
}
@@ -48,7 +49,7 @@
t.Fatalf("Unable to get server group: %v", err)
}
- PrintServerGroup(t, serverGroup)
+ tools.PrintResource(t, serverGroup)
}
func TestServergroupsAffinityPolicy(t *testing.T) {
@@ -57,18 +58,13 @@
t.Fatalf("Unable to create a compute client: %v", err)
}
- choices, err := clients.AcceptanceTestChoicesFromEnv()
- 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)
+ firstServer, err := CreateServerInServerGroup(t, client, serverGroup)
if err != nil {
t.Fatalf("Unable to create server: %v", err)
}
@@ -76,7 +72,7 @@
firstServer, err = servers.Get(client, firstServer.ID).Extract()
- secondServer, err := CreateServerInServerGroup(t, client, choices, serverGroup)
+ secondServer, err := CreateServerInServerGroup(t, client, serverGroup)
if err != nil {
t.Fatalf("Unable to create server: %v", err)
}
diff --git a/acceptance/openstack/compute/v2/servers_test.go b/acceptance/openstack/compute/v2/servers_test.go
index fa6603d..22b6580 100644
--- a/acceptance/openstack/compute/v2/servers_test.go
+++ b/acceptance/openstack/compute/v2/servers_test.go
@@ -30,7 +30,7 @@
}
for _, server := range allServers {
- PrintServer(t, &server)
+ tools.PrintResource(t, server)
}
}
@@ -45,7 +45,7 @@
t.Fatal(err)
}
- server, err := CreateServer(t, client, choices)
+ server, err := CreateServer(t, client)
if err != nil {
t.Fatalf("Unable to create server: %v", err)
}
@@ -56,7 +56,7 @@
if err != nil {
t.Errorf("Unable to retrieve server: %v", err)
}
- PrintServer(t, newServer)
+ tools.PrintResource(t, newServer)
allAddressPages, err := servers.ListAddresses(client, server.ID).AllPages()
if err != nil {
@@ -94,12 +94,7 @@
t.Fatalf("Unable to create a compute client: %v", err)
}
- choices, err := clients.AcceptanceTestChoicesFromEnv()
- if err != nil {
- t.Fatal(err)
- }
-
- server, err := CreateServerWithoutImageRef(t, client, choices)
+ server, err := CreateServerWithoutImageRef(t, client)
if err != nil {
if err400, ok := err.(*gophercloud.ErrUnexpectedResponseCode); ok {
if !strings.Contains("Missing imageRef attribute", string(err400.Body)) {
@@ -115,12 +110,7 @@
t.Fatalf("Unable to create a compute client: %v", err)
}
- choices, err := clients.AcceptanceTestChoicesFromEnv()
- if err != nil {
- t.Fatal(err)
- }
-
- server, err := CreateServer(t, client, choices)
+ server, err := CreateServer(t, client)
if err != nil {
t.Fatal(err)
}
@@ -159,17 +149,12 @@
func TestServersMetadata(t *testing.T) {
t.Parallel()
- choices, err := clients.AcceptanceTestChoicesFromEnv()
- if err != nil {
- t.Fatal(err)
- }
-
client, err := clients.NewComputeV2Client()
if err != nil {
t.Fatalf("Unable to create a compute client: %v", err)
}
- server, err := CreateServer(t, client, choices)
+ server, err := CreateServer(t, client)
if err != nil {
t.Fatal(err)
}
@@ -226,12 +211,7 @@
t.Fatalf("Unable to create a compute client: %v", err)
}
- choices, err := clients.AcceptanceTestChoicesFromEnv()
- if err != nil {
- t.Fatal(err)
- }
-
- server, err := CreateServer(t, client, choices)
+ server, err := CreateServer(t, client)
if err != nil {
t.Fatal(err)
}
@@ -260,12 +240,7 @@
t.Fatalf("Unable to create a compute client: %v", err)
}
- choices, err := clients.AcceptanceTestChoicesFromEnv()
- if err != nil {
- t.Fatal(err)
- }
-
- server, err := CreateServer(t, client, choices)
+ server, err := CreateServer(t, client)
if err != nil {
t.Fatal(err)
}
@@ -303,7 +278,7 @@
t.Fatal(err)
}
- server, err := CreateServer(t, client, choices)
+ server, err := CreateServer(t, client)
if err != nil {
t.Fatal(err)
}
@@ -338,24 +313,19 @@
func TestServersActionResizeConfirm(t *testing.T) {
t.Parallel()
- choices, err := clients.AcceptanceTestChoicesFromEnv()
- if err != nil {
- t.Fatal(err)
- }
-
client, err := clients.NewComputeV2Client()
if err != nil {
t.Fatalf("Unable to create a compute client: %v", err)
}
- server, err := CreateServer(t, client, choices)
+ server, err := CreateServer(t, client)
if err != nil {
t.Fatal(err)
}
defer DeleteServer(t, client, server)
t.Logf("Attempting to resize server %s", server.ID)
- ResizeServer(t, client, server, choices)
+ ResizeServer(t, client, server)
t.Logf("Attempting to confirm resize for server %s", server.ID)
if res := servers.ConfirmResize(client, server.ID); res.Err != nil {
@@ -370,24 +340,19 @@
func TestServersActionResizeRevert(t *testing.T) {
t.Parallel()
- choices, err := clients.AcceptanceTestChoicesFromEnv()
- if err != nil {
- t.Fatal(err)
- }
-
client, err := clients.NewComputeV2Client()
if err != nil {
t.Fatalf("Unable to create a compute client: %v", err)
}
- server, err := CreateServer(t, client, choices)
+ server, err := CreateServer(t, client)
if err != nil {
t.Fatal(err)
}
defer DeleteServer(t, client, server)
t.Logf("Attempting to resize server %s", server.ID)
- ResizeServer(t, client, server, choices)
+ ResizeServer(t, client, server)
t.Logf("Attempting to revert resize for server %s", server.ID)
if res := servers.RevertResize(client, server.ID); res.Err != nil {
diff --git a/acceptance/openstack/compute/v2/tenantnetworks_test.go b/acceptance/openstack/compute/v2/tenantnetworks_test.go
index 7d9c167..9b6b527 100644
--- a/acceptance/openstack/compute/v2/tenantnetworks_test.go
+++ b/acceptance/openstack/compute/v2/tenantnetworks_test.go
@@ -6,6 +6,7 @@
"testing"
"github.com/gophercloud/gophercloud/acceptance/clients"
+ "github.com/gophercloud/gophercloud/acceptance/tools"
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/tenantnetworks"
)
@@ -26,7 +27,7 @@
}
for _, network := range allTenantNetworks {
- PrintTenantNetwork(t, &network)
+ tools.PrintResource(t, network)
}
}
@@ -51,5 +52,5 @@
t.Fatalf("Unable to get network %s: %v", networkID, err)
}
- PrintTenantNetwork(t, network)
+ tools.PrintResource(t, network)
}
diff --git a/acceptance/openstack/compute/v2/volumeattach_test.go b/acceptance/openstack/compute/v2/volumeattach_test.go
index d791992..78d85a9 100644
--- a/acceptance/openstack/compute/v2/volumeattach_test.go
+++ b/acceptance/openstack/compute/v2/volumeattach_test.go
@@ -21,17 +21,12 @@
t.Fatalf("Unable to create a compute client: %v", err)
}
- choices, err :=clients.AcceptanceTestChoicesFromEnv()
- if err != nil {
- t.Fatal(err)
- }
-
blockClient, err := clients.NewBlockStorageV1Client()
if err != nil {
t.Fatalf("Unable to create a blockstorage client: %v", err)
}
- server, err := CreateServer(t, client, choices)
+ server, err := CreateServer(t, client)
if err != nil {
t.Fatalf("Unable to create server: %v", err)
}
@@ -53,7 +48,7 @@
}
defer DeleteVolumeAttachment(t, client, blockClient, server, volumeAttachment)
- PrintVolumeAttachment(t, volumeAttachment)
+ tools.PrintResource(t, volumeAttachment)
}