move block storage extensions from 'v2' to 'blockstorage' (#112)
diff --git a/acceptance/openstack/blockstorage/extensions/extensions.go b/acceptance/openstack/blockstorage/extensions/extensions.go
new file mode 100644
index 0000000..05a3e12
--- /dev/null
+++ b/acceptance/openstack/blockstorage/extensions/extensions.go
@@ -0,0 +1,97 @@
+// Package extensions contains common functions for creating block storage
+// resources that are extensions of the block storage API. See the `*_test.go`
+// files for example usages.
+package extensions
+
+import (
+ "testing"
+
+ "github.com/gophercloud/gophercloud"
+ "github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/volumeactions"
+ "github.com/gophercloud/gophercloud/openstack/blockstorage/v2/volumes"
+ "github.com/gophercloud/gophercloud/openstack/compute/v2/servers"
+)
+
+// CreateVolumeAttach will attach a volume to an instance. An error will be
+// returned if the attachment failed.
+func CreateVolumeAttach(t *testing.T, client *gophercloud.ServiceClient, volume *volumes.Volume, server *servers.Server) error {
+ if testing.Short() {
+ t.Skip("Skipping test that requires volume attachment in short mode.")
+ }
+
+ attachOpts := volumeactions.AttachOpts{
+ MountPoint: "/mnt",
+ Mode: "rw",
+ InstanceUUID: server.ID,
+ }
+
+ t.Logf("Attempting to attach volume %s to server %s", volume.ID, server.ID)
+
+ if err := volumeactions.Attach(client, volume.ID, attachOpts).ExtractErr(); err != nil {
+ return err
+ }
+
+ if err := volumes.WaitForStatus(client, volume.ID, "in-use", 60); err != nil {
+ return err
+ }
+
+ t.Logf("Attached volume %s to server %s", volume.ID, server.ID)
+
+ return nil
+}
+
+// CreateVolumeReserve creates a volume reservation. An error will be returned
+// if the reservation failed.
+func CreateVolumeReserve(t *testing.T, client *gophercloud.ServiceClient, volume *volumes.Volume) error {
+ if testing.Short() {
+ t.Skip("Skipping test that requires volume reservation in short mode.")
+ }
+
+ t.Logf("Attempting to reserve volume %s", volume.ID)
+
+ if err := volumeactions.Reserve(client, volume.ID).ExtractErr(); err != nil {
+ return err
+ }
+
+ t.Logf("Reserved volume %s", volume.ID)
+
+ return nil
+}
+
+// DeleteVolumeAttach will detach a volume from an instance. A fatal error will
+// occur if the snapshot failed to be deleted. This works best when used as a
+// deferred function.
+func DeleteVolumeAttach(t *testing.T, client *gophercloud.ServiceClient, volume *volumes.Volume) {
+ t.Logf("Attepting to detach volume volume: %s", volume.ID)
+
+ detachOpts := volumeactions.DetachOpts{
+ AttachmentID: volume.Attachments[0].AttachmentID,
+ }
+
+ if err := volumeactions.Detach(client, volume.ID, detachOpts).ExtractErr(); err != nil {
+ t.Fatalf("Unable to detach volume %s: %v", volume.ID, err)
+ }
+
+ if err := volumes.WaitForStatus(client, volume.ID, "available", 60); err != nil {
+ t.Fatalf("Volume %s failed to become unavailable in 60 seconds: %v", volume.ID, err)
+ }
+
+ t.Logf("Detached volume: %s", volume.ID)
+}
+
+// DeleteVolumeReserve deletes a volume reservation. A fatal error will occur
+// if the deletion request failed. This works best when used as a deferred
+// function.
+func DeleteVolumeReserve(t *testing.T, client *gophercloud.ServiceClient, volume *volumes.Volume) {
+ if testing.Short() {
+ t.Skip("Skipping test that requires volume reservation in short mode.")
+ }
+
+ t.Logf("Attempting to unreserve volume %s", volume.ID)
+
+ if err := volumeactions.Unreserve(client, volume.ID).ExtractErr(); err != nil {
+ t.Fatalf("Unable to unreserve volume %s: %v", volume.ID, err)
+ }
+
+ t.Logf("Unreserved volume %s", volume.ID)
+}
diff --git a/acceptance/openstack/blockstorage/extensions/pkg.go b/acceptance/openstack/blockstorage/extensions/pkg.go
new file mode 100644
index 0000000..f18039d
--- /dev/null
+++ b/acceptance/openstack/blockstorage/extensions/pkg.go
@@ -0,0 +1,3 @@
+// The extensions package contains acceptance tests for the Openstack Cinder extensions service.
+
+package extensions
diff --git a/acceptance/openstack/blockstorage/extensions/volumeactions_test.go b/acceptance/openstack/blockstorage/extensions/volumeactions_test.go
new file mode 100644
index 0000000..83d1571
--- /dev/null
+++ b/acceptance/openstack/blockstorage/extensions/volumeactions_test.go
@@ -0,0 +1,118 @@
+// +build acceptance blockstorage
+
+package extensions
+
+import (
+ "testing"
+
+ "github.com/gophercloud/gophercloud/acceptance/clients"
+ "github.com/gophercloud/gophercloud/openstack/blockstorage/v2/volumes"
+
+ blockstorage "github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/v2"
+ compute "github.com/gophercloud/gophercloud/acceptance/openstack/compute/v2"
+)
+
+func TestVolumeActionsAttachCreateDestroy(t *testing.T) {
+ blockClient, err := clients.NewBlockStorageV2Client()
+ if err != nil {
+ t.Fatalf("Unable to create a blockstorage client: %v", err)
+ }
+
+ computeClient, err := clients.NewComputeV2Client()
+ if err != nil {
+ t.Fatalf("Unable to create a compute client: %v", err)
+ }
+
+ choices, err := clients.AcceptanceTestChoicesFromEnv()
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ server, err := compute.CreateServer(t, computeClient, choices)
+ if err != nil {
+ t.Fatalf("Unable to create server: %v", err)
+ }
+ defer compute.DeleteServer(t, computeClient, server)
+
+ volume, err := blockstorage.CreateVolume(t, blockClient)
+ if err != nil {
+ t.Fatalf("Unable to create volume: %v", err)
+ }
+ defer blockstorage.DeleteVolume(t, blockClient, volume)
+
+ err = CreateVolumeAttach(t, blockClient, volume, server)
+ if err != nil {
+ t.Fatalf("Unable to attach volume: %v", err)
+ }
+
+ newVolume, err := volumes.Get(blockClient, volume.ID).Extract()
+ if err != nil {
+ t.Fatal("Unable to get updated volume information: %v", err)
+ }
+
+ DeleteVolumeAttach(t, blockClient, newVolume)
+}
+
+func TestVolumeActionsReserveUnreserve(t *testing.T) {
+ client, err := clients.NewBlockStorageV2Client()
+ if err != nil {
+ t.Fatalf("Unable to create blockstorage client: %v", err)
+ }
+
+ volume, err := blockstorage.CreateVolume(t, client)
+ if err != nil {
+ t.Fatalf("Unable to create volume: %v", err)
+ }
+ defer blockstorage.DeleteVolume(t, client, volume)
+
+ err = CreateVolumeReserve(t, client, volume)
+ if err != nil {
+ t.Fatalf("Unable to create volume reserve: %v", err)
+ }
+ defer DeleteVolumeReserve(t, client, volume)
+}
+
+// Note(jtopjian): I plan to work on this at some point, but it requires
+// setting up a server with iscsi utils.
+/*
+func TestVolumeConns(t *testing.T) {
+ client, err := newClient()
+ th.AssertNoErr(t, err)
+
+ t.Logf("Creating volume")
+ cv, err := volumes.Create(client, &volumes.CreateOpts{
+ Size: 1,
+ Name: "blockv2-volume",
+ }).Extract()
+ th.AssertNoErr(t, err)
+
+ defer func() {
+ err = volumes.WaitForStatus(client, cv.ID, "available", 60)
+ th.AssertNoErr(t, err)
+
+ t.Logf("Deleting volume")
+ err = volumes.Delete(client, cv.ID).ExtractErr()
+ th.AssertNoErr(t, err)
+ }()
+
+ err = volumes.WaitForStatus(client, cv.ID, "available", 60)
+ th.AssertNoErr(t, err)
+
+ connOpts := &volumeactions.ConnectorOpts{
+ IP: "127.0.0.1",
+ Host: "stack",
+ Initiator: "iqn.1994-05.com.redhat:17cf566367d2",
+ Multipath: false,
+ Platform: "x86_64",
+ OSType: "linux2",
+ }
+
+ t.Logf("Initializing connection")
+ _, err = volumeactions.InitializeConnection(client, cv.ID, connOpts).Extract()
+ th.AssertNoErr(t, err)
+
+ t.Logf("Terminating connection")
+ err = volumeactions.TerminateConnection(client, cv.ID, connOpts).ExtractErr()
+ th.AssertNoErr(t, err)
+}
+*/