Jon Perritt | 35e27e4 | 2014-12-05 11:10:46 -0700 | [diff] [blame^] | 1 | // +build acceptance |
| 2 | |
| 3 | package v1 |
| 4 | |
| 5 | import ( |
| 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 | |
| 14 | const template = ` |
| 15 | { |
| 16 | "heat_template_version": "2013-05-23", |
| 17 | "description": "Simple template to test heat commands", |
| 18 | "parameters": { |
| 19 | "flavor": { |
| 20 | "default": "m1.tiny", |
| 21 | "type": "string" |
| 22 | } |
| 23 | }, |
| 24 | "resources": { |
| 25 | "hello_world": { |
| 26 | "type":"OS::Nova::Server", |
| 27 | "properties": { |
| 28 | "key_name": "heat_key", |
| 29 | "flavor": { |
| 30 | "get_param": "flavor" |
| 31 | }, |
| 32 | "image": "ad091b52-742f-469e-8f3c-fd81cadf0743", |
| 33 | "user_data": "#!/bin/bash -xv\necho \"hello world\" > /root/hello-world.txt\n" |
| 34 | } |
| 35 | } |
| 36 | } |
| 37 | } |
| 38 | ` |
| 39 | |
| 40 | func TestStacks(t *testing.T) { |
| 41 | // Create a provider client for making the HTTP requests. |
| 42 | // See common.go in this directory for more information. |
| 43 | client := newClient(t) |
| 44 | |
| 45 | stackName1 := "gophercloud-test-stack-2" |
| 46 | createOpts := stacks.CreateOpts{ |
| 47 | Name: stackName1, |
| 48 | Template: template, |
| 49 | Timeout: 5, |
| 50 | } |
| 51 | stack, err := stacks.Create(client, createOpts).Extract() |
| 52 | th.AssertNoErr(t, err) |
| 53 | t.Logf("Created stack: %+v\n", stack) |
| 54 | defer func() { |
| 55 | err := stacks.Delete(client, stackName1, stack.ID).ExtractErr() |
| 56 | th.AssertNoErr(t, err) |
| 57 | t.Logf("Deleted stack (%s)", stackName1) |
| 58 | }() |
| 59 | err = gophercloud.WaitFor(60, func() (bool, error) { |
| 60 | stack, err = stacks.Get(client, stackName1, stack.ID).Extract() |
| 61 | if err != nil { |
| 62 | return false, err |
| 63 | } |
| 64 | if stack.Status == "CREATE_COMPLETE" { |
| 65 | return true, nil |
| 66 | } |
| 67 | return false, nil |
| 68 | }) |
| 69 | /* |
| 70 | adoptOpts := stacks.AdoptOpts{} |
| 71 | stack, err := stacks.Adopt(client, adoptOpts).Extract() |
| 72 | th.AssertNoErr(t, err) |
| 73 | t.Logf("Adopted stack: %+v\n", stack) |
| 74 | */ |
| 75 | |
| 76 | updateOpts := stacks.UpdateOpts{ |
| 77 | Template: template, |
| 78 | Timeout: 20, |
| 79 | } |
| 80 | err = stacks.Update(client, stackName1, stack.ID, updateOpts).ExtractErr() |
| 81 | th.AssertNoErr(t, err) |
| 82 | t.Logf("Updated stack") |
| 83 | |
| 84 | err = stacks.List(client, nil).EachPage(func(page pagination.Page) (bool, error) { |
| 85 | stackList, err := stacks.ExtractStacks(page) |
| 86 | th.AssertNoErr(t, err) |
| 87 | |
| 88 | t.Logf("Got stack list: %+v\n", stackList) |
| 89 | |
| 90 | return true, nil |
| 91 | }) |
| 92 | th.AssertNoErr(t, err) |
| 93 | |
| 94 | stack, err = stacks.Get(client, stackName1, stack.ID).Extract() |
| 95 | th.AssertNoErr(t, err) |
| 96 | t.Logf("Got stack: %+v\n", stack) |
| 97 | } |