Jon Perritt | 0b09d1d | 2014-10-24 13:26:18 -0500 | [diff] [blame] | 1 | // +build acceptance |
| 2 | |
| 3 | package v2 |
| 4 | |
| 5 | import ( |
| 6 | "testing" |
| 7 | |
Jamie Hannaford | a75c77d | 2014-10-30 11:42:20 +0100 | [diff] [blame] | 8 | "github.com/rackspace/gophercloud/acceptance/tools" |
Jon Perritt | 0b09d1d | 2014-10-24 13:26:18 -0500 | [diff] [blame] | 9 | "github.com/rackspace/gophercloud/openstack/compute/v2/extensions/bootfromvolume" |
| 10 | "github.com/rackspace/gophercloud/openstack/compute/v2/servers" |
| 11 | th "github.com/rackspace/gophercloud/testhelper" |
Jon Perritt | 0b09d1d | 2014-10-24 13:26:18 -0500 | [diff] [blame] | 12 | ) |
| 13 | |
| 14 | func TestBootFromVolume(t *testing.T) { |
| 15 | client, err := newClient() |
| 16 | th.AssertNoErr(t, err) |
| 17 | |
| 18 | if testing.Short() { |
| 19 | t.Skip("Skipping test that requires server creation in short mode.") |
| 20 | } |
| 21 | |
| 22 | choices, err := ComputeChoicesFromEnv() |
| 23 | if err != nil { |
| 24 | t.Fatal(err) |
| 25 | } |
| 26 | |
| 27 | name := tools.RandomString("Gophercloud-", 8) |
| 28 | t.Logf("Creating server [%s].", name) |
| 29 | |
Jon Perritt | 01686cd | 2014-10-24 14:10:16 -0500 | [diff] [blame] | 30 | bd := []bootfromvolume.BlockDevice{ |
| 31 | bootfromvolume.BlockDevice{ |
| 32 | UUID: choices.ImageID, |
| 33 | SourceType: bootfromvolume.Image, |
| 34 | VolumeSize: 10, |
| 35 | }, |
Jon Perritt | 0b09d1d | 2014-10-24 13:26:18 -0500 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | serverCreateOpts := servers.CreateOpts{ |
| 39 | Name: name, |
| 40 | FlavorRef: "3", |
| 41 | } |
| 42 | server, err := bootfromvolume.Create(client, bootfromvolume.CreateOptsExt{ |
| 43 | serverCreateOpts, |
| 44 | bd, |
| 45 | }).Extract() |
| 46 | th.AssertNoErr(t, err) |
| 47 | t.Logf("Created server: %+v\n", server) |
Jon Perritt | 5fdb722 | 2014-11-17 14:41:54 -0700 | [diff] [blame^] | 48 | defer servers.Delete(client, server.ID) |
Jon Perritt | 0b09d1d | 2014-10-24 13:26:18 -0500 | [diff] [blame] | 49 | t.Logf("Deleting server [%s]...", name) |
| 50 | } |