blob: d85070d685f7aff4e4c1a7654b30d0da45705548 [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{
Jon Perrittdb0ae142016-03-13 00:33:41 -060021 UUID: "123456",
22 SourceType: Image,
23 DestinationType: "volume",
24 VolumeSize: 10,
25 DeleteOnTermination: false,
Jon Perritt01686cd2014-10-24 14:10:16 -050026 },
Jon Perrittd9a4bf72014-10-23 23:44:04 -050027 },
28 }
29
30 expected := `
31 {
32 "server": {
33 "name": "createdserver",
34 "imageRef": "asdfasdfasdf",
35 "flavorRef": "performance1-1",
36 "block_device_mapping_v2":[
37 {
38 "uuid":"123456",
39 "source_type":"image",
40 "destination_type":"volume",
Jon Perrittdb0ae142016-03-13 00:33:41 -060041 "boot_index": 0,
42 "delete_on_termination": false,
43 "volume_size": 10
Jon Perrittd9a4bf72014-10-23 23:44:04 -050044 }
45 ]
46 }
47 }
48 `
49 actual, err := ext.ToServerCreateMap()
50 th.AssertNoErr(t, err)
51 th.CheckJSONEquals(t, expected, actual)
52}
Joe Topjianecf63dd2015-12-12 20:33:50 +000053
54func TestCreateMultiEphemeralOpts(t *testing.T) {
55 base := servers.CreateOpts{
56 Name: "createdserver",
57 ImageRef: "asdfasdfasdf",
58 FlavorRef: "performance1-1",
59 }
60
61 ext := CreateOptsExt{
62 CreateOptsBuilder: base,
63 BlockDevice: []BlockDevice{
64 BlockDevice{
65 BootIndex: 0,
66 DeleteOnTermination: true,
67 DestinationType: "local",
68 SourceType: Image,
69 UUID: "123456",
70 },
71 BlockDevice{
72 BootIndex: -1,
73 DeleteOnTermination: true,
74 DestinationType: "local",
75 GuestFormat: "ext4",
76 SourceType: Blank,
77 VolumeSize: 1,
78 },
79 BlockDevice{
80 BootIndex: -1,
81 DeleteOnTermination: true,
82 DestinationType: "local",
83 GuestFormat: "ext4",
84 SourceType: Blank,
85 VolumeSize: 1,
86 },
87 },
88 }
89
90 expected := `
91 {
92 "server": {
93 "name": "createdserver",
94 "imageRef": "asdfasdfasdf",
95 "flavorRef": "performance1-1",
Joe Topjianecf63dd2015-12-12 20:33:50 +000096 "block_device_mapping_v2":[
97 {
Jon Perrittdb0ae142016-03-13 00:33:41 -060098 "boot_index": 0,
99 "delete_on_termination": true,
Joe Topjianecf63dd2015-12-12 20:33:50 +0000100 "destination_type":"local",
101 "source_type":"image",
102 "uuid":"123456",
Jon Perrittdb0ae142016-03-13 00:33:41 -0600103 "volume_size": 0
Joe Topjianecf63dd2015-12-12 20:33:50 +0000104 },
105 {
Jon Perrittdb0ae142016-03-13 00:33:41 -0600106 "boot_index": -1,
107 "delete_on_termination": true,
Joe Topjianecf63dd2015-12-12 20:33:50 +0000108 "destination_type":"local",
109 "guest_format":"ext4",
110 "source_type":"blank",
Jon Perrittdb0ae142016-03-13 00:33:41 -0600111 "volume_size": 1
Joe Topjianecf63dd2015-12-12 20:33:50 +0000112 },
113 {
Jon Perrittdb0ae142016-03-13 00:33:41 -0600114 "boot_index": -1,
115 "delete_on_termination": true,
Joe Topjianecf63dd2015-12-12 20:33:50 +0000116 "destination_type":"local",
117 "guest_format":"ext4",
118 "source_type":"blank",
Jon Perrittdb0ae142016-03-13 00:33:41 -0600119 "volume_size": 1
Joe Topjianecf63dd2015-12-12 20:33:50 +0000120 }
121 ]
122 }
123 }
124 `
125 actual, err := ext.ToServerCreateMap()
126 th.AssertNoErr(t, err)
127 th.CheckJSONEquals(t, expected, actual)
128}