blob: a92ce506cf0993fa13b82232a06dc69387517850 [file] [log] [blame]
Jon Perritt034ef072015-02-03 13:14:44 -07001package stacks
2
3import (
4 "testing"
5
6 os "github.com/rackspace/gophercloud/openstack/orchestration/v1/stacks"
7 th "github.com/rackspace/gophercloud/testhelper"
8 fake "github.com/rackspace/gophercloud/testhelper/client"
9)
10
11func TestCreateStack(t *testing.T) {
12 th.SetupHTTP()
13 defer th.TeardownHTTP()
14 os.HandleCreateSuccessfully(t, CreateOutput)
15
16 createOpts := os.CreateOpts{
17 Name: "stackcreated",
18 Timeout: 60,
19 Template: `{
20 "outputs": {
21 "db_host": {
22 "value": {
23 "get_attr": [
24 "db",
25 "hostname"
26 ]
27 }
28 }
29 },
30 "heat_template_version": "2014-10-16",
31 "description": "HEAT template for creating a Cloud Database.\n",
32 "parameters": {
33 "db_name": {
34 "default": "wordpress",
35 "type": "string",
36 "description": "the name for the database",
37 "constraints": [
38 {
39 "length": {
40 "max": 64,
41 "min": 1
42 },
43 "description": "must be between 1 and 64 characters"
44 },
45 {
46 "allowed_pattern": "[a-zA-Z][a-zA-Z0-9]*",
47 "description": "must begin with a letter and contain only alphanumeric characters."
48 }
49 ]
50 },
51 "db_instance_name": {
52 "default": "Cloud_DB",
53 "type": "string",
54 "description": "the database instance name"
55 },
56 "db_username": {
57 "default": "admin",
58 "hidden": true,
59 "type": "string",
60 "description": "database admin account username",
61 "constraints": [
62 {
63 "length": {
64 "max": 16,
65 "min": 1
66 },
67 "description": "must be between 1 and 16 characters"
68 },
69 {
70 "allowed_pattern": "[a-zA-Z][a-zA-Z0-9]*",
71 "description": "must begin with a letter and contain only alphanumeric characters."
72 }
73 ]
74 },
75 "db_volume_size": {
76 "default": 30,
77 "type": "number",
78 "description": "database volume size (in GB)",
79 "constraints": [
80 {
81 "range": {
82 "max": 1024,
83 "min": 1
84 },
85 "description": "must be between 1 and 1024 GB"
86 }
87 ]
88 },
89 "db_flavor": {
90 "default": "1GB Instance",
91 "type": "string",
92 "description": "database instance size",
93 "constraints": [
94 {
95 "description": "must be a valid cloud database flavor",
96 "allowed_values": [
97 "1GB Instance",
98 "2GB Instance",
99 "4GB Instance",
100 "8GB Instance",
101 "16GB Instance"
102 ]
103 }
104 ]
105 },
106 "db_password": {
107 "default": "admin",
108 "hidden": true,
109 "type": "string",
110 "description": "database admin account password",
111 "constraints": [
112 {
113 "length": {
114 "max": 41,
115 "min": 1
116 },
117 "description": "must be between 1 and 14 characters"
118 },
119 {
120 "allowed_pattern": "[a-zA-Z0-9]*",
121 "description": "must contain only alphanumeric characters."
122 }
123 ]
124 }
125 },
126 "resources": {
127 "db": {
128 "type": "OS::Trove::Instance",
129 "properties": {
130 "flavor": {
131 "get_param": "db_flavor"
132 },
133 "size": {
134 "get_param": "db_volume_size"
135 },
136 "users": [
137 {
138 "password": {
139 "get_param": "db_password"
140 },
141 "name": {
142 "get_param": "db_username"
143 },
144 "databases": [
145 {
146 "get_param": "db_name"
147 }
148 ]
149 }
150 ],
151 "name": {
152 "get_param": "db_instance_name"
153 },
154 "databases": [
155 {
156 "name": {
157 "get_param": "db_name"
158 }
159 }
160 ]
161 }
162 }
163 }
164 }`,
165 DisableRollback: os.Disable,
166 }
167 actual, err := Create(fake.ServiceClient(), createOpts).Extract()
168 th.AssertNoErr(t, err)
169
170 expected := CreateExpected
171 th.AssertDeepEquals(t, expected, actual)
172}
Jon Perritt1d3bc4b2015-02-04 12:06:19 -0700173
174func TestAdoptStack(t *testing.T) {
175 th.SetupHTTP()
176 defer th.TeardownHTTP()
177 os.HandleCreateSuccessfully(t, CreateOutput)
178
179 adoptOpts := os.AdoptOpts{
180 AdoptStackData: `{\"environment\":{\"parameters\":{}}, \"status\":\"COMPLETE\",\"name\": \"trovestack\",\n \"template\": {\n \"outputs\": {\n \"db_host\": {\n \"value\": {\n \"get_attr\": [\n \"db\",\n \"hostname\"\n ]\n }\n }\n },\n \"heat_template_version\": \"2014-10-16\",\n \"description\": \"HEAT template for creating a Cloud Database.\\n\",\n \"parameters\": {\n \"db_instance_name\": {\n \"default\": \"Cloud_DB\",\n \"type\": \"string\",\n \"description\": \"the database instance name\"\n },\n \"db_flavor\": {\n \"default\": \"1GB Instance\",\n \"type\": \"string\",\n \"description\": \"database instance size\",\n \"constraints\": [\n {\n \"description\": \"must be a valid cloud database flavor\",\n \"allowed_values\": [\n \"1GB Instance\",\n \"2GB Instance\",\n \"4GB Instance\",\n \"8GB Instance\",\n \"16GB Instance\"\n ]\n }\n ]\n },\n \"db_password\": {\n \"default\": \"admin\",\n \"hidden\": true,\n \"type\": \"string\",\n \"description\": \"database admin account password\",\n \"constraints\": [\n {\n \"length\": {\n \"max\": 41,\n \"min\": 1\n },\n \"description\": \"must be between 1 and 14 characters\"\n },\n {\n \"allowed_pattern\": \"[a-zA-Z0-9]*\",\n \"description\": \"must contain only alphanumeric characters.\"\n }\n ]\n },\n \"db_name\": {\n \"default\": \"wordpress\",\n \"type\": \"string\",\n \"description\": \"the name for the database\",\n \"constraints\": [\n {\n \"length\": {\n \"max\": 64,\n \"min\": 1\n },\n \"description\": \"must be between 1 and 64 characters\"\n },\n {\n \"allowed_pattern\": \"[a-zA-Z][a-zA-Z0-9]*\",\n \"description\": \"must begin with a letter and contain only alphanumeric characters.\"\n }\n ]\n },\n \"db_username\": {\n \"default\": \"admin\",\n \"hidden\": true,\n \"type\": \"string\",\n \"description\": \"database admin account username\",\n \"constraints\": [\n {\n \"length\": {\n \"max\": 16,\n \"min\": 1\n },\n \"description\": \"must be between 1 and 16 characters\"\n },\n {\n \"allowed_pattern\": \"[a-zA-Z][a-zA-Z0-9]*\",\n \"description\": \"must begin with a letter and contain only alphanumeric characters.\"\n }\n ]\n },\n \"db_volume_size\": {\n \"default\": 30,\n \"type\": \"number\",\n \"description\": \"database volume size (in GB)\",\n \"constraints\": [\n {\n \"range\": {\n \"max\": 1024,\n \"min\": 1\n },\n \"description\": \"must be between 1 and 1024 GB\"\n }\n ]\n }\n },\n \"resources\": {\n \"db\": {\n \"type\": \"OS::Trove::Instance\",\n \"properties\": {\n \"flavor\": {\n \"get_param\": \"db_flavor\"\n },\n \"databases\": [\n {\n \"name\": {\n \"get_param\": \"db_name\"\n }\n }\n ],\n \"users\": [\n {\n \"password\": {\n \"get_param\": \"db_password\"\n },\n \"name\": {\n \"get_param\": \"db_username\"\n },\n \"databases\": [\n {\n \"get_param\": \"db_name\"\n }\n ]\n }\n ],\n \"name\": {\n \"get_param\": \"db_instance_name\"\n },\n \"size\": {\n \"get_param\": \"db_volume_size\"\n }\n }\n }\n }\n },\n \"action\": \"CREATE\",\n \"id\": \"exxxxd-7xx5-4xxb-bxx2-cxxxxxx5\",\n \"resources\": {\n \"db\": {\n \"status\": \"COMPLETE\",\n \"name\": \"db\",\n \"resource_data\": {},\n \"resource_id\": \"exxxx2-9xx0-4xxxb-bxx2-dxxxxxx4\",\n \"action\": \"CREATE\",\n \"type\": \"OS::Trove::Instance\",\n \"metadata\": {}\n }\n }\n},`,
181 Name: "stackadopted",
182 Timeout: 60,
183 Template: `{
184 "outputs": {
185 "db_host": {
186 "value": {
187 "get_attr": [
188 "db",
189 "hostname"
190 ]
191 }
192 }
193 },
194 "heat_template_version": "2014-10-16",
195 "description": "HEAT template for creating a Cloud Database.\n",
196 "parameters": {
197 "db_name": {
198 "default": "wordpress",
199 "type": "string",
200 "description": "the name for the database",
201 "constraints": [
202 {
203 "length": {
204 "max": 64,
205 "min": 1
206 },
207 "description": "must be between 1 and 64 characters"
208 },
209 {
210 "allowed_pattern": "[a-zA-Z][a-zA-Z0-9]*",
211 "description": "must begin with a letter and contain only alphanumeric characters."
212 }
213 ]
214 },
215 "db_instance_name": {
216 "default": "Cloud_DB",
217 "type": "string",
218 "description": "the database instance name"
219 },
220 "db_username": {
221 "default": "admin",
222 "hidden": true,
223 "type": "string",
224 "description": "database admin account username",
225 "constraints": [
226 {
227 "length": {
228 "max": 16,
229 "min": 1
230 },
231 "description": "must be between 1 and 16 characters"
232 },
233 {
234 "allowed_pattern": "[a-zA-Z][a-zA-Z0-9]*",
235 "description": "must begin with a letter and contain only alphanumeric characters."
236 }
237 ]
238 },
239 "db_volume_size": {
240 "default": 30,
241 "type": "number",
242 "description": "database volume size (in GB)",
243 "constraints": [
244 {
245 "range": {
246 "max": 1024,
247 "min": 1
248 },
249 "description": "must be between 1 and 1024 GB"
250 }
251 ]
252 },
253 "db_flavor": {
254 "default": "1GB Instance",
255 "type": "string",
256 "description": "database instance size",
257 "constraints": [
258 {
259 "description": "must be a valid cloud database flavor",
260 "allowed_values": [
261 "1GB Instance",
262 "2GB Instance",
263 "4GB Instance",
264 "8GB Instance",
265 "16GB Instance"
266 ]
267 }
268 ]
269 },
270 "db_password": {
271 "default": "admin",
272 "hidden": true,
273 "type": "string",
274 "description": "database admin account password",
275 "constraints": [
276 {
277 "length": {
278 "max": 41,
279 "min": 1
280 },
281 "description": "must be between 1 and 14 characters"
282 },
283 {
284 "allowed_pattern": "[a-zA-Z0-9]*",
285 "description": "must contain only alphanumeric characters."
286 }
287 ]
288 }
289 },
290 "resources": {
291 "db": {
292 "type": "OS::Trove::Instance",
293 "properties": {
294 "flavor": {
295 "get_param": "db_flavor"
296 },
297 "size": {
298 "get_param": "db_volume_size"
299 },
300 "users": [
301 {
302 "password": {
303 "get_param": "db_password"
304 },
305 "name": {
306 "get_param": "db_username"
307 },
308 "databases": [
309 {
310 "get_param": "db_name"
311 }
312 ]
313 }
314 ],
315 "name": {
316 "get_param": "db_instance_name"
317 },
318 "databases": [
319 {
320 "name": {
321 "get_param": "db_name"
322 }
323 }
324 ]
325 }
326 }
327 }
328 }`,
329 DisableRollback: os.Disable,
330 }
331 actual, err := Adopt(fake.ServiceClient(), adoptOpts).Extract()
332 th.AssertNoErr(t, err)
333
334 expected := CreateExpected
335 th.AssertDeepEquals(t, expected, actual)
336}