blob: add0e5fc11e0caa058a245d977c6e147fd6043cf [file] [log] [blame]
Jon Perritt0b09d1d2014-10-24 13:26:18 -05001// +build acceptance
2
3package v2
4
5import (
6 "testing"
7
Jamie Hannaforda75c77d2014-10-30 11:42:20 +01008 "github.com/rackspace/gophercloud/acceptance/tools"
Jon Perritt0b09d1d2014-10-24 13:26:18 -05009 "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 Perritt0b09d1d2014-10-24 13:26:18 -050012)
13
14func 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 Perritt01686cd2014-10-24 14:10:16 -050030 bd := []bootfromvolume.BlockDevice{
31 bootfromvolume.BlockDevice{
32 UUID: choices.ImageID,
33 SourceType: bootfromvolume.Image,
34 VolumeSize: 10,
35 },
Jon Perritt0b09d1d2014-10-24 13:26:18 -050036 }
37
38 serverCreateOpts := servers.CreateOpts{
39 Name: name,
Jon Perrittcf01b932014-11-18 13:49:26 -070040 FlavorRef: choices.FlavorID,
41 ImageRef: choices.ImageID,
Jon Perritt0b09d1d2014-10-24 13:26:18 -050042 }
43 server, err := bootfromvolume.Create(client, bootfromvolume.CreateOptsExt{
44 serverCreateOpts,
45 bd,
46 }).Extract()
47 th.AssertNoErr(t, err)
Jon Perrittcf01b932014-11-18 13:49:26 -070048 if err = waitForStatus(client, server, "ACTIVE"); err != nil {
49 t.Fatal(err)
50 }
51
Jon Perritt0b09d1d2014-10-24 13:26:18 -050052 t.Logf("Created server: %+v\n", server)
Jon Perritt5fdb7222014-11-17 14:41:54 -070053 defer servers.Delete(client, server.ID)
Jon Perritt0b09d1d2014-10-24 13:26:18 -050054 t.Logf("Deleting server [%s]...", name)
55}