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