blob: b2693b2ed254c8ca370e2608109765398481c831 [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}