FIX #2762 retry Virtualbox commands

Signed-off-by: David Gageot <david@gageot.net>
This commit is contained in:
David Gageot 2016-01-06 13:36:39 +01:00
parent 276e7e48b6
commit fcb31f99f2
1 changed files with 15 additions and 0 deletions

View File

@ -14,6 +14,10 @@ import (
"github.com/docker/machine/libmachine/log"
)
const (
retryCountOnObjectNotReadyError = 5
)
var (
reColonLine = regexp.MustCompile(`(.+):\s+(.*)`)
reEqualLine = regexp.MustCompile(`(.+)=(.*)`)
@ -49,6 +53,10 @@ func (v *VBoxCmdManager) vbmOut(args ...string) (string, error) {
}
func (v *VBoxCmdManager) vbmOutErr(args ...string) (string, string, error) {
return v.vbmOutErrRetry(retryCountOnObjectNotReadyError, args...)
}
func (v *VBoxCmdManager) vbmOutErrRetry(retry int, args ...string) (string, string, error) {
cmd := exec.Command(vboxManageCmd, args...)
log.Debugf("COMMAND: %v %v", vboxManageCmd, strings.Join(args, " "))
var stdout bytes.Buffer
@ -68,6 +76,13 @@ func (v *VBoxCmdManager) vbmOutErr(args ...string) (string, string, error) {
}
}
// Sometimes, we just need to retry...
if retry > 0 {
if strings.Contains(stderrStr, "error: The object is not ready") {
return v.vbmOutErrRetry(retry-1, args...)
}
}
if err == nil || strings.HasPrefix(err.Error(), "exit status ") {
// VBoxManage will sometimes not set the return code, but has a fatal error
// such as VBoxManage.exe: error: VT-x is not available. (VERR_VMX_NO_VMX)