Retry command execution when VM session is locked (#8483)

pull/8485/head
Sylvia Moss 6 years ago committed by GitHub
parent 1933e7acbe
commit 2ee3311082
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -165,9 +165,6 @@ func (d *VBox42Driver) Stop(name string) error {
return err return err
} }
// We sleep here for a little bit to let the session "unlock"
time.Sleep(2 * time.Second)
return nil return nil
} }
@ -189,7 +186,18 @@ func (d *VBox42Driver) SuppressMessages() error {
} }
func (d *VBox42Driver) VBoxManage(args ...string) 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 return err
} }

@ -41,5 +41,9 @@ func (c *ShutdownConfig) Prepare(ctx *interpolate.Context) []error {
c.ShutdownTimeout = 5 * time.Minute c.ShutdownTimeout = 5 * time.Minute
} }
if c.PostShutdownDelay == 0 {
c.PostShutdownDelay = 2 * time.Second
}
return nil return nil
} }

@ -49,8 +49,8 @@ func TestShutdownConfigPrepare_PostShutdownDelay(t *testing.T) {
if len(errs) > 0 { if len(errs) > 0 {
t.Fatalf("err: %#v", errs) t.Fatalf("err: %#v", errs)
} }
if c.PostShutdownDelay.Nanoseconds() != 0 { if c.PostShutdownDelay != 2*time.Second {
t.Fatalf("bad: %s", c.PostShutdownDelay) t.Fatalf("bad: PostShutdownDelay should be 2 seconds but was %s", c.PostShutdownDelay)
} }
// Test with a good one // Test with a good one

Loading…
Cancel
Save