blob: bee8f848ed950566dc3e4cf3d5eea3276f5cb95b [file] [log] [blame]
Jon Perritt35e27e42014-12-05 11:10:46 -07001// +build acceptance
2
3package v1
4
5import (
Jon Perrittebc9e4c2015-02-09 12:52:00 -07006 "encoding/json"
Jon Perritt35e27e42014-12-05 11:10:46 -07007 "testing"
8
9 "github.com/rackspace/gophercloud"
10 "github.com/rackspace/gophercloud/openstack/orchestration/v1/stacks"
11 "github.com/rackspace/gophercloud/pagination"
12 th "github.com/rackspace/gophercloud/testhelper"
13)
14
Jon Perritt35e27e42014-12-05 11:10:46 -070015func 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 := stacks.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) {
Jon Perritt93e02bb2014-12-18 11:39:41 -070035 getStack, err := stacks.Get(client, stackName1, stack.ID).Extract()
Jon Perritt35e27e42014-12-05 11:10:46 -070036 if err != nil {
37 return false, err
38 }
Jon Perritt93e02bb2014-12-18 11:39:41 -070039 if getStack.Status == "CREATE_COMPLETE" {
Jon Perritt35e27e42014-12-05 11:10:46 -070040 return true, nil
41 }
42 return false, nil
43 })
Jon Perritt35e27e42014-12-05 11:10:46 -070044
45 updateOpts := stacks.UpdateOpts{
46 Template: template,
47 Timeout: 20,
48 }
49 err = stacks.Update(client, stackName1, stack.ID, updateOpts).ExtractErr()
50 th.AssertNoErr(t, err)
Jon Perrittebc9e4c2015-02-09 12:52:00 -070051 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
Jon Perritt35e27e42014-12-05 11:10:46 -070062 t.Logf("Updated stack")
63
64 err = stacks.List(client, nil).EachPage(func(page pagination.Page) (bool, error) {
65 stackList, err := stacks.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
Jon Perritt93e02bb2014-12-18 11:39:41 -070074 getStack, err := stacks.Get(client, stackName1, stack.ID).Extract()
Jon Perritt35e27e42014-12-05 11:10:46 -070075 th.AssertNoErr(t, err)
Jon Perritt93e02bb2014-12-18 11:39:41 -070076 t.Logf("Got stack: %+v\n", getStack)
Jon Perrittebc9e4c2015-02-09 12:52:00 -070077
78 abandonedStack, err := stacks.Abandon(client, stackName1, stack.ID).Extract()
79 th.AssertNoErr(t, err)
80 t.Logf("Abandonded stack %+v\n", abandonedStack)
81
82 abandonedStackBytes, err := json.Marshal(*abandonedStack)
83 th.AssertNoErr(t, err)
Jon Perritt35e27e42014-12-05 11:10:46 -070084}