builder/vmware: generic checksum types [GH-175]
This commit is contained in:
parent
3007498282
commit
569ec0a2bb
|
@ -31,7 +31,8 @@ type config struct {
|
||||||
DiskSize uint `mapstructure:"disk_size"`
|
DiskSize uint `mapstructure:"disk_size"`
|
||||||
FloppyFiles []string `mapstructure:"floppy_files"`
|
FloppyFiles []string `mapstructure:"floppy_files"`
|
||||||
GuestOSType string `mapstructure:"guest_os_type"`
|
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"`
|
ISOUrl string `mapstructure:"iso_url"`
|
||||||
VMName string `mapstructure:"vm_name"`
|
VMName string `mapstructure:"vm_name"`
|
||||||
OutputDir string `mapstructure:"output_directory"`
|
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"))
|
errs = append(errs, errors.New("http_port_min must be less than http_port_max"))
|
||||||
}
|
}
|
||||||
|
|
||||||
if b.config.ISOMD5 == "" {
|
if b.config.ISOChecksum == "" {
|
||||||
errs = append(errs, errors.New("Due to large file sizes, an iso_md5 is required"))
|
errs = append(errs, errors.New("Due to large file sizes, an iso_checksum is required"))
|
||||||
} else {
|
} 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 == "" {
|
if b.config.ISOUrl == "" {
|
||||||
|
|
|
@ -11,9 +11,10 @@ import (
|
||||||
|
|
||||||
func testConfig() map[string]interface{} {
|
func testConfig() map[string]interface{} {
|
||||||
return map[string]interface{}{
|
return map[string]interface{}{
|
||||||
"iso_md5": "foo",
|
"iso_checksum": "foo",
|
||||||
"iso_url": "http://www.packer.io",
|
"iso_checksum_type": "md5",
|
||||||
"ssh_username": "foo",
|
"iso_url": "http://www.packer.io",
|
||||||
|
"ssh_username": "foo",
|
||||||
|
|
||||||
packer.BuildNameConfigKey: "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) {
|
func TestBuilderPrepare_Defaults(t *testing.T) {
|
||||||
var b Builder
|
var b Builder
|
||||||
config := testConfig()
|
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) {
|
func TestBuilderPrepare_ISOUrl(t *testing.T) {
|
||||||
var b Builder
|
var b Builder
|
||||||
config := testConfig()
|
config := testConfig()
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package vmware
|
package vmware
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/md5"
|
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/mitchellh/multistep"
|
"github.com/mitchellh/multistep"
|
||||||
|
@ -27,7 +26,7 @@ func (s stepDownloadISO) Run(state map[string]interface{}) multistep.StepAction
|
||||||
config := state["config"].(*config)
|
config := state["config"].(*config)
|
||||||
ui := state["ui"].(packer.Ui)
|
ui := state["ui"].(packer.Ui)
|
||||||
|
|
||||||
checksum, err := hex.DecodeString(config.ISOMD5)
|
checksum, err := hex.DecodeString(config.ISOChecksum)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err := fmt.Errorf("Error parsing checksum: %s", err)
|
err := fmt.Errorf("Error parsing checksum: %s", err)
|
||||||
state["error"] = err
|
state["error"] = err
|
||||||
|
@ -43,7 +42,7 @@ func (s stepDownloadISO) Run(state map[string]interface{}) multistep.StepAction
|
||||||
Url: config.ISOUrl,
|
Url: config.ISOUrl,
|
||||||
TargetPath: cachePath,
|
TargetPath: cachePath,
|
||||||
CopyFile: false,
|
CopyFile: false,
|
||||||
Hash: md5.New(),
|
Hash: common.HashForType(config.ISOChecksumType),
|
||||||
Checksum: checksum,
|
Checksum: checksum,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue