From 6d2e50e5982eae719e1b5bc4fc7ea0b88d5af3f9 Mon Sep 17 00:00:00 2001 From: Greg Lu Date: Tue, 31 Dec 2013 18:28:33 -0500 Subject: [PATCH] builder/virtualbox/ovf: fix shutdown_timeout handling The shutdown_timeout config parameter was being ignored (for both the user setting and the "5m" default) on the virtualbox-ovf builder. As a result, packer complained of timeouts on graceful shutdowns, and the build process would error out. This fixes that along with some newly created tests. --- builder/virtualbox/ovf/config.go | 1 + builder/virtualbox/ovf/config_test.go | 36 +++++++++++++++++++++++---- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/builder/virtualbox/ovf/config.go b/builder/virtualbox/ovf/config.go index 9e37659fc..51918fdb2 100644 --- a/builder/virtualbox/ovf/config.go +++ b/builder/virtualbox/ovf/config.go @@ -51,6 +51,7 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) { errs = packer.MultiErrorAppend(errs, c.FloppyConfig.Prepare(c.tpl)...) errs = packer.MultiErrorAppend(errs, c.OutputConfig.Prepare(c.tpl, &c.PackerConfig)...) errs = packer.MultiErrorAppend(errs, c.RunConfig.Prepare(c.tpl)...) + errs = packer.MultiErrorAppend(errs, c.ShutdownConfig.Prepare(c.tpl)...) errs = packer.MultiErrorAppend(errs, c.SSHConfig.Prepare(c.tpl)...) errs = packer.MultiErrorAppend(errs, c.VBoxManageConfig.Prepare(c.tpl)...) errs = packer.MultiErrorAppend(errs, c.VBoxVersionConfig.Prepare(c.tpl)...) diff --git a/builder/virtualbox/ovf/config_test.go b/builder/virtualbox/ovf/config_test.go index dbb156ce1..a94c26bf9 100644 --- a/builder/virtualbox/ovf/config_test.go +++ b/builder/virtualbox/ovf/config_test.go @@ -13,6 +13,19 @@ func testConfig(t *testing.T) map[string]interface{} { } } +func getTempFile(t *testing.T) *os.File { + tf, err := ioutil.TempFile("", "packer") + if err != nil { + t.Fatalf("err: %s", err) + } + tf.Close() + + // don't forget to cleanup the file downstream: + // defer os.Remove(tf.Name()) + + return tf +} + func testConfigErr(t *testing.T, warns []string, err error) { if len(warns) > 0 { t.Fatalf("bad: %#v", warns) @@ -45,11 +58,7 @@ func TestNewConfig_sourcePath(t *testing.T) { testConfigErr(t, warns, errs) // Good - tf, err := ioutil.TempFile("", "packer") - if err != nil { - t.Fatalf("err: %s", err) - } - tf.Close() + tf := getTempFile(t) defer os.Remove(tf.Name()) c = testConfig(t) @@ -57,3 +66,20 @@ func TestNewConfig_sourcePath(t *testing.T) { _, warns, errs = NewConfig(c) testConfigOk(t, warns, errs) } + +func TestNewConfig_shutdown_timeout(t *testing.T) { + c := testConfig(t) + tf := getTempFile(t) + defer os.Remove(tf.Name()) + + // Expect this to fail + c["source_path"] = tf.Name() + c["shutdown_timeout"] = "NaN" + _, warns, errs := NewConfig(c) + testConfigErr(t, warns, errs) + + // Passes when given a valid time duration + c["shutdown_timeout"] = "10s" + _, warns, errs = NewConfig(c) + testConfigOk(t, warns, errs) +}