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 | |
Krzysztof Szukiełojć | 3f41d08 | 2017-05-07 14:43:06 +0200 | [diff] [blame] | 8 | "gerrit.mcp.mirantis.net/debian/gophercloud.git" |
Krzysztof Szukiełojć | 24a29ce | 2017-05-07 14:24:02 +0200 | [diff] [blame] | 9 | "gerrit.mcp.mirantis.net/debian/gophercloud.git/openstack/orchestration/v1/stacks" |
| 10 | "gerrit.mcp.mirantis.net/debian/gophercloud.git/pagination" |
| 11 | th "gerrit.mcp.mirantis.net/debian/gophercloud.git/testhelper" |
Jon Perritt | 35e27e4 | 2014-12-05 11:10:46 -0700 | [diff] [blame] | 12 | ) |
| 13 | |
Jon Perritt | 35e27e4 | 2014-12-05 11:10:46 -0700 | [diff] [blame] | 14 | func 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 Perritt | 93e02bb | 2014-12-18 11:39:41 -0700 | [diff] [blame] | 34 | getStack, err := stacks.Get(client, stackName1, stack.ID).Extract() |
Jon Perritt | 35e27e4 | 2014-12-05 11:10:46 -0700 | [diff] [blame] | 35 | if err != nil { |
| 36 | return false, err |
| 37 | } |
Jon Perritt | 93e02bb | 2014-12-18 11:39:41 -0700 | [diff] [blame] | 38 | if getStack.Status == "CREATE_COMPLETE" { |
Jon Perritt | 35e27e4 | 2014-12-05 11:10:46 -0700 | [diff] [blame] | 39 | return true, nil |
| 40 | } |
| 41 | return false, nil |
| 42 | }) |
Jon Perritt | 35e27e4 | 2014-12-05 11:10:46 -0700 | [diff] [blame] | 43 | |
| 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 Perritt | ebc9e4c | 2015-02-09 12:52:00 -0700 | [diff] [blame] | 50 | 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 Perritt | 35e27e4 | 2014-12-05 11:10:46 -0700 | [diff] [blame] | 61 | 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 Perritt | 93e02bb | 2014-12-18 11:39:41 -0700 | [diff] [blame] | 73 | getStack, err := stacks.Get(client, stackName1, stack.ID).Extract() |
Jon Perritt | 35e27e4 | 2014-12-05 11:10:46 -0700 | [diff] [blame] | 74 | th.AssertNoErr(t, err) |
Jon Perritt | 93e02bb | 2014-12-18 11:39:41 -0700 | [diff] [blame] | 75 | t.Logf("Got stack: %+v\n", getStack) |
Jon Perritt | ebc9e4c | 2015-02-09 12:52:00 -0700 | [diff] [blame] | 76 | |
| 77 | abandonedStack, err := stacks.Abandon(client, stackName1, stack.ID).Extract() |
| 78 | th.AssertNoErr(t, err) |
| 79 | t.Logf("Abandonded stack %+v\n", abandonedStack) |
Jon Perritt | ebc9e4c | 2015-02-09 12:52:00 -0700 | [diff] [blame] | 80 | th.AssertNoErr(t, err) |
Jon Perritt | 35e27e4 | 2014-12-05 11:10:46 -0700 | [diff] [blame] | 81 | } |
Pratik Mallya | f7fdc2f | 2015-09-17 15:19:00 -0500 | [diff] [blame] | 82 | |
| 83 | // Test using the updated interface |
| 84 | func TestStacksNewTemplateFormat(t *testing.T) { |
| 85 | // Create a provider client for making the HTTP requests. |
| 86 | // See common.go in this directory for more information. |
| 87 | client := newClient(t) |
| 88 | |
| 89 | stackName1 := "gophercloud-test-stack-2" |
| 90 | templateOpts := new(osStacks.Template) |
| 91 | templateOpts.Bin = []byte(template) |
| 92 | createOpts := osStacks.CreateOpts{ |
| 93 | Name: stackName1, |
| 94 | TemplateOpts: templateOpts, |
| 95 | Timeout: 5, |
| 96 | } |
| 97 | stack, err := stacks.Create(client, createOpts).Extract() |
| 98 | th.AssertNoErr(t, err) |
| 99 | t.Logf("Created stack: %+v\n", stack) |
| 100 | defer func() { |
| 101 | err := stacks.Delete(client, stackName1, stack.ID).ExtractErr() |
| 102 | th.AssertNoErr(t, err) |
| 103 | t.Logf("Deleted stack (%s)", stackName1) |
| 104 | }() |
| 105 | err = gophercloud.WaitFor(60, func() (bool, error) { |
| 106 | getStack, err := stacks.Get(client, stackName1, stack.ID).Extract() |
| 107 | if err != nil { |
| 108 | return false, err |
| 109 | } |
| 110 | if getStack.Status == "CREATE_COMPLETE" { |
| 111 | return true, nil |
| 112 | } |
| 113 | return false, nil |
| 114 | }) |
| 115 | |
| 116 | updateOpts := osStacks.UpdateOpts{ |
| 117 | TemplateOpts: templateOpts, |
| 118 | Timeout: 20, |
| 119 | } |
| 120 | err = stacks.Update(client, stackName1, stack.ID, updateOpts).ExtractErr() |
| 121 | th.AssertNoErr(t, err) |
| 122 | err = gophercloud.WaitFor(60, func() (bool, error) { |
| 123 | getStack, err := stacks.Get(client, stackName1, stack.ID).Extract() |
| 124 | if err != nil { |
| 125 | return false, err |
| 126 | } |
| 127 | if getStack.Status == "UPDATE_COMPLETE" { |
| 128 | return true, nil |
| 129 | } |
| 130 | return false, nil |
| 131 | }) |
| 132 | |
| 133 | t.Logf("Updated stack") |
| 134 | |
| 135 | err = stacks.List(client, nil).EachPage(func(page pagination.Page) (bool, error) { |
| 136 | stackList, err := osStacks.ExtractStacks(page) |
| 137 | th.AssertNoErr(t, err) |
| 138 | |
| 139 | t.Logf("Got stack list: %+v\n", stackList) |
| 140 | |
| 141 | return true, nil |
| 142 | }) |
| 143 | th.AssertNoErr(t, err) |
| 144 | |
| 145 | getStack, err := stacks.Get(client, stackName1, stack.ID).Extract() |
| 146 | th.AssertNoErr(t, err) |
| 147 | t.Logf("Got stack: %+v\n", getStack) |
| 148 | |
| 149 | abandonedStack, err := stacks.Abandon(client, stackName1, stack.ID).Extract() |
| 150 | th.AssertNoErr(t, err) |
| 151 | t.Logf("Abandonded stack %+v\n", abandonedStack) |
| 152 | th.AssertNoErr(t, err) |
| 153 | } |