builder/virtualbox,vmware: warning if shutdown_command is not specified

This commit is contained in:
Mitchell Hashimoto 2013-11-02 23:17:21 -05:00
parent 87e88dc847
commit 9acaa97a32
4 changed files with 55 additions and 7 deletions

View File

@ -84,8 +84,9 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
}
b.config.tpl.UserVars = b.config.PackerUserVars
// Accumulate any errors
// Accumulate any errors and warnings
errs := common.CheckUnusedConfig(md)
warnings := make([]string, 0)
if b.config.DiskSize == 0 {
b.config.DiskSize = 40000
@ -363,11 +364,18 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
}
}
if errs != nil && len(errs.Errors) > 0 {
return nil, errs
// Warnings
if b.config.ShutdownCommand == "" {
warnings = append(warnings,
"A shutdown_command was not specified. Without a shutdown command, Packer\n"+
"will forcibly halt the virtual machine, which may result in data loss.")
}
return nil, nil
if errs != nil && len(errs.Errors) > 0 {
return warnings, errs
}
return warnings, nil
}
func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) {

View File

@ -43,6 +43,7 @@ func testConfig() map[string]interface{} {
"iso_checksum": "foo",
"iso_checksum_type": "md5",
"iso_url": "http://www.google.com/",
"shutdown_command": "yes",
"ssh_username": "foo",
packer.BuildNameConfigKey: "foo",
@ -645,6 +646,21 @@ func TestBuilderPrepare_OutputDir(t *testing.T) {
}
}
func TestBuilderPrepare_ShutdownCommand(t *testing.T) {
var b Builder
config := testConfig()
delete(config, "shutdown_command")
warns, err := b.Prepare(config)
if err != nil {
t.Fatalf("bad: %s", err)
}
if len(warns) != 1 {
t.Fatalf("bad: %#v", warns)
}
}
func TestBuilderPrepare_ShutdownTimeout(t *testing.T) {
var b Builder
config := testConfig()

View File

@ -80,6 +80,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
// Accumulate any errors
errs := common.CheckUnusedConfig(md)
warnings := make([]string, 0)
if b.config.DiskName == "" {
b.config.DiskName = "disk"
@ -326,11 +327,18 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
errs, fmt.Errorf("vnc_port_min must be less than vnc_port_max"))
}
if errs != nil && len(errs.Errors) > 0 {
return nil, errs
// Warnings
if b.config.ShutdownCommand == "" {
warnings = append(warnings,
"A shutdown_command was not specified. Without a shutdown command, Packer\n"+
"will forcibly halt the virtual machine, which may result in data loss.")
}
return nil, nil
if errs != nil && len(errs.Errors) > 0 {
return warnings, errs
}
return warnings, nil
}
func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) {

View File

@ -44,6 +44,7 @@ func testConfig() map[string]interface{} {
"iso_checksum": "foo",
"iso_checksum_type": "md5",
"iso_url": "http://www.packer.io",
"shutdown_command": "foo",
"ssh_username": "foo",
packer.BuildNameConfigKey: "foo",
@ -418,6 +419,21 @@ func TestBuilderPrepare_OutputDir(t *testing.T) {
}
}
func TestBuilderPrepare_ShutdownCommand(t *testing.T) {
var b Builder
config := testConfig()
delete(config, "shutdown_command")
warns, err := b.Prepare(config)
if err != nil {
t.Fatalf("bad: %s", err)
}
if len(warns) != 1 {
t.Fatalf("bad: %#v", warns)
}
}
func TestBuilderPrepare_ShutdownTimeout(t *testing.T) {
var b Builder
config := testConfig()