Merge pull request #5014 from Lee303/builder-hyperv-floppydirs
Add support for floppy_dirs with hyperv-iso builder
This commit is contained in:
commit
d569a1b879
|
@ -1,19 +0,0 @@
|
|||
package common
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/packer/template/interpolate"
|
||||
)
|
||||
|
||||
// FloppyConfig is configuration related to created floppy disks and attaching
|
||||
// them to a Parallels virtual machine.
|
||||
type FloppyConfig struct {
|
||||
FloppyFiles []string `mapstructure:"floppy_files"`
|
||||
}
|
||||
|
||||
func (c *FloppyConfig) Prepare(ctx *interpolate.Context) []error {
|
||||
if c.FloppyFiles == nil {
|
||||
c.FloppyFiles = make([]string, 0)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
package common
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestFloppyConfigPrepare(t *testing.T) {
|
||||
c := new(FloppyConfig)
|
||||
|
||||
errs := c.Prepare(testConfigTemplate(t))
|
||||
if len(errs) > 0 {
|
||||
t.Fatalf("err: %#v", errs)
|
||||
}
|
||||
|
||||
if len(c.FloppyFiles) > 0 {
|
||||
t.Fatal("should not have floppy files")
|
||||
}
|
||||
}
|
|
@ -45,7 +45,7 @@ type Config struct {
|
|||
common.PackerConfig `mapstructure:",squash"`
|
||||
common.HTTPConfig `mapstructure:",squash"`
|
||||
common.ISOConfig `mapstructure:",squash"`
|
||||
hypervcommon.FloppyConfig `mapstructure:",squash"`
|
||||
common.FloppyConfig `mapstructure:",squash"`
|
||||
hypervcommon.OutputConfig `mapstructure:",squash"`
|
||||
hypervcommon.SSHConfig `mapstructure:",squash"`
|
||||
hypervcommon.RunConfig `mapstructure:",squash"`
|
||||
|
@ -57,16 +57,6 @@ type Config struct {
|
|||
// The size, in megabytes, of the computer memory in the VM.
|
||||
// By default, this is 1024 (about 1 GB).
|
||||
RamSize uint `mapstructure:"ram_size"`
|
||||
// A list of files to place onto a floppy disk that is attached when the
|
||||
// VM is booted. This is most useful for unattended Windows installs,
|
||||
// which look for an Autounattend.xml file on removable media. By default,
|
||||
// no floppy will be attached. All files listed in this setting get
|
||||
// placed into the root directory of the floppy and the floppy is attached
|
||||
// as the first floppy device. Currently, no support exists for creating
|
||||
// sub-directories on the floppy. Wildcard characters (*, ?, and [])
|
||||
// are allowed. Directory names are also allowed, which will add all
|
||||
// the files found in the directory to the floppy.
|
||||
FloppyFiles []string `mapstructure:"floppy_files"`
|
||||
//
|
||||
SecondaryDvdImages []string `mapstructure:"secondary_iso_images"`
|
||||
|
||||
|
@ -156,7 +146,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
|
|||
}
|
||||
|
||||
if b.config.Generation == 2 {
|
||||
if len(b.config.FloppyFiles) > 0 {
|
||||
if len(b.config.FloppyFiles) > 0 || len(b.config.FloppyDirectories) > 0 {
|
||||
err = errors.New("Generation 2 vms don't support floppy drives. Use ISO image instead.")
|
||||
errs = packer.MultiErrorAppend(errs, err)
|
||||
}
|
||||
|
@ -318,7 +308,8 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
|||
TargetPath: b.config.TargetPath,
|
||||
},
|
||||
&common.StepCreateFloppy{
|
||||
Files: b.config.FloppyFiles,
|
||||
Files: b.config.FloppyConfig.FloppyFiles,
|
||||
Directories: b.config.FloppyConfig.FloppyDirectories,
|
||||
},
|
||||
&common.StepHTTPServer{
|
||||
HTTPDir: b.config.HTTPDir,
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package iso
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
|
@ -78,6 +79,55 @@ func TestBuilderPrepare_DiskSize(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestBuilderPrepare_FloppyFiles(t *testing.T) {
|
||||
var b Builder
|
||||
config := testConfig()
|
||||
|
||||
delete(config, "floppy_files")
|
||||
warns, err := b.Prepare(config)
|
||||
if len(warns) > 0 {
|
||||
t.Fatalf("bad: %#v", warns)
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatalf("bad err: %s", err)
|
||||
}
|
||||
|
||||
if len(b.config.FloppyFiles) != 0 {
|
||||
t.Fatalf("bad: %#v", b.config.FloppyFiles)
|
||||
}
|
||||
|
||||
floppiesPath := "../../../common/test-fixtures/floppies"
|
||||
config["floppy_files"] = []string{fmt.Sprintf("%s/bar.bat", floppiesPath), fmt.Sprintf("%s/foo.ps1", floppiesPath)}
|
||||
b = Builder{}
|
||||
warns, err = b.Prepare(config)
|
||||
if len(warns) > 0 {
|
||||
t.Fatalf("bad: %#v", warns)
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatalf("should not have error: %s", err)
|
||||
}
|
||||
|
||||
expected := []string{fmt.Sprintf("%s/bar.bat", floppiesPath), fmt.Sprintf("%s/foo.ps1", floppiesPath)}
|
||||
if !reflect.DeepEqual(b.config.FloppyFiles, expected) {
|
||||
t.Fatalf("bad: %#v", b.config.FloppyFiles)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuilderPrepare_InvalidFloppies(t *testing.T) {
|
||||
var b Builder
|
||||
config := testConfig()
|
||||
config["floppy_files"] = []string{"nonexistent.bat", "nonexistent.ps1"}
|
||||
b = Builder{}
|
||||
_, errs := b.Prepare(config)
|
||||
if errs == nil {
|
||||
t.Fatalf("Nonexistent floppies should trigger multierror")
|
||||
}
|
||||
|
||||
if len(errs.(*packer.MultiError).Errors) != 2 {
|
||||
t.Fatalf("Multierror should work and report 2 errors")
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuilderPrepare_InvalidKey(t *testing.T) {
|
||||
var b Builder
|
||||
config := testConfig()
|
||||
|
|
|
@ -113,6 +113,14 @@ can be configured for this builder.
|
|||
characters (`*`, `?`, and `[]`) are allowed. Directory names are also allowed,
|
||||
which will add all the files found in the directory to the floppy.
|
||||
|
||||
- `floppy_dirs` (array of strings) - A list of directories to place onto
|
||||
the floppy disk recursively. This is similar to the `floppy_files` option
|
||||
except that the directory structure is preserved. This is useful for when
|
||||
your floppy disk includes drivers or if you just want to organize it's
|
||||
contents as a hierarchy. Wildcard characters (\*, ?, and \[\]) are allowed.
|
||||
The maximum summary size of all files in the listed directories are the
|
||||
same as in `floppy_files`.
|
||||
|
||||
- `generation` (integer) - The Hyper-V generation for the virtual machine. By
|
||||
default, this is 1. Generation 2 Hyper-V virtual machines do not support
|
||||
floppy drives. In this scenario use `secondary_iso_images` instead. Hard
|
||||
|
|
Loading…
Reference in New Issue