packer: Tempaltes understand "pause_before" in provisioners

This commit is contained in:
Mitchell Hashimoto 2013-12-20 12:34:20 -08:00
parent 5eb16895cd
commit ca70cd8f0e
2 changed files with 52 additions and 2 deletions

View File

@ -9,6 +9,7 @@ import (
"io/ioutil"
"os"
"sort"
"time"
)
// The rawTemplate struct represents the structure of a template read
@ -65,8 +66,11 @@ type RawProvisionerConfig struct {
Type string
Override map[string]interface{}
RawPauseBefore string `mapstructure:"pause_before"`
RawConfig interface{}
pauseBefore time.Duration
}
// RawVariable represents a variable configuration within a template.
@ -289,6 +293,19 @@ func ParseTemplate(data []byte) (t *Template, err error) {
}
}
// Setup the pause settings
if raw.RawPauseBefore != "" {
duration, err := time.ParseDuration(raw.RawPauseBefore)
if err != nil {
errors = append(
errors, fmt.Errorf(
"provisioner %d: pause_before invalid: %s",
i+1, err))
}
raw.pauseBefore = duration
}
raw.RawConfig = v
}

View File

@ -6,6 +6,7 @@ import (
"reflect"
"sort"
"testing"
"time"
)
func testTemplateComponentFinder() *ComponentFinder {
@ -445,6 +446,38 @@ func TestParseTemplate_Provisioners(t *testing.T) {
}
}
func TestParseTemplate_ProvisionerPauseBefore(t *testing.T) {
data := `
{
"builders": [{"type": "foo"}],
"provisioners": [
{
"type": "shell",
"pause_before": "10s"
}
]
}
`
result, err := ParseTemplate([]byte(data))
if err != nil {
t.Fatal("err: %s", err)
}
if result == nil {
t.Fatal("should have result")
}
if len(result.Provisioners) != 1 {
t.Fatalf("bad: %#v", result.Provisioners)
}
if result.Provisioners[0].Type != "shell" {
t.Fatalf("bad: %#v", result.Provisioners[0].Type)
}
if result.Provisioners[0].pauseBefore != 10 * time.Second {
t.Fatalf("bad: %s", result.Provisioners[0].pauseBefore)
}
}
func TestParseTemplate_Variables(t *testing.T) {
data := `
{