From 4b46181f69264aeb474982de76f2eb8deca43704 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 9 Jun 2013 22:47:58 -0700 Subject: [PATCH] builder/vmware: require an MD5 for ISO --- builder/vmware/builder.go | 5 +++++ builder/vmware/builder_test.go | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/builder/vmware/builder.go b/builder/vmware/builder.go index 542113dda..c53eb778b 100644 --- a/builder/vmware/builder.go +++ b/builder/vmware/builder.go @@ -26,6 +26,7 @@ type Builder struct { type config struct { DiskName string `mapstructure:"vmdk_name"` GuestOSType string `mapstructure:"guest_os_type"` + ISOMD5 string `mapstructure:"iso_md5"` ISOUrl string `mapstructure:"iso_url"` VMName string `mapstructure:"vm_name"` OutputDir string `mapstructure:"output_directory"` @@ -93,6 +94,10 @@ func (b *Builder) Prepare(raw interface{}) (err error) { errs = append(errs, errors.New("http_port_min must be less than http_port_max")) } + if b.config.ISOMD5 == "" { + errs = append(errs, errors.New("Due to large file sizes, an iso_md5 is required")) + } + if b.config.ISOUrl == "" { errs = append(errs, errors.New("An iso_url must be specified.")) } else { diff --git a/builder/vmware/builder_test.go b/builder/vmware/builder_test.go index bc30fd03c..9230280d5 100644 --- a/builder/vmware/builder_test.go +++ b/builder/vmware/builder_test.go @@ -10,6 +10,7 @@ import ( func testConfig() map[string]interface{} { return map[string]interface{}{ + "iso_md5": "foo", "iso_url": "http://www.packer.io", "ssh_username": "foo", } @@ -95,6 +96,25 @@ func TestBuilderPrepare_HTTPPort(t *testing.T) { } } +func TestBuilderPrepare_ISOMD5(t *testing.T) { + var b Builder + config := testConfig() + + // Test bad + config["iso_md5"] = "" + err := b.Prepare(config) + if err == nil { + t.Fatal("should have error") + } + + // Test good + config["iso_md5"] = "foo" + err = b.Prepare(config) + if err != nil { + t.Fatalf("should not have error: %s", err) + } +} + func TestBuilderPrepare_ISOUrl(t *testing.T) { var b Builder config := testConfig()