builder/vmware: StepCompactDisk

This commit is contained in:
Mitchell Hashimoto 2013-12-24 23:09:22 -07:00
parent f01b21c610
commit 87ab914a3c
3 changed files with 70 additions and 10 deletions

View File

@ -1,9 +1,8 @@
package iso package common
import ( import (
"fmt" "fmt"
"github.com/mitchellh/multistep" "github.com/mitchellh/multistep"
vmwcommon "github.com/mitchellh/packer/builder/vmware/common"
"github.com/mitchellh/packer/packer" "github.com/mitchellh/packer/packer"
"log" "log"
) )
@ -12,22 +11,22 @@ import (
// boolean is true. // boolean is true.
// //
// Uses: // Uses:
// config *config
// driver Driver // driver Driver
// full_disk_path string // full_disk_path string
// ui packer.Ui // ui packer.Ui
// //
// Produces: // Produces:
// <nothing> // <nothing>
type stepCompactDisk struct{} type StepCompactDisk struct {
Skip bool
}
func (stepCompactDisk) Run(state multistep.StateBag) multistep.StepAction { func (s StepCompactDisk) Run(state multistep.StateBag) multistep.StepAction {
config := state.Get("config").(*config) driver := state.Get("driver").(Driver)
driver := state.Get("driver").(vmwcommon.Driver)
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)
full_disk_path := state.Get("full_disk_path").(string) full_disk_path := state.Get("full_disk_path").(string)
if config.SkipCompaction == true { if s.Skip {
log.Println("Skipping disk compaction step...") log.Println("Skipping disk compaction step...")
return multistep.ActionContinue return multistep.ActionContinue
} }
@ -41,4 +40,4 @@ func (stepCompactDisk) Run(state multistep.StateBag) multistep.StepAction {
return multistep.ActionContinue return multistep.ActionContinue
} }
func (stepCompactDisk) Cleanup(multistep.StateBag) {} func (StepCompactDisk) Cleanup(multistep.StateBag) {}

View File

@ -0,0 +1,59 @@
package common
import (
"testing"
"github.com/mitchellh/multistep"
)
func TestStepCompactDisk_impl(t *testing.T) {
var _ multistep.Step = new(StepCompactDisk)
}
func TestStepCompactDisk(t *testing.T) {
state := testState(t)
step := new(StepCompactDisk)
state.Put("full_disk_path", "foo")
driver := state.Get("driver").(*DriverMock)
// Test the run
if action := step.Run(state); action != multistep.ActionContinue {
t.Fatalf("bad action: %#v", action)
}
if _, ok := state.GetOk("error"); ok {
t.Fatal("should NOT have error")
}
// Test the driver
if !driver.CompactDiskCalled {
t.Fatal("should've called")
}
if driver.CompactDiskPath != "foo" {
t.Fatal("should call with right path")
}
}
func TestStepCompactDisk_skip(t *testing.T) {
state := testState(t)
step := new(StepCompactDisk)
step.Skip = true
state.Put("full_disk_path", "foo")
driver := state.Get("driver").(*DriverMock)
// Test the run
if action := step.Run(state); action != multistep.ActionContinue {
t.Fatalf("bad action: %#v", action)
}
if _, ok := state.GetOk("error"); ok {
t.Fatal("should NOT have error")
}
// Test the driver
if driver.CompactDiskCalled {
t.Fatal("should not have called")
}
}

View File

@ -413,7 +413,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
&stepShutdown{}, &stepShutdown{},
&vmwcommon.StepCleanFiles{}, &vmwcommon.StepCleanFiles{},
&vmwcommon.StepCleanVMX{}, &vmwcommon.StepCleanVMX{},
&stepCompactDisk{}, &vmwcommon.StepCompactDisk{
Skip: b.config.SkipCompaction,
},
} }
// Run! // Run!