From 0363a1cdc2ce89cc87a731466712af9421b6b40b Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 29 Jul 2013 00:13:03 -0700 Subject: [PATCH] builder/virtualbox,vmware: use DownloadableURL --- CHANGELOG.md | 3 ++ builder/virtualbox/builder.go | 73 ++---------------------------- builder/virtualbox/builder_test.go | 56 ----------------------- builder/vmware/builder.go | 37 +-------------- builder/vmware/builder_test.go | 28 ------------ 5 files changed, 9 insertions(+), 188 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 78b343007..ec1af733a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ ## 0.2.2 (unreleased) +BUG FIXES: +* builder/virtualbox,vmware: relative paths work properly as URL + configurations. [GH-215] ## 0.2.1 (July 26, 2013) diff --git a/builder/virtualbox/builder.go b/builder/virtualbox/builder.go index 25a2855f8..ed8743bc8 100644 --- a/builder/virtualbox/builder.go +++ b/builder/virtualbox/builder.go @@ -7,7 +7,6 @@ import ( "github.com/mitchellh/packer/builder/common" "github.com/mitchellh/packer/packer" "log" - "net/url" "os" "os/exec" "path/filepath" @@ -153,42 +152,10 @@ func (b *Builder) Prepare(raws ...interface{}) error { errs = packer.MultiErrorAppend( errs, errors.New("An iso_url must be specified.")) } else { - url, err := url.Parse(b.config.ISOUrl) + b.config.ISOUrl, err = common.DownloadableURL(b.config.ISOUrl) if err != nil { errs = packer.MultiErrorAppend( - errs, fmt.Errorf("iso_url is not a valid URL: %s", err)) - } else { - if url.Scheme == "" { - url.Scheme = "file" - } - - if url.Scheme == "file" { - if _, err := os.Stat(url.Path); err != nil { - errs = packer.MultiErrorAppend( - errs, fmt.Errorf("iso_url points to bad file: %s", err)) - } - } else { - supportedSchemes := []string{"file", "http", "https"} - scheme := strings.ToLower(url.Scheme) - - found := false - for _, supported := range supportedSchemes { - if scheme == supported { - found = true - break - } - } - - if !found { - errs = packer.MultiErrorAppend( - errs, fmt.Errorf("Unsupported URL scheme in iso_url: %s", scheme)) - } - } - } - - if errs == nil || len(errs.Errors) == 0 { - // Put the URL back together since we may have modified it - b.config.ISOUrl = url.String() + errs, fmt.Errorf("iso_url: %s", err)) } } @@ -197,42 +164,10 @@ func (b *Builder) Prepare(raws ...interface{}) error { } if b.config.GuestAdditionsURL != "" { - url, err := url.Parse(b.config.GuestAdditionsURL) + b.config.GuestAdditionsURL, err = common.DownloadableURL(b.config.GuestAdditionsURL) if err != nil { errs = packer.MultiErrorAppend( - errs, fmt.Errorf("guest_additions_url is not a valid URL: %s", err)) - } else { - if url.Scheme == "" { - url.Scheme = "file" - } - - if url.Scheme == "file" { - if _, err := os.Stat(url.Path); err != nil { - errs = packer.MultiErrorAppend( - errs, fmt.Errorf("guest_additions_url points to bad file: %s", err)) - } - } else { - supportedSchemes := []string{"file", "http", "https"} - scheme := strings.ToLower(url.Scheme) - - found := false - for _, supported := range supportedSchemes { - if scheme == supported { - found = true - break - } - } - - if !found { - errs = packer.MultiErrorAppend( - errs, fmt.Errorf("Unsupported URL scheme in guest_additions_url: %s", scheme)) - } - } - } - - if errs == nil || len(errs.Errors) == 0 { - // Put the URL back together since we may have modified it - b.config.GuestAdditionsURL = url.String() + errs, fmt.Errorf("guest_additions_url: %s", err)) } } diff --git a/builder/virtualbox/builder_test.go b/builder/virtualbox/builder_test.go index aed68ac46..64e24e141 100644 --- a/builder/virtualbox/builder_test.go +++ b/builder/virtualbox/builder_test.go @@ -209,39 +209,11 @@ func TestBuilderPrepare_GuestAdditionsURL(t *testing.T) { t.Fatalf("should be empty: %s", b.config.GuestAdditionsURL) } - config["guest_additions_url"] = "i/am/a/file/that/doesnt/exist" - err = b.Prepare(config) - if err == nil { - t.Error("should have error") - } - - config["guest_additions_url"] = "file:i/am/a/file/that/doesnt/exist" - err = b.Prepare(config) - if err == nil { - t.Error("should have error") - } - config["guest_additions_url"] = "http://www.packer.io" err = b.Prepare(config) if err != nil { t.Errorf("should not have error: %s", err) } - - tf, err := ioutil.TempFile("", "packer") - if err != nil { - t.Fatalf("error tempfile: %s", err) - } - defer os.Remove(tf.Name()) - - config["guest_additions_url"] = tf.Name() - err = b.Prepare(config) - if err != nil { - t.Fatalf("should not have error: %s", err) - } - - if b.config.GuestAdditionsURL != "file://"+tf.Name() { - t.Fatalf("guest_additions_url should be modified: %s", b.config.GuestAdditionsURL) - } } func TestBuilderPrepare_HTTPPort(t *testing.T) { @@ -347,39 +319,11 @@ func TestBuilderPrepare_ISOUrl(t *testing.T) { t.Fatal("should have error") } - config["iso_url"] = "i/am/a/file/that/doesnt/exist" - err = b.Prepare(config) - if err == nil { - t.Error("should have error") - } - - config["iso_url"] = "file:i/am/a/file/that/doesnt/exist" - err = b.Prepare(config) - if err == nil { - t.Error("should have error") - } - config["iso_url"] = "http://www.packer.io" err = b.Prepare(config) if err != nil { t.Errorf("should not have error: %s", err) } - - tf, err := ioutil.TempFile("", "packer") - if err != nil { - t.Fatalf("error tempfile: %s", err) - } - defer os.Remove(tf.Name()) - - config["iso_url"] = tf.Name() - err = b.Prepare(config) - if err != nil { - t.Fatalf("should not have error: %s", err) - } - - if b.config.ISOUrl != "file://"+tf.Name() { - t.Fatalf("iso_url should be modified: %s", b.config.ISOUrl) - } } func TestBuilderPrepare_OutputDir(t *testing.T) { diff --git a/builder/vmware/builder.go b/builder/vmware/builder.go index 48d19a3cf..6b9caf11d 100644 --- a/builder/vmware/builder.go +++ b/builder/vmware/builder.go @@ -8,7 +8,6 @@ import ( "github.com/mitchellh/packer/packer" "log" "math/rand" - "net/url" "os" "path/filepath" "strings" @@ -150,42 +149,10 @@ func (b *Builder) Prepare(raws ...interface{}) error { errs = packer.MultiErrorAppend( errs, errors.New("An iso_url must be specified.")) } else { - url, err := url.Parse(b.config.ISOUrl) + b.config.ISOUrl, err = common.DownloadableURL(b.config.ISOUrl) if err != nil { errs = packer.MultiErrorAppend( - errs, fmt.Errorf("iso_url is not a valid URL: %s", err)) - } else { - if url.Scheme == "" { - url.Scheme = "file" - } - - if url.Scheme == "file" { - if _, err := os.Stat(url.Path); err != nil { - errs = packer.MultiErrorAppend( - errs, fmt.Errorf("iso_url points to bad file: %s", err)) - } - } else { - supportedSchemes := []string{"file", "http", "https"} - scheme := strings.ToLower(url.Scheme) - - found := false - for _, supported := range supportedSchemes { - if scheme == supported { - found = true - break - } - } - - if !found { - errs = packer.MultiErrorAppend( - errs, fmt.Errorf("Unsupported URL scheme in iso_url: %s", scheme)) - } - } - } - - if errs == nil || len(errs.Errors) == 0 { - // Put the URL back together since we may have modified it - b.config.ISOUrl = url.String() + errs, fmt.Errorf("iso_url: %s", err)) } } diff --git a/builder/vmware/builder_test.go b/builder/vmware/builder_test.go index 99f0b0d71..4ad6c3ee7 100644 --- a/builder/vmware/builder_test.go +++ b/builder/vmware/builder_test.go @@ -238,39 +238,11 @@ func TestBuilderPrepare_ISOUrl(t *testing.T) { t.Fatal("should have error") } - config["iso_url"] = "i/am/a/file/that/doesnt/exist" - err = b.Prepare(config) - if err == nil { - t.Error("should have error") - } - - config["iso_url"] = "file:i/am/a/file/that/doesnt/exist" - err = b.Prepare(config) - if err == nil { - t.Error("should have error") - } - config["iso_url"] = "http://www.packer.io" err = b.Prepare(config) if err != nil { t.Errorf("should not have error: %s", err) } - - tf, err := ioutil.TempFile("", "packer") - if err != nil { - t.Fatalf("error tempfile: %s", err) - } - defer os.Remove(tf.Name()) - - config["iso_url"] = tf.Name() - err = b.Prepare(config) - if err != nil { - t.Fatalf("should not have error: %s", err) - } - - if b.config.ISOUrl != "file://"+tf.Name() { - t.Fatalf("iso_url should be modified: %s", b.config.ISOUrl) - } } func TestBuilderPrepare_OutputDir(t *testing.T) {