blob: 9992e0c044e591da1b7d7e066cae740e08eb490e [file] [log] [blame]
Jon Perritt79f185f2015-02-09 16:01:06 -07001// +build acceptance
2
3package v1
4
5import (
6 "testing"
7
Jon Perritt27249f42016-02-18 10:35:59 -06008 "github.com/gophercloud/gophercloud"
9 "github.com/gophercloud/gophercloud/openstack/orchestration/v1/stacks"
10 "github.com/gophercloud/gophercloud/openstack/orchestration/v1/stacktemplates"
11 th "github.com/gophercloud/gophercloud/testhelper"
Jon Perritt79f185f2015-02-09 16:01:06 -070012)
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
Pratik Mallyaf7fdc2f2015-09-17 15:19:00 -050049 validateOpts := osStacktemplates.ValidateOpts{
50 Template: `{"heat_template_version": "2013-05-23",
51 "description": "Simple template to test heat commands",
52 "parameters": {
53 "flavor": {
Jon Perritt79f185f2015-02-09 16:01:06 -070054 "default": "m1.tiny",
55 "type": "string",
56 },
57 },
Pratik Mallyaf7fdc2f2015-09-17 15:19:00 -050058 "resources": {
59 "hello_world": {
Jon Perritt79f185f2015-02-09 16:01:06 -070060 "type": "OS::Nova::Server",
Pratik Mallyaf7fdc2f2015-09-17 15:19:00 -050061 "properties": {
Jon Perritt79f185f2015-02-09 16:01:06 -070062 "key_name": "heat_key",
Pratik Mallyaf7fdc2f2015-09-17 15:19:00 -050063 "flavor": {
Jon Perritt79f185f2015-02-09 16:01:06 -070064 "get_param": "flavor",
65 },
66 "image": "ad091b52-742f-469e-8f3c-fd81cadf0743",
67 "user_data": "#!/bin/bash -xv\necho \"hello world\" > /root/hello-world.txt\n",
68 },
69 },
70 },
Pratik Mallyaf7fdc2f2015-09-17 15:19:00 -050071 }`}
Jon Perritt79f185f2015-02-09 16:01:06 -070072 validatedTemplate, err := stacktemplates.Validate(client, validateOpts).Extract()
73 th.AssertNoErr(t, err)
74 t.Logf("validated template: %+v\n", validatedTemplate)
75}