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
9362cb53
Commit
9362cb53
authored
Dec 26, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/vmware/vmx: set the full_disk_path so compacting works
parent
8e75075e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
4 deletions
+58
-4
builder/vmware/vmx/step_clone_vmx.go
builder/vmware/vmx/step_clone_vmx.go
+15
-1
builder/vmware/vmx/step_clone_vmx_test.go
builder/vmware/vmx/step_clone_vmx_test.go
+43
-3
No files found.
builder/vmware/vmx/step_clone_vmx.go
View file @
9362cb53
package
vmx
import
(
"fmt"
"log"
"path/filepath"
...
...
@@ -25,12 +26,25 @@ func (s *StepCloneVMX) Run(state multistep.StateBag) multistep.StepAction {
ui
.
Say
(
"Cloning source VM..."
)
log
.
Printf
(
"Cloning from: %s"
,
s
.
Path
)
log
.
Printf
(
"Cloning to: %s"
,
vmxPath
)
if
err
:=
driver
.
Clone
(
vmxPath
,
s
.
Path
);
err
!=
nil
{
state
.
Put
(
"error"
,
err
)
return
multistep
.
ActionHalt
}
vmxData
,
err
:=
vmwcommon
.
ReadVMX
(
vmxPath
)
if
err
!=
nil
{
state
.
Put
(
"error"
,
err
)
return
multistep
.
ActionHalt
}
diskName
,
ok
:=
vmxData
[
"scsi0:0.filename"
]
if
!
ok
{
err
:=
fmt
.
Errorf
(
"Root disk filename could not be found!"
)
state
.
Put
(
"error"
,
err
)
return
multistep
.
ActionHalt
}
state
.
Put
(
"full_disk_path"
,
filepath
.
Join
(
s
.
OutputDir
,
diskName
))
state
.
Put
(
"vmx_path"
,
vmxPath
)
return
multistep
.
ActionContinue
}
...
...
builder/vmware/vmx/step_clone_vmx_test.go
View file @
9362cb53
package
vmx
import
(
"io/ioutil"
"os"
"path/filepath"
"testing"
"github.com/mitchellh/multistep"
...
...
@@ -12,10 +15,29 @@ func TestStepCloneVMX_impl(t *testing.T) {
}
func
TestStepCloneVMX
(
t
*
testing
.
T
)
{
// Setup some state
td
,
err
:=
ioutil
.
TempDir
(
""
,
"packer"
)
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
defer
os
.
RemoveAll
(
td
)
// Create the source
sourcePath
:=
filepath
.
Join
(
td
,
"source.vmx"
)
if
err
:=
ioutil
.
WriteFile
(
sourcePath
,
[]
byte
(
testCloneVMX
),
0644
);
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
// Create the dest because the mock driver won't
destPath
:=
filepath
.
Join
(
td
,
"foo.vmx"
)
if
err
:=
ioutil
.
WriteFile
(
destPath
,
[]
byte
(
testCloneVMX
),
0644
);
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
state
:=
testState
(
t
)
step
:=
new
(
StepCloneVMX
)
step
.
OutputDir
=
"/foo"
step
.
Path
=
"/bar/bar.vmx"
step
.
OutputDir
=
td
step
.
Path
=
sourcePath
step
.
VMName
=
"foo"
driver
:=
state
.
Get
(
"driver"
)
.
(
*
vmwcommon
.
DriverMock
)
...
...
@@ -28,7 +50,25 @@ func TestStepCloneVMX(t *testing.T) {
t
.
Fatal
(
"should NOT have error"
)
}
// Test we cloned
if
!
driver
.
CloneCalled
{
t
.
Fatal
(
"clone should be called"
)
t
.
Fatal
(
"should call clone"
)
}
// Test that we have our paths
if
vmxPath
,
ok
:=
state
.
GetOk
(
"vmx_path"
);
!
ok
{
t
.
Fatal
(
"should set vmx_path"
)
}
else
if
vmxPath
!=
destPath
{
t
.
Fatalf
(
"bad: %#v"
,
vmxPath
)
}
if
diskPath
,
ok
:=
state
.
GetOk
(
"full_disk_path"
);
!
ok
{
t
.
Fatal
(
"should set full_disk_path"
)
}
else
if
diskPath
!=
filepath
.
Join
(
td
,
"foo"
)
{
t
.
Fatalf
(
"bad: %#v"
,
diskPath
)
}
}
const
testCloneVMX
=
`
scsi0:0.fileName = "foo"
`
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