Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
packer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kristopher Ruzic
packer
Commits
c7bf38b6
Commit
c7bf38b6
authored
Dec 22, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/virtualbox/common: only remove ISO if it was attached
parent
473fe8a9
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
16 deletions
+41
-16
builder/virtualbox/common/step_remove_devices.go
builder/virtualbox/common/step_remove_devices.go
+14
-12
builder/virtualbox/common/step_remove_devices_test.go
builder/virtualbox/common/step_remove_devices_test.go
+24
-4
builder/virtualbox/iso/step_attach_iso.go
builder/virtualbox/iso/step_attach_iso.go
+3
-0
No files found.
builder/virtualbox/common/step_remove_devices.go
View file @
c7bf38b6
...
@@ -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
...
...
builder/virtualbox/common/step_remove_devices_test.go
View file @
c7bf38b6
...
@@ -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
)
}
}
}
builder/virtualbox/iso/step_attach_iso.go
View file @
c7bf38b6
...
@@ -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
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment