From 7912e496aa1e6b4572a381a33c24228f06dd6946 Mon Sep 17 00:00:00 2001 From: Moss Date: Fri, 20 Dec 2019 11:50:18 +0100 Subject: [PATCH] Remove config dependency inside StepImport --- builder/virtualbox/ovf/builder.go | 5 +++-- builder/virtualbox/ovf/step_import.go | 8 ++++---- builder/virtualbox/ovf/step_import_test.go | 12 ++---------- 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/builder/virtualbox/ovf/builder.go b/builder/virtualbox/ovf/builder.go index 9fdb7b189..9bf46b564 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 adf4055f8..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 73914a9c1..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" @@ -52,17 +49,12 @@ 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) - c.KeepRegistered = true - state.Put("config", c) + step.KeepRegistered = true step.Cleanup(state) if driver.DeleteCalled { t.Fatal("delete should not be called")