Clean VMX step should always remove floppy.

When using the VMX builder its possible for the source machine to have a floppy configured which gets cloned to the new VM Packer spins up. When the new VM's Packer config doesn't have a floppy_files config entry, the Packer clean VMX step fails to remove the floppy disk from the new VM. This can cause build failures, for example with the vsphere post processor; generating errors like:

* Post-processor failed: Failed: exit status 1
Error: File (/home/teamcity/tmp/buildTmp/packer941120499) could not be found.

Opening the cloned VM's VMX file you can clearly see it has a floppy entry from the source machine's VMX file (exact same path) even though the Packer config contains no floppy_files entry.
This commit is contained in:
Shawn Neal 2014-09-16 18:27:00 -07:00
parent a7122b3cf3
commit 7d9c252b3a
2 changed files with 7 additions and 10 deletions

View File

@ -32,17 +32,15 @@ func (s StepCleanVMX) Run(state multistep.StateBag) multistep.StepAction {
return multistep.ActionHalt return multistep.ActionHalt
} }
if _, ok := state.GetOk("floppy_path"); ok { // Delete the floppy0 entries so the floppy is no longer mounted
// Delete the floppy0 entries so the floppy is no longer mounted ui.Message("Unmounting floppy from VMX...")
ui.Message("Unmounting floppy from VMX...") for k, _ := range vmxData {
for k, _ := range vmxData { if strings.HasPrefix(k, "floppy0.") {
if strings.HasPrefix(k, "floppy0.") { log.Printf("Deleting key: %s", k)
log.Printf("Deleting key: %s", k) delete(vmxData, k)
delete(vmxData, k)
}
} }
vmxData["floppy0.present"] = "FALSE"
} }
vmxData["floppy0.present"] = "FALSE"
if isoPathRaw, ok := state.GetOk("iso_path"); ok { if isoPathRaw, ok := state.GetOk("iso_path"); ok {
isoPath := isoPathRaw.(string) isoPath := isoPathRaw.(string)

View File

@ -39,7 +39,6 @@ func TestStepCleanVMX_floppyPath(t *testing.T) {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
} }
state.Put("floppy_path", "foo")
state.Put("vmx_path", vmxPath) state.Put("vmx_path", vmxPath)
// Test the run // Test the run