Keith Byrne | bda4859 | 2016-03-23 11:37:08 +0000 | [diff] [blame] | 1 | // +build fixtures |
| 2 | |
Jon Perritt | 4a5c849 | 2015-02-03 13:13:59 -0700 | [diff] [blame] | 3 | package stacks |
| 4 | |
| 5 | import ( |
| 6 | "fmt" |
| 7 | "net/http" |
| 8 | "testing" |
Jon Perritt | 9cd3d38 | 2015-02-04 15:49:41 -0700 | [diff] [blame] | 9 | "time" |
Jon Perritt | 4a5c849 | 2015-02-03 13:13:59 -0700 | [diff] [blame] | 10 | |
Jon Perritt | 27249f4 | 2016-02-18 10:35:59 -0600 | [diff] [blame] | 11 | "github.com/gophercloud/gophercloud" |
| 12 | th "github.com/gophercloud/gophercloud/testhelper" |
| 13 | fake "github.com/gophercloud/gophercloud/testhelper/client" |
Jon Perritt | 4a5c849 | 2015-02-03 13:13:59 -0700 | [diff] [blame] | 14 | ) |
| 15 | |
| 16 | // CreateExpected represents the expected object from a Create request. |
| 17 | var CreateExpected = &CreatedStack{ |
| 18 | ID: "16ef0584-4458-41eb-87c8-0dc8d5f66c87", |
| 19 | Links: []gophercloud.Link{ |
| 20 | gophercloud.Link{ |
| 21 | Href: "http://168.28.170.117:8004/v1/98606384f58drad0bhdb7d02779549ac/stacks/stackcreated/16ef0584-4458-41eb-87c8-0dc8d5f66c87", |
| 22 | Rel: "self", |
| 23 | }, |
| 24 | }, |
| 25 | } |
| 26 | |
| 27 | // CreateOutput represents the response body from a Create request. |
| 28 | const CreateOutput = ` |
| 29 | { |
| 30 | "stack": { |
| 31 | "id": "16ef0584-4458-41eb-87c8-0dc8d5f66c87", |
| 32 | "links": [ |
| 33 | { |
| 34 | "href": "http://168.28.170.117:8004/v1/98606384f58drad0bhdb7d02779549ac/stacks/stackcreated/16ef0584-4458-41eb-87c8-0dc8d5f66c87", |
| 35 | "rel": "self" |
| 36 | } |
| 37 | ] |
| 38 | } |
| 39 | }` |
| 40 | |
| 41 | // HandleCreateSuccessfully creates an HTTP handler at `/stacks` on the test handler mux |
| 42 | // that responds with a `Create` response. |
| 43 | func HandleCreateSuccessfully(t *testing.T, output string) { |
| 44 | th.Mux.HandleFunc("/stacks", func(w http.ResponseWriter, r *http.Request) { |
| 45 | th.TestMethod(t, r, "POST") |
| 46 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 47 | th.TestHeader(t, r, "Accept", "application/json") |
| 48 | w.WriteHeader(http.StatusCreated) |
| 49 | fmt.Fprintf(w, output) |
| 50 | }) |
| 51 | } |
Jon Perritt | 9cd3d38 | 2015-02-04 15:49:41 -0700 | [diff] [blame] | 52 | |
| 53 | // ListExpected represents the expected object from a List request. |
| 54 | var ListExpected = []ListedStack{ |
| 55 | ListedStack{ |
| 56 | Description: "Simple template to test heat commands", |
| 57 | Links: []gophercloud.Link{ |
| 58 | gophercloud.Link{ |
| 59 | Href: "http://166.76.160.117:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/16ef0584-4458-41eb-87c8-0dc8d5f66c87", |
| 60 | Rel: "self", |
| 61 | }, |
| 62 | }, |
| 63 | StatusReason: "Stack CREATE completed successfully", |
| 64 | Name: "postman_stack", |
Jon Perritt | 3c16647 | 2016-02-25 03:07:41 -0600 | [diff] [blame] | 65 | CreationTime: gophercloud.JSONRFC3339NoZ(time.Date(2015, 2, 3, 20, 7, 39, 0, time.UTC)), |
Jon Perritt | 9cd3d38 | 2015-02-04 15:49:41 -0700 | [diff] [blame] | 66 | Status: "CREATE_COMPLETE", |
| 67 | ID: "16ef0584-4458-41eb-87c8-0dc8d5f66c87", |
Pratik Mallya | 827c03e | 2015-09-17 00:10:47 -0500 | [diff] [blame] | 68 | Tags: []string{"rackspace", "atx"}, |
Jon Perritt | 9cd3d38 | 2015-02-04 15:49:41 -0700 | [diff] [blame] | 69 | }, |
| 70 | ListedStack{ |
| 71 | Description: "Simple template to test heat commands", |
| 72 | Links: []gophercloud.Link{ |
| 73 | gophercloud.Link{ |
| 74 | Href: "http://166.76.160.117:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/gophercloud-test-stack-2/db6977b2-27aa-4775-9ae7-6213212d4ada", |
| 75 | Rel: "self", |
| 76 | }, |
| 77 | }, |
| 78 | StatusReason: "Stack successfully updated", |
| 79 | Name: "gophercloud-test-stack-2", |
Jon Perritt | 3c16647 | 2016-02-25 03:07:41 -0600 | [diff] [blame] | 80 | CreationTime: gophercloud.JSONRFC3339NoZ(time.Date(2014, 12, 11, 17, 39, 16, 0, time.UTC)), |
| 81 | UpdatedTime: gophercloud.JSONRFC3339NoZ(time.Date(2014, 12, 11, 17, 40, 37, 0, time.UTC)), |
Jon Perritt | 9cd3d38 | 2015-02-04 15:49:41 -0700 | [diff] [blame] | 82 | Status: "UPDATE_COMPLETE", |
| 83 | ID: "db6977b2-27aa-4775-9ae7-6213212d4ada", |
Pratik Mallya | 827c03e | 2015-09-17 00:10:47 -0500 | [diff] [blame] | 84 | Tags: []string{"sfo", "satx"}, |
Jon Perritt | 9cd3d38 | 2015-02-04 15:49:41 -0700 | [diff] [blame] | 85 | }, |
| 86 | } |
| 87 | |
| 88 | // FullListOutput represents the response body from a List request without a marker. |
| 89 | const FullListOutput = ` |
| 90 | { |
| 91 | "stacks": [ |
| 92 | { |
| 93 | "description": "Simple template to test heat commands", |
| 94 | "links": [ |
| 95 | { |
| 96 | "href": "http://166.76.160.117:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/16ef0584-4458-41eb-87c8-0dc8d5f66c87", |
| 97 | "rel": "self" |
| 98 | } |
| 99 | ], |
| 100 | "stack_status_reason": "Stack CREATE completed successfully", |
| 101 | "stack_name": "postman_stack", |
Pratik Mallya | e1b6cbb | 2015-09-09 14:24:14 -0500 | [diff] [blame] | 102 | "creation_time": "2015-02-03T20:07:39", |
Jon Perritt | 9cd3d38 | 2015-02-04 15:49:41 -0700 | [diff] [blame] | 103 | "updated_time": null, |
| 104 | "stack_status": "CREATE_COMPLETE", |
Pratik Mallya | 827c03e | 2015-09-17 00:10:47 -0500 | [diff] [blame] | 105 | "id": "16ef0584-4458-41eb-87c8-0dc8d5f66c87", |
| 106 | "tags": ["rackspace", "atx"] |
Jon Perritt | 9cd3d38 | 2015-02-04 15:49:41 -0700 | [diff] [blame] | 107 | }, |
| 108 | { |
| 109 | "description": "Simple template to test heat commands", |
| 110 | "links": [ |
| 111 | { |
| 112 | "href": "http://166.76.160.117:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/gophercloud-test-stack-2/db6977b2-27aa-4775-9ae7-6213212d4ada", |
| 113 | "rel": "self" |
| 114 | } |
| 115 | ], |
| 116 | "stack_status_reason": "Stack successfully updated", |
| 117 | "stack_name": "gophercloud-test-stack-2", |
Pratik Mallya | e1b6cbb | 2015-09-09 14:24:14 -0500 | [diff] [blame] | 118 | "creation_time": "2014-12-11T17:39:16", |
| 119 | "updated_time": "2014-12-11T17:40:37", |
Jon Perritt | 9cd3d38 | 2015-02-04 15:49:41 -0700 | [diff] [blame] | 120 | "stack_status": "UPDATE_COMPLETE", |
Pratik Mallya | 827c03e | 2015-09-17 00:10:47 -0500 | [diff] [blame] | 121 | "id": "db6977b2-27aa-4775-9ae7-6213212d4ada", |
| 122 | "tags": ["sfo", "satx"] |
Jon Perritt | 9cd3d38 | 2015-02-04 15:49:41 -0700 | [diff] [blame] | 123 | } |
| 124 | ] |
| 125 | } |
| 126 | ` |
| 127 | |
| 128 | // HandleListSuccessfully creates an HTTP handler at `/stacks` on the test handler mux |
| 129 | // that responds with a `List` response. |
| 130 | func HandleListSuccessfully(t *testing.T, output string) { |
| 131 | th.Mux.HandleFunc("/stacks", func(w http.ResponseWriter, r *http.Request) { |
| 132 | th.TestMethod(t, r, "GET") |
| 133 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 134 | th.TestHeader(t, r, "Accept", "application/json") |
| 135 | |
| 136 | w.Header().Set("Content-Type", "application/json") |
| 137 | r.ParseForm() |
| 138 | marker := r.Form.Get("marker") |
| 139 | switch marker { |
| 140 | case "": |
| 141 | fmt.Fprintf(w, output) |
| 142 | case "db6977b2-27aa-4775-9ae7-6213212d4ada": |
| 143 | fmt.Fprintf(w, `[]`) |
| 144 | default: |
| 145 | t.Fatalf("Unexpected marker: [%s]", marker) |
| 146 | } |
| 147 | }) |
| 148 | } |
Jon Perritt | 7726e49 | 2015-02-04 17:54:28 -0700 | [diff] [blame] | 149 | |
| 150 | // GetExpected represents the expected object from a Get request. |
| 151 | var GetExpected = &RetrievedStack{ |
| 152 | DisableRollback: true, |
| 153 | Description: "Simple template to test heat commands", |
| 154 | Parameters: map[string]string{ |
| 155 | "flavor": "m1.tiny", |
| 156 | "OS::stack_name": "postman_stack", |
| 157 | "OS::stack_id": "16ef0584-4458-41eb-87c8-0dc8d5f66c87", |
| 158 | }, |
| 159 | StatusReason: "Stack CREATE completed successfully", |
| 160 | Name: "postman_stack", |
| 161 | Outputs: []map[string]interface{}{}, |
Jon Perritt | 3c16647 | 2016-02-25 03:07:41 -0600 | [diff] [blame] | 162 | CreationTime: gophercloud.JSONRFC3339NoZ(time.Date(2015, 2, 3, 20, 7, 39, 0, time.UTC)), |
Jon Perritt | 7726e49 | 2015-02-04 17:54:28 -0700 | [diff] [blame] | 163 | Links: []gophercloud.Link{ |
| 164 | gophercloud.Link{ |
| 165 | Href: "http://166.76.160.117:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/16ef0584-4458-41eb-87c8-0dc8d5f66c87", |
| 166 | Rel: "self", |
| 167 | }, |
| 168 | }, |
| 169 | Capabilities: []interface{}{}, |
| 170 | NotificationTopics: []interface{}{}, |
| 171 | Status: "CREATE_COMPLETE", |
| 172 | ID: "16ef0584-4458-41eb-87c8-0dc8d5f66c87", |
| 173 | TemplateDescription: "Simple template to test heat commands", |
Pratik Mallya | 827c03e | 2015-09-17 00:10:47 -0500 | [diff] [blame] | 174 | Tags: []string{"rackspace", "atx"}, |
Jon Perritt | 7726e49 | 2015-02-04 17:54:28 -0700 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | // GetOutput represents the response body from a Get request. |
| 178 | const GetOutput = ` |
| 179 | { |
| 180 | "stack": { |
| 181 | "disable_rollback": true, |
| 182 | "description": "Simple template to test heat commands", |
| 183 | "parameters": { |
| 184 | "flavor": "m1.tiny", |
| 185 | "OS::stack_name": "postman_stack", |
| 186 | "OS::stack_id": "16ef0584-4458-41eb-87c8-0dc8d5f66c87" |
| 187 | }, |
| 188 | "stack_status_reason": "Stack CREATE completed successfully", |
| 189 | "stack_name": "postman_stack", |
| 190 | "outputs": [], |
Pratik Mallya | e1b6cbb | 2015-09-09 14:24:14 -0500 | [diff] [blame] | 191 | "creation_time": "2015-02-03T20:07:39", |
Jon Perritt | 7726e49 | 2015-02-04 17:54:28 -0700 | [diff] [blame] | 192 | "links": [ |
| 193 | { |
| 194 | "href": "http://166.76.160.117:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/16ef0584-4458-41eb-87c8-0dc8d5f66c87", |
| 195 | "rel": "self" |
| 196 | } |
| 197 | ], |
| 198 | "capabilities": [], |
| 199 | "notification_topics": [], |
| 200 | "timeout_mins": null, |
| 201 | "stack_status": "CREATE_COMPLETE", |
| 202 | "updated_time": null, |
| 203 | "id": "16ef0584-4458-41eb-87c8-0dc8d5f66c87", |
Pratik Mallya | 827c03e | 2015-09-17 00:10:47 -0500 | [diff] [blame] | 204 | "template_description": "Simple template to test heat commands", |
| 205 | "tags": ["rackspace", "atx"] |
Jon Perritt | 7726e49 | 2015-02-04 17:54:28 -0700 | [diff] [blame] | 206 | } |
| 207 | } |
| 208 | ` |
| 209 | |
| 210 | // HandleGetSuccessfully creates an HTTP handler at `/stacks/postman_stack/16ef0584-4458-41eb-87c8-0dc8d5f66c87` |
| 211 | // on the test handler mux that responds with a `Get` response. |
| 212 | func HandleGetSuccessfully(t *testing.T, output string) { |
| 213 | th.Mux.HandleFunc("/stacks/postman_stack/16ef0584-4458-41eb-87c8-0dc8d5f66c87", func(w http.ResponseWriter, r *http.Request) { |
| 214 | th.TestMethod(t, r, "GET") |
| 215 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 216 | th.TestHeader(t, r, "Accept", "application/json") |
| 217 | |
| 218 | w.Header().Set("Content-Type", "application/json") |
| 219 | w.WriteHeader(http.StatusOK) |
| 220 | fmt.Fprintf(w, output) |
| 221 | }) |
| 222 | } |
| 223 | |
| 224 | // HandleUpdateSuccessfully creates an HTTP handler at `/stacks/postman_stack/16ef0584-4458-41eb-87c8-0dc8d5f66c87` |
| 225 | // on the test handler mux that responds with an `Update` response. |
| 226 | func HandleUpdateSuccessfully(t *testing.T) { |
| 227 | th.Mux.HandleFunc("/stacks/gophercloud-test-stack-2/db6977b2-27aa-4775-9ae7-6213212d4ada", func(w http.ResponseWriter, r *http.Request) { |
| 228 | th.TestMethod(t, r, "PUT") |
| 229 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 230 | th.TestHeader(t, r, "Accept", "application/json") |
| 231 | |
| 232 | w.Header().Set("Content-Type", "application/json") |
| 233 | w.WriteHeader(http.StatusAccepted) |
| 234 | }) |
| 235 | } |
Jon Perritt | a433dd9 | 2015-02-04 18:04:13 -0700 | [diff] [blame] | 236 | |
| 237 | // HandleDeleteSuccessfully creates an HTTP handler at `/stacks/postman_stack/16ef0584-4458-41eb-87c8-0dc8d5f66c87` |
Jon Perritt | 9209df4 | 2015-02-05 12:55:33 -0700 | [diff] [blame] | 238 | // on the test handler mux that responds with a `Delete` response. |
Jon Perritt | a433dd9 | 2015-02-04 18:04:13 -0700 | [diff] [blame] | 239 | func HandleDeleteSuccessfully(t *testing.T) { |
| 240 | th.Mux.HandleFunc("/stacks/gophercloud-test-stack-2/db6977b2-27aa-4775-9ae7-6213212d4ada", func(w http.ResponseWriter, r *http.Request) { |
| 241 | th.TestMethod(t, r, "DELETE") |
| 242 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 243 | th.TestHeader(t, r, "Accept", "application/json") |
| 244 | |
| 245 | w.Header().Set("Content-Type", "application/json") |
| 246 | w.WriteHeader(http.StatusNoContent) |
| 247 | }) |
| 248 | } |
Jon Perritt | 37f9774 | 2015-02-04 18:55:05 -0700 | [diff] [blame] | 249 | |
| 250 | // GetExpected represents the expected object from a Get request. |
| 251 | var PreviewExpected = &PreviewedStack{ |
| 252 | DisableRollback: true, |
| 253 | Description: "Simple template to test heat commands", |
| 254 | Parameters: map[string]string{ |
| 255 | "flavor": "m1.tiny", |
| 256 | "OS::stack_name": "postman_stack", |
| 257 | "OS::stack_id": "16ef0584-4458-41eb-87c8-0dc8d5f66c87", |
| 258 | }, |
Jon Perritt | 37f9774 | 2015-02-04 18:55:05 -0700 | [diff] [blame] | 259 | Name: "postman_stack", |
Jon Perritt | 3c16647 | 2016-02-25 03:07:41 -0600 | [diff] [blame] | 260 | CreationTime: gophercloud.JSONRFC3339NoZ(time.Date(2015, 2, 3, 20, 7, 39, 0, time.UTC)), |
Jon Perritt | 37f9774 | 2015-02-04 18:55:05 -0700 | [diff] [blame] | 261 | Links: []gophercloud.Link{ |
| 262 | gophercloud.Link{ |
| 263 | Href: "http://166.76.160.117:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/16ef0584-4458-41eb-87c8-0dc8d5f66c87", |
| 264 | Rel: "self", |
| 265 | }, |
| 266 | }, |
| 267 | Capabilities: []interface{}{}, |
| 268 | NotificationTopics: []interface{}{}, |
Jon Perritt | 37f9774 | 2015-02-04 18:55:05 -0700 | [diff] [blame] | 269 | ID: "16ef0584-4458-41eb-87c8-0dc8d5f66c87", |
| 270 | TemplateDescription: "Simple template to test heat commands", |
| 271 | } |
| 272 | |
| 273 | // HandlePreviewSuccessfully creates an HTTP handler at `/stacks/preview` |
Jon Perritt | 9209df4 | 2015-02-05 12:55:33 -0700 | [diff] [blame] | 274 | // on the test handler mux that responds with a `Preview` response. |
Jon Perritt | 37f9774 | 2015-02-04 18:55:05 -0700 | [diff] [blame] | 275 | func HandlePreviewSuccessfully(t *testing.T, output string) { |
| 276 | th.Mux.HandleFunc("/stacks/preview", func(w http.ResponseWriter, r *http.Request) { |
| 277 | th.TestMethod(t, r, "POST") |
| 278 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 279 | th.TestHeader(t, r, "Accept", "application/json") |
| 280 | |
| 281 | w.Header().Set("Content-Type", "application/json") |
| 282 | w.WriteHeader(http.StatusOK) |
| 283 | fmt.Fprintf(w, output) |
| 284 | }) |
| 285 | } |
Jon Perritt | 9209df4 | 2015-02-05 12:55:33 -0700 | [diff] [blame] | 286 | |
| 287 | // AbandonExpected represents the expected object from an Abandon request. |
| 288 | var AbandonExpected = &AbandonedStack{ |
| 289 | Status: "COMPLETE", |
| 290 | Name: "postman_stack", |
Jon Perritt | 6ec27cf | 2015-02-09 12:51:41 -0700 | [diff] [blame] | 291 | Template: map[string]interface{}{ |
| 292 | "heat_template_version": "2013-05-23", |
| 293 | "description": "Simple template to test heat commands", |
| 294 | "parameters": map[string]interface{}{ |
| 295 | "flavor": map[string]interface{}{ |
| 296 | "default": "m1.tiny", |
| 297 | "type": "string", |
| 298 | }, |
| 299 | }, |
| 300 | "resources": map[string]interface{}{ |
| 301 | "hello_world": map[string]interface{}{ |
| 302 | "type": "OS::Nova::Server", |
| 303 | "properties": map[string]interface{}{ |
| 304 | "key_name": "heat_key", |
| 305 | "flavor": map[string]interface{}{ |
| 306 | "get_param": "flavor", |
| 307 | }, |
| 308 | "image": "ad091b52-742f-469e-8f3c-fd81cadf0743", |
| 309 | "user_data": "#!/bin/bash -xv\necho \"hello world\" > /root/hello-world.txt\n", |
| 310 | }, |
| 311 | }, |
| 312 | }, |
| 313 | }, |
Jon Perritt | 9209df4 | 2015-02-05 12:55:33 -0700 | [diff] [blame] | 314 | Action: "CREATE", |
| 315 | ID: "16ef0584-4458-41eb-87c8-0dc8d5f66c87", |
| 316 | Resources: map[string]interface{}{ |
| 317 | "hello_world": map[string]interface{}{ |
| 318 | "status": "COMPLETE", |
| 319 | "name": "hello_world", |
| 320 | "resource_id": "8a310d36-46fc-436f-8be4-37a696b8ac63", |
| 321 | "action": "CREATE", |
| 322 | "type": "OS::Nova::Server", |
| 323 | }, |
| 324 | }, |
Pratik Mallya | 827c03e | 2015-09-17 00:10:47 -0500 | [diff] [blame] | 325 | Files: map[string]string{ |
| 326 | "file:///Users/prat8228/go/src/github.com/rackspace/rack/my_nova.yaml": "heat_template_version: 2014-10-16\nparameters:\n flavor:\n type: string\n description: Flavor for the server to be created\n default: 4353\n hidden: true\nresources:\n test_server:\n type: \"OS::Nova::Server\"\n properties:\n name: test-server\n flavor: 2 GB General Purpose v1\n image: Debian 7 (Wheezy) (PVHVM)\n", |
| 327 | }, |
| 328 | StackUserProjectID: "897686", |
| 329 | ProjectID: "897686", |
| 330 | Environment: map[string]interface{}{ |
| 331 | "encrypted_param_names": make([]map[string]interface{}, 0), |
| 332 | "parameter_defaults": make(map[string]interface{}), |
| 333 | "parameters": make(map[string]interface{}), |
| 334 | "resource_registry": map[string]interface{}{ |
| 335 | "file:///Users/prat8228/go/src/github.com/rackspace/rack/my_nova.yaml": "file:///Users/prat8228/go/src/github.com/rackspace/rack/my_nova.yaml", |
| 336 | "resources": make(map[string]interface{}), |
| 337 | }, |
| 338 | }, |
Jon Perritt | 9209df4 | 2015-02-05 12:55:33 -0700 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | // AbandonOutput represents the response body from an Abandon request. |
| 342 | const AbandonOutput = ` |
| 343 | { |
| 344 | "status": "COMPLETE", |
| 345 | "name": "postman_stack", |
| 346 | "template": { |
| 347 | "heat_template_version": "2013-05-23", |
| 348 | "description": "Simple template to test heat commands", |
| 349 | "parameters": { |
| 350 | "flavor": { |
| 351 | "default": "m1.tiny", |
| 352 | "type": "string" |
| 353 | } |
| 354 | }, |
| 355 | "resources": { |
| 356 | "hello_world": { |
| 357 | "type": "OS::Nova::Server", |
| 358 | "properties": { |
| 359 | "key_name": "heat_key", |
| 360 | "flavor": { |
| 361 | "get_param": "flavor" |
| 362 | }, |
| 363 | "image": "ad091b52-742f-469e-8f3c-fd81cadf0743", |
| 364 | "user_data": "#!/bin/bash -xv\necho \"hello world\" > /root/hello-world.txt\n" |
| 365 | } |
| 366 | } |
| 367 | } |
| 368 | }, |
| 369 | "action": "CREATE", |
| 370 | "id": "16ef0584-4458-41eb-87c8-0dc8d5f66c87", |
| 371 | "resources": { |
| 372 | "hello_world": { |
| 373 | "status": "COMPLETE", |
| 374 | "name": "hello_world", |
| 375 | "resource_id": "8a310d36-46fc-436f-8be4-37a696b8ac63", |
| 376 | "action": "CREATE", |
Pratik Mallya | 827c03e | 2015-09-17 00:10:47 -0500 | [diff] [blame] | 377 | "type": "OS::Nova::Server" |
Jon Perritt | 9209df4 | 2015-02-05 12:55:33 -0700 | [diff] [blame] | 378 | } |
Pratik Mallya | 827c03e | 2015-09-17 00:10:47 -0500 | [diff] [blame] | 379 | }, |
| 380 | "files": { |
| 381 | "file:///Users/prat8228/go/src/github.com/rackspace/rack/my_nova.yaml": "heat_template_version: 2014-10-16\nparameters:\n flavor:\n type: string\n description: Flavor for the server to be created\n default: 4353\n hidden: true\nresources:\n test_server:\n type: \"OS::Nova::Server\"\n properties:\n name: test-server\n flavor: 2 GB General Purpose v1\n image: Debian 7 (Wheezy) (PVHVM)\n" |
| 382 | }, |
| 383 | "environment": { |
| 384 | "encrypted_param_names": [], |
| 385 | "parameter_defaults": {}, |
| 386 | "parameters": {}, |
| 387 | "resource_registry": { |
| 388 | "file:///Users/prat8228/go/src/github.com/rackspace/rack/my_nova.yaml": "file:///Users/prat8228/go/src/github.com/rackspace/rack/my_nova.yaml", |
| 389 | "resources": {} |
| 390 | } |
| 391 | }, |
| 392 | "stack_user_project_id": "897686", |
| 393 | "project_id": "897686" |
Jon Perritt | 9209df4 | 2015-02-05 12:55:33 -0700 | [diff] [blame] | 394 | }` |
| 395 | |
| 396 | // HandleAbandonSuccessfully creates an HTTP handler at `/stacks/postman_stack/16ef0584-4458-41eb-87c8-0dc8d5f66c87/abandon` |
| 397 | // on the test handler mux that responds with an `Abandon` response. |
Pratik Mallya | 827c03e | 2015-09-17 00:10:47 -0500 | [diff] [blame] | 398 | func HandleAbandonSuccessfully(t *testing.T, output string) { |
| 399 | th.Mux.HandleFunc("/stacks/postman_stack/16ef0584-4458-41eb-87c8-0dc8d5f66c8/abandon", func(w http.ResponseWriter, r *http.Request) { |
Jon Perritt | 9209df4 | 2015-02-05 12:55:33 -0700 | [diff] [blame] | 400 | th.TestMethod(t, r, "DELETE") |
| 401 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 402 | th.TestHeader(t, r, "Accept", "application/json") |
| 403 | |
| 404 | w.Header().Set("Content-Type", "application/json") |
| 405 | w.WriteHeader(http.StatusOK) |
Pratik Mallya | 827c03e | 2015-09-17 00:10:47 -0500 | [diff] [blame] | 406 | fmt.Fprintf(w, output) |
Jon Perritt | 9209df4 | 2015-02-05 12:55:33 -0700 | [diff] [blame] | 407 | }) |
| 408 | } |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 409 | |
Pratik Mallya | 3de347f | 2015-09-22 12:25:59 -0500 | [diff] [blame] | 410 | // ValidJSONTemplate is a valid OpenStack Heat template in JSON format |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 411 | const ValidJSONTemplate = ` |
| 412 | { |
| 413 | "heat_template_version": "2014-10-16", |
| 414 | "parameters": { |
| 415 | "flavor": { |
| 416 | "default": 4353, |
| 417 | "description": "Flavor for the server to be created", |
| 418 | "hidden": true, |
| 419 | "type": "string" |
| 420 | } |
| 421 | }, |
| 422 | "resources": { |
| 423 | "test_server": { |
| 424 | "properties": { |
| 425 | "flavor": "2 GB General Purpose v1", |
| 426 | "image": "Debian 7 (Wheezy) (PVHVM)", |
| 427 | "name": "test-server" |
| 428 | }, |
| 429 | "type": "OS::Nova::Server" |
| 430 | } |
| 431 | } |
| 432 | } |
| 433 | ` |
| 434 | |
Pratik Mallya | 3de347f | 2015-09-22 12:25:59 -0500 | [diff] [blame] | 435 | // ValidJSONTemplateParsed is the expected parsed version of ValidJSONTemplate |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 436 | var ValidJSONTemplateParsed = map[string]interface{}{ |
| 437 | "heat_template_version": "2014-10-16", |
| 438 | "parameters": map[string]interface{}{ |
| 439 | "flavor": map[string]interface{}{ |
| 440 | "default": 4353, |
| 441 | "description": "Flavor for the server to be created", |
| 442 | "hidden": true, |
| 443 | "type": "string", |
| 444 | }, |
| 445 | }, |
| 446 | "resources": map[string]interface{}{ |
| 447 | "test_server": map[string]interface{}{ |
| 448 | "properties": map[string]interface{}{ |
| 449 | "flavor": "2 GB General Purpose v1", |
| 450 | "image": "Debian 7 (Wheezy) (PVHVM)", |
| 451 | "name": "test-server", |
| 452 | }, |
| 453 | "type": "OS::Nova::Server", |
| 454 | }, |
| 455 | }, |
| 456 | } |
| 457 | |
Pratik Mallya | 3de347f | 2015-09-22 12:25:59 -0500 | [diff] [blame] | 458 | // ValidYAMLTemplate is a valid OpenStack Heat template in YAML format |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 459 | const ValidYAMLTemplate = ` |
| 460 | heat_template_version: 2014-10-16 |
| 461 | parameters: |
| 462 | flavor: |
| 463 | type: string |
| 464 | description: Flavor for the server to be created |
| 465 | default: 4353 |
| 466 | hidden: true |
| 467 | resources: |
| 468 | test_server: |
| 469 | type: "OS::Nova::Server" |
| 470 | properties: |
| 471 | name: test-server |
| 472 | flavor: 2 GB General Purpose v1 |
| 473 | image: Debian 7 (Wheezy) (PVHVM) |
| 474 | ` |
| 475 | |
Pratik Mallya | 3de347f | 2015-09-22 12:25:59 -0500 | [diff] [blame] | 476 | // InvalidTemplateNoVersion is an invalid template as it has no `version` section |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 477 | const InvalidTemplateNoVersion = ` |
| 478 | parameters: |
| 479 | flavor: |
| 480 | type: string |
| 481 | description: Flavor for the server to be created |
| 482 | default: 4353 |
| 483 | hidden: true |
| 484 | resources: |
| 485 | test_server: |
| 486 | type: "OS::Nova::Server" |
| 487 | properties: |
| 488 | name: test-server |
| 489 | flavor: 2 GB General Purpose v1 |
| 490 | image: Debian 7 (Wheezy) (PVHVM) |
| 491 | ` |
| 492 | |
Pratik Mallya | 3de347f | 2015-09-22 12:25:59 -0500 | [diff] [blame] | 493 | // ValidJSONEnvironment is a valid environment for a stack in JSON format |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 494 | const ValidJSONEnvironment = ` |
| 495 | { |
| 496 | "parameters": { |
| 497 | "user_key": "userkey" |
| 498 | }, |
| 499 | "resource_registry": { |
| 500 | "My::WP::Server": "file:///home/shardy/git/heat-templates/hot/F18/WordPress_Native.yaml", |
| 501 | "OS::Quantum*": "OS::Neutron*", |
| 502 | "AWS::CloudWatch::Alarm": "file:///etc/heat/templates/AWS_CloudWatch_Alarm.yaml", |
| 503 | "OS::Metering::Alarm": "OS::Ceilometer::Alarm", |
| 504 | "AWS::RDS::DBInstance": "file:///etc/heat/templates/AWS_RDS_DBInstance.yaml", |
| 505 | "resources": { |
| 506 | "my_db_server": { |
| 507 | "OS::DBInstance": "file:///home/mine/all_my_cool_templates/db.yaml" |
| 508 | }, |
| 509 | "my_server": { |
| 510 | "OS::DBInstance": "file:///home/mine/all_my_cool_templates/db.yaml", |
| 511 | "hooks": "pre-create" |
| 512 | }, |
| 513 | "nested_stack": { |
| 514 | "nested_resource": { |
| 515 | "hooks": "pre-update" |
| 516 | }, |
| 517 | "another_resource": { |
| 518 | "hooks": [ |
| 519 | "pre-create", |
| 520 | "pre-update" |
| 521 | ] |
| 522 | } |
| 523 | } |
| 524 | } |
| 525 | } |
| 526 | } |
| 527 | ` |
| 528 | |
Pratik Mallya | 3de347f | 2015-09-22 12:25:59 -0500 | [diff] [blame] | 529 | // ValidJSONEnvironmentParsed is the expected parsed version of ValidJSONEnvironment |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 530 | var ValidJSONEnvironmentParsed = map[string]interface{}{ |
| 531 | "parameters": map[string]interface{}{ |
| 532 | "user_key": "userkey", |
| 533 | }, |
| 534 | "resource_registry": map[string]interface{}{ |
| 535 | "My::WP::Server": "file:///home/shardy/git/heat-templates/hot/F18/WordPress_Native.yaml", |
| 536 | "OS::Quantum*": "OS::Neutron*", |
| 537 | "AWS::CloudWatch::Alarm": "file:///etc/heat/templates/AWS_CloudWatch_Alarm.yaml", |
| 538 | "OS::Metering::Alarm": "OS::Ceilometer::Alarm", |
| 539 | "AWS::RDS::DBInstance": "file:///etc/heat/templates/AWS_RDS_DBInstance.yaml", |
| 540 | "resources": map[string]interface{}{ |
| 541 | "my_db_server": map[string]interface{}{ |
| 542 | "OS::DBInstance": "file:///home/mine/all_my_cool_templates/db.yaml", |
| 543 | }, |
| 544 | "my_server": map[string]interface{}{ |
| 545 | "OS::DBInstance": "file:///home/mine/all_my_cool_templates/db.yaml", |
| 546 | "hooks": "pre-create", |
| 547 | }, |
| 548 | "nested_stack": map[string]interface{}{ |
| 549 | "nested_resource": map[string]interface{}{ |
| 550 | "hooks": "pre-update", |
| 551 | }, |
| 552 | "another_resource": map[string]interface{}{ |
| 553 | "hooks": []interface{}{ |
| 554 | "pre-create", |
| 555 | "pre-update", |
| 556 | }, |
| 557 | }, |
| 558 | }, |
| 559 | }, |
| 560 | }, |
| 561 | } |
| 562 | |
Pratik Mallya | 3de347f | 2015-09-22 12:25:59 -0500 | [diff] [blame] | 563 | // ValidYAMLEnvironment is a valid environment for a stack in YAML format |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 564 | const ValidYAMLEnvironment = ` |
| 565 | parameters: |
| 566 | user_key: userkey |
| 567 | resource_registry: |
| 568 | My::WP::Server: file:///home/shardy/git/heat-templates/hot/F18/WordPress_Native.yaml |
| 569 | # allow older templates with Quantum in them. |
| 570 | "OS::Quantum*": "OS::Neutron*" |
| 571 | # Choose your implementation of AWS::CloudWatch::Alarm |
| 572 | "AWS::CloudWatch::Alarm": "file:///etc/heat/templates/AWS_CloudWatch_Alarm.yaml" |
| 573 | #"AWS::CloudWatch::Alarm": "OS::Heat::CWLiteAlarm" |
| 574 | "OS::Metering::Alarm": "OS::Ceilometer::Alarm" |
| 575 | "AWS::RDS::DBInstance": "file:///etc/heat/templates/AWS_RDS_DBInstance.yaml" |
| 576 | resources: |
| 577 | my_db_server: |
| 578 | "OS::DBInstance": file:///home/mine/all_my_cool_templates/db.yaml |
| 579 | my_server: |
| 580 | "OS::DBInstance": file:///home/mine/all_my_cool_templates/db.yaml |
| 581 | hooks: pre-create |
| 582 | nested_stack: |
| 583 | nested_resource: |
| 584 | hooks: pre-update |
| 585 | another_resource: |
| 586 | hooks: [pre-create, pre-update] |
| 587 | ` |
| 588 | |
Pratik Mallya | 3de347f | 2015-09-22 12:25:59 -0500 | [diff] [blame] | 589 | // InvalidEnvironment is an invalid environment as it has an extra section called `resources` |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 590 | const InvalidEnvironment = ` |
| 591 | parameters: |
| 592 | flavor: |
| 593 | type: string |
| 594 | description: Flavor for the server to be created |
| 595 | default: 4353 |
| 596 | hidden: true |
| 597 | resources: |
| 598 | test_server: |
| 599 | type: "OS::Nova::Server" |
| 600 | properties: |
| 601 | name: test-server |
| 602 | flavor: 2 GB General Purpose v1 |
| 603 | image: Debian 7 (Wheezy) (PVHVM) |
| 604 | parameter_defaults: |
| 605 | KeyName: heat_key |
| 606 | ` |