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 {
|
func (d *ESX5Driver) Register(vmxPathLocal string) error {
|
||||||
vmxPath := filepath.ToSlash(filepath.Join(d.outputDir, filepath.Base(vmxPathLocal)))
|
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
|
return err
|
||||||
}
|
}
|
||||||
r, err := d.run(nil, "vim-cmd", "solo/registervm", strconv.Quote(vmxPath))
|
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
|
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)
|
finalPath := d.CachePath(localPath)
|
||||||
if err := d.mkdir(filepath.ToSlash(filepath.Dir(finalPath))); err != nil {
|
if err := d.mkdir(filepath.ToSlash(filepath.Dir(finalPath))); err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -198,7 +198,7 @@ func (d *ESX5Driver) UploadISO(localPath string, checksum string) (string, error
|
||||||
}
|
}
|
||||||
log.Println("Initial checksum did not match, uploading.")
|
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
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -667,12 +667,26 @@ func (d *ESX5Driver) mkdir(path string) error {
|
||||||
return d.sh("mkdir", "-p", strconv.Quote(path))
|
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)
|
f, err := os.Open(src)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer f.Close()
|
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)
|
return d.comm.Upload(dst, f, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,16 @@
|
||||||
package common
|
package common
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/hashicorp/packer/packer"
|
||||||
|
)
|
||||||
|
|
||||||
type RemoteDriver interface {
|
type RemoteDriver interface {
|
||||||
Driver
|
Driver
|
||||||
|
|
||||||
// UploadISO uploads a local ISO to the remote side and returns the
|
// 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
|
// new path that should be used in the VMX along with an error if it
|
||||||
// exists.
|
// 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 deletes localPath from the remote cache.
|
||||||
RemoveCache(localPath string) error
|
RemoveCache(localPath string) error
|
||||||
|
@ -24,7 +28,7 @@ type RemoteDriver interface {
|
||||||
IsDestroyed() (bool, error)
|
IsDestroyed() (bool, error)
|
||||||
|
|
||||||
// Uploads a local file to remote side.
|
// 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 a remote file to a local file.
|
||||||
Download(src, dst string) error
|
Download(src, dst string) error
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
package common
|
package common
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/hashicorp/packer/packer"
|
||||||
|
)
|
||||||
|
|
||||||
type RemoteDriverMock struct {
|
type RemoteDriverMock struct {
|
||||||
DriverMock
|
DriverMock
|
||||||
|
|
||||||
|
@ -32,7 +36,7 @@ type RemoteDriverMock struct {
|
||||||
ReloadVMErr error
|
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.UploadISOCalled = true
|
||||||
d.UploadISOPath = path
|
d.UploadISOPath = path
|
||||||
return d.UploadISOResult, d.UploadISOErr
|
return d.UploadISOResult, d.UploadISOErr
|
||||||
|
@ -60,7 +64,7 @@ func (d *RemoteDriverMock) IsDestroyed() (bool, error) {
|
||||||
return d.IsDestroyedResult, d.IsDestroyedErr
|
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
|
return d.UploadErr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ func (s *StepRemoteUpload) Run(ctx context.Context, state multistep.StateBag) mu
|
||||||
|
|
||||||
ui.Say(s.Message)
|
ui.Say(s.Message)
|
||||||
log.Printf("Remote uploading: %s", path)
|
log.Printf("Remote uploading: %s", path)
|
||||||
newPath, err := remote.UploadISO(path, s.Checksum)
|
newPath, err := remote.UploadISO(path, s.Checksum, ui)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err := fmt.Errorf("Error uploading file: %s", err)
|
err := fmt.Errorf("Error uploading file: %s", err)
|
||||||
state.Put("error", err)
|
state.Put("error", err)
|
||||||
|
|
|
@ -32,7 +32,7 @@ func (c *StepUploadVMX) Run(ctx context.Context, state multistep.StateBag) multi
|
||||||
remoteDriver, ok := driver.(RemoteDriver)
|
remoteDriver, ok := driver.(RemoteDriver)
|
||||||
if ok {
|
if ok {
|
||||||
remoteVmxPath := filepath.ToSlash(filepath.Join(fmt.Sprintf("%s", remoteDriver), filepath.Base(vmxPath)))
|
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))
|
state.Put("error", fmt.Errorf("Error writing VMX: %s", err))
|
||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue