Skip to content

Commit

Permalink
Fixes hashicorp#1244, Add a check for upload iso hash to ESXi Driver
Browse files Browse the repository at this point in the history
  • Loading branch information
higebu authored and mbrukman committed Jul 21, 2014
1 parent 05d40d5 commit 3302b5c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
8 changes: 7 additions & 1 deletion builder/vmware/iso/driver_esx5.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (d *ESX5Driver) Unregister(vmxPathLocal string) error {
return d.sh("vim-cmd", "vmsvc/unregister", d.vmId)
}

func (d *ESX5Driver) UploadISO(localPath string) (string, error) {
func (d *ESX5Driver) UploadISO(localPath string, checksum string, checksumType string) (string, error) {
cacheRoot, _ := filepath.Abs(".")
targetFile, err := filepath.Rel(cacheRoot, localPath)
if err != nil {
Expand All @@ -96,6 +96,12 @@ func (d *ESX5Driver) UploadISO(localPath string) (string, error) {
return "", err
}

log.Printf("Verifying checksum of %s", finalPath)
if d.verifyChecksum(checksumType, checksum, finalPath) {
log.Println("Initial checksum matched, no upload needed.")
return finalPath, nil
}

if err := d.upload(finalPath, localPath); err != nil {
return "", err
}
Expand Down
2 changes: 1 addition & 1 deletion builder/vmware/iso/remote_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type RemoteDriver interface {
// UploadISO uploads a local ISO to the remote side and returns the
// new path that should be used in the VMX along with an error if it
// exists.
UploadISO(string) (string, error)
UploadISO(string, string, string) (string, error)

// Adds a VM to inventory specified by the path to the VMX given.
Register(string) error
Expand Down
2 changes: 1 addition & 1 deletion builder/vmware/iso/remote_driver_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type RemoteDriverMock struct {
UnregisterErr error
}

func (d *RemoteDriverMock) UploadISO(path string) (string, error) {
func (d *RemoteDriverMock) UploadISO(path string, checksum string, checksumType string) (string, error) {
d.UploadISOCalled = true
d.UploadISOPath = path
return d.UploadISOResult, d.UploadISOErr
Expand Down
6 changes: 5 additions & 1 deletion builder/vmware/iso/step_remote_upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@ func (s *stepRemoteUpload) Run(state multistep.StateBag) multistep.StepAction {
return multistep.ActionContinue
}

config := state.Get("config").(*config)
checksum := config.ISOChecksum
checksumType := config.ISOChecksumType

ui.Say(s.Message)
log.Printf("Remote uploading: %s", path)
newPath, err := remote.UploadISO(path)
newPath, err := remote.UploadISO(path, checksum, checksumType)
if err != nil {
err := fmt.Errorf("Error uploading file: %s", err)
state.Put("error", err)
Expand Down

0 comments on commit 3302b5c

Please sign in to comment.