| // +build acceptance compute bootfromvolume |
| |
| package v2 |
| |
| import ( |
| "testing" |
| |
| "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" |
| ) |
| |
| func TestBootFromImage(t *testing.T) { |
| if testing.Short() { |
| t.Skip("Skipping test that requires server creation in short mode.") |
| } |
| |
| client, 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) |
| } |
| |
| blockDevices := []bootfromvolume.BlockDevice{ |
| bootfromvolume.BlockDevice{ |
| BootIndex: 0, |
| DeleteOnTermination: true, |
| DestinationType: bootfromvolume.DestinationLocal, |
| SourceType: bootfromvolume.SourceImage, |
| UUID: choices.ImageID, |
| }, |
| } |
| |
| server, err := CreateBootableVolumeServer(t, client, blockDevices) |
| if err != nil { |
| t.Fatalf("Unable to create server: %v", err) |
| } |
| defer DeleteServer(t, client, server) |
| |
| tools.PrintResource(t, server) |
| } |
| |
| func TestBootFromNewVolume(t *testing.T) { |
| if testing.Short() { |
| t.Skip("Skipping test that requires server creation in short mode.") |
| } |
| |
| client, 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) |
| } |
| |
| blockDevices := []bootfromvolume.BlockDevice{ |
| bootfromvolume.BlockDevice{ |
| DeleteOnTermination: true, |
| DestinationType: bootfromvolume.DestinationVolume, |
| SourceType: bootfromvolume.SourceImage, |
| UUID: choices.ImageID, |
| VolumeSize: 2, |
| }, |
| } |
| |
| server, err := CreateBootableVolumeServer(t, client, blockDevices) |
| if err != nil { |
| t.Fatalf("Unable to create server: %v", err) |
| } |
| defer DeleteServer(t, client, server) |
| |
| tools.PrintResource(t, server) |
| } |
| |
| func TestBootFromExistingVolume(t *testing.T) { |
| if testing.Short() { |
| t.Skip("Skipping test that requires server creation in short mode.") |
| } |
| |
| computeClient, err := clients.NewComputeV2Client() |
| if err != nil { |
| t.Fatalf("Unable to create a compute client: %v", err) |
| } |
| |
| blockStorageClient, err := clients.NewBlockStorageV2Client() |
| if err != nil { |
| t.Fatalf("Unable to create a block storage client: %v", err) |
| } |
| |
| volume, err := blockstorage.CreateVolumeFromImage(t, blockStorageClient) |
| if err != nil { |
| t.Fatal(err) |
| } |
| |
| blockDevices := []bootfromvolume.BlockDevice{ |
| bootfromvolume.BlockDevice{ |
| DeleteOnTermination: true, |
| DestinationType: bootfromvolume.DestinationVolume, |
| SourceType: bootfromvolume.SourceVolume, |
| UUID: volume.ID, |
| }, |
| } |
| |
| server, err := CreateBootableVolumeServer(t, computeClient, blockDevices) |
| if err != nil { |
| t.Fatalf("Unable to create server: %v", err) |
| } |
| defer DeleteServer(t, computeClient, server) |
| |
| tools.PrintResource(t, server) |
| } |
| |
| func TestBootFromMultiEphemeralServer(t *testing.T) { |
| if testing.Short() { |
| t.Skip("Skipping test that requires server creation in short mode.") |
| } |
| |
| client, 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) |
| } |
| |
| blockDevices := []bootfromvolume.BlockDevice{ |
| bootfromvolume.BlockDevice{ |
| BootIndex: 0, |
| DestinationType: bootfromvolume.DestinationLocal, |
| DeleteOnTermination: true, |
| SourceType: bootfromvolume.SourceImage, |
| UUID: choices.ImageID, |
| VolumeSize: 5, |
| }, |
| bootfromvolume.BlockDevice{ |
| BootIndex: -1, |
| DestinationType: bootfromvolume.DestinationLocal, |
| DeleteOnTermination: true, |
| GuestFormat: "ext4", |
| SourceType: bootfromvolume.SourceBlank, |
| VolumeSize: 1, |
| }, |
| bootfromvolume.BlockDevice{ |
| BootIndex: -1, |
| DestinationType: bootfromvolume.DestinationLocal, |
| DeleteOnTermination: true, |
| GuestFormat: "ext4", |
| SourceType: bootfromvolume.SourceBlank, |
| VolumeSize: 1, |
| }, |
| } |
| |
| server, err := CreateMultiEphemeralServer(t, client, blockDevices) |
| if err != nil { |
| t.Fatalf("Unable to create server: %v", err) |
| } |
| defer DeleteServer(t, client, server) |
| |
| tools.PrintResource(t, server) |
| } |
| |
| func TestAttachNewVolume(t *testing.T) { |
| if testing.Short() { |
| t.Skip("Skipping test that requires server creation in short mode.") |
| } |
| |
| client, 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) |
| } |
| |
| blockDevices := []bootfromvolume.BlockDevice{ |
| bootfromvolume.BlockDevice{ |
| BootIndex: 0, |
| DeleteOnTermination: true, |
| DestinationType: bootfromvolume.DestinationLocal, |
| SourceType: bootfromvolume.SourceImage, |
| UUID: choices.ImageID, |
| }, |
| bootfromvolume.BlockDevice{ |
| BootIndex: 1, |
| DeleteOnTermination: true, |
| DestinationType: bootfromvolume.DestinationVolume, |
| SourceType: bootfromvolume.SourceBlank, |
| VolumeSize: 2, |
| }, |
| } |
| |
| server, err := CreateBootableVolumeServer(t, client, blockDevices) |
| if err != nil { |
| t.Fatalf("Unable to create server: %v", err) |
| } |
| defer DeleteServer(t, client, server) |
| |
| tools.PrintResource(t, server) |
| } |
| |
| func TestAttachExistingVolume(t *testing.T) { |
| if testing.Short() { |
| t.Skip("Skipping test that requires server creation in short mode.") |
| } |
| |
| computeClient, err := clients.NewComputeV2Client() |
| if err != nil { |
| t.Fatalf("Unable to create a compute client: %v", err) |
| } |
| |
| blockStorageClient, err := clients.NewBlockStorageV2Client() |
| if err != nil { |
| t.Fatalf("Unable to create a block storage client: %v", err) |
| } |
| |
| choices, err := clients.AcceptanceTestChoicesFromEnv() |
| if err != nil { |
| t.Fatal(err) |
| } |
| |
| volume, err := blockstorage.CreateVolume(t, blockStorageClient) |
| if err != nil { |
| t.Fatal(err) |
| } |
| |
| blockDevices := []bootfromvolume.BlockDevice{ |
| bootfromvolume.BlockDevice{ |
| BootIndex: 0, |
| DeleteOnTermination: true, |
| DestinationType: bootfromvolume.DestinationLocal, |
| SourceType: bootfromvolume.SourceImage, |
| UUID: choices.ImageID, |
| }, |
| bootfromvolume.BlockDevice{ |
| BootIndex: 1, |
| DeleteOnTermination: true, |
| DestinationType: bootfromvolume.DestinationVolume, |
| SourceType: bootfromvolume.SourceVolume, |
| UUID: volume.ID, |
| }, |
| } |
| |
| server, err := CreateBootableVolumeServer(t, computeClient, blockDevices) |
| if err != nil { |
| t.Fatalf("Unable to create server: %v", err) |
| } |
| defer DeleteServer(t, computeClient, server) |
| |
| tools.PrintResource(t, server) |
| } |