Exemple #1
0
func TestVolumeAttach(t *testing.T) {
	tf := func(config gofig.Config, client types.Client, t *testing.T) {

		nextDevice, err := client.Executor().NextDevice(
			context.Background().WithValue(context.ServiceKey, vfs.Name),
			utils.NewStore())
		assert.NoError(t, err)
		if err != nil {
			t.FailNow()
		}

		request := &types.VolumeAttachRequest{
			NextDeviceName: &nextDevice,
		}

		reply, attTokn, err := client.API().VolumeAttach(
			nil, vfs.Name, "vfs-002", request)
		assert.NoError(t, err)
		if reply == nil {
			t.FailNow()
		}
		assert.Equal(t, "/dev/xvdc", attTokn)
		assert.Equal(t, "vfs-002", reply.ID)
		assert.Equal(t, "/dev/xvdc", reply.Attachments[0].DeviceName)

	}
	apitests.Run(t, vfs.Name, newTestConfig(t), tf)
}
Exemple #2
0
func TestVolumeDetachAll(t *testing.T) {
	tc, _, vols, _ := newTestConfigAll(t)
	tf := func(config gofig.Config, client types.Client, t *testing.T) {
		request := &types.VolumeDetachRequest{}
		reply, err := client.API().VolumeDetachAll(
			nil, request)
		assert.NoError(t, err)
		for _, v := range vols {
			v.Attachments = nil
		}
		assert.Equal(t, 1, len(reply))
		assert.Equal(t, 3, len(reply[vfs.Name]))
		assert.EqualValues(t, vols, reply[vfs.Name])

		reply, err = client.API().Volumes(nil, types.VolAttReqTrue)
		assert.NoError(t, err)
		assert.Equal(t, 1, len(reply))
		assert.Equal(t, 0, len(reply[vfs.Name]))

		reply, err = client.API().Volumes(nil, 0)
		assert.NoError(t, err)
		assert.Equal(t, 1, len(reply))
		assert.Equal(t, 3, len(reply[vfs.Name]))
	}
	apitests.Run(t, vfs.Name, tc, tf)
}
Exemple #3
0
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)
}
Exemple #4
0
func TestVolumeCopy(t *testing.T) {
	tf := func(config gofig.Config, client types.Client, t *testing.T) {
		request := &types.VolumeCopyRequest{
			VolumeName: "Copy of Volume 000",
			Opts: map[string]interface{}{
				"priority": 7,
				"owner":    "*****@*****.**",
			},
		}

		reply, err := client.API().VolumeCopy(nil, vfs.Name, "vfs-000", request)
		assert.NoError(t, err)
		if err != nil {
			t.FailNow()
		}

		assert.NotNil(t, reply)

		assertVolDir(t, config, reply.ID, true)
		assert.Equal(t, "vfs-003", reply.ID)
		assert.Equal(t, request.VolumeName, reply.Name)
		assert.Equal(t, "7", reply.Fields["priority"])
		assert.Equal(t, request.Opts["owner"], reply.Fields["owner"])
	}

	apitests.Run(t, vfs.Name, newTestConfig(t), tf)
}
Exemple #5
0
///////////////////////////////////////////////////////////////////////
/////////                    PUBLIC TESTS                     /////////
///////////////////////////////////////////////////////////////////////
// Test if backwards compatibility for "ec2" and "ebs" work in config
func TestConfig(t *testing.T) {
	if skipTests() {
		t.SkipNow()
	}
	tfEBS := func(config gofig.Config, client types.Client, t *testing.T) {
		assert.NotEqual(t, config.GetString("ebs.tag"), "")
		assert.Equal(t, config.GetString("ec2.tag"), "")
	}
	tfEC2 := func(config gofig.Config, client types.Client, t *testing.T) {
		assert.NotEqual(t, config.GetString("ec2.tag"), "")
		assert.Equal(t, config.GetString("ebs.tag"), "")
	}
	apitests.Run(t, "ec2", configYAMLebs, tfEBS)
	apitests.Run(t, "ec2", configYAMLec2, tfEC2)
	apitests.Run(t, ebs.Name, configYAMLebs, tfEBS)
	apitests.Run(t, ebs.Name, configYAMLec2, tfEC2)
}
Exemple #6
0
func TestVolumeCreateRemove(t *testing.T) { //PASSES lowercase hidden for testing other stuff
	if skipTests() {
		t.SkipNow()
	}
	tf := func(config gofig.Config, client types.Client, t *testing.T) {
		vol := volumeCreate(t, client, volumeName)
		volumeRemove(t, client, vol.ID)
	}
	apitests.Run(t, rackspace.Name, configYAML, tf)
}
Exemple #7
0
func TestServiceInpspect(t *testing.T) {
	tf := func(config gofig.Config, client types.Client, t *testing.T) {

		reply, err := client.API().ServiceInspect(nil, vfs.Name)
		assert.NoError(t, err)
		assert.Equal(t, vfs.Name, reply.Name)
		assert.Equal(t, vfs.Name, reply.Driver.Name)
		assert.True(t, reply.Driver.NextDevice.Ignore)
	}
	apitests.Run(t, vfs.Name, newTestConfig(t), tf)
}
Exemple #8
0
func TestClient(t *testing.T) {
	apitests.Run(t, vfs.Name, newTestConfig(t),
		func(config gofig.Config, client types.Client, t *testing.T) {
			ctx := context.Background()
			iid, err := client.Executor().InstanceID(
				ctx.WithValue(context.ServiceKey, vfs.Name),
				utils.NewStore())
			assert.NoError(t, err)
			assert.NotNil(t, iid)
		})
}
Exemple #9
0
func TestVolumeCreateRemove(t *testing.T) {
	if skipTests() {
		t.SkipNow()
	}

	tf := func(config gofig.Config, client types.Client, t *testing.T) {
		vol := volumeCreate(t, client, volumeName)
		volumeRemove(t, client, vol.ID)
	}
	apitests.Run(t, sio.Name, configYAML, tf)
}
Exemple #10
0
// Test volume functionality from storage driver
func TestEncryptedVolumeCreateRemove(t *testing.T) {
	if skipTests() {
		t.SkipNow()
	}

	tf := func(config gofig.Config, client types.Client, t *testing.T) {
		vol := volumeCreateEncrypted(t, client, volumeName, config.GetString("ec2.tag"))
		volumeRemove(t, client, vol.ID)
	}
	//apitests.Run(t, ebs.Name, configYAMLec2, tf)
	apitests.Run(t, "ebs", configYAMLec2, tf)
}
Exemple #11
0
func TestInstanceID(t *testing.T) {
	iid, err := instanceID()
	assert.NoError(t, err)
	if err != nil {
		t.FailNow()
	}
	apitests.Run(
		t, vfs.Name, newTestConfig(t),
		(&apitests.InstanceIDTest{
			Driver:   vfs.Name,
			Expected: iid,
		}).Test)
}
Exemple #12
0
func TestVolumeInspectWithAttachments(t *testing.T) {
	tc, _, vols, _ := newTestConfigAll(t)
	tf := func(config gofig.Config, client types.Client, t *testing.T) {
		reply, err := client.API().VolumeInspect(
			nil, "vfs", "vfs-000", types.VolAttReqTrue)
		if err != nil {
			t.Fatal(err)
		}
		assert.NotNil(t, reply)
		assert.EqualValues(t, vols[reply.ID], reply)
	}
	apitests.Run(t, vfs.Name, tc, tf)
}
Exemple #13
0
func TestStorageDriverVolumes(t *testing.T) {
	apitests.Run(t, vfs.Name, newTestConfig(t),
		func(config gofig.Config, client types.Client, t *testing.T) {

			vols, err := client.Storage().Volumes(
				context.Background().WithValue(
					context.ServiceKey, vfs.Name),
				&types.VolumesOpts{
					Attachments: types.VolAttReqTrue,
					Opts:        utils.NewStore()})
			assert.NoError(t, err)
			assert.Len(t, vols, 2)
		})
}
Exemple #14
0
func TestSnapshotsByService(t *testing.T) {
	tc, _, _, snaps := newTestConfigAll(t)
	tf := func(config gofig.Config, client types.Client, t *testing.T) {
		reply, err := client.API().SnapshotsByService(nil, "vfs")
		if err != nil {
			t.Fatal(err)
		}
		for snapshotID, snapshot := range snaps {
			assert.NotNil(t, reply[snapshotID])
			assert.EqualValues(t, snapshot, reply[snapshotID])
		}
	}
	apitests.Run(t, vfs.Name, tc, tf)
}
Exemple #15
0
func TestServices(t *testing.T) { //PASSES lowercase hidden for testing other stuff
	if skipTests() {
		t.SkipNow()
	}

	tf := func(config gofig.Config, client types.Client, t *testing.T) {
		reply, err := client.API().Services(nil)
		assert.NoError(t, err)
		assert.Equal(t, len(reply), 1)

		_, ok := reply[rackspace.Name]
		assert.True(t, ok)
	}
	apitests.Run(t, rackspace.Name, configYAML, tf)
}
Exemple #16
0
// TestVolumeAttach TODO how many times did I instruct people to use RunGroup
// for situations exactly like this? Fix it.
func TestVolumeAttach(t *testing.T) {
	if skipTests() {
		t.SkipNow()
	}
	var vol *types.Volume
	tf := func(config gofig.Config, client types.Client, t *testing.T) {
		vol = volumeCreate(t, client, volumeName)
		_ = volumeAttach(t, client, vol.ID)
		_ = volumeInspectAttached(t, client, vol.ID)
		_ = volumeDetach(t, client, vol.ID)
		_ = volumeInspectDetached(t, client, vol.ID)
		volumeRemove(t, client, vol.ID)
	}
	apitests.Run(t, isilon.Name, configYAML, tf)
}
Exemple #17
0
func TestVolumesByService(t *testing.T) {
	tc, _, vols, _ := newTestConfigAll(t)
	tf := func(config gofig.Config, client types.Client, t *testing.T) {
		reply, err := client.API().VolumesByService(nil, "vfs", 0)
		if err != nil {
			t.Fatal(err)
		}
		for volumeID, volume := range vols {
			volume.Attachments = nil
			assert.NotNil(t, reply[volumeID])
			assert.EqualValues(t, volume, reply[volumeID])
		}
	}
	apitests.Run(t, vfs.Name, tc, tf)
}
Exemple #18
0
// Test if Services are configured and returned properly from the client
func TestServices(t *testing.T) {
	if skipTests() {
		t.SkipNow()
	}

	tf := func(config gofig.Config, client types.Client, t *testing.T) {
		reply, err := client.API().Services(nil)
		assert.NoError(t, err)
		assert.Equal(t, len(reply), 1)

		_, ok := reply[ebs.Name]
		assert.True(t, ok)
	}
	tf2 := func(config gofig.Config, client types.Client, t *testing.T) {
		reply, err := client.API().Services(nil)
		assert.NoError(t, err)
		assert.Equal(t, len(reply), 1)

		_, ok := reply["ec2"]
		assert.True(t, ok)
	}
	apitests.Run(t, ebs.Name, configYAMLec2, tf)
	apitests.Run(t, "ec2", configYAMLec2, tf2)
}
Exemple #19
0
func TestVolumesWithAttachmentsUnattached(t *testing.T) {
	tc, _, _, _ := newTestConfigAll(t)
	tf := func(config gofig.Config, client types.Client, t *testing.T) {
		reply, err := client.API().Volumes(nil,
			types.VolAttReqOnlyUnattachedVols)
		if err != nil {
			t.Fatal(err)
		}

		assert.Nil(t, reply["vfs"]["vfs-000"])
		assert.Nil(t, reply["vfs"]["vfs-001"])
		assert.NotNil(t, reply["vfs"]["vfs-002"])
		assert.Len(t, reply["vfs"]["vfs-002"].Attachments, 0)
	}
	apitests.Run(t, vfs.Name, tc, tf)
}
Exemple #20
0
func TestInstance(t *testing.T) {
	iid, err := instanceID()
	assert.NoError(t, err)
	if err != nil {
		t.FailNow()
	}
	apitests.Run(
		t, vfs.Name, nil,
		(&apitests.InstanceTest{
			Driver: vfs.Name,
			Expected: &types.Instance{
				InstanceID: iid,
				Name:       "vfsInstance",
			},
		}).Test)
}
Exemple #21
0
// Test volume functionality from storage driver
func TestVolumeAttach(t *testing.T) {
	if skipTests() {
		t.SkipNow()
	}
	var vol *types.Volume
	tf := func(config gofig.Config, client types.Client, t *testing.T) {
		vol = volumeCreate(t, client, volumeName, config.GetString("ec2.tag"))
		_ = volumeAttach(t, client, vol.ID)
		_ = volumeInspectAttached(t, client, vol.ID)
		_ = volumeInspectDetachedFail(t, client, vol.ID)
		_ = volumeDetach(t, client, vol.ID)
		_ = volumeInspectDetached(t, client, vol.ID)
		volumeRemove(t, client, vol.ID)
	}
	apitests.Run(t, ebs.Name, configYAMLec2, tf)
}
Exemple #22
0
func TestVolumeAttach(t *testing.T) { //PASSES lowercase hidden to test other stuff
	if skipTests() {
		t.SkipNow()
	}
	var vol *types.Volume
	tf := func(config gofig.Config, client types.Client, t *testing.T) {
		vol = volumeCreate(t, client, volumeName)
		_ = volumeAttach(t, client, vol.ID)
		_ = volumeInspectAttached(t, client, vol.ID)
		_ = volumeInspectDetachedFail(t, client, vol.ID)
		_ = volumeDetach(t, client, vol.ID)
		_ = volumeInspectDetached(t, client, vol.ID)
		volumeRemove(t, client, vol.ID)
	}
	apitests.Run(t, rackspace.Name, configYAML, tf)
}
Exemple #23
0
func TestVolumeSnapshot(t *testing.T) {
	tf := func(config gofig.Config, client types.Client, t *testing.T) {
		volumeID := "vfs-000"
		snapshotName := "snapshot1"
		opts := map[string]interface{}{
			"priority": 2,
		}

		request := &types.VolumeSnapshotRequest{
			SnapshotName: snapshotName,
			Opts:         opts,
		}

		reply, err := client.API().VolumeSnapshot(
			nil, vfs.Name, volumeID, request)
		assert.NoError(t, err)
		if err != nil {
			t.FailNow()
		}
		assert.Equal(t, snapshotName, reply.Name)
		assert.Equal(t, volumeID, reply.VolumeID)

		snap, err := client.API().SnapshotInspect(nil, vfs.Name, reply.ID)
		assert.NoError(t, err)
		if err != nil {
			t.FailNow()
		}
		assert.Equal(t, snapshotName, snap.Name)
		assert.Equal(t, volumeID, snap.VolumeID)

		snapCountEqual := false
		for x := 0; x < 10; x++ {
			time.Sleep(time.Duration(1) * time.Second)
			snapshots, err := client.API().SnapshotsByService(nil, vfs.Name)
			if !assert.NoError(t, err) {
				t.FailNow()
			}
			if len(snapshots) != 10 {
				continue
			}
			snapCountEqual = assert.EqualValues(t, 10, len(snapshots))
			break
		}
		assert.True(t, snapCountEqual)
	}
	apitests.Run(t, vfs.Name, newTestConfig(t), tf)
}
Exemple #24
0
func TestVolumeDetach(t *testing.T) {
	tf := func(config gofig.Config, client types.Client, t *testing.T) {
		request := &types.VolumeDetachRequest{}
		reply, err := client.API().VolumeDetach(
			nil, vfs.Name, "vfs-001", request)
		assert.NoError(t, err)
		assert.Equal(t, "vfs-001", reply.ID)
		assert.Equal(t, 0, len(reply.Attachments))

		reply, err = client.API().VolumeInspect(
			nil, vfs.Name, "vfs-001", 0)
		assert.NoError(t, err)
		assert.Equal(t, "vfs-001", reply.ID)
		assert.Equal(t, 0, len(reply.Attachments))
	}
	apitests.Run(t, vfs.Name, newTestConfig(t), tf)
}
Exemple #25
0
// Test volume functionality from storage driver
func TestVolumes(t *testing.T) {
	if skipTests() {
		t.SkipNow()
	}

	tf := func(config gofig.Config, client types.Client, t *testing.T) {
		_ = volumeCreate(t, client, volumeName, config.GetString("ec2.tag"))
		_ = volumeCreate(t, client, volumeName2, config.GetString("ec2.tag"))

		vol1 := volumeByName(t, client, volumeName, config.GetString("ec2.tag"))
		vol2 := volumeByName(t, client, volumeName2, config.GetString("ec2.tag"))

		volumeRemove(t, client, vol1.ID)
		volumeRemove(t, client, vol2.ID)
	}
	apitests.Run(t, ebs.Name, configYAMLec2, tf)
}
Exemple #26
0
func TestSnapshotRemove(t *testing.T) {
	tf := func(config gofig.Config, client types.Client, t *testing.T) {
		reply, err := client.API().SnapshotInspect(nil, "vfs", "vfs-000-002")
		assert.NoError(t, err)
		assert.NotNil(t, reply)
		assert.Equal(t, "vfs-000-002", reply.ID)

		err = client.API().SnapshotRemove(nil, "vfs", reply.ID)
		assert.NoError(t, err)

		reply, err = client.API().SnapshotInspect(nil, "vfs", "vfs-000-002")
		assert.Error(t, err)
		assert.Nil(t, reply)

	}
	apitests.Run(t, vfs.Name, newTestConfig(t), tf)
}
Exemple #27
0
func TestVolumes(t *testing.T) {
	if skipTests() {
		t.SkipNow()
	}

	tf := func(config gofig.Config, client types.Client, t *testing.T) {
		_ = volumeCreate(t, client, volumeName)
		_ = volumeCreate(t, client, volumeName2)

		_ = volumeByName(t, client, "tt1")
		vol1 := volumeByName(t, client, volumeName)
		vol2 := volumeByName(t, client, volumeName2)

		volumeRemove(t, client, vol1.ID)
		volumeRemove(t, client, vol2.ID)
	}
	apitests.Run(t, isilon.Name, configYAML, tf)
}
Exemple #28
0
func TestInstanceID(t *testing.T) {
	if skipTests() {
		t.SkipNow()
	}

	iid, err := siox.GetInstanceID()
	assert.NoError(t, err)
	if err != nil {
		t.Error("failed TestInstanceID")
		t.FailNow()
	}
	assert.NotEqual(t, iid, "")

	apitests.Run(
		t, sio.Name, configYAML,
		(&apitests.InstanceIDTest{
			Driver:   sio.Name,
			Expected: iid,
		}).Test)
}
Exemple #29
0
// Check if InstanceID metadata is properly returned by executor
// and InstanceID.ID is filled out by InstanceInspect
func TestInstanceID(t *testing.T) {
	if skipTests() {
		t.SkipNow()
	}

	// create storage driver
	sd, err := registry.NewStorageDriver(ebs.Name)
	if err != nil {
		t.Fatal(err)
	}

	// initialize storage driver
	ctx := context.Background()
	if err := sd.Init(ctx, registry.NewConfig()); err != nil {
		t.Fatal(err)
	}
	// Get Instance ID metadata from executor
	iid, err := ebsUtils.InstanceID(ctx)
	assert.NoError(t, err)
	if err != nil {
		t.Fatal(err)
	}

	// Fill in Instance ID's ID field with InstanceInspect
	ctx = ctx.WithValue(context.InstanceIDKey, iid)
	i, err := sd.InstanceInspect(ctx, utils.NewStore())
	if err != nil {
		t.Fatal(err)
	}

	iid = i.InstanceID

	// test resulting InstanceID
	apitests.Run(
		t, ebs.Name, nil,
		(&apitests.InstanceIDTest{
			Driver:   ebs.Name,
			Expected: iid,
		}).Test)

}
Exemple #30
0
func TestVolumeCreate(t *testing.T) {
	tf := func(config gofig.Config, client types.Client, t *testing.T) {
		volumeName := "Volume 003"
		availabilityZone := "US"
		iops := int64(1000)
		size := int64(10240)
		volType := "myType"

		opts := map[string]interface{}{
			"priority": 2,
			"owner":    "*****@*****.**",
		}

		request := &types.VolumeCreateRequest{
			Name:             volumeName,
			AvailabilityZone: &availabilityZone,
			IOPS:             &iops,
			Size:             &size,
			Type:             &volType,
			Opts:             opts,
		}

		reply, err := client.API().VolumeCreate(nil, vfs.Name, request)
		assert.NoError(t, err)
		if err != nil {
			t.FailNow()
		}
		assert.NotNil(t, reply)

		assertVolDir(t, config, reply.ID, true)
		assert.Equal(t, availabilityZone, reply.AvailabilityZone)
		assert.Equal(t, iops, reply.IOPS)
		assert.Equal(t, volumeName, reply.Name)
		assert.Equal(t, size, reply.Size)
		assert.Equal(t, volType, reply.Type)
		assert.Equal(t, "2", reply.Fields["priority"])
		assert.Equal(t, "*****@*****.**", reply.Fields["owner"])
	}

	apitests.Run(t, vfs.Name, newTestConfig(t), tf)
}