builder/virtualbox,vmware: use DownloadableURL

This commit is contained in:
Mitchell Hashimoto 2013-07-29 00:13:03 -07:00
parent 3ae0b2f0a5
commit 0363a1cdc2
5 changed files with 9 additions and 188 deletions

View File

@ -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)

View File

@ -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))
}
}

View File

@ -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) {

View File

@ -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))
}
}

View File

@ -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) {