blob: 9e3fc084ad872ff140f428ba4deb5e52a5216ed3 [file] [log] [blame]
Jon Perritt5a0ddd82015-02-09 17:07:21 -07001// +build acceptance
2
3package v1
4
5import (
6 "testing"
7
8 "github.com/rackspace/gophercloud"
9 osStackEvents "github.com/rackspace/gophercloud/openstack/orchestration/v1/stackevents"
10 osStacks "github.com/rackspace/gophercloud/openstack/orchestration/v1/stacks"
11 "github.com/rackspace/gophercloud/pagination"
12 "github.com/rackspace/gophercloud/rackspace/orchestration/v1/stackevents"
13 "github.com/rackspace/gophercloud/rackspace/orchestration/v1/stacks"
14 th "github.com/rackspace/gophercloud/testhelper"
15)
16
17func TestStackEvents(t *testing.T) {
18 // Create a provider client for making the HTTP requests.
19 // See common.go in this directory for more information.
20 client := newClient(t)
21
22 stackName := "postman_stack_2"
23 resourceName := "hello_world"
24 var eventID string
25
26 createOpts := osStacks.CreateOpts{
27 Name: stackName,
28 Template: template,
29 Timeout: 5,
30 }
31 stack, err := stacks.Create(client, createOpts).Extract()
32 th.AssertNoErr(t, err)
33 t.Logf("Created stack: %+v\n", stack)
34 defer func() {
35 err := stacks.Delete(client, stackName, stack.ID).ExtractErr()
36 th.AssertNoErr(t, err)
37 t.Logf("Deleted stack (%s)", stackName)
38 }()
39 err = gophercloud.WaitFor(60, func() (bool, error) {
40 getStack, err := stacks.Get(client, stackName, stack.ID).Extract()
41 if err != nil {
42 return false, err
43 }
44 if getStack.Status == "CREATE_COMPLETE" {
45 return true, nil
46 }
47 return false, nil
48 })
49
50 err = stackevents.List(client, stackName, stack.ID, nil).EachPage(func(page pagination.Page) (bool, error) {
51 events, err := osStackEvents.ExtractEvents(page)
52 th.AssertNoErr(t, err)
53 t.Logf("listed events: %+v\n", events)
54 eventID = events[0].ID
55 return false, nil
56 })
57 th.AssertNoErr(t, err)
58
59 err = stackevents.ListResourceEvents(client, stackName, stack.ID, resourceName, nil).EachPage(func(page pagination.Page) (bool, error) {
60 resourceEvents, err := osStackEvents.ExtractResourceEvents(page)
61 th.AssertNoErr(t, err)
62 t.Logf("listed resource events: %+v\n", resourceEvents)
63 return false, nil
64 })
65 th.AssertNoErr(t, err)
66
67 event, err := stackevents.Get(client, stackName, stack.ID, resourceName, eventID).Extract()
68 th.AssertNoErr(t, err)
69 t.Logf("retrieved event: %+v\n", event)
70}