blob: bfebd2d8791d1e23d902da2f5abadbd51d235e38 [file] [log] [blame]
Jon Perritt35e27e42014-12-05 11:10:46 -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/pagination"
11 th "github.com/rackspace/gophercloud/testhelper"
12)
13
14const template = `
15{
16 "heat_template_version": "2013-05-23",
17 "description": "Simple template to test heat commands",
18 "parameters": {
19 "flavor": {
20 "default": "m1.tiny",
21 "type": "string"
22 }
23 },
24 "resources": {
25 "hello_world": {
26 "type":"OS::Nova::Server",
27 "properties": {
28 "key_name": "heat_key",
29 "flavor": {
30 "get_param": "flavor"
31 },
32 "image": "ad091b52-742f-469e-8f3c-fd81cadf0743",
33 "user_data": "#!/bin/bash -xv\necho \"hello world\" > /root/hello-world.txt\n"
34 }
35 }
36 }
37}
38`
39
40func TestStacks(t *testing.T) {
41 // Create a provider client for making the HTTP requests.
42 // See common.go in this directory for more information.
43 client := newClient(t)
44
45 stackName1 := "gophercloud-test-stack-2"
46 createOpts := stacks.CreateOpts{
47 Name: stackName1,
48 Template: template,
49 Timeout: 5,
50 }
51 stack, err := stacks.Create(client, createOpts).Extract()
52 th.AssertNoErr(t, err)
53 t.Logf("Created stack: %+v\n", stack)
54 defer func() {
55 err := stacks.Delete(client, stackName1, stack.ID).ExtractErr()
56 th.AssertNoErr(t, err)
57 t.Logf("Deleted stack (%s)", stackName1)
58 }()
59 err = gophercloud.WaitFor(60, func() (bool, error) {
Jon Perritt93e02bb2014-12-18 11:39:41 -070060 getStack, err := stacks.Get(client, stackName1, stack.ID).Extract()
Jon Perritt35e27e42014-12-05 11:10:46 -070061 if err != nil {
62 return false, err
63 }
Jon Perritt93e02bb2014-12-18 11:39:41 -070064 if getStack.Status == "CREATE_COMPLETE" {
Jon Perritt35e27e42014-12-05 11:10:46 -070065 return true, nil
66 }
67 return false, nil
68 })
69 /*
70 adoptOpts := stacks.AdoptOpts{}
71 stack, err := stacks.Adopt(client, adoptOpts).Extract()
72 th.AssertNoErr(t, err)
73 t.Logf("Adopted stack: %+v\n", stack)
74 */
75
76 updateOpts := stacks.UpdateOpts{
77 Template: template,
78 Timeout: 20,
79 }
80 err = stacks.Update(client, stackName1, stack.ID, updateOpts).ExtractErr()
81 th.AssertNoErr(t, err)
82 t.Logf("Updated stack")
83
84 err = stacks.List(client, nil).EachPage(func(page pagination.Page) (bool, error) {
85 stackList, err := stacks.ExtractStacks(page)
86 th.AssertNoErr(t, err)
87
88 t.Logf("Got stack list: %+v\n", stackList)
89
90 return true, nil
91 })
92 th.AssertNoErr(t, err)
93
Jon Perritt93e02bb2014-12-18 11:39:41 -070094 getStack, err := stacks.Get(client, stackName1, stack.ID).Extract()
Jon Perritt35e27e42014-12-05 11:10:46 -070095 th.AssertNoErr(t, err)
Jon Perritt93e02bb2014-12-18 11:39:41 -070096 t.Logf("Got stack: %+v\n", getStack)
Jon Perritt35e27e42014-12-05 11:10:46 -070097}