func TestVolumeFromImageScenarios(t *testing.T) {
	if testing.Short() {
		t.Skip("skipping test in short mode.")
	}

	imageID := os.Getenv("VATestImageID")

	if imageID == "" {
		t.Skip("Skipping test as not all env variables are set: 'VATestImageID'")
	}

	authenticator, err := identity.AuthenticateFromEnvVars()
	if err != nil {
		t.Fatal("Cannot authenticate from env vars:", err)
	}

	blockstorageService := blockstorage.NewService(authenticator)

	volumeTypes, err := blockstorageService.VolumeTypes()
	if err != nil {
		t.Fatal("Cannot access volumeTypes:", err)
	}

	volumes, err := blockstorageService.Volumes()
	if err != nil {
		t.Fatal("Cannot access volumes:", err)
	}

	if len(volumes) > 0 {
		_, err := blockstorageService.Volume(volumes[0].ID)
		if err != nil {
			t.Fatal("Cannot requery volume:", err)
		}
	}

	createVolumeParameters := blockstorage.CreateVolumeParameters{
		DisplayName: "TestVolumeDisplayNameFromImage",
		Desciption:  "test description",
		VolumeType:  volumeTypes[0].ID,
		Size:        5,
		ImageRef:    imageID,
	}

	createdVolume, err := blockstorageService.CreateVolume(createVolumeParameters)
	if err != nil {
		t.Fatal("Cannot create volume:", err)
	}

	queriedVolume, err := blockstorageService.Volume(createdVolume.ID)
	if err != nil {
		t.Fatal("Cannot requery volume:", err)
	}

	err = blockstorageService.DeleteVolume(queriedVolume.ID)
	if err != nil {
		t.Fatal("Cannot delete volume:", err)
	}
}
func TestVolumeTypeScenarios(t *testing.T) {
	if testing.Short() {
		t.Skip("skipping test in short mode.")
	}

	authenticator, err := identity.AuthenticateFromEnvVars()
	if err != nil {
		t.Fatal("Cannot authenticate from env vars:", err)
	}

	blockstorageService := blockstorage.NewService(authenticator)

	volumeTypes, err := blockstorageService.VolumeTypes()
	if err != nil {
		t.Fatal("Cannot access volumeTypes:", err)
	}

	if len(volumeTypes) > 0 {
		_, err := blockstorageService.VolumeType(volumeTypes[0].ID)
		if err != nil {
			t.Fatal("Cannot requery volume type:", err)
		}
	}

	createVolumeParameters := blockstorage.CreateVolumeTypeParameters{Name: "nonstandard"}

	createdVolumeType, err := blockstorageService.CreateVolumeType(createVolumeParameters)

	skipRestOfTest := false
	if err != nil {
		status, ok := err.(misc.HTTPStatus)

		if ok && status.StatusCode == 404 || status.StatusCode == 403 {
			t.Log("Cannot test volume type create, so not attempting to delete.")
			skipRestOfTest = true
		} else {
			t.Fatal("Cannot create volume type:", err)
		}
	}

	if !skipRestOfTest {
		queriedVolumeType, err := blockstorageService.VolumeType(createdVolumeType.ID)
		if err != nil {
			t.Fatal("Cannot requery volume type:", err)
		}

		err = blockstorageService.DeleteVolumeType(queriedVolumeType.ID)
		if err != nil {
			t.Fatal("Cannot delete volume type:", err)
		}
	}
}
예제 #3
0
func CreateVolumeService(url string) blockstorage.Service {
	return blockstorage.NewService(common.SimpleAuthenticator{Token: tokn, ServiceURL: url})
}