diff --git a/builder/virtualbox/common/driver_4_2.go b/builder/virtualbox/common/driver_4_2.go index 0599251ff..338aee4d1 100644 --- a/builder/virtualbox/common/driver_4_2.go +++ b/builder/virtualbox/common/driver_4_2.go @@ -185,7 +185,7 @@ func (d *VBox42Driver) VBoxManage(args ...string) error { ShouldRetry: func(err error) bool { return strings.Contains(err.Error(), "VBOX_E_INVALID_OBJECT_STATE") }, - RetryDelay: func() time.Duration { return 2 * time.Minute }, + RetryDelay: func() time.Duration { return 1 * time.Minute }, }.Run(ctx, func(ctx context.Context) error { _, err := d.VBoxManageWithOutput(args...) return err diff --git a/builder/virtualbox/ovf/builder.go b/builder/virtualbox/ovf/builder.go index d1db85944..3cbd16675 100644 --- a/builder/virtualbox/ovf/builder.go +++ b/builder/virtualbox/ovf/builder.go @@ -86,8 +86,9 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack Url: []string{b.config.SourcePath}, }, &StepImport{ - Name: b.config.VMName, - ImportFlags: b.config.ImportFlags, + Name: b.config.VMName, + ImportFlags: b.config.ImportFlags, + KeepRegistered: b.config.KeepRegistered, }, &vboxcommon.StepAttachGuestAdditions{ GuestAdditionsMode: b.config.GuestAdditionsMode, diff --git a/builder/virtualbox/ovf/step_import.go b/builder/virtualbox/ovf/step_import.go index caab759b2..b3dd53a19 100644 --- a/builder/virtualbox/ovf/step_import.go +++ b/builder/virtualbox/ovf/step_import.go @@ -11,8 +11,9 @@ import ( // This step imports an OVF VM into VirtualBox. type StepImport struct { - Name string - ImportFlags []string + Name string + ImportFlags []string + KeepRegistered bool vmName string } @@ -42,11 +43,10 @@ func (s *StepImport) Cleanup(state multistep.StateBag) { driver := state.Get("driver").(vboxcommon.Driver) ui := state.Get("ui").(packer.Ui) - config := state.Get("config").(*Config) _, cancelled := state.GetOk(multistep.StateCancelled) _, halted := state.GetOk(multistep.StateHalted) - if (config.KeepRegistered) && (!cancelled && !halted) { + if (s.KeepRegistered) && (!cancelled && !halted) { ui.Say("Keeping virtual machine registered with VirtualBox host (keep_registered = true)") return } diff --git a/builder/virtualbox/ovf/step_import_test.go b/builder/virtualbox/ovf/step_import_test.go index 482bfdcdc..ae7425a22 100644 --- a/builder/virtualbox/ovf/step_import_test.go +++ b/builder/virtualbox/ovf/step_import_test.go @@ -14,11 +14,8 @@ func TestStepImport_impl(t *testing.T) { func TestStepImport(t *testing.T) { state := testState(t) - cfg := testConfig(t) - var c Config - c.Prepare(cfg) state.Put("vm_path", "foo") - state.Put("config", &c) + step := new(StepImport) step.Name = "bar" @@ -46,16 +43,24 @@ func TestStepImport(t *testing.T) { } else if name != "bar" { t.Fatalf("bad: %#v", name) } +} - // Test cleanup - c.KeepRegistered = true - step.Cleanup(state) +func TestStepImport_Cleanup(t *testing.T) { + state := testState(t) + state.Put("vm_path", "foo") + step := new(StepImport) + step.vmName = "bar" + + driver := state.Get("driver").(*vboxcommon.DriverMock) + + step.KeepRegistered = true + step.Cleanup(state) if driver.DeleteCalled { t.Fatal("delete should not be called") } - c.KeepRegistered = false + state.Put(multistep.StateHalted, true) step.Cleanup(state) if !driver.DeleteCalled { t.Fatal("delete should be called")