Jon Perritt | 79f185f | 2015-02-09 16:01:06 -0700 | [diff] [blame] | 1 | // +build acceptance |
| 2 | |
| 3 | package v1 |
| 4 | |
| 5 | import ( |
| 6 | "testing" |
| 7 | |
Jon Perritt | 27249f4 | 2016-02-18 10:35:59 -0600 | [diff] [blame^] | 8 | "github.com/gophercloud/gophercloud" |
| 9 | "github.com/gophercloud/gophercloud/openstack/orchestration/v1/stacks" |
| 10 | "github.com/gophercloud/gophercloud/openstack/orchestration/v1/stacktemplates" |
| 11 | th "github.com/gophercloud/gophercloud/testhelper" |
Jon Perritt | 79f185f | 2015-02-09 16:01:06 -0700 | [diff] [blame] | 12 | ) |
| 13 | |
| 14 | func TestStackTemplates(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 | stackName := "postman_stack_2" |
| 20 | |
| 21 | createOpts := stacks.CreateOpts{ |
| 22 | Name: stackName, |
| 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, stackName, stack.ID).ExtractErr() |
| 31 | th.AssertNoErr(t, err) |
| 32 | t.Logf("Deleted stack (%s)", stackName) |
| 33 | }() |
| 34 | err = gophercloud.WaitFor(60, func() (bool, error) { |
| 35 | getStack, err := stacks.Get(client, stackName, 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 | tmpl, err := stacktemplates.Get(client, stackName, stack.ID).Extract() |
| 46 | th.AssertNoErr(t, err) |
| 47 | t.Logf("retrieved template: %+v\n", tmpl) |
| 48 | |
Pratik Mallya | f7fdc2f | 2015-09-17 15:19:00 -0500 | [diff] [blame] | 49 | validateOpts := osStacktemplates.ValidateOpts{ |
| 50 | Template: `{"heat_template_version": "2013-05-23", |
| 51 | "description": "Simple template to test heat commands", |
| 52 | "parameters": { |
| 53 | "flavor": { |
Jon Perritt | 79f185f | 2015-02-09 16:01:06 -0700 | [diff] [blame] | 54 | "default": "m1.tiny", |
| 55 | "type": "string", |
| 56 | }, |
| 57 | }, |
Pratik Mallya | f7fdc2f | 2015-09-17 15:19:00 -0500 | [diff] [blame] | 58 | "resources": { |
| 59 | "hello_world": { |
Jon Perritt | 79f185f | 2015-02-09 16:01:06 -0700 | [diff] [blame] | 60 | "type": "OS::Nova::Server", |
Pratik Mallya | f7fdc2f | 2015-09-17 15:19:00 -0500 | [diff] [blame] | 61 | "properties": { |
Jon Perritt | 79f185f | 2015-02-09 16:01:06 -0700 | [diff] [blame] | 62 | "key_name": "heat_key", |
Pratik Mallya | f7fdc2f | 2015-09-17 15:19:00 -0500 | [diff] [blame] | 63 | "flavor": { |
Jon Perritt | 79f185f | 2015-02-09 16:01:06 -0700 | [diff] [blame] | 64 | "get_param": "flavor", |
| 65 | }, |
| 66 | "image": "ad091b52-742f-469e-8f3c-fd81cadf0743", |
| 67 | "user_data": "#!/bin/bash -xv\necho \"hello world\" > /root/hello-world.txt\n", |
| 68 | }, |
| 69 | }, |
| 70 | }, |
Pratik Mallya | f7fdc2f | 2015-09-17 15:19:00 -0500 | [diff] [blame] | 71 | }`} |
Jon Perritt | 79f185f | 2015-02-09 16:01:06 -0700 | [diff] [blame] | 72 | validatedTemplate, err := stacktemplates.Validate(client, validateOpts).Extract() |
| 73 | th.AssertNoErr(t, err) |
| 74 | t.Logf("validated template: %+v\n", validatedTemplate) |
| 75 | } |