From d13647ee0f9ed8726781a01b7772f3e58c2d149a Mon Sep 17 00:00:00 2001 From: Chris Bednarski Date: Thu, 20 Aug 2015 14:03:16 -0700 Subject: [PATCH 1/4] Updated test for qemu VMName. Previously (0.7.5) a file extension was automatically added to the VMname but this logic is not exposed for testing. --- builder/qemu/builder_test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/builder/qemu/builder_test.go b/builder/qemu/builder_test.go index 84d1d40c3..5e96d2fa7 100644 --- a/builder/qemu/builder_test.go +++ b/builder/qemu/builder_test.go @@ -1,11 +1,12 @@ package qemu import ( - "github.com/mitchellh/packer/packer" "io/ioutil" "os" "reflect" "testing" + + "github.com/mitchellh/packer/packer" ) var testPem = ` @@ -83,7 +84,7 @@ func TestBuilderPrepare_Defaults(t *testing.T) { t.Errorf("bad ssh port: %d", b.config.Comm.SSHPort) } - if b.config.VMName != "packer-foo" { + if b.config.VMName != "packer-foo.qcow2" { t.Errorf("bad vm name: %s", b.config.VMName) } From 1830c81eab2f3327bd0ab5b43f09abbfc6a4a140 Mon Sep 17 00:00:00 2001 From: Chris Bednarski Date: Thu, 20 Aug 2015 14:15:52 -0700 Subject: [PATCH 2/4] Correct and expand docker config tests for commit, discard, export_path --- builder/docker/config_test.go | 38 +++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/builder/docker/config_test.go b/builder/docker/config_test.go index 907222b4f..442c6ffe2 100644 --- a/builder/docker/config_test.go +++ b/builder/docker/config_test.go @@ -52,10 +52,11 @@ func TestConfigPrepare_exportPath(t *testing.T) { raw := testConfig() - // No export path + // No export path. This is invalid. Previously this would not error during + // validation and as a result the failure would happen at build time. delete(raw, "export_path") _, warns, errs := NewConfig(raw) - testConfigOk(t, warns, errs) + testConfigErr(t, warns, errs) // Good export path raw["export_path"] = "good" @@ -70,14 +71,39 @@ func TestConfigPrepare_exportPath(t *testing.T) { func TestConfigPrepare_exportPathAndCommit(t *testing.T) { raw := testConfig() - raw["commit"] = true - // No export path + // Export but no commit (explicit default) + raw["commit"] = false _, warns, errs := NewConfig(raw) + testConfigOk(t, warns, errs) + + // Commit AND export specified (invalid) + raw["commit"] = true + _, warns, errs = NewConfig(raw) testConfigErr(t, warns, errs) - // No commit - raw["commit"] = false + // Commit but no export + delete(raw, "export_path") + _, warns, errs = NewConfig(raw) + testConfigOk(t, warns, errs) +} + +func TestConfigPrepare_exportDiscard(t *testing.T) { + raw := testConfig() + + // Export but no discard (explicit default) + raw["discard"] = false + _, warns, errs := NewConfig(raw) + testConfigOk(t, warns, errs) + + // Discard AND export (invalid) + raw["discard"] = true + _, warns, errs = NewConfig(raw) + testConfigErr(t, warns, errs) + + // Discard but no export + raw["discard"] = true + delete(raw, "export_path") _, warns, errs = NewConfig(raw) testConfigOk(t, warns, errs) } From c8d1c650f0d5563ed4b5a24a50777d1d0755c0ac Mon Sep 17 00:00:00 2001 From: Chris Bednarski Date: Fri, 21 Aug 2015 16:45:47 -0700 Subject: [PATCH 3/4] Revert "Updated test for qemu VMName. Previously (0.7.5) a file extension was automatically added to the VMname but this logic is not exposed for testing." This reverts commit d13647ee0f9ed8726781a01b7772f3e58c2d149a. --- builder/qemu/builder_test.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/builder/qemu/builder_test.go b/builder/qemu/builder_test.go index 5e96d2fa7..84d1d40c3 100644 --- a/builder/qemu/builder_test.go +++ b/builder/qemu/builder_test.go @@ -1,12 +1,11 @@ package qemu import ( + "github.com/mitchellh/packer/packer" "io/ioutil" "os" "reflect" "testing" - - "github.com/mitchellh/packer/packer" ) var testPem = ` @@ -84,7 +83,7 @@ func TestBuilderPrepare_Defaults(t *testing.T) { t.Errorf("bad ssh port: %d", b.config.Comm.SSHPort) } - if b.config.VMName != "packer-foo.qcow2" { + if b.config.VMName != "packer-foo" { t.Errorf("bad vm name: %s", b.config.VMName) } From bf733b75d5554cfc4ed2236ccd0e034af64f73b7 Mon Sep 17 00:00:00 2001 From: Chris Bednarski Date: Fri, 21 Aug 2015 16:46:29 -0700 Subject: [PATCH 4/4] Revert "By default, Qemu will now have an extension added based on the file format. This is a change to more closely match behavior from 0.7.5." This reverts commit 55fadd96bccc3d762ca93cbc4d12b27f6117e196. --- builder/qemu/builder.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/builder/qemu/builder.go b/builder/qemu/builder.go index 39984d68b..4ac22b59b 100644 --- a/builder/qemu/builder.go +++ b/builder/qemu/builder.go @@ -201,13 +201,12 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) { b.config.VNCPortMax = 6000 } - if b.config.Format == "" { - b.config.Format = "qcow2" + if b.config.VMName == "" { + b.config.VMName = fmt.Sprintf("packer-%s", b.config.PackerBuildName) } - if b.config.VMName == "" { - b.config.VMName = fmt.Sprintf("packer-%s.%s", - b.config.PackerBuildName, b.config.Format) + if b.config.Format == "" { + b.config.Format = "qcow2" } if b.config.FloppyFiles == nil {