Merge pull request #8509 from hashicorp/fix_step_import_panic

Remove config dependency from inside StepImport
pull/8699/head
Megan Marsh 6 years ago committed by GitHub
commit 348e00422e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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

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

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

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

Loading…
Cancel
Save