Commit 79c0c6b5 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

builder/virtualbox: step attach floppy

parent d731dcd8
......@@ -15,9 +15,8 @@ type DriverMock struct {
SuppressMessagesCalled bool
SuppressMessagesErr error
VBoxManageCalled bool
VBoxManageArgs []string
VBoxManageErr error
VBoxManageCalls [][]string
VBoxManageErrs []error
VerifyCalled bool
VerifyErr error
......@@ -49,9 +48,12 @@ func (d *DriverMock) SuppressMessages() error {
}
func (d *DriverMock) VBoxManage(args ...string) error {
d.VBoxManageCalled = true
d.VBoxManageArgs = args
return d.VBoxManageErr
d.VBoxManageCalls = append(d.VBoxManageCalls, args)
if len(d.VBoxManageErrs) >= len(d.VBoxManageCalls) {
return d.VBoxManageErrs[len(d.VBoxManageCalls)-1]
}
return nil
}
func (d *DriverMock) Verify() error {
......
package iso
package common
import (
"fmt"
"github.com/mitchellh/multistep"
vboxcommon "github.com/mitchellh/packer/builder/virtualbox/common"
"github.com/mitchellh/packer/packer"
"io"
"io/ioutil"
......@@ -15,13 +14,16 @@ import (
// This step attaches the ISO to the virtual machine.
//
// Uses:
// driver Driver
// ui packer.Ui
// vmName string
//
// Produces:
type stepAttachFloppy struct {
type StepAttachFloppy struct {
floppyPath string
}
func (s *stepAttachFloppy) Run(state multistep.StateBag) multistep.StepAction {
func (s *StepAttachFloppy) Run(state multistep.StateBag) multistep.StepAction {
// Determine if we even have a floppy disk to attach
var floppyPath string
if floppyPathRaw, ok := state.GetOk("floppy_path"); ok {
......@@ -40,7 +42,7 @@ func (s *stepAttachFloppy) Run(state multistep.StateBag) multistep.StepAction {
return multistep.ActionHalt
}
driver := state.Get("driver").(vboxcommon.Driver)
driver := state.Get("driver").(Driver)
ui := state.Get("ui").(packer.Ui)
vmName := state.Get("vmName").(string)
......@@ -77,7 +79,7 @@ func (s *stepAttachFloppy) Run(state multistep.StateBag) multistep.StepAction {
return multistep.ActionContinue
}
func (s *stepAttachFloppy) Cleanup(state multistep.StateBag) {
func (s *StepAttachFloppy) Cleanup(state multistep.StateBag) {
if s.floppyPath == "" {
return
}
......@@ -85,7 +87,7 @@ func (s *stepAttachFloppy) Cleanup(state multistep.StateBag) {
// Delete the floppy disk
defer os.Remove(s.floppyPath)
driver := state.Get("driver").(vboxcommon.Driver)
driver := state.Get("driver").(Driver)
vmName := state.Get("vmName").(string)
command := []string{
......@@ -101,7 +103,7 @@ func (s *stepAttachFloppy) Cleanup(state multistep.StateBag) {
}
}
func (s *stepAttachFloppy) copyFloppy(path string) (string, error) {
func (s *StepAttachFloppy) copyFloppy(path string) (string, error) {
tempdir, err := ioutil.TempDir("", "packer")
if err != nil {
return "", err
......
package common
import (
"github.com/mitchellh/multistep"
"io/ioutil"
"os"
"testing"
)
func TestStepAttachFloppy_impl(t *testing.T) {
var _ multistep.Step = new(StepAttachFloppy)
}
func TestStepAttachFloppy(t *testing.T) {
state := testState(t)
step := new(StepAttachFloppy)
// Create a temporary file for our floppy file
tf, err := ioutil.TempFile("", "packer")
if err != nil {
t.Fatalf("err: %s", err)
}
tf.Close()
defer os.Remove(tf.Name())
state.Put("floppy_path", tf.Name())
state.Put("vmName", "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")
}
if len(driver.VBoxManageCalls) != 2 {
t.Fatal("not enough calls to VBoxManage")
}
if driver.VBoxManageCalls[0][0] != "storagectl" {
t.Fatal("bad call")
}
if driver.VBoxManageCalls[1][0] != "storageattach" {
t.Fatal("bad call")
}
// Test the cleanup
step.Cleanup(state)
if driver.VBoxManageCalls[2][0] != "storageattach" {
t.Fatal("bad call")
}
}
func TestStepAttachFloppy_noFloppy(t *testing.T) {
state := testState(t)
step := new(StepAttachFloppy)
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")
}
if len(driver.VBoxManageCalls) > 0 {
t.Fatal("should not call vboxmanage")
}
}
......@@ -381,7 +381,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
new(stepCreateDisk),
new(stepAttachISO),
new(stepAttachGuestAdditions),
new(stepAttachFloppy),
new(vboxcommon.StepAttachFloppy),
new(stepForwardSSH),
new(stepVBoxManage),
new(stepRun),
......
......@@ -52,7 +52,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
},
/*
new(stepAttachGuestAdditions),
new(stepAttachFloppy),
*/
new(vboxcommon.StepAttachFloppy),
/*
new(stepForwardSSH),
new(stepVBoxManage),
new(stepRun),
......
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