Merge pull request #7419 from vhaidamaka/vbox_check_none_communicator
Validate 'none' communicator in the virtualbox builder
This commit is contained in:
commit
e5ddf3e56b
|
@ -1,9 +0,0 @@
|
|||
package common
|
||||
|
||||
// These are the different valid mode values for "guest_additions_mode" which
|
||||
// determine how guest additions are delivered to the guest.
|
||||
const (
|
||||
GuestAdditionsModeDisable string = "disable"
|
||||
GuestAdditionsModeAttach = "attach"
|
||||
GuestAdditionsModeUpload = "upload"
|
||||
)
|
|
@ -0,0 +1,31 @@
|
|||
package common
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/hashicorp/packer/template/interpolate"
|
||||
)
|
||||
|
||||
// These are the different valid mode values for "guest_additions_mode" which
|
||||
// determine how guest additions are delivered to the guest.
|
||||
const (
|
||||
GuestAdditionsModeDisable string = "disable"
|
||||
GuestAdditionsModeAttach = "attach"
|
||||
GuestAdditionsModeUpload = "upload"
|
||||
)
|
||||
|
||||
type GuestAdditionsConfig struct {
|
||||
Communicator string `mapstructure:"communicator"`
|
||||
GuestAdditionsMode string `mapstructure:"guest_additions_mode"`
|
||||
}
|
||||
|
||||
func (c *GuestAdditionsConfig) Prepare(ctx *interpolate.Context) []error {
|
||||
var errs []error
|
||||
|
||||
if c.Communicator == "none" && c.GuestAdditionsMode != "disable" {
|
||||
errs = append(errs, fmt.Errorf("guest_additions_mode has to be "+
|
||||
"'disable' when communicator = 'none'."))
|
||||
}
|
||||
|
||||
return errs
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package common
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGuestAdditionsConfigPrepare(t *testing.T) {
|
||||
c := new(GuestAdditionsConfig)
|
||||
var errs []error
|
||||
|
||||
c.GuestAdditionsMode = "disable"
|
||||
c.Communicator = "none"
|
||||
errs = c.Prepare(testConfigTemplate(t))
|
||||
if len(errs) > 0 {
|
||||
t.Fatalf("should not have error: %s", errs)
|
||||
}
|
||||
}
|
|
@ -1,18 +1,28 @@
|
|||
package common
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/hashicorp/packer/template/interpolate"
|
||||
)
|
||||
|
||||
type VBoxVersionConfig struct {
|
||||
Communicator string `mapstructure:"communicator"`
|
||||
VBoxVersionFile *string `mapstructure:"virtualbox_version_file"`
|
||||
}
|
||||
|
||||
func (c *VBoxVersionConfig) Prepare(ctx *interpolate.Context) []error {
|
||||
var errs []error
|
||||
|
||||
if c.VBoxVersionFile == nil {
|
||||
default_file := ".vbox_version"
|
||||
c.VBoxVersionFile = &default_file
|
||||
}
|
||||
|
||||
return nil
|
||||
if c.Communicator == "none" && *c.VBoxVersionFile != "" {
|
||||
errs = append(errs, fmt.Errorf("virtualbox_version_file has to be an "+
|
||||
"empty string when communicator = 'none'."))
|
||||
}
|
||||
|
||||
return errs
|
||||
}
|
||||
|
|
|
@ -62,3 +62,18 @@ func TestVBoxVersionConfigPrepare_empty(t *testing.T) {
|
|||
t.Fatalf("bad value: %s", *c.VBoxVersionFile)
|
||||
}
|
||||
}
|
||||
|
||||
func TestVBoxVersionConfigPrepare_communicator(t *testing.T) {
|
||||
var c *VBoxVersionConfig
|
||||
var errs []error
|
||||
|
||||
// Test with 'none' communicator and non-empty virtualbox_version_file
|
||||
c = new(VBoxVersionConfig)
|
||||
filename := "test"
|
||||
c.VBoxVersionFile = &filename
|
||||
c.Communicator = "none"
|
||||
errs = c.Prepare(testConfigTemplate(t))
|
||||
if len(errs) == 0 {
|
||||
t.Fatalf("should have an error")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,6 +40,7 @@ type Config struct {
|
|||
vboxcommon.VBoxManagePostConfig `mapstructure:",squash"`
|
||||
vboxcommon.VBoxVersionConfig `mapstructure:",squash"`
|
||||
vboxcommon.VBoxBundleConfig `mapstructure:",squash"`
|
||||
vboxcommon.GuestAdditionsConfig `mapstructure:",squash"`
|
||||
|
||||
DiskSize uint `mapstructure:"disk_size"`
|
||||
GuestAdditionsMode string `mapstructure:"guest_additions_mode"`
|
||||
|
@ -101,6 +102,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
|
|||
errs = packer.MultiErrorAppend(errs, b.config.VBoxManagePostConfig.Prepare(&b.config.ctx)...)
|
||||
errs = packer.MultiErrorAppend(errs, b.config.VBoxVersionConfig.Prepare(&b.config.ctx)...)
|
||||
errs = packer.MultiErrorAppend(errs, b.config.BootConfig.Prepare(&b.config.ctx)...)
|
||||
errs = packer.MultiErrorAppend(errs, b.config.GuestAdditionsConfig.Prepare(&b.config.ctx)...)
|
||||
|
||||
if b.config.DiskSize == 0 {
|
||||
b.config.DiskSize = 40000
|
||||
|
|
|
@ -28,6 +28,7 @@ type Config struct {
|
|||
vboxcommon.VBoxManageConfig `mapstructure:",squash"`
|
||||
vboxcommon.VBoxManagePostConfig `mapstructure:",squash"`
|
||||
vboxcommon.VBoxVersionConfig `mapstructure:",squash"`
|
||||
vboxcommon.GuestAdditionsConfig `mapstructure:",squash"`
|
||||
|
||||
Checksum string `mapstructure:"checksum"`
|
||||
ChecksumType string `mapstructure:"checksum_type"`
|
||||
|
@ -97,6 +98,7 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
|
|||
errs = packer.MultiErrorAppend(errs, c.VBoxManagePostConfig.Prepare(&c.ctx)...)
|
||||
errs = packer.MultiErrorAppend(errs, c.VBoxVersionConfig.Prepare(&c.ctx)...)
|
||||
errs = packer.MultiErrorAppend(errs, c.BootConfig.Prepare(&c.ctx)...)
|
||||
errs = packer.MultiErrorAppend(errs, c.GuestAdditionsConfig.Prepare(&c.ctx)...)
|
||||
|
||||
c.ChecksumType = strings.ToLower(c.ChecksumType)
|
||||
c.Checksum = strings.ToLower(c.Checksum)
|
||||
|
|
Loading…
Reference in New Issue