| 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{ | 
 | 52 | 		Template: map[string]interface{}{ | 
 | 53 | 			"heat_template_version": "2013-05-23", | 
 | 54 | 			"description":           "Simple template to test heat commands", | 
 | 55 | 			"parameters": map[string]interface{}{ | 
 | 56 | 				"flavor": map[string]interface{}{ | 
 | 57 | 					"default": "m1.tiny", | 
 | 58 | 					"type":    "string", | 
 | 59 | 				}, | 
 | 60 | 			}, | 
 | 61 | 			"resources": map[string]interface{}{ | 
 | 62 | 				"hello_world": map[string]interface{}{ | 
 | 63 | 					"type": "OS::Nova::Server", | 
 | 64 | 					"properties": map[string]interface{}{ | 
 | 65 | 						"key_name": "heat_key", | 
 | 66 | 						"flavor": map[string]interface{}{ | 
 | 67 | 							"get_param": "flavor", | 
 | 68 | 						}, | 
 | 69 | 						"image":     "ad091b52-742f-469e-8f3c-fd81cadf0743", | 
 | 70 | 						"user_data": "#!/bin/bash -xv\necho \"hello world\" > /root/hello-world.txt\n", | 
 | 71 | 					}, | 
 | 72 | 				}, | 
 | 73 | 			}, | 
 | 74 | 		}, | 
 | 75 | 	} | 
 | 76 | 	validatedTemplate, err := stacktemplates.Validate(client, validateOpts).Extract() | 
 | 77 | 	th.AssertNoErr(t, err) | 
 | 78 | 	t.Logf("validated template: %+v\n", validatedTemplate) | 
 | 79 | } |