blob: 57afb3ada86d3598f1d559dd513ed0fac768539a [file] [log] [blame]
Jon Perritt5a0ddd82015-02-09 17:07:21 -07001// +build acceptance
2
3package v1
4
5import (
6 "testing"
7
Jon Perritt27249f42016-02-18 10:35:59 -06008 "github.com/gophercloud/gophercloud"
9 osStacks "github.com/gophercloud/gophercloud/openstack/orchestration/v1/stacks"
10 "github.com/gophercloud/gophercloud/pagination"
11 "github.com/gophercloud/gophercloud/rackspace/orchestration/v1/stacks"
12 th "github.com/gophercloud/gophercloud/testhelper"
Jon Perritt5a0ddd82015-02-09 17:07:21 -070013)
14
15func TestStacks(t *testing.T) {
16 // Create a provider client for making the HTTP requests.
17 // See common.go in this directory for more information.
18 client := newClient(t)
19
20 stackName1 := "gophercloud-test-stack-2"
21 createOpts := osStacks.CreateOpts{
22 Name: stackName1,
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, stackName1, stack.ID).ExtractErr()
31 th.AssertNoErr(t, err)
32 t.Logf("Deleted stack (%s)", stackName1)
33 }()
34 err = gophercloud.WaitFor(60, func() (bool, error) {
35 getStack, err := stacks.Get(client, stackName1, 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 updateOpts := osStacks.UpdateOpts{
46 Template: template,
47 Timeout: 20,
48 }
49 err = stacks.Update(client, stackName1, stack.ID, updateOpts).ExtractErr()
50 th.AssertNoErr(t, err)
51 err = gophercloud.WaitFor(60, func() (bool, error) {
52 getStack, err := stacks.Get(client, stackName1, stack.ID).Extract()
53 if err != nil {
54 return false, err
55 }
56 if getStack.Status == "UPDATE_COMPLETE" {
57 return true, nil
58 }
59 return false, nil
60 })
61
62 t.Logf("Updated stack")
63
64 err = stacks.List(client, nil).EachPage(func(page pagination.Page) (bool, error) {
65 stackList, err := osStacks.ExtractStacks(page)
66 th.AssertNoErr(t, err)
67
68 t.Logf("Got stack list: %+v\n", stackList)
69
70 return true, nil
71 })
72 th.AssertNoErr(t, err)
73
74 getStack, err := stacks.Get(client, stackName1, stack.ID).Extract()
75 th.AssertNoErr(t, err)
76 t.Logf("Got stack: %+v\n", getStack)
77
78 abandonedStack, err := stacks.Abandon(client, stackName1, stack.ID).Extract()
79 th.AssertNoErr(t, err)
80 t.Logf("Abandonded stack %+v\n", abandonedStack)
81 th.AssertNoErr(t, err)
82}
Pratik Mallyaf7fdc2f2015-09-17 15:19:00 -050083
84// Test using the updated interface
85func TestStacksNewTemplateFormat(t *testing.T) {
86 // Create a provider client for making the HTTP requests.
87 // See common.go in this directory for more information.
88 client := newClient(t)
89
90 stackName1 := "gophercloud-test-stack-2"
91 templateOpts := new(osStacks.Template)
92 templateOpts.Bin = []byte(template)
93 createOpts := osStacks.CreateOpts{
94 Name: stackName1,
95 TemplateOpts: templateOpts,
96 Timeout: 5,
97 }
98 stack, err := stacks.Create(client, createOpts).Extract()
99 th.AssertNoErr(t, err)
100 t.Logf("Created stack: %+v\n", stack)
101 defer func() {
102 err := stacks.Delete(client, stackName1, stack.ID).ExtractErr()
103 th.AssertNoErr(t, err)
104 t.Logf("Deleted stack (%s)", stackName1)
105 }()
106 err = gophercloud.WaitFor(60, func() (bool, error) {
107 getStack, err := stacks.Get(client, stackName1, stack.ID).Extract()
108 if err != nil {
109 return false, err
110 }
111 if getStack.Status == "CREATE_COMPLETE" {
112 return true, nil
113 }
114 return false, nil
115 })
116
117 updateOpts := osStacks.UpdateOpts{
118 TemplateOpts: templateOpts,
119 Timeout: 20,
120 }
121 err = stacks.Update(client, stackName1, stack.ID, updateOpts).ExtractErr()
122 th.AssertNoErr(t, err)
123 err = gophercloud.WaitFor(60, func() (bool, error) {
124 getStack, err := stacks.Get(client, stackName1, stack.ID).Extract()
125 if err != nil {
126 return false, err
127 }
128 if getStack.Status == "UPDATE_COMPLETE" {
129 return true, nil
130 }
131 return false, nil
132 })
133
134 t.Logf("Updated stack")
135
136 err = stacks.List(client, nil).EachPage(func(page pagination.Page) (bool, error) {
137 stackList, err := osStacks.ExtractStacks(page)
138 th.AssertNoErr(t, err)
139
140 t.Logf("Got stack list: %+v\n", stackList)
141
142 return true, nil
143 })
144 th.AssertNoErr(t, err)
145
146 getStack, err := stacks.Get(client, stackName1, stack.ID).Extract()
147 th.AssertNoErr(t, err)
148 t.Logf("Got stack: %+v\n", getStack)
149
150 abandonedStack, err := stacks.Abandon(client, stackName1, stack.ID).Extract()
151 th.AssertNoErr(t, err)
152 t.Logf("Abandonded stack %+v\n", abandonedStack)
153 th.AssertNoErr(t, err)
154}