// Test volume attachment by volume ID func volumeAttach( t *testing.T, client types.Client, volumeID string) *types.Volume { log.WithField("volumeID", volumeID).Info("attaching volume") // Get next device name from executor nextDevice, err := client.Executor().NextDevice(context.Background().WithValue(context.ServiceKey, ebs.Name), utils.NewStore()) assert.NoError(t, err) if err != nil { t.Error("error getting next device name from executor") t.FailNow() } reply, token, err := client.API().VolumeAttach( nil, ebs.Name, volumeID, &types.VolumeAttachRequest{ NextDeviceName: &nextDevice, }) assert.NoError(t, err) if err != nil { t.Error("failed volumeAttach") t.FailNow() } apitests.LogAsJSON(reply, t) assert.NotEqual(t, token, "") return reply }
func volumeCopy( t *testing.T, client types.Client, volumeID, volumeName string) *types.Volume { fields := map[string]interface{}{ "volumeID": volumeID, "volumeName": volumeName, } log.WithFields(fields).Info("copying volume") volumeCopyRequest := &types.VolumeCopyRequest{ VolumeName: volumeName, } reply, err := client.API().VolumeCopy(nil, rackspace.Name, volumeID, volumeCopyRequest) assert.NoError(t, err) if err != nil { t.FailNow() t.Error("failed volumeCopy") } apitests.LogAsJSON(reply, t) assert.Equal(t, volumeName, reply.Name) return reply }
/////////////////////////////////////////////////////////////////////// ///////// PRIVATE TESTS FOR VOLUME FUNCTIONALITY ///////// /////////////////////////////////////////////////////////////////////// // Test volume creation specifying size and volume name func volumeCreate( t *testing.T, client types.Client, volumeName, tag string) *types.Volume { log.WithField("volumeName", volumeName).Info("creating volume") // Prepare request for storage driver call to create volume size := int64(1) opts := map[string]interface{}{ "priority": 2, "owner": "*****@*****.**", } volumeCreateRequest := &types.VolumeCreateRequest{ Name: volumeName, Size: &size, Opts: opts, } // Send request and retrieve created libStorage types.Volume reply, err := client.API().VolumeCreate(nil, ebs.Name, volumeCreateRequest) assert.NoError(t, err) if err != nil { t.FailNow() t.Error("failed volumeCreate") } apitests.LogAsJSON(reply, t) // If tag is set, then add tag to expected volumeName if tag != "" { volumeName = tag + ebs.TagDelimiter + volumeName } // Check if name and size are same assert.Equal(t, volumeName, reply.Name) assert.Equal(t, size, reply.Size) return reply }
func volumeInspectDetachedFail( t *testing.T, client types.Client, volumeID string) *types.Volume { log.WithField("volumeID", volumeID).Info("inspecting volume") reply, err := client.API().VolumeInspect(nil, rackspace.Name, volumeID, 0) assert.NoError(t, err) if err != nil { t.Error("failed volumeInspectDetachedFail") t.FailNow() } apitests.LogAsJSON(reply, t) assert.Len(t, reply.Attachments, 1) apitests.LogAsJSON(reply, t) return reply }
func volumeSnapshot( t *testing.T, client types.Client, volumeID, snapshotName string) *types.Snapshot { log.WithField("snapshotName", snapshotName).Info("creating snapshot") /* opts := map[string]interface{}{ "priority": 2, "owner": "*****@*****.**", }*/ volumeSnapshotRequest := &types.VolumeSnapshotRequest{ SnapshotName: snapshotName, // Opts: opts, } reply, err := client.API().VolumeSnapshot(nil, rackspace.Name, volumeID, volumeSnapshotRequest) assert.NoError(t, err) if err != nil { t.FailNow() t.Error("failed snapshotCreate") } apitests.LogAsJSON(reply, t) assert.Equal(t, snapshotName, reply.Name) assert.Equal(t, volumeID, reply.VolumeID) return reply }
func volumeCreate( t *testing.T, client types.Client, volumeName string) *types.Volume { log.WithField("volumeName", volumeName).Info("creating volume") size := int64(8) opts := map[string]interface{}{ "priority": 2, "owner": "*****@*****.**", } volumeCreateRequest := &types.VolumeCreateRequest{ Name: volumeName, Size: &size, Opts: opts, } reply, err := client.API().VolumeCreate(nil, rackspace.Name, volumeCreateRequest) assert.NoError(t, err) if err != nil { t.FailNow() t.Error("failed volumeCreate") } apitests.LogAsJSON(reply, t) assert.Equal(t, volumeName, reply.Name) assert.Equal(t, int64(75), reply.Size) return reply }
func TestSnapshotCopy(t *testing.T) { tf := func(config gofig.Config, client types.Client, t *testing.T) { snapshotName := "Snapshot from vfs-000-000" opts := map[string]interface{}{ "priority": 2, "owner": "*****@*****.**", } request := &types.SnapshotCopyRequest{ SnapshotName: snapshotName, Opts: opts, } reply, err := client.API().SnapshotCopy( nil, vfs.Name, "vfs-000-000", request) assert.NoError(t, err) apitests.LogAsJSON(reply, t) assert.Equal(t, snapshotName, reply.Name) assert.Equal(t, "vfs-000", reply.VolumeID) assert.Equal(t, "2", reply.Fields["priority"]) assert.Equal(t, "*****@*****.**", reply.Fields["owner"]) } apitests.Run(t, vfs.Name, newTestConfig(t), tf) }
// Test volume retrieval by volume ID using VolumeInspect, which directly // retrieves matching volumes from the storage driver. Contrast with // volumeByID, which uses Volumes to retrieve all volumes from the storage // driver without filtering, and filters the volumes externally. func volumeInspect( t *testing.T, client types.Client, volumeID string) *types.Volume { log.WithField("volumeID", volumeID).Info("inspecting volume") reply, err := client.API().VolumeInspect(nil, ebs.Name, volumeID, 0) assert.NoError(t, err) if err != nil { t.Error("failed volumeInspect") t.FailNow() } apitests.LogAsJSON(reply, t) return reply }
func snapshotInspect( t *testing.T, client types.Client, snapshotID string) *types.Snapshot { log.WithField("snapshotID", snapshotID).Info("inspecting snapshot") reply, err := client.API().SnapshotInspect(nil, rackspace.Name, snapshotID) assert.NoError(t, err) if err != nil { t.Error("failed snapshotInspect") t.FailNow() } apitests.LogAsJSON(reply, t) return reply }
// Test detaching volume by volume ID func volumeDetach( t *testing.T, client types.Client, volumeID string) *types.Volume { log.WithField("volumeID", volumeID).Info("detaching volume") reply, err := client.API().VolumeDetach( nil, ebs.Name, volumeID, &types.VolumeDetachRequest{}) assert.NoError(t, err) if err != nil { t.Error("failed volumeDetach") t.FailNow() } apitests.LogAsJSON(reply, t) assert.Len(t, reply.Attachments, 0) return reply }
func volumeAttach( t *testing.T, client types.Client, volumeID string) *types.Volume { log.WithField("volumeID", volumeID).Info("attaching volume") reply, token, err := client.API().VolumeAttach( nil, rackspace.Name, volumeID, &types.VolumeAttachRequest{}) assert.NoError(t, err) if err != nil { t.Error("failed volumeAttach") t.FailNow() } apitests.LogAsJSON(reply, t) assert.NotEqual(t, token, "") return reply }
func volumeInspectAttached( t *testing.T, client types.Client, volumeID string) *types.Volume { log.WithField("volumeID", volumeID).Info("inspecting volume") reply, err := client.API().VolumeInspect( nil, isilon.Name, volumeID, types.VolAttReqTrue) assert.NoError(t, err) if err != nil { t.Error("failed volumeInspectAttached") t.FailNow() } apitests.LogAsJSON(reply, t) assert.Len(t, reply.Attachments, 1) // assert.NotEqual(t, "", reply.Attachments[0].DeviceName) return reply }
func snapshotCopy( t *testing.T, client types.Client, snapshotID, snapshotName, destinationID string) *types.Snapshot { log.WithField("snapshotName", snapshotName).Info("copying snapshot") snapshotCopyRequest := &types.SnapshotCopyRequest{ SnapshotName: snapshotName, } reply, err := client.API().SnapshotCopy(nil, rackspace.Name, snapshotID, snapshotCopyRequest) assert.NoError(t, err) if err != nil { t.FailNow() t.Error("failed snapshotCopy") } apitests.LogAsJSON(reply, t) assert.Equal(t, snapshotName, reply.Name) return reply }
func volumeCreateFromSnapshot( t *testing.T, client types.Client, snapshotID, volumeName string) *types.Volume { fields := map[string]interface{}{ "snapshotID": snapshotID, "volumeName": volumeName, } log.WithFields(fields).Info("creating volume from snapshot") size := int64(8) opts := map[string]interface{}{ "priority": 2, "owner": "*****@*****.**", } volumeCreateRequest := &types.VolumeCreateRequest{ Name: volumeName, Size: &size, Opts: opts, } reply, err := client.API().VolumeCreateFromSnapshot(nil, rackspace.Name, snapshotID, volumeCreateRequest) assert.NoError(t, err) if err != nil { t.FailNow() t.Error("failed volumeCreateFromSnapshot") } apitests.LogAsJSON(reply, t) assert.Equal(t, volumeName, reply.Name) assert.Equal(t, size, reply.Size) assert.Equal(t, opts["priority"], 2) assert.Equal(t, opts["owner"], "*****@*****.**") return reply }