diff --git a/builder/vmware/builder.go b/builder/vmware/builder.go index 6cd7575df..6445ac97c 100644 --- a/builder/vmware/builder.go +++ b/builder/vmware/builder.go @@ -31,7 +31,8 @@ type config struct { DiskSize uint `mapstructure:"disk_size"` FloppyFiles []string `mapstructure:"floppy_files"` GuestOSType string `mapstructure:"guest_os_type"` - ISOMD5 string `mapstructure:"iso_md5"` + ISOChecksum string `mapstructure:"iso_checksum"` + ISOChecksumType string `mapstructure:"iso_checksum_type"` ISOUrl string `mapstructure:"iso_url"` VMName string `mapstructure:"vm_name"` OutputDir string `mapstructure:"output_directory"` @@ -152,10 +153,21 @@ func (b *Builder) Prepare(raws ...interface{}) 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.ISOChecksum == "" { + errs = append(errs, errors.New("Due to large file sizes, an iso_checksum is required")) } else { - b.config.ISOMD5 = strings.ToLower(b.config.ISOMD5) + b.config.ISOChecksum = strings.ToLower(b.config.ISOChecksum) + } + + if b.config.ISOChecksumType == "" { + errs = append(errs, errors.New("The iso_checksum_type must be specified.")) + } else { + b.config.ISOChecksumType = strings.ToLower(b.config.ISOChecksumType) + if h := common.HashForType(b.config.ISOChecksumType); h == nil { + errs = append( + errs, + fmt.Errorf("Unsupported checksum type: %s", b.config.ISOChecksumType)) + } } if b.config.ISOUrl == "" { diff --git a/builder/vmware/builder_test.go b/builder/vmware/builder_test.go index 9b35249d1..be6badd4f 100644 --- a/builder/vmware/builder_test.go +++ b/builder/vmware/builder_test.go @@ -11,9 +11,10 @@ import ( func testConfig() map[string]interface{} { return map[string]interface{}{ - "iso_md5": "foo", - "iso_url": "http://www.packer.io", - "ssh_username": "foo", + "iso_checksum": "foo", + "iso_checksum_type": "md5", + "iso_url": "http://www.packer.io", + "ssh_username": "foo", packer.BuildNameConfigKey: "foo", } @@ -57,6 +58,58 @@ func TestBuilderPrepare_BootWait(t *testing.T) { } } +func TestBuilderPrepare_ISOChecksum(t *testing.T) { + var b Builder + config := testConfig() + + // Test bad + config["iso_checksum"] = "" + err := b.Prepare(config) + if err == nil { + t.Fatal("should have error") + } + + // Test good + config["iso_checksum"] = "FOo" + err = b.Prepare(config) + if err != nil { + t.Fatalf("should not have error: %s", err) + } + + if b.config.ISOChecksum != "foo" { + t.Fatalf("should've lowercased: %s", b.config.ISOChecksum) + } +} + +func TestBuilderPrepare_ISOChecksumType(t *testing.T) { + var b Builder + config := testConfig() + + // Test bad + config["iso_checksum_type"] = "" + err := b.Prepare(config) + if err == nil { + t.Fatal("should have error") + } + + // Test good + config["iso_checksum_type"] = "mD5" + err = b.Prepare(config) + if err != nil { + t.Fatalf("should not have error: %s", err) + } + + if b.config.ISOChecksumType != "md5" { + t.Fatalf("should've lowercased: %s", b.config.ISOChecksumType) + } + + // Test unknown + config["iso_checksum_type"] = "fake" + err = b.Prepare(config) + if err == nil { + t.Fatal("should have error") + } +} func TestBuilderPrepare_Defaults(t *testing.T) { var b Builder config := testConfig() @@ -175,29 +228,6 @@ func TestBuilderPrepare_InvalidKey(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) - } - - if b.config.ISOMD5 != "foo" { - t.Fatalf("should've lowercased: %s", b.config.ISOMD5) - } -} - func TestBuilderPrepare_ISOUrl(t *testing.T) { var b Builder config := testConfig() diff --git a/builder/vmware/step_download_iso.go b/builder/vmware/step_download_iso.go index bea1335f1..0cf12e2a9 100644 --- a/builder/vmware/step_download_iso.go +++ b/builder/vmware/step_download_iso.go @@ -1,7 +1,6 @@ package vmware import ( - "crypto/md5" "encoding/hex" "fmt" "github.com/mitchellh/multistep" @@ -27,7 +26,7 @@ func (s stepDownloadISO) Run(state map[string]interface{}) multistep.StepAction config := state["config"].(*config) ui := state["ui"].(packer.Ui) - checksum, err := hex.DecodeString(config.ISOMD5) + checksum, err := hex.DecodeString(config.ISOChecksum) if err != nil { err := fmt.Errorf("Error parsing checksum: %s", err) state["error"] = err @@ -43,7 +42,7 @@ func (s stepDownloadISO) Run(state map[string]interface{}) multistep.StepAction Url: config.ISOUrl, TargetPath: cachePath, CopyFile: false, - Hash: md5.New(), + Hash: common.HashForType(config.ISOChecksumType), Checksum: checksum, }