Hi _packer_,
Issue: (Virtualbox) On slow machine:Port forwarding and unregister machine fail:
Thank you for your time,
Turloch
Details follow.
Port Forwarding
virtualbox-ovf: Deleting forwarded port mapping for SSH (host port 3294)
==> virtualbox-ovf: Error deleting port forwarding rule: VBoxManage error: VBoxManage.exe: error: The machine 'packer-virtualbox-ovf-1436190505' is already locked for a session (or being unlocked)
Unregister machine (different run)
==> virtualbox-ovf: Error deleting VM: VBoxManage error: VBoxManage.exe: error: Cannot unregister the machine 'packer-virtualbox-ovf-1436175757' while it is locked
If I use -debug and periodically press enter the VM has time to unlock. (This would be hard to script)
(and while I am at it: (tried to halt the machine myself so I could add a pause after halt, packer had an error on stopping as it wanted to shut the machine down.)
==> virtualbox-ovf: Halting the virtual machine...
==> virtualbox-ovf: Error stopping VM: VBoxManage error: VBoxManage.exe: error: Invalid machine state: PoweredOff (must be Running, Paused or Stuck))
From a quick look at port forwarding:
func (s *StepExport) Run(state multistep.StateBag) multistep.StepAction {
driver := state.Get("driver").(Driver)
ui := state.Get("ui").(packer.Ui)
vmName := state.Get("vmName").(string)
//XXXXXXXXXXX Wait a second to ensure VM is really shutdown not enough on a slow machine.XXXXXXXXXXXX
log.Println("1 second timeout to ensure VM is really shutdown")
time.Sleep(1 * time.Second)
ui.Say("Preparing to export machine...")
From a quick look at
// Wait for the machine to actually shut down
log.Printf("Waiting max %s for shutdown to complete", s.Timeout)
shutdownTimer := time.After(s.Timeout)
for {
running, _ := driver.IsRunning(vmName)
if !running {
break
}
select {
case <-shutdownTimer:
err := errors.New("Timeout while waiting for machine to shut down.")
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
default:
time.Sleep(500 * time.Millisecond)
}
}
Maybe it is locked for a couple of seconds after !running,
(
Test:Sleep in the shutdown command shell script:
Result:small test case works either way.
Test:Could be database shutting down - will stop than in advance
).