From b3c6ef9f6bff04dc568f4c6efef6613eaf9939e9 Mon Sep 17 00:00:00 2001 From: huiyang Date: Tue, 7 Mar 2017 18:22:23 -0800 Subject: [PATCH] Skip disk compaction for plain disks --- builder/parallels/iso/builder.go | 6 ++++++ builder/parallels/iso/builder_test.go | 18 ++++++++++++++++-- .../source/docs/builders/parallels-iso.html.md | 10 ++++++---- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/builder/parallels/iso/builder.go b/builder/parallels/iso/builder.go index cfe6241a8..e53509c50 100644 --- a/builder/parallels/iso/builder.go +++ b/builder/parallels/iso/builder.go @@ -114,6 +114,12 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) { errs, errors.New("disk_type can only be expand, or plain")) } + if b.config.DiskType == "plain" && !b.config.SkipCompaction { + b.config.SkipCompaction = true + warnings = append(warnings, + "'skip_compaction' is enforced to be true for plain disks.") + } + if b.config.HardDriveInterface != "ide" && b.config.HardDriveInterface != "sata" && b.config.HardDriveInterface != "scsi" { errs = packer.MultiErrorAppend( errs, errors.New("hard_drive_interface can only be ide, sata, or scsi")) diff --git a/builder/parallels/iso/builder_test.go b/builder/parallels/iso/builder_test.go index 668ec1c07..b43da12f9 100644 --- a/builder/parallels/iso/builder_test.go +++ b/builder/parallels/iso/builder_test.go @@ -134,7 +134,7 @@ func TestBuilderPrepare_DiskType(t *testing.T) { var b Builder config := testConfig() - // Test a default boot_wait + // Test a default disk_type delete(config, "disk_type") warns, err := b.Prepare(config) if len(warns) > 0 { @@ -159,8 +159,21 @@ func TestBuilderPrepare_DiskType(t *testing.T) { t.Fatal("should have error") } - // Test with a good + // Test with plain disk with wrong setting for compaction config["disk_type"] = "plain" + config["skip_compaction"] = false + b = Builder{} + warns, err = b.Prepare(config) + if len(warns) == 0 { + t.Fatalf("should have warning") + } + if err != nil { + t.Fatalf("should not have error: %s", err) + } + + // Test with plain disk with correct setting for compaction + config["disk_type"] = "plain" + config["skip_compaction"] = true b = Builder{} warns, err = b.Prepare(config) if len(warns) > 0 { @@ -169,6 +182,7 @@ func TestBuilderPrepare_DiskType(t *testing.T) { if err != nil { t.Fatalf("should not have error: %s", err) } + } func TestBuilderPrepare_HardDriveInterface(t *testing.T) { diff --git a/website/source/docs/builders/parallels-iso.html.md b/website/source/docs/builders/parallels-iso.html.md index 4f3d73c4f..fa221b7ed 100644 --- a/website/source/docs/builders/parallels-iso.html.md +++ b/website/source/docs/builders/parallels-iso.html.md @@ -110,7 +110,8 @@ builder. image file is small initially and grows in size as you add data to it, and `plain` (plain disk) that the image file has a fixed size from the moment it is created (i.e the space is allocated for the drive fully). Plain disks - perform faster than expanding disks. + perform faster than expanding disks. `skip_compaction` will be set to true + automatically for plain disks. - `floppy_files` (array of strings) - A list of files to place onto a floppy disk that is attached when the VM is booted. This is most useful for @@ -225,9 +226,10 @@ builder. "5m", or five minutes. - `skip_compaction` (boolean) - Virtual disk image is compacted at the end of - the build process using `prl_disk_tool` utility. In certain rare cases, this - might corrupt the resulting disk image. If you find this to be the case, - you can disable compaction using this configuration value. + the build process using `prl_disk_tool` utility (except for the case that + `disk_type` is set to `plain`). In certain rare cases, this might corrupt + the resulting disk image. If you find this to be the case, you can disable + compaction using this configuration value. - `vm_name` (string) - This is the name of the PVM directory for the new virtual machine, without the file extension. By default this is