blob: 2359a77120d4fc49df7ccd7ac6343feeef3e0fe1 [file] [log] [blame]
Jon Perritt654fb0e2014-10-23 20:54:14 -05001package bootfromvolume
Jon Perrittd9a4bf72014-10-23 23:44:04 -05002
3import (
4 "testing"
5
Jon Perritt27249f42016-02-18 10:35:59 -06006 "github.com/gophercloud/gophercloud/openstack/compute/v2/servers"
7 th "github.com/gophercloud/gophercloud/testhelper"
Jon Perrittd9a4bf72014-10-23 23:44:04 -05008)
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",
35 "block_device_mapping_v2":[
36 {
37 "uuid":"123456",
38 "source_type":"image",
39 "destination_type":"volume",
40 "boot_index": "0",
41 "delete_on_termination": "false",
42 "volume_size": "10"
43 }
44 ]
45 }
46 }
47 `
48 actual, err := ext.ToServerCreateMap()
49 th.AssertNoErr(t, err)
50 th.CheckJSONEquals(t, expected, actual)
51}
Joe Topjianecf63dd2015-12-12 20:33:50 +000052
53func TestCreateMultiEphemeralOpts(t *testing.T) {
54 base := servers.CreateOpts{
55 Name: "createdserver",
56 ImageRef: "asdfasdfasdf",
57 FlavorRef: "performance1-1",
58 }
59
60 ext := CreateOptsExt{
61 CreateOptsBuilder: base,
62 BlockDevice: []BlockDevice{
63 BlockDevice{
64 BootIndex: 0,
65 DeleteOnTermination: true,
66 DestinationType: "local",
67 SourceType: Image,
68 UUID: "123456",
69 },
70 BlockDevice{
71 BootIndex: -1,
72 DeleteOnTermination: true,
73 DestinationType: "local",
74 GuestFormat: "ext4",
75 SourceType: Blank,
76 VolumeSize: 1,
77 },
78 BlockDevice{
79 BootIndex: -1,
80 DeleteOnTermination: true,
81 DestinationType: "local",
82 GuestFormat: "ext4",
83 SourceType: Blank,
84 VolumeSize: 1,
85 },
86 },
87 }
88
89 expected := `
90 {
91 "server": {
92 "name": "createdserver",
93 "imageRef": "asdfasdfasdf",
94 "flavorRef": "performance1-1",
Joe Topjianecf63dd2015-12-12 20:33:50 +000095 "block_device_mapping_v2":[
96 {
97 "boot_index": "0",
98 "delete_on_termination": "true",
99 "destination_type":"local",
100 "source_type":"image",
101 "uuid":"123456",
102 "volume_size": "0"
103 },
104 {
105 "boot_index": "-1",
106 "delete_on_termination": "true",
107 "destination_type":"local",
108 "guest_format":"ext4",
109 "source_type":"blank",
110 "volume_size": "1"
111 },
112 {
113 "boot_index": "-1",
114 "delete_on_termination": "true",
115 "destination_type":"local",
116 "guest_format":"ext4",
117 "source_type":"blank",
118 "volume_size": "1"
119 }
120 ]
121 }
122 }
123 `
124 actual, err := ext.ToServerCreateMap()
125 th.AssertNoErr(t, err)
126 th.CheckJSONEquals(t, expected, actual)
127}