Commit c7bf38b6 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

builder/virtualbox/common: only remove ISO if it was attached

parent 473fe8a9
...@@ -40,19 +40,21 @@ func (s *StepRemoveDevices) Run(state multistep.StateBag) multistep.StepAction { ...@@ -40,19 +40,21 @@ func (s *StepRemoveDevices) Run(state multistep.StateBag) multistep.StepAction {
} }
} }
command := []string{ if _, ok := state.GetOk("attachedIso"); ok {
"storageattach", vmName, command := []string{
"--storagectl", "IDE Controller", "storageattach", vmName,
"--port", "0", "--storagectl", "IDE Controller",
"--device", "1", "--port", "0",
"--medium", "none", "--device", "1",
} "--medium", "none",
}
if err := driver.VBoxManage(command...); err != nil { if err := driver.VBoxManage(command...); err != nil {
err := fmt.Errorf("Error detaching ISO: %s", err) err := fmt.Errorf("Error detaching ISO: %s", err)
state.Put("error", err) state.Put("error", err)
ui.Error(err.Error()) ui.Error(err.Error())
return multistep.ActionHalt return multistep.ActionHalt
}
} }
return multistep.ActionContinue return multistep.ActionContinue
......
...@@ -25,6 +25,29 @@ func TestStepRemoveDevices(t *testing.T) { ...@@ -25,6 +25,29 @@ func TestStepRemoveDevices(t *testing.T) {
t.Fatal("should NOT have error") t.Fatal("should NOT have error")
} }
// Test that ISO was removed
if len(driver.VBoxManageCalls) != 0 {
t.Fatalf("bad: %#v", driver.VBoxManageCalls)
}
}
func TestStepRemoveDevices_attachedIso(t *testing.T) {
state := testState(t)
step := new(StepRemoveDevices)
state.Put("attachedIso", true)
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")
}
// Test that ISO was removed // Test that ISO was removed
if len(driver.VBoxManageCalls) != 1 { if len(driver.VBoxManageCalls) != 1 {
t.Fatalf("bad: %#v", driver.VBoxManageCalls) t.Fatalf("bad: %#v", driver.VBoxManageCalls)
...@@ -52,13 +75,10 @@ func TestStepRemoveDevices_floppyPath(t *testing.T) { ...@@ -52,13 +75,10 @@ func TestStepRemoveDevices_floppyPath(t *testing.T) {
} }
// Test that both were removed // Test that both were removed
if len(driver.VBoxManageCalls) != 2 { if len(driver.VBoxManageCalls) != 1 {
t.Fatalf("bad: %#v", driver.VBoxManageCalls) t.Fatalf("bad: %#v", driver.VBoxManageCalls)
} }
if driver.VBoxManageCalls[0][3] != "Floppy Controller" { if driver.VBoxManageCalls[0][3] != "Floppy Controller" {
t.Fatalf("bad: %#v", driver.VBoxManageCalls) t.Fatalf("bad: %#v", driver.VBoxManageCalls)
} }
if driver.VBoxManageCalls[1][3] != "IDE Controller" {
t.Fatalf("bad: %#v", driver.VBoxManageCalls)
}
} }
...@@ -41,6 +41,9 @@ func (s *stepAttachISO) Run(state multistep.StateBag) multistep.StepAction { ...@@ -41,6 +41,9 @@ func (s *stepAttachISO) Run(state multistep.StateBag) multistep.StepAction {
// Track the path so that we can unregister it from VirtualBox later // Track the path so that we can unregister it from VirtualBox later
s.diskPath = isoPath s.diskPath = isoPath
// Set some state so we know to remove
state.Put("attachedIso", true)
return multistep.ActionContinue return multistep.ActionContinue
} }
......
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