builder/virtualbox: step attach floppy
This commit is contained in:
parent
d731dcd8f7
commit
79c0c6b545
|
@ -15,9 +15,8 @@ type DriverMock struct {
|
||||||
SuppressMessagesCalled bool
|
SuppressMessagesCalled bool
|
||||||
SuppressMessagesErr error
|
SuppressMessagesErr error
|
||||||
|
|
||||||
VBoxManageCalled bool
|
VBoxManageCalls [][]string
|
||||||
VBoxManageArgs []string
|
VBoxManageErrs []error
|
||||||
VBoxManageErr error
|
|
||||||
|
|
||||||
VerifyCalled bool
|
VerifyCalled bool
|
||||||
VerifyErr error
|
VerifyErr error
|
||||||
|
@ -49,9 +48,12 @@ func (d *DriverMock) SuppressMessages() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DriverMock) VBoxManage(args ...string) error {
|
func (d *DriverMock) VBoxManage(args ...string) error {
|
||||||
d.VBoxManageCalled = true
|
d.VBoxManageCalls = append(d.VBoxManageCalls, args)
|
||||||
d.VBoxManageArgs = args
|
|
||||||
return d.VBoxManageErr
|
if len(d.VBoxManageErrs) >= len(d.VBoxManageCalls) {
|
||||||
|
return d.VBoxManageErrs[len(d.VBoxManageCalls)-1]
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DriverMock) Verify() error {
|
func (d *DriverMock) Verify() error {
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
package iso
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/mitchellh/multistep"
|
"github.com/mitchellh/multistep"
|
||||||
vboxcommon "github.com/mitchellh/packer/builder/virtualbox/common"
|
|
||||||
"github.com/mitchellh/packer/packer"
|
"github.com/mitchellh/packer/packer"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
@ -15,13 +14,16 @@ import (
|
||||||
// This step attaches the ISO to the virtual machine.
|
// This step attaches the ISO to the virtual machine.
|
||||||
//
|
//
|
||||||
// Uses:
|
// Uses:
|
||||||
|
// driver Driver
|
||||||
|
// ui packer.Ui
|
||||||
|
// vmName string
|
||||||
//
|
//
|
||||||
// Produces:
|
// Produces:
|
||||||
type stepAttachFloppy struct {
|
type StepAttachFloppy struct {
|
||||||
floppyPath string
|
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
|
// Determine if we even have a floppy disk to attach
|
||||||
var floppyPath string
|
var floppyPath string
|
||||||
if floppyPathRaw, ok := state.GetOk("floppy_path"); ok {
|
if floppyPathRaw, ok := state.GetOk("floppy_path"); ok {
|
||||||
|
@ -40,7 +42,7 @@ func (s *stepAttachFloppy) Run(state multistep.StateBag) multistep.StepAction {
|
||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
}
|
}
|
||||||
|
|
||||||
driver := state.Get("driver").(vboxcommon.Driver)
|
driver := state.Get("driver").(Driver)
|
||||||
ui := state.Get("ui").(packer.Ui)
|
ui := state.Get("ui").(packer.Ui)
|
||||||
vmName := state.Get("vmName").(string)
|
vmName := state.Get("vmName").(string)
|
||||||
|
|
||||||
|
@ -77,7 +79,7 @@ func (s *stepAttachFloppy) Run(state multistep.StateBag) multistep.StepAction {
|
||||||
return multistep.ActionContinue
|
return multistep.ActionContinue
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *stepAttachFloppy) Cleanup(state multistep.StateBag) {
|
func (s *StepAttachFloppy) Cleanup(state multistep.StateBag) {
|
||||||
if s.floppyPath == "" {
|
if s.floppyPath == "" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -85,7 +87,7 @@ func (s *stepAttachFloppy) Cleanup(state multistep.StateBag) {
|
||||||
// Delete the floppy disk
|
// Delete the floppy disk
|
||||||
defer os.Remove(s.floppyPath)
|
defer os.Remove(s.floppyPath)
|
||||||
|
|
||||||
driver := state.Get("driver").(vboxcommon.Driver)
|
driver := state.Get("driver").(Driver)
|
||||||
vmName := state.Get("vmName").(string)
|
vmName := state.Get("vmName").(string)
|
||||||
|
|
||||||
command := []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")
|
tempdir, err := ioutil.TempDir("", "packer")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
|
@ -0,0 +1,73 @@
|
||||||
|
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(stepCreateDisk),
|
||||||
new(stepAttachISO),
|
new(stepAttachISO),
|
||||||
new(stepAttachGuestAdditions),
|
new(stepAttachGuestAdditions),
|
||||||
new(stepAttachFloppy),
|
new(vboxcommon.StepAttachFloppy),
|
||||||
new(stepForwardSSH),
|
new(stepForwardSSH),
|
||||||
new(stepVBoxManage),
|
new(stepVBoxManage),
|
||||||
new(stepRun),
|
new(stepRun),
|
||||||
|
|
|
@ -52,7 +52,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
||||||
},
|
},
|
||||||
/*
|
/*
|
||||||
new(stepAttachGuestAdditions),
|
new(stepAttachGuestAdditions),
|
||||||
new(stepAttachFloppy),
|
*/
|
||||||
|
new(vboxcommon.StepAttachFloppy),
|
||||||
|
/*
|
||||||
new(stepForwardSSH),
|
new(stepForwardSSH),
|
||||||
new(stepVBoxManage),
|
new(stepVBoxManage),
|
||||||
new(stepRun),
|
new(stepRun),
|
||||||
|
|
Loading…
Reference in New Issue