blob: 2c8bf496b0dd40abcf146183c57e979e7b184752 [file] [log] [blame]
Jon Perritt654fb0e2014-10-23 20:54:14 -05001package bootfromvolume
Jon Perrittd9a4bf72014-10-23 23:44:04 -05002
3import (
4 "testing"
5
6 "github.com/rackspace/gophercloud/openstack/compute/v2/servers"
7 th "github.com/rackspace/gophercloud/testhelper"
8)
9
10func TestCreateOpts(t *testing.T) {
11 base := servers.CreateOpts{
12 Name: "createdserver",
13 ImageRef: "asdfasdfasdf",
14 FlavorRef: "performance1-1",
15 }
16
17 ext := CreateOptsExt{
18 CreateOptsBuilder: base,
Jon Perritt01686cd2014-10-24 14:10:16 -050019 BlockDevice: []BlockDevice{
20 BlockDevice{
21 UUID: "123456",
22 SourceType: Image,
23 DestinationType: "volume",
24 VolumeSize: 10,
25 },
Jon Perrittd9a4bf72014-10-23 23:44:04 -050026 },
27 }
28
29 expected := `
30 {
31 "server": {
32 "name": "createdserver",
33 "imageRef": "asdfasdfasdf",
34 "flavorRef": "performance1-1",
Joe Topjianecf63dd2015-12-12 20:33:50 +000035 "flavorName": "",
36 "imageName": "",
Jon Perrittd9a4bf72014-10-23 23:44:04 -050037 "block_device_mapping_v2":[
38 {
39 "uuid":"123456",
40 "source_type":"image",
41 "destination_type":"volume",
42 "boot_index": "0",
43 "delete_on_termination": "false",
44 "volume_size": "10"
45 }
46 ]
47 }
48 }
49 `
50 actual, err := ext.ToServerCreateMap()
51 th.AssertNoErr(t, err)
52 th.CheckJSONEquals(t, expected, actual)
53}
Joe Topjianecf63dd2015-12-12 20:33:50 +000054
55func TestCreateMultiEphemeralOpts(t *testing.T) {
56 base := servers.CreateOpts{
57 Name: "createdserver",
58 ImageRef: "asdfasdfasdf",
59 FlavorRef: "performance1-1",
60 }
61
62 ext := CreateOptsExt{
63 CreateOptsBuilder: base,
64 BlockDevice: []BlockDevice{
65 BlockDevice{
66 BootIndex: 0,
67 DeleteOnTermination: true,
68 DestinationType: "local",
69 SourceType: Image,
70 UUID: "123456",
71 },
72 BlockDevice{
73 BootIndex: -1,
74 DeleteOnTermination: true,
75 DestinationType: "local",
76 GuestFormat: "ext4",
77 SourceType: Blank,
78 VolumeSize: 1,
79 },
80 BlockDevice{
81 BootIndex: -1,
82 DeleteOnTermination: true,
83 DestinationType: "local",
84 GuestFormat: "ext4",
85 SourceType: Blank,
86 VolumeSize: 1,
87 },
88 },
89 }
90
91 expected := `
92 {
93 "server": {
94 "name": "createdserver",
95 "imageRef": "asdfasdfasdf",
96 "flavorRef": "performance1-1",
97 "flavorName": "",
98 "imageName": "",
99 "block_device_mapping_v2":[
100 {
101 "boot_index": "0",
102 "delete_on_termination": "true",
103 "destination_type":"local",
104 "source_type":"image",
105 "uuid":"123456",
106 "volume_size": "0"
107 },
108 {
109 "boot_index": "-1",
110 "delete_on_termination": "true",
111 "destination_type":"local",
112 "guest_format":"ext4",
113 "source_type":"blank",
114 "volume_size": "1"
115 },
116 {
117 "boot_index": "-1",
118 "delete_on_termination": "true",
119 "destination_type":"local",
120 "guest_format":"ext4",
121 "source_type":"blank",
122 "volume_size": "1"
123 }
124 ]
125 }
126 }
127 `
128 actual, err := ext.ToServerCreateMap()
129 th.AssertNoErr(t, err)
130 th.CheckJSONEquals(t, expected, actual)
131}