track whether we've detached disks so we don't duplicate work

This commit is contained in:
Megan Marsh 2020-09-14 11:00:35 -07:00
parent a92491d17b
commit 698bef434f
2 changed files with 11 additions and 7 deletions

View File

@ -145,14 +145,14 @@ func (s *StepAttachISOs) Cleanup(state multistep.StateBag) {
}
driver := state.Get("driver").(Driver)
_, ok := state.GetOk("detached_isos")
for _, command := range s.diskUnmountCommands {
// Remove the ISO. Note that this will probably fail since
// stepRemoveDevices does this as well. No big deal.
err := driver.VBoxManage(command...)
if err != nil {
log.Printf("error detaching iso; probably was already detached " +
"in step_remove_devices")
if !ok {
for _, command := range s.diskUnmountCommands {
err := driver.VBoxManage(command...)
if err != nil {
log.Printf("error detaching iso: %s", err)
}
}
}
}

View File

@ -95,6 +95,10 @@ func (s *StepRemoveDevices) Run(ctx context.Context, state multistep.StateBag) m
}
}
// log that we removed the isos, so we don't waste time trying to do it
// in the step_attach_isos cleanup.
state.Put("detached_isos", true)
return multistep.ActionContinue
}