Retry command execution when VM session is locked (#8483)
This commit is contained in:
parent
1933e7acbe
commit
2ee3311082
|
@ -165,9 +165,6 @@ func (d *VBox42Driver) Stop(name string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
// We sleep here for a little bit to let the session "unlock"
|
||||
time.Sleep(2 * time.Second)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -189,7 +186,18 @@ func (d *VBox42Driver) SuppressMessages() error {
|
|||
}
|
||||
|
||||
func (d *VBox42Driver) VBoxManage(args ...string) error {
|
||||
_, err := d.VBoxManageWithOutput(args...)
|
||||
ctx := context.TODO()
|
||||
err := retry.Config{
|
||||
Tries: 5,
|
||||
ShouldRetry: func(err error) bool {
|
||||
return strings.Contains(err.Error(), "VBOX_E_INVALID_OBJECT_STATE")
|
||||
},
|
||||
RetryDelay: func() time.Duration { return 2 * time.Minute },
|
||||
}.Run(ctx, func(ctx context.Context) error {
|
||||
_, err := d.VBoxManageWithOutput(args...)
|
||||
return err
|
||||
})
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
@ -41,5 +41,9 @@ func (c *ShutdownConfig) Prepare(ctx *interpolate.Context) []error {
|
|||
c.ShutdownTimeout = 5 * time.Minute
|
||||
}
|
||||
|
||||
if c.PostShutdownDelay == 0 {
|
||||
c.PostShutdownDelay = 2 * time.Second
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -49,8 +49,8 @@ func TestShutdownConfigPrepare_PostShutdownDelay(t *testing.T) {
|
|||
if len(errs) > 0 {
|
||||
t.Fatalf("err: %#v", errs)
|
||||
}
|
||||
if c.PostShutdownDelay.Nanoseconds() != 0 {
|
||||
t.Fatalf("bad: %s", c.PostShutdownDelay)
|
||||
if c.PostShutdownDelay != 2*time.Second {
|
||||
t.Fatalf("bad: PostShutdownDelay should be 2 seconds but was %s", c.PostShutdownDelay)
|
||||
}
|
||||
|
||||
// Test with a good one
|
||||
|
|
Loading…
Reference in New Issue