Jon Perritt | 5a0ddd8 | 2015-02-09 17:07:21 -0700 | [diff] [blame] | 1 | // +build acceptance |
| 2 | |
| 3 | package v1 |
| 4 | |
| 5 | import ( |
| 6 | "testing" |
| 7 | |
| 8 | "github.com/rackspace/gophercloud" |
| 9 | osStacks "github.com/rackspace/gophercloud/openstack/orchestration/v1/stacks" |
| 10 | "github.com/rackspace/gophercloud/pagination" |
| 11 | "github.com/rackspace/gophercloud/rackspace/orchestration/v1/stacks" |
| 12 | th "github.com/rackspace/gophercloud/testhelper" |
| 13 | ) |
| 14 | |
| 15 | func 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 | } |