add progress tracker to vmware-esx iso upload. Add colored prefix to … (#9779)
* add progress tracker to vmware-esx iso upload. Add colored prefix to tracker to make it clear which build a tracker belongs to. * fix mock; fix tests
This commit is contained in:
parent
c88ff4ec45
commit
aa2418cf01
|
@ -154,7 +154,7 @@ func (d *ESX5Driver) Stop(vmxPathLocal string) error {
|
|||
|
||||
func (d *ESX5Driver) Register(vmxPathLocal string) error {
|
||||
vmxPath := filepath.ToSlash(filepath.Join(d.outputDir, filepath.Base(vmxPathLocal)))
|
||||
if err := d.upload(vmxPath, vmxPathLocal); err != nil {
|
||||
if err := d.upload(vmxPath, vmxPathLocal, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
r, err := d.run(nil, "vim-cmd", "solo/registervm", strconv.Quote(vmxPath))
|
||||
|
@ -185,7 +185,7 @@ func (d *ESX5Driver) IsDestroyed() (bool, error) {
|
|||
return true, err
|
||||
}
|
||||
|
||||
func (d *ESX5Driver) UploadISO(localPath string, checksum string) (string, error) {
|
||||
func (d *ESX5Driver) UploadISO(localPath string, checksum string, ui packer.Ui) (string, error) {
|
||||
finalPath := d.CachePath(localPath)
|
||||
if err := d.mkdir(filepath.ToSlash(filepath.Dir(finalPath))); err != nil {
|
||||
return "", err
|
||||
|
@ -198,7 +198,7 @@ func (d *ESX5Driver) UploadISO(localPath string, checksum string) (string, error
|
|||
}
|
||||
log.Println("Initial checksum did not match, uploading.")
|
||||
|
||||
if err := d.upload(finalPath, localPath); err != nil {
|
||||
if err := d.upload(finalPath, localPath, ui); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
|
@ -667,12 +667,26 @@ func (d *ESX5Driver) mkdir(path string) error {
|
|||
return d.sh("mkdir", "-p", strconv.Quote(path))
|
||||
}
|
||||
|
||||
func (d *ESX5Driver) upload(dst, src string) error {
|
||||
func (d *ESX5Driver) upload(dst, src string, ui packer.Ui) error {
|
||||
// Get size so we can set up progress tracker
|
||||
info, err := os.Stat(src)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
f, err := os.Open(src)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
if ui != nil {
|
||||
pf := ui.TrackProgress(filepath.Base(src), 0, info.Size(), f)
|
||||
defer pf.Close()
|
||||
|
||||
return d.comm.Upload(dst, pf, &info)
|
||||
}
|
||||
|
||||
return d.comm.Upload(dst, f, nil)
|
||||
}
|
||||
|
||||
|
|
|
@ -1,12 +1,16 @@
|
|||
package common
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/packer/packer"
|
||||
)
|
||||
|
||||
type RemoteDriver interface {
|
||||
Driver
|
||||
|
||||
// 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(path string, checksum string) (string, error)
|
||||
UploadISO(path string, checksum string, ui packer.Ui) (string, error)
|
||||
|
||||
// RemoveCache deletes localPath from the remote cache.
|
||||
RemoveCache(localPath string) error
|
||||
|
@ -24,7 +28,7 @@ type RemoteDriver interface {
|
|||
IsDestroyed() (bool, error)
|
||||
|
||||
// Uploads a local file to remote side.
|
||||
upload(dst, src string) error
|
||||
upload(dst, src string, ui packer.Ui) error
|
||||
|
||||
// Download a remote file to a local file.
|
||||
Download(src, dst string) error
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
package common
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/packer/packer"
|
||||
)
|
||||
|
||||
type RemoteDriverMock struct {
|
||||
DriverMock
|
||||
|
||||
|
@ -32,7 +36,7 @@ type RemoteDriverMock struct {
|
|||
ReloadVMErr error
|
||||
}
|
||||
|
||||
func (d *RemoteDriverMock) UploadISO(path string, checksum string) (string, error) {
|
||||
func (d *RemoteDriverMock) UploadISO(path string, checksum string, ui packer.Ui) (string, error) {
|
||||
d.UploadISOCalled = true
|
||||
d.UploadISOPath = path
|
||||
return d.UploadISOResult, d.UploadISOErr
|
||||
|
@ -60,7 +64,7 @@ func (d *RemoteDriverMock) IsDestroyed() (bool, error) {
|
|||
return d.IsDestroyedResult, d.IsDestroyedErr
|
||||
}
|
||||
|
||||
func (d *RemoteDriverMock) upload(dst, src string) error {
|
||||
func (d *RemoteDriverMock) upload(dst, src string, ui packer.Ui) error {
|
||||
return d.UploadErr
|
||||
}
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ func (s *StepRemoteUpload) Run(ctx context.Context, state multistep.StateBag) mu
|
|||
|
||||
ui.Say(s.Message)
|
||||
log.Printf("Remote uploading: %s", path)
|
||||
newPath, err := remote.UploadISO(path, s.Checksum)
|
||||
newPath, err := remote.UploadISO(path, s.Checksum, ui)
|
||||
if err != nil {
|
||||
err := fmt.Errorf("Error uploading file: %s", err)
|
||||
state.Put("error", err)
|
||||
|
|
|
@ -32,7 +32,7 @@ func (c *StepUploadVMX) Run(ctx context.Context, state multistep.StateBag) multi
|
|||
remoteDriver, ok := driver.(RemoteDriver)
|
||||
if ok {
|
||||
remoteVmxPath := filepath.ToSlash(filepath.Join(fmt.Sprintf("%s", remoteDriver), filepath.Base(vmxPath)))
|
||||
if err := remoteDriver.upload(remoteVmxPath, vmxPath); err != nil {
|
||||
if err := remoteDriver.upload(remoteVmxPath, vmxPath, nil); err != nil {
|
||||
state.Put("error", fmt.Errorf("Error writing VMX: %s", err))
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue