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 | osStacktemplates "github.com/rackspace/gophercloud/openstack/orchestration/v1/stacktemplates" |
| 11 | "github.com/rackspace/gophercloud/rackspace/orchestration/v1/stacks" |
| 12 | "github.com/rackspace/gophercloud/rackspace/orchestration/v1/stacktemplates" |
| 13 | th "github.com/rackspace/gophercloud/testhelper" |
| 14 | ) |
| 15 | |
| 16 | func TestStackTemplates(t *testing.T) { |
| 17 | // Create a provider client for making the HTTP requests. |
| 18 | // See common.go in this directory for more information. |
| 19 | client := newClient(t) |
| 20 | |
| 21 | stackName := "postman_stack_2" |
| 22 | |
| 23 | createOpts := osStacks.CreateOpts{ |
| 24 | Name: stackName, |
| 25 | Template: template, |
| 26 | Timeout: 5, |
| 27 | } |
| 28 | stack, err := stacks.Create(client, createOpts).Extract() |
| 29 | th.AssertNoErr(t, err) |
| 30 | t.Logf("Created stack: %+v\n", stack) |
| 31 | defer func() { |
| 32 | err := stacks.Delete(client, stackName, stack.ID).ExtractErr() |
| 33 | th.AssertNoErr(t, err) |
| 34 | t.Logf("Deleted stack (%s)", stackName) |
| 35 | }() |
| 36 | err = gophercloud.WaitFor(60, func() (bool, error) { |
| 37 | getStack, err := stacks.Get(client, stackName, stack.ID).Extract() |
| 38 | if err != nil { |
| 39 | return false, err |
| 40 | } |
| 41 | if getStack.Status == "CREATE_COMPLETE" { |
| 42 | return true, nil |
| 43 | } |
| 44 | return false, nil |
| 45 | }) |
| 46 | |
| 47 | tmpl, err := stacktemplates.Get(client, stackName, stack.ID).Extract() |
| 48 | th.AssertNoErr(t, err) |
| 49 | t.Logf("retrieved template: %+v\n", tmpl) |
| 50 | |
| 51 | validateOpts := osStacktemplates.ValidateOpts{ |
Pratik Mallya | f7fdc2f | 2015-09-17 15:19:00 -0500 | [diff] [blame^] | 52 | Template: `{"heat_template_version": "2013-05-23", |
Jon Perritt | 5a0ddd8 | 2015-02-09 17:07:21 -0700 | [diff] [blame] | 53 | "description": "Simple template to test heat commands", |
Pratik Mallya | f7fdc2f | 2015-09-17 15:19:00 -0500 | [diff] [blame^] | 54 | "parameters": { |
| 55 | "flavor": { |
Jon Perritt | 5a0ddd8 | 2015-02-09 17:07:21 -0700 | [diff] [blame] | 56 | "default": "m1.tiny", |
| 57 | "type": "string", |
| 58 | }, |
| 59 | }, |
Pratik Mallya | f7fdc2f | 2015-09-17 15:19:00 -0500 | [diff] [blame^] | 60 | "resources": { |
| 61 | "hello_world": { |
Jon Perritt | 5a0ddd8 | 2015-02-09 17:07:21 -0700 | [diff] [blame] | 62 | "type": "OS::Nova::Server", |
Pratik Mallya | f7fdc2f | 2015-09-17 15:19:00 -0500 | [diff] [blame^] | 63 | "properties": { |
Jon Perritt | 5a0ddd8 | 2015-02-09 17:07:21 -0700 | [diff] [blame] | 64 | "key_name": "heat_key", |
Pratik Mallya | f7fdc2f | 2015-09-17 15:19:00 -0500 | [diff] [blame^] | 65 | "flavor": { |
Jon Perritt | 5a0ddd8 | 2015-02-09 17:07:21 -0700 | [diff] [blame] | 66 | "get_param": "flavor", |
| 67 | }, |
| 68 | "image": "ad091b52-742f-469e-8f3c-fd81cadf0743", |
| 69 | "user_data": "#!/bin/bash -xv\necho \"hello world\" > /root/hello-world.txt\n", |
| 70 | }, |
| 71 | }, |
| 72 | }, |
Pratik Mallya | f7fdc2f | 2015-09-17 15:19:00 -0500 | [diff] [blame^] | 73 | }`} |
Jon Perritt | 5a0ddd8 | 2015-02-09 17:07:21 -0700 | [diff] [blame] | 74 | validatedTemplate, err := stacktemplates.Validate(client, validateOpts).Extract() |
| 75 | th.AssertNoErr(t, err) |
| 76 | t.Logf("validated template: %+v\n", validatedTemplate) |
| 77 | } |