builder/virtualbox: allow disabling guest addition uploading
This commit is contained in:
parent
254653475e
commit
aa95caa261
|
@ -16,6 +16,14 @@ import (
|
|||
|
||||
const BuilderId = "mitchellh.virtualbox"
|
||||
|
||||
// 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 Builder struct {
|
||||
config config
|
||||
runner multistep.Runner
|
||||
|
@ -28,7 +36,7 @@ type config struct {
|
|||
DiskSize uint `mapstructure:"disk_size"`
|
||||
FloppyFiles []string `mapstructure:"floppy_files"`
|
||||
Format string `mapstructure:"format"`
|
||||
GuestAdditionsAttach bool `mapstructure:"guest_additions_attach"`
|
||||
GuestAdditionsMode string `mapstructure:"guest_additions_mode"`
|
||||
GuestAdditionsPath string `mapstructure:"guest_additions_path"`
|
||||
GuestAdditionsURL string `mapstructure:"guest_additions_url"`
|
||||
GuestAdditionsSHA256 string `mapstructure:"guest_additions_sha256"`
|
||||
|
@ -87,6 +95,10 @@ func (b *Builder) Prepare(raws ...interface{}) error {
|
|||
b.config.FloppyFiles = make([]string, 0)
|
||||
}
|
||||
|
||||
if b.config.GuestAdditionsMode == "" {
|
||||
b.config.GuestAdditionsMode = "upload"
|
||||
}
|
||||
|
||||
if b.config.GuestAdditionsPath == "" {
|
||||
b.config.GuestAdditionsPath = "VBoxGuestAdditions.iso"
|
||||
}
|
||||
|
@ -145,6 +157,7 @@ func (b *Builder) Prepare(raws ...interface{}) error {
|
|||
|
||||
// Errors
|
||||
templates := map[string]*string{
|
||||
"guest_additions_mode": &b.config.GuestAdditionsMode,
|
||||
"guest_additions_sha256": &b.config.GuestAdditionsSHA256,
|
||||
"guest_os_type": &b.config.GuestOSType,
|
||||
"hard_drive_interface": &b.config.HardDriveInterface,
|
||||
|
@ -264,6 +277,25 @@ func (b *Builder) Prepare(raws ...interface{}) error {
|
|||
}
|
||||
}
|
||||
|
||||
validMode := false
|
||||
validModes := []string{
|
||||
GuestAdditionsModeDisable,
|
||||
GuestAdditionsModeAttach,
|
||||
GuestAdditionsModeUpload,
|
||||
}
|
||||
|
||||
for _, mode := range validModes {
|
||||
if b.config.GuestAdditionsMode == mode {
|
||||
validMode = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !validMode {
|
||||
errs = packer.MultiErrorAppend(errs,
|
||||
fmt.Errorf("guest_additions_mode is invalid. Must be one of: %v", validModes))
|
||||
}
|
||||
|
||||
if b.config.GuestAdditionsSHA256 != "" {
|
||||
b.config.GuestAdditionsSHA256 = strings.ToLower(b.config.GuestAdditionsSHA256)
|
||||
}
|
||||
|
|
|
@ -65,6 +65,10 @@ func TestBuilderPrepare_Defaults(t *testing.T) {
|
|||
t.Fatalf("should not have error: %s", err)
|
||||
}
|
||||
|
||||
if b.config.GuestAdditionsMode != GuestAdditionsModeUpload {
|
||||
t.Errorf("bad guest additions mode: %s", b.config.GuestAdditionsMode)
|
||||
}
|
||||
|
||||
if b.config.GuestOSType != "Other" {
|
||||
t.Errorf("bad guest OS type: %s", b.config.GuestOSType)
|
||||
}
|
||||
|
@ -178,6 +182,38 @@ func TestBuilderPrepare_FloppyFiles(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestBuilderPrepare_GuestAdditionsMode(t *testing.T) {
|
||||
var b Builder
|
||||
config := testConfig()
|
||||
|
||||
// test default mode
|
||||
delete(config, "guest_additions_mode")
|
||||
err := b.Prepare(config)
|
||||
if err != nil {
|
||||
t.Fatalf("bad err: %s", err)
|
||||
}
|
||||
|
||||
// Test another mode
|
||||
config["guest_additions_mode"] = "attach"
|
||||
b = Builder{}
|
||||
err = b.Prepare(config)
|
||||
if err != nil {
|
||||
t.Fatalf("should not have error: %s", err)
|
||||
}
|
||||
|
||||
if b.config.GuestAdditionsMode != GuestAdditionsModeAttach {
|
||||
t.Fatalf("bad: %s", b.config.GuestAdditionsMode)
|
||||
}
|
||||
|
||||
// Test bad mode
|
||||
config["guest_additions_mode"] = "teleport"
|
||||
b = Builder{}
|
||||
err = b.Prepare(config)
|
||||
if err == nil {
|
||||
t.Fatal("should error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuilderPrepare_GuestAdditionsPath(t *testing.T) {
|
||||
var b Builder
|
||||
config := testConfig()
|
||||
|
|
|
@ -30,7 +30,7 @@ func (s *stepAttachGuestAdditions) Run(state multistep.StateBag) multistep.StepA
|
|||
vmName := state.Get("vmName").(string)
|
||||
|
||||
// If we're not attaching the guest additions then just return
|
||||
if !config.GuestAdditionsAttach {
|
||||
if config.GuestAdditionsMode != GuestAdditionsModeAttach {
|
||||
log.Println("Not attaching guest additions since we're uploading.")
|
||||
return multistep.ActionContinue
|
||||
}
|
||||
|
|
|
@ -23,8 +23,8 @@ func (s *stepUploadGuestAdditions) Run(state multistep.StateBag) multistep.StepA
|
|||
ui := state.Get("ui").(packer.Ui)
|
||||
|
||||
// If we're attaching then don't do this, since we attached.
|
||||
if config.GuestAdditionsAttach {
|
||||
log.Println("Not uploading guest additions since we're attaching.")
|
||||
if config.GuestAdditionsMode != GuestAdditionsModeUpload {
|
||||
log.Println("Not uploading guest additions since mode is not upload")
|
||||
return multistep.ActionContinue
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue