mirror of https://github.com/hashicorp/packer
Merge pull request #7419 from vhaidamaka/vbox_check_none_communicator
Validate 'none' communicator in the virtualbox builderpull/7464/head
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
|
||||
}
|
||||
|
||||
Loading…
Reference in new issue