Commit 9362cb53 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

builder/vmware/vmx: set the full_disk_path so compacting works

parent 8e75075e
package vmx package vmx
import ( import (
"fmt"
"log" "log"
"path/filepath" "path/filepath"
...@@ -25,12 +26,25 @@ func (s *StepCloneVMX) Run(state multistep.StateBag) multistep.StepAction { ...@@ -25,12 +26,25 @@ func (s *StepCloneVMX) Run(state multistep.StateBag) multistep.StepAction {
ui.Say("Cloning source VM...") ui.Say("Cloning source VM...")
log.Printf("Cloning from: %s", s.Path) log.Printf("Cloning from: %s", s.Path)
log.Printf("Cloning to: %s", vmxPath) log.Printf("Cloning to: %s", vmxPath)
if err := driver.Clone(vmxPath, s.Path); err != nil { if err := driver.Clone(vmxPath, s.Path); err != nil {
state.Put("error", err) state.Put("error", err)
return multistep.ActionHalt return multistep.ActionHalt
} }
vmxData, err := vmwcommon.ReadVMX(vmxPath)
if err != nil {
state.Put("error", err)
return multistep.ActionHalt
}
diskName, ok := vmxData["scsi0:0.filename"]
if !ok {
err := fmt.Errorf("Root disk filename could not be found!")
state.Put("error", err)
return multistep.ActionHalt
}
state.Put("full_disk_path", filepath.Join(s.OutputDir, diskName))
state.Put("vmx_path", vmxPath) state.Put("vmx_path", vmxPath)
return multistep.ActionContinue return multistep.ActionContinue
} }
......
package vmx package vmx
import ( import (
"io/ioutil"
"os"
"path/filepath"
"testing" "testing"
"github.com/mitchellh/multistep" "github.com/mitchellh/multistep"
...@@ -12,10 +15,29 @@ func TestStepCloneVMX_impl(t *testing.T) { ...@@ -12,10 +15,29 @@ func TestStepCloneVMX_impl(t *testing.T) {
} }
func TestStepCloneVMX(t *testing.T) { func TestStepCloneVMX(t *testing.T) {
// Setup some state
td, err := ioutil.TempDir("", "packer")
if err != nil {
t.Fatalf("err: %s", err)
}
defer os.RemoveAll(td)
// Create the source
sourcePath := filepath.Join(td, "source.vmx")
if err := ioutil.WriteFile(sourcePath, []byte(testCloneVMX), 0644); err != nil {
t.Fatalf("err: %s", err)
}
// Create the dest because the mock driver won't
destPath := filepath.Join(td, "foo.vmx")
if err := ioutil.WriteFile(destPath, []byte(testCloneVMX), 0644); err != nil {
t.Fatalf("err: %s", err)
}
state := testState(t) state := testState(t)
step := new(StepCloneVMX) step := new(StepCloneVMX)
step.OutputDir = "/foo" step.OutputDir = td
step.Path = "/bar/bar.vmx" step.Path = sourcePath
step.VMName = "foo" step.VMName = "foo"
driver := state.Get("driver").(*vmwcommon.DriverMock) driver := state.Get("driver").(*vmwcommon.DriverMock)
...@@ -28,7 +50,25 @@ func TestStepCloneVMX(t *testing.T) { ...@@ -28,7 +50,25 @@ func TestStepCloneVMX(t *testing.T) {
t.Fatal("should NOT have error") t.Fatal("should NOT have error")
} }
// Test we cloned
if !driver.CloneCalled { if !driver.CloneCalled {
t.Fatal("clone should be called") t.Fatal("should call clone")
}
// Test that we have our paths
if vmxPath, ok := state.GetOk("vmx_path"); !ok {
t.Fatal("should set vmx_path")
} else if vmxPath != destPath {
t.Fatalf("bad: %#v", vmxPath)
}
if diskPath, ok := state.GetOk("full_disk_path"); !ok {
t.Fatal("should set full_disk_path")
} else if diskPath != filepath.Join(td, "foo") {
t.Fatalf("bad: %#v", diskPath)
} }
} }
const testCloneVMX = `
scsi0:0.fileName = "foo"
`
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment