builder/virtualbox: support boot_wait
This commit is contained in:
parent
4d351edadf
commit
9e4a5a227b
|
@ -11,6 +11,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
const BuilderId = "mitchellh.virtualbox"
|
const BuilderId = "mitchellh.virtualbox"
|
||||||
|
@ -22,6 +23,7 @@ type Builder struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type config struct {
|
type config struct {
|
||||||
|
BootWait time.Duration ``
|
||||||
GuestOSType string `mapstructure:"guest_os_type"`
|
GuestOSType string `mapstructure:"guest_os_type"`
|
||||||
ISOMD5 string `mapstructure:"iso_md5"`
|
ISOMD5 string `mapstructure:"iso_md5"`
|
||||||
ISOUrl string `mapstructure:"iso_url"`
|
ISOUrl string `mapstructure:"iso_url"`
|
||||||
|
@ -30,6 +32,8 @@ type config struct {
|
||||||
SSHHostPortMax uint `mapstructure:"ssh_host_port_max"`
|
SSHHostPortMax uint `mapstructure:"ssh_host_port_max"`
|
||||||
SSHPort uint `mapstructure:"ssh_port"`
|
SSHPort uint `mapstructure:"ssh_port"`
|
||||||
VMName string `mapstructure:"vm_name"`
|
VMName string `mapstructure:"vm_name"`
|
||||||
|
|
||||||
|
RawBootWait string `mapstructure:"boot_wait"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Builder) Prepare(raw interface{}) error {
|
func (b *Builder) Prepare(raw interface{}) error {
|
||||||
|
@ -109,6 +113,13 @@ func (b *Builder) Prepare(raw interface{}) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if b.config.RawBootWait != "" {
|
||||||
|
b.config.BootWait, err = time.ParseDuration(b.config.RawBootWait)
|
||||||
|
if err != nil {
|
||||||
|
errs = append(errs, fmt.Errorf("Failed parsing boot_wait: %s", err))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if b.config.SSHHostPortMin > b.config.SSHHostPortMax {
|
if b.config.SSHHostPortMin > b.config.SSHHostPortMax {
|
||||||
errs = append(errs, errors.New("ssh_host_port_min must be less than ssh_host_port_max"))
|
errs = append(errs, errors.New("ssh_host_port_min must be less than ssh_host_port_max"))
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,6 +55,25 @@ func TestBuilderPrepare_Defaults(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestBuilderPrepare_BootWait(t *testing.T) {
|
||||||
|
var b Builder
|
||||||
|
config := testConfig()
|
||||||
|
|
||||||
|
// Test with a bad boot_wait
|
||||||
|
config["boot_wait"] = "this is not good"
|
||||||
|
err := b.Prepare(config)
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("should have error")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test with a good one
|
||||||
|
config["boot_wait"] = "5s"
|
||||||
|
err = b.Prepare(config)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("should not have error: %s", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestBuilderPrepare_ISOMD5(t *testing.T) {
|
func TestBuilderPrepare_ISOMD5(t *testing.T) {
|
||||||
var b Builder
|
var b Builder
|
||||||
config := testConfig()
|
config := testConfig()
|
||||||
|
|
|
@ -17,6 +17,7 @@ type stepRun struct{
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *stepRun) Run(state map[string]interface{}) multistep.StepAction {
|
func (s *stepRun) Run(state map[string]interface{}) multistep.StepAction {
|
||||||
|
config := state["config"].(*config)
|
||||||
driver := state["driver"].(Driver)
|
driver := state["driver"].(Driver)
|
||||||
ui := state["ui"].(packer.Ui)
|
ui := state["ui"].(packer.Ui)
|
||||||
vmName := state["vmName"].(string)
|
vmName := state["vmName"].(string)
|
||||||
|
@ -30,7 +31,11 @@ func (s *stepRun) Run(state map[string]interface{}) multistep.StepAction {
|
||||||
|
|
||||||
s.vmName = vmName
|
s.vmName = vmName
|
||||||
|
|
||||||
time.Sleep(15 * time.Second)
|
if int64(config.BootWait) > 0 {
|
||||||
|
ui.Say(fmt.Sprintf("Waiting %s for boot...", config.BootWait))
|
||||||
|
time.Sleep(config.BootWait)
|
||||||
|
}
|
||||||
|
|
||||||
return multistep.ActionContinue
|
return multistep.ActionContinue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue