blob: 01e76d61403b60bcbb90625804578bd2dd96eb8e [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
Jon Perritt35e27e42014-12-05 11:10:46 -070014func TestStacks(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 stackName1 := "gophercloud-test-stack-2"
20 createOpts := stacks.CreateOpts{
21 Name: stackName1,
22 Template: template,
23 Timeout: 5,
24 }
25 stack, err := stacks.Create(client, createOpts).Extract()
26 th.AssertNoErr(t, err)
27 t.Logf("Created stack: %+v\n", stack)
28 defer func() {
29 err := stacks.Delete(client, stackName1, stack.ID).ExtractErr()
30 th.AssertNoErr(t, err)
31 t.Logf("Deleted stack (%s)", stackName1)
32 }()
33 err = gophercloud.WaitFor(60, func() (bool, error) {
Jon Perritt93e02bb2014-12-18 11:39:41 -070034 getStack, err := stacks.Get(client, stackName1, stack.ID).Extract()
Jon Perritt35e27e42014-12-05 11:10:46 -070035 if err != nil {
36 return false, err
37 }
Jon Perritt93e02bb2014-12-18 11:39:41 -070038 if getStack.Status == "CREATE_COMPLETE" {
Jon Perritt35e27e42014-12-05 11:10:46 -070039 return true, nil
40 }
41 return false, nil
42 })
Jon Perritt35e27e42014-12-05 11:10:46 -070043
44 updateOpts := stacks.UpdateOpts{
45 Template: template,
46 Timeout: 20,
47 }
48 err = stacks.Update(client, stackName1, stack.ID, updateOpts).ExtractErr()
49 th.AssertNoErr(t, err)
Jon Perrittebc9e4c2015-02-09 12:52:00 -070050 err = gophercloud.WaitFor(60, func() (bool, error) {
51 getStack, err := stacks.Get(client, stackName1, stack.ID).Extract()
52 if err != nil {
53 return false, err
54 }
55 if getStack.Status == "UPDATE_COMPLETE" {
56 return true, nil
57 }
58 return false, nil
59 })
60
Jon Perritt35e27e42014-12-05 11:10:46 -070061 t.Logf("Updated stack")
62
63 err = stacks.List(client, nil).EachPage(func(page pagination.Page) (bool, error) {
64 stackList, err := stacks.ExtractStacks(page)
65 th.AssertNoErr(t, err)
66
67 t.Logf("Got stack list: %+v\n", stackList)
68
69 return true, nil
70 })
71 th.AssertNoErr(t, err)
72
Jon Perritt93e02bb2014-12-18 11:39:41 -070073 getStack, err := stacks.Get(client, stackName1, stack.ID).Extract()
Jon Perritt35e27e42014-12-05 11:10:46 -070074 th.AssertNoErr(t, err)
Jon Perritt93e02bb2014-12-18 11:39:41 -070075 t.Logf("Got stack: %+v\n", getStack)
Jon Perrittebc9e4c2015-02-09 12:52:00 -070076
77 abandonedStack, err := stacks.Abandon(client, stackName1, stack.ID).Extract()
78 th.AssertNoErr(t, err)
79 t.Logf("Abandonded stack %+v\n", abandonedStack)
Jon Perrittebc9e4c2015-02-09 12:52:00 -070080 th.AssertNoErr(t, err)
Jon Perritt35e27e42014-12-05 11:10:46 -070081}