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
378a7320
Commit
378a7320
authored
Jun 06, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/vmware: A lot more validation, testing
parent
057d656e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
7 deletions
+55
-7
builder/vmware/builder.go
builder/vmware/builder.go
+18
-7
builder/vmware/builder_test.go
builder/vmware/builder_test.go
+37
-0
No files found.
builder/vmware/builder.go
View file @
378a7320
package
vmware
import
(
"errors"
"fmt"
"github.com/mitchellh/mapstructure"
"github.com/mitchellh/multistep"
...
...
@@ -25,7 +26,7 @@ type config struct {
HTTPDir
string
`mapstructure:"http_directory"`
BootCommand
[]
string
`mapstructure:"boot_command"`
BootWait
time
.
Duration
SSHUser
string
`mapstructure:"ssh_user"`
SSHUser
string
`mapstructure:"ssh_user
name
"`
SSHPassword
string
`mapstructure:"ssh_password"`
SSHWaitTimeout
time
.
Duration
...
...
@@ -51,11 +52,21 @@ func (b *Builder) Prepare(raw interface{}) (err error) {
b
.
config
.
OutputDir
=
"vmware"
}
errors
:=
make
([]
error
,
0
)
// Accumulate any errors
errs
:=
make
([]
error
,
0
)
if
b
.
config
.
ISOUrl
==
""
{
errs
=
append
(
errs
,
errors
.
New
(
"An iso_url must be specified."
))
}
if
b
.
config
.
SSHUser
==
""
{
errs
=
append
(
errs
,
errors
.
New
(
"An ssh_username must be specified."
))
}
if
b
.
config
.
RawBootWait
!=
""
{
b
.
config
.
BootWait
,
err
=
time
.
ParseDuration
(
b
.
config
.
RawBootWait
)
if
err
!=
nil
{
err
ors
=
append
(
erro
rs
,
fmt
.
Errorf
(
"Failed parsing boot_wait: %s"
,
err
))
err
s
=
append
(
er
rs
,
fmt
.
Errorf
(
"Failed parsing boot_wait: %s"
,
err
))
}
}
...
...
@@ -65,16 +76,16 @@ func (b *Builder) Prepare(raw interface{}) (err error) {
b
.
config
.
SSHWaitTimeout
,
err
=
time
.
ParseDuration
(
b
.
config
.
RawSSHWaitTimeout
)
if
err
!=
nil
{
err
ors
=
append
(
erro
rs
,
fmt
.
Errorf
(
"Failed parsing ssh_wait_timeout: %s"
,
err
))
err
s
=
append
(
er
rs
,
fmt
.
Errorf
(
"Failed parsing ssh_wait_timeout: %s"
,
err
))
}
b
.
driver
,
err
=
b
.
newDriver
()
if
err
!=
nil
{
err
ors
=
append
(
erro
rs
,
fmt
.
Errorf
(
"Failed creating VMware driver: %s"
,
err
))
err
s
=
append
(
er
rs
,
fmt
.
Errorf
(
"Failed creating VMware driver: %s"
,
err
))
}
if
len
(
err
or
s
)
>
0
{
return
&
packer
.
MultiError
{
err
or
s
}
if
len
(
errs
)
>
0
{
return
&
packer
.
MultiError
{
errs
}
}
return
nil
...
...
builder/vmware/builder_test.go
View file @
378a7320
...
...
@@ -8,6 +8,8 @@ import (
func
testConfig
()
map
[
string
]
interface
{}
{
return
map
[
string
]
interface
{}{
"iso_url"
:
"foo"
,
"ssh_username"
:
"foo"
,
}
}
...
...
@@ -63,6 +65,41 @@ func TestBuilderPrepare_Defaults(t *testing.T) {
}
}
func
TestBuilderPrepare_ISOUrl
(
t
*
testing
.
T
)
{
var
b
Builder
config
:=
testConfig
()
// Test iso_url
config
[
"iso_url"
]
=
""
err
:=
b
.
Prepare
(
config
)
if
err
==
nil
{
t
.
Fatal
(
"should have error"
)
}
config
[
"iso_url"
]
=
"exists"
err
=
b
.
Prepare
(
config
)
if
err
!=
nil
{
t
.
Fatalf
(
"should not have error: %s"
,
err
)
}
}
func
TestBuilderPrepare_SSHUser
(
t
*
testing
.
T
)
{
var
b
Builder
config
:=
testConfig
()
config
[
"ssh_username"
]
=
""
err
:=
b
.
Prepare
(
config
)
if
err
==
nil
{
t
.
Fatal
(
"should have error"
)
}
config
[
"ssh_username"
]
=
"exists"
err
=
b
.
Prepare
(
config
)
if
err
!=
nil
{
t
.
Fatalf
(
"should not have error: %s"
,
err
)
}
}
func
TestBuilderPrepare_SSHWaitTimeout
(
t
*
testing
.
T
)
{
var
b
Builder
config
:=
testConfig
()
...
...
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