blob: 1fb44e81d9ffa2d59478f943219f39f8f6dd35e5 [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,
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 Perritt5fdb7222014-11-17 14:41:54 -070048 defer servers.Delete(client, server.ID)
Jon Perritt0b09d1d2014-10-24 13:26:18 -050049 t.Logf("Deleting server [%s]...", name)
50}