blob: bbecfad691a38cb0ada57bf94979e592cd5efd41 [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}
Joe Topjianecf63dd2015-12-12 20:33:50 +000056
57func TestMultiEphemeral(t *testing.T) {
58 client, err := newClient()
59 th.AssertNoErr(t, err)
60
61 if testing.Short() {
62 t.Skip("Skipping test that requires server creation in short mode.")
63 }
64
65 choices, err := ComputeChoicesFromEnv()
66 if err != nil {
67 t.Fatal(err)
68 }
69
70 name := tools.RandomString("Gophercloud-", 8)
71 t.Logf("Creating server [%s].", name)
72
73 bd := []bootfromvolume.BlockDevice{
74 bootfromvolume.BlockDevice{
75 BootIndex: 0,
76 UUID: choices.ImageID,
77 SourceType: bootfromvolume.Image,
78 DestinationType: "local",
79 DeleteOnTermination: true,
80 },
81 bootfromvolume.BlockDevice{
82 BootIndex: -1,
83 SourceType: bootfromvolume.Blank,
84 DestinationType: "local",
85 DeleteOnTermination: true,
86 GuestFormat: "ext4",
87 VolumeSize: 1,
88 },
89 bootfromvolume.BlockDevice{
90 BootIndex: -1,
91 SourceType: bootfromvolume.Blank,
92 DestinationType: "local",
93 DeleteOnTermination: true,
94 GuestFormat: "ext4",
95 VolumeSize: 1,
96 },
97 }
98
99 serverCreateOpts := servers.CreateOpts{
100 Name: name,
101 FlavorRef: choices.FlavorID,
102 ImageRef: choices.ImageID,
103 }
104 server, err := bootfromvolume.Create(client, bootfromvolume.CreateOptsExt{
105 serverCreateOpts,
106 bd,
107 }).Extract()
108 th.AssertNoErr(t, err)
109 if err = waitForStatus(client, server, "ACTIVE"); err != nil {
110 t.Fatal(err)
111 }
112
113 t.Logf("Created server: %+v\n", server)
114 defer servers.Delete(client, server.ID)
115 t.Logf("Deleting server [%s]...", name)
116}