From 83138569495f4b14e0c997f4df0640cb7e4ee7df Mon Sep 17 00:00:00 2001 From: Ross Smith II Date: Mon, 12 May 2014 18:24:03 -0700 Subject: [PATCH] builder/vmware-vmx: add floppy_files support --- builder/vmware/vmx/builder_test.go | 49 ++++++++++++++++++++++++++++++ builder/vmware/vmx/config.go | 10 ++++++ 2 files changed, 59 insertions(+) diff --git a/builder/vmware/vmx/builder_test.go b/builder/vmware/vmx/builder_test.go index e6b128721..f23f2f2e5 100644 --- a/builder/vmware/vmx/builder_test.go +++ b/builder/vmware/vmx/builder_test.go @@ -1 +1,50 @@ package vmx + +import ( + "io/ioutil" + "os" + "reflect" + "testing" +) + +func TestBuilderPrepare_FloppyFiles(t *testing.T) { + var b Builder + + tf, err := ioutil.TempFile("", "packer") + if err != nil { + t.Fatalf("err: %s", err) + } + tf.Close() + defer os.Remove(tf.Name()) + + config := testConfig(t) + config["source_path"] = tf.Name() + + delete(config, "floppy_files") + warns, err := b.Prepare(config) + if len(warns) > 0 { + t.Fatalf("bad: %#v", warns) + } + if err != nil { + t.Fatalf("bad err: %s", err) + } + + if len(b.config.FloppyFiles) != 0 { + t.Fatalf("bad: %#v", b.config.FloppyFiles) + } + + config["floppy_files"] = []string{"foo", "bar"} + b = Builder{} + warns, err = b.Prepare(config) + if len(warns) > 0 { + t.Fatalf("bad: %#v", warns) + } + if err != nil { + t.Fatalf("should not have error: %s", err) + } + + expected := []string{"foo", "bar"} + if !reflect.DeepEqual(b.config.FloppyFiles, expected) { + t.Fatalf("bad: %#v", b.config.FloppyFiles) + } +} diff --git a/builder/vmware/vmx/config.go b/builder/vmware/vmx/config.go index 4aac4d970..75fb6440f 100644 --- a/builder/vmware/vmx/config.go +++ b/builder/vmware/vmx/config.go @@ -72,6 +72,16 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) { } } + for i, file := range c.FloppyFiles { + var err error + c.FloppyFiles[i], err = c.tpl.Process(file, nil) + if err != nil { + errs = packer.MultiErrorAppend(errs, + fmt.Errorf("Error processing floppy_files[%d]: %s", + i, err)) + } + } + if c.SourcePath == "" { errs = packer.MultiErrorAppend(errs, fmt.Errorf("source_path is required")) } else {