From 42cf9ef064365cafc14b1f942338987e5b7ec16a Mon Sep 17 00:00:00 2001 From: Moss Date: Thu, 19 Dec 2019 13:30:54 +0100 Subject: [PATCH] Remove pointer fixing panic on interface conversion --- builder/virtualbox/common/driver_4_2.go | 2 +- builder/virtualbox/ovf/step_import.go | 2 +- builder/virtualbox/ovf/step_import_test.go | 21 +++++++++++++++++---- 3 files changed, 19 insertions(+), 6 deletions(-) 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/step_import.go b/builder/virtualbox/ovf/step_import.go index caab759b2..adf4055f8 100644 --- a/builder/virtualbox/ovf/step_import.go +++ b/builder/virtualbox/ovf/step_import.go @@ -42,7 +42,7 @@ func (s *StepImport) Cleanup(state multistep.StateBag) { driver := state.Get("driver").(vboxcommon.Driver) ui := state.Get("ui").(packer.Ui) - config := state.Get("config").(*Config) + config := state.Get("config").(Config) _, cancelled := state.GetOk(multistep.StateCancelled) _, halted := state.GetOk(multistep.StateHalted) diff --git a/builder/virtualbox/ovf/step_import_test.go b/builder/virtualbox/ovf/step_import_test.go index 482bfdcdc..73914a9c1 100644 --- a/builder/virtualbox/ovf/step_import_test.go +++ b/builder/virtualbox/ovf/step_import_test.go @@ -18,7 +18,7 @@ func TestStepImport(t *testing.T) { var c Config c.Prepare(cfg) state.Put("vm_path", "foo") - state.Put("config", &c) + state.Put("config", c) step := new(StepImport) step.Name = "bar" @@ -46,16 +46,29 @@ func TestStepImport(t *testing.T) { } else if name != "bar" { t.Fatalf("bad: %#v", name) } +} + +func TestStepImport_Cleanup(t *testing.T) { + state := testState(t) + state.Put("vm_path", "foo") + + cfg := testConfig(t) + var c Config + c.Prepare(cfg) + + step := new(StepImport) + step.vmName = "bar" + + driver := state.Get("driver").(*vboxcommon.DriverMock) - // Test cleanup c.KeepRegistered = true + state.Put("config", c) 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")