Remove config dependency inside StepImport

This commit is contained in:
Moss 2019-12-20 11:50:18 +01:00
parent 42cf9ef064
commit 7912e496aa
3 changed files with 9 additions and 16 deletions

View File

@ -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,

View File

@ -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
}

View File

@ -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")