blob: e4ccd9e6b197fceb2618b985495cfaa8605d46b5 [file] [log] [blame]
Jon Perritt5a0ddd82015-02-09 17:07:21 -07001// +build acceptance
2
3package v1
4
5import (
6 "testing"
7
8 "github.com/rackspace/gophercloud"
9 osStacks "github.com/rackspace/gophercloud/openstack/orchestration/v1/stacks"
10 osStacktemplates "github.com/rackspace/gophercloud/openstack/orchestration/v1/stacktemplates"
11 "github.com/rackspace/gophercloud/rackspace/orchestration/v1/stacks"
12 "github.com/rackspace/gophercloud/rackspace/orchestration/v1/stacktemplates"
13 th "github.com/rackspace/gophercloud/testhelper"
14)
15
16func TestStackTemplates(t *testing.T) {
17 // Create a provider client for making the HTTP requests.
18 // See common.go in this directory for more information.
19 client := newClient(t)
20
21 stackName := "postman_stack_2"
22
23 createOpts := osStacks.CreateOpts{
24 Name: stackName,
25 Template: template,
26 Timeout: 5,
27 }
28 stack, err := stacks.Create(client, createOpts).Extract()
29 th.AssertNoErr(t, err)
30 t.Logf("Created stack: %+v\n", stack)
31 defer func() {
32 err := stacks.Delete(client, stackName, stack.ID).ExtractErr()
33 th.AssertNoErr(t, err)
34 t.Logf("Deleted stack (%s)", stackName)
35 }()
36 err = gophercloud.WaitFor(60, func() (bool, error) {
37 getStack, err := stacks.Get(client, stackName, stack.ID).Extract()
38 if err != nil {
39 return false, err
40 }
41 if getStack.Status == "CREATE_COMPLETE" {
42 return true, nil
43 }
44 return false, nil
45 })
46
47 tmpl, err := stacktemplates.Get(client, stackName, stack.ID).Extract()
48 th.AssertNoErr(t, err)
49 t.Logf("retrieved template: %+v\n", tmpl)
50
51 validateOpts := osStacktemplates.ValidateOpts{
Pratik Mallyaf7fdc2f2015-09-17 15:19:00 -050052 Template: `{"heat_template_version": "2013-05-23",
Jon Perritt5a0ddd82015-02-09 17:07:21 -070053 "description": "Simple template to test heat commands",
Pratik Mallyaf7fdc2f2015-09-17 15:19:00 -050054 "parameters": {
55 "flavor": {
Jon Perritt5a0ddd82015-02-09 17:07:21 -070056 "default": "m1.tiny",
57 "type": "string",
58 },
59 },
Pratik Mallyaf7fdc2f2015-09-17 15:19:00 -050060 "resources": {
61 "hello_world": {
Jon Perritt5a0ddd82015-02-09 17:07:21 -070062 "type": "OS::Nova::Server",
Pratik Mallyaf7fdc2f2015-09-17 15:19:00 -050063 "properties": {
Jon Perritt5a0ddd82015-02-09 17:07:21 -070064 "key_name": "heat_key",
Pratik Mallyaf7fdc2f2015-09-17 15:19:00 -050065 "flavor": {
Jon Perritt5a0ddd82015-02-09 17:07:21 -070066 "get_param": "flavor",
67 },
68 "image": "ad091b52-742f-469e-8f3c-fd81cadf0743",
69 "user_data": "#!/bin/bash -xv\necho \"hello world\" > /root/hello-world.txt\n",
70 },
71 },
72 },
Pratik Mallyaf7fdc2f2015-09-17 15:19:00 -050073 }`}
Jon Perritt5a0ddd82015-02-09 17:07:21 -070074 validatedTemplate, err := stacktemplates.Validate(client, validateOpts).Extract()
75 th.AssertNoErr(t, err)
76 t.Logf("validated template: %+v\n", validatedTemplate)
77}