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
e44aea49
Commit
e44aea49
authored
Nov 05, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/qemu: passing tests
parent
2e438b7e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
173 additions
and
47 deletions
+173
-47
builder/qemu/builder.go
builder/qemu/builder.go
+5
-5
builder/qemu/builder_test.go
builder/qemu/builder_test.go
+168
-42
No files found.
builder/qemu/builder.go
View file @
e44aea49
...
...
@@ -92,15 +92,15 @@ type config struct {
tpl
*
packer
.
ConfigTemplate
}
func
(
b
*
Builder
)
Prepare
(
raws
...
interface
{})
error
{
func
(
b
*
Builder
)
Prepare
(
raws
...
interface
{})
([]
string
,
error
)
{
md
,
err
:=
common
.
DecodeConfig
(
&
b
.
config
,
raws
...
)
if
err
!=
nil
{
return
err
return
nil
,
err
}
b
.
config
.
tpl
,
err
=
packer
.
NewConfigTemplate
()
if
err
!=
nil
{
return
err
return
nil
,
err
}
b
.
config
.
tpl
.
UserVars
=
b
.
config
.
PackerUserVars
...
...
@@ -361,10 +361,10 @@ func (b *Builder) Prepare(raws ...interface{}) error {
}
if
errs
!=
nil
&&
len
(
errs
.
Errors
)
>
0
{
return
errs
return
nil
,
errs
}
return
nil
return
nil
,
nil
}
func
(
b
*
Builder
)
Run
(
ui
packer
.
Ui
,
hook
packer
.
Hook
,
cache
packer
.
Cache
)
(
packer
.
Artifact
,
error
)
{
...
...
builder/qemu/builder_test.go
View file @
e44aea49
...
...
@@ -59,7 +59,10 @@ func TestBuilder_ImplementsBuilder(t *testing.T) {
func
TestBuilderPrepare_Defaults
(
t
*
testing
.
T
)
{
var
b
Builder
config
:=
testConfig
()
err
:=
b
.
Prepare
(
config
)
warns
,
err
:=
b
.
Prepare
(
config
)
if
len
(
warns
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
warns
)
}
if
err
!=
nil
{
t
.
Fatalf
(
"should not have error: %s"
,
err
)
}
...
...
@@ -95,7 +98,10 @@ func TestBuilderPrepare_BootWait(t *testing.T) {
// Test a default boot_wait
delete
(
config
,
"boot_wait"
)
err
:=
b
.
Prepare
(
config
)
warns
,
err
:=
b
.
Prepare
(
config
)
if
len
(
warns
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
warns
)
}
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
...
...
@@ -106,7 +112,10 @@ func TestBuilderPrepare_BootWait(t *testing.T) {
// Test with a bad boot_wait
config
[
"boot_wait"
]
=
"this is not good"
err
=
b
.
Prepare
(
config
)
warns
,
err
=
b
.
Prepare
(
config
)
if
len
(
warns
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
warns
)
}
if
err
==
nil
{
t
.
Fatal
(
"should have error"
)
}
...
...
@@ -114,7 +123,10 @@ func TestBuilderPrepare_BootWait(t *testing.T) {
// Test with a good one
config
[
"boot_wait"
]
=
"5s"
b
=
Builder
{}
err
=
b
.
Prepare
(
config
)
warns
,
err
=
b
.
Prepare
(
config
)
if
len
(
warns
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
warns
)
}
if
err
!=
nil
{
t
.
Fatalf
(
"should not have error: %s"
,
err
)
}
...
...
@@ -125,7 +137,10 @@ func TestBuilderPrepare_DiskSize(t *testing.T) {
config
:=
testConfig
()
delete
(
config
,
"disk_size"
)
err
:=
b
.
Prepare
(
config
)
warns
,
err
:=
b
.
Prepare
(
config
)
if
len
(
warns
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
warns
)
}
if
err
!=
nil
{
t
.
Fatalf
(
"bad err: %s"
,
err
)
}
...
...
@@ -136,7 +151,10 @@ func TestBuilderPrepare_DiskSize(t *testing.T) {
config
[
"disk_size"
]
=
60000
b
=
Builder
{}
err
=
b
.
Prepare
(
config
)
warns
,
err
=
b
.
Prepare
(
config
)
if
len
(
warns
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
warns
)
}
if
err
!=
nil
{
t
.
Fatalf
(
"should not have error: %s"
,
err
)
}
...
...
@@ -151,7 +169,10 @@ func TestBuilderPrepare_FloppyFiles(t *testing.T) {
config
:=
testConfig
()
delete
(
config
,
"floppy_files"
)
err
:=
b
.
Prepare
(
config
)
warns
,
err
:=
b
.
Prepare
(
config
)
if
len
(
warns
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
warns
)
}
if
err
!=
nil
{
t
.
Fatalf
(
"bad err: %s"
,
err
)
}
...
...
@@ -162,7 +183,10 @@ func TestBuilderPrepare_FloppyFiles(t *testing.T) {
config
[
"floppy_files"
]
=
[]
string
{
"foo"
,
"bar"
}
b
=
Builder
{}
err
=
b
.
Prepare
(
config
)
warns
,
err
=
b
.
Prepare
(
config
)
if
len
(
warns
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
warns
)
}
if
err
!=
nil
{
t
.
Fatalf
(
"should not have error: %s"
,
err
)
}
...
...
@@ -180,7 +204,10 @@ func TestBuilderPrepare_HTTPPort(t *testing.T) {
// Bad
config
[
"http_port_min"
]
=
1000
config
[
"http_port_max"
]
=
500
err
:=
b
.
Prepare
(
config
)
warns
,
err
:=
b
.
Prepare
(
config
)
if
len
(
warns
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
warns
)
}
if
err
==
nil
{
t
.
Fatal
(
"should have error"
)
}
...
...
@@ -188,7 +215,10 @@ func TestBuilderPrepare_HTTPPort(t *testing.T) {
// Bad
config
[
"http_port_min"
]
=
-
500
b
=
Builder
{}
err
=
b
.
Prepare
(
config
)
warns
,
err
=
b
.
Prepare
(
config
)
if
len
(
warns
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
warns
)
}
if
err
==
nil
{
t
.
Fatal
(
"should have error"
)
}
...
...
@@ -197,7 +227,10 @@ func TestBuilderPrepare_HTTPPort(t *testing.T) {
config
[
"http_port_min"
]
=
500
config
[
"http_port_max"
]
=
1000
b
=
Builder
{}
err
=
b
.
Prepare
(
config
)
warns
,
err
=
b
.
Prepare
(
config
)
if
len
(
warns
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
warns
)
}
if
err
!=
nil
{
t
.
Fatalf
(
"should not have error: %s"
,
err
)
}
...
...
@@ -209,7 +242,10 @@ func TestBuilderPrepare_Format(t *testing.T) {
// Bad
config
[
"format"
]
=
"illegal value"
err
:=
b
.
Prepare
(
config
)
warns
,
err
:=
b
.
Prepare
(
config
)
if
len
(
warns
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
warns
)
}
if
err
==
nil
{
t
.
Fatal
(
"should have error"
)
}
...
...
@@ -217,7 +253,10 @@ func TestBuilderPrepare_Format(t *testing.T) {
// Good
config
[
"format"
]
=
"qcow2"
b
=
Builder
{}
err
=
b
.
Prepare
(
config
)
warns
,
err
=
b
.
Prepare
(
config
)
if
len
(
warns
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
warns
)
}
if
err
!=
nil
{
t
.
Fatalf
(
"should not have error: %s"
,
err
)
}
...
...
@@ -225,7 +264,10 @@ func TestBuilderPrepare_Format(t *testing.T) {
// Good
config
[
"format"
]
=
"raw"
b
=
Builder
{}
err
=
b
.
Prepare
(
config
)
warns
,
err
=
b
.
Prepare
(
config
)
if
len
(
warns
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
warns
)
}
if
err
!=
nil
{
t
.
Fatalf
(
"should not have error: %s"
,
err
)
}
...
...
@@ -237,7 +279,10 @@ func TestBuilderPrepare_InvalidKey(t *testing.T) {
// Add a random key
config
[
"i_should_not_be_valid"
]
=
true
err
:=
b
.
Prepare
(
config
)
warns
,
err
:=
b
.
Prepare
(
config
)
if
len
(
warns
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
warns
)
}
if
err
==
nil
{
t
.
Fatal
(
"should have error"
)
}
...
...
@@ -249,7 +294,10 @@ func TestBuilderPrepare_ISOChecksum(t *testing.T) {
// Test bad
config
[
"iso_checksum"
]
=
""
err
:=
b
.
Prepare
(
config
)
warns
,
err
:=
b
.
Prepare
(
config
)
if
len
(
warns
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
warns
)
}
if
err
==
nil
{
t
.
Fatal
(
"should have error"
)
}
...
...
@@ -257,7 +305,10 @@ func TestBuilderPrepare_ISOChecksum(t *testing.T) {
// Test good
config
[
"iso_checksum"
]
=
"FOo"
b
=
Builder
{}
err
=
b
.
Prepare
(
config
)
warns
,
err
=
b
.
Prepare
(
config
)
if
len
(
warns
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
warns
)
}
if
err
!=
nil
{
t
.
Fatalf
(
"should not have error: %s"
,
err
)
}
...
...
@@ -273,7 +324,10 @@ func TestBuilderPrepare_ISOChecksumType(t *testing.T) {
// Test bad
config
[
"iso_checksum_type"
]
=
""
err
:=
b
.
Prepare
(
config
)
warns
,
err
:=
b
.
Prepare
(
config
)
if
len
(
warns
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
warns
)
}
if
err
==
nil
{
t
.
Fatal
(
"should have error"
)
}
...
...
@@ -281,7 +335,10 @@ func TestBuilderPrepare_ISOChecksumType(t *testing.T) {
// Test good
config
[
"iso_checksum_type"
]
=
"mD5"
b
=
Builder
{}
err
=
b
.
Prepare
(
config
)
warns
,
err
=
b
.
Prepare
(
config
)
if
len
(
warns
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
warns
)
}
if
err
!=
nil
{
t
.
Fatalf
(
"should not have error: %s"
,
err
)
}
...
...
@@ -293,7 +350,10 @@ func TestBuilderPrepare_ISOChecksumType(t *testing.T) {
// Test unknown
config
[
"iso_checksum_type"
]
=
"fake"
b
=
Builder
{}
err
=
b
.
Prepare
(
config
)
warns
,
err
=
b
.
Prepare
(
config
)
if
len
(
warns
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
warns
)
}
if
err
==
nil
{
t
.
Fatal
(
"should have error"
)
}
...
...
@@ -308,7 +368,10 @@ func TestBuilderPrepare_ISOUrl(t *testing.T) {
// Test both epty
config
[
"iso_url"
]
=
""
b
=
Builder
{}
err
:=
b
.
Prepare
(
config
)
warns
,
err
:=
b
.
Prepare
(
config
)
if
len
(
warns
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
warns
)
}
if
err
==
nil
{
t
.
Fatal
(
"should have error"
)
}
...
...
@@ -316,7 +379,10 @@ func TestBuilderPrepare_ISOUrl(t *testing.T) {
// Test iso_url set
config
[
"iso_url"
]
=
"http://www.packer.io"
b
=
Builder
{}
err
=
b
.
Prepare
(
config
)
warns
,
err
=
b
.
Prepare
(
config
)
if
len
(
warns
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
warns
)
}
if
err
!=
nil
{
t
.
Errorf
(
"should not have error: %s"
,
err
)
}
...
...
@@ -330,7 +396,10 @@ func TestBuilderPrepare_ISOUrl(t *testing.T) {
config
[
"iso_url"
]
=
"http://www.packer.io"
config
[
"iso_urls"
]
=
[]
string
{
"http://www.packer.io"
}
b
=
Builder
{}
err
=
b
.
Prepare
(
config
)
warns
,
err
=
b
.
Prepare
(
config
)
if
len
(
warns
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
warns
)
}
if
err
==
nil
{
t
.
Fatal
(
"should have error"
)
}
...
...
@@ -343,7 +412,10 @@ func TestBuilderPrepare_ISOUrl(t *testing.T) {
}
b
=
Builder
{}
err
=
b
.
Prepare
(
config
)
warns
,
err
=
b
.
Prepare
(
config
)
if
len
(
warns
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
warns
)
}
if
err
!=
nil
{
t
.
Errorf
(
"should not have error: %s"
,
err
)
}
...
...
@@ -370,7 +442,10 @@ func TestBuilderPrepare_OutputDir(t *testing.T) {
config
[
"output_directory"
]
=
dir
b
=
Builder
{}
err
=
b
.
Prepare
(
config
)
warns
,
err
:=
b
.
Prepare
(
config
)
if
len
(
warns
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
warns
)
}
if
err
==
nil
{
t
.
Fatal
(
"should have error"
)
}
...
...
@@ -378,7 +453,10 @@ func TestBuilderPrepare_OutputDir(t *testing.T) {
// Test with a good one
config
[
"output_directory"
]
=
"i-hope-i-dont-exist"
b
=
Builder
{}
err
=
b
.
Prepare
(
config
)
warns
,
err
=
b
.
Prepare
(
config
)
if
len
(
warns
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
warns
)
}
if
err
!=
nil
{
t
.
Fatalf
(
"should not have error: %s"
,
err
)
}
...
...
@@ -390,7 +468,10 @@ func TestBuilderPrepare_ShutdownTimeout(t *testing.T) {
// Test with a bad value
config
[
"shutdown_timeout"
]
=
"this is not good"
err
:=
b
.
Prepare
(
config
)
warns
,
err
:=
b
.
Prepare
(
config
)
if
len
(
warns
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
warns
)
}
if
err
==
nil
{
t
.
Fatal
(
"should have error"
)
}
...
...
@@ -398,7 +479,10 @@ func TestBuilderPrepare_ShutdownTimeout(t *testing.T) {
// Test with a good one
config
[
"shutdown_timeout"
]
=
"5s"
b
=
Builder
{}
err
=
b
.
Prepare
(
config
)
warns
,
err
=
b
.
Prepare
(
config
)
if
len
(
warns
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
warns
)
}
if
err
!=
nil
{
t
.
Fatalf
(
"should not have error: %s"
,
err
)
}
...
...
@@ -412,7 +496,10 @@ func TestBuilderPrepare_SSHHostPort(t *testing.T) {
config
[
"ssh_host_port_min"
]
=
1000
config
[
"ssh_host_port_max"
]
=
500
b
=
Builder
{}
err
:=
b
.
Prepare
(
config
)
warns
,
err
:=
b
.
Prepare
(
config
)
if
len
(
warns
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
warns
)
}
if
err
==
nil
{
t
.
Fatal
(
"should have error"
)
}
...
...
@@ -420,7 +507,10 @@ func TestBuilderPrepare_SSHHostPort(t *testing.T) {
// Bad
config
[
"ssh_host_port_min"
]
=
-
500
b
=
Builder
{}
err
=
b
.
Prepare
(
config
)
warns
,
err
=
b
.
Prepare
(
config
)
if
len
(
warns
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
warns
)
}
if
err
==
nil
{
t
.
Fatal
(
"should have error"
)
}
...
...
@@ -429,7 +519,10 @@ func TestBuilderPrepare_SSHHostPort(t *testing.T) {
config
[
"ssh_host_port_min"
]
=
500
config
[
"ssh_host_port_max"
]
=
1000
b
=
Builder
{}
err
=
b
.
Prepare
(
config
)
warns
,
err
=
b
.
Prepare
(
config
)
if
len
(
warns
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
warns
)
}
if
err
!=
nil
{
t
.
Fatalf
(
"should not have error: %s"
,
err
)
}
...
...
@@ -441,14 +534,20 @@ func TestBuilderPrepare_sshKeyPath(t *testing.T) {
config
[
"ssh_key_path"
]
=
""
b
=
Builder
{}
err
:=
b
.
Prepare
(
config
)
warns
,
err
:=
b
.
Prepare
(
config
)
if
len
(
warns
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
warns
)
}
if
err
!=
nil
{
t
.
Fatalf
(
"should not have error: %s"
,
err
)
}
config
[
"ssh_key_path"
]
=
"/i/dont/exist"
b
=
Builder
{}
err
=
b
.
Prepare
(
config
)
warns
,
err
=
b
.
Prepare
(
config
)
if
len
(
warns
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
warns
)
}
if
err
==
nil
{
t
.
Fatal
(
"should have error"
)
}
...
...
@@ -467,7 +566,10 @@ func TestBuilderPrepare_sshKeyPath(t *testing.T) {
config
[
"ssh_key_path"
]
=
tf
.
Name
()
b
=
Builder
{}
err
=
b
.
Prepare
(
config
)
warns
,
err
=
b
.
Prepare
(
config
)
if
len
(
warns
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
warns
)
}
if
err
==
nil
{
t
.
Fatal
(
"should have error"
)
}
...
...
@@ -478,7 +580,10 @@ func TestBuilderPrepare_sshKeyPath(t *testing.T) {
tf
.
Write
([]
byte
(
testPem
))
config
[
"ssh_key_path"
]
=
tf
.
Name
()
b
=
Builder
{}
err
=
b
.
Prepare
(
config
)
warns
,
err
=
b
.
Prepare
(
config
)
if
len
(
warns
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
warns
)
}
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
...
...
@@ -490,14 +595,20 @@ func TestBuilderPrepare_SSHUser(t *testing.T) {
config
[
"ssh_username"
]
=
""
b
=
Builder
{}
err
:=
b
.
Prepare
(
config
)
warns
,
err
:=
b
.
Prepare
(
config
)
if
len
(
warns
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
warns
)
}
if
err
==
nil
{
t
.
Fatal
(
"should have error"
)
}
config
[
"ssh_username"
]
=
"exists"
b
=
Builder
{}
err
=
b
.
Prepare
(
config
)
warns
,
err
=
b
.
Prepare
(
config
)
if
len
(
warns
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
warns
)
}
if
err
!=
nil
{
t
.
Fatalf
(
"should not have error: %s"
,
err
)
}
...
...
@@ -509,7 +620,10 @@ func TestBuilderPrepare_SSHWaitTimeout(t *testing.T) {
// Test a default boot_wait
delete
(
config
,
"ssh_wait_timeout"
)
err
:=
b
.
Prepare
(
config
)
warns
,
err
:=
b
.
Prepare
(
config
)
if
len
(
warns
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
warns
)
}
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
...
...
@@ -521,7 +635,10 @@ func TestBuilderPrepare_SSHWaitTimeout(t *testing.T) {
// Test with a bad value
config
[
"ssh_wait_timeout"
]
=
"this is not good"
b
=
Builder
{}
err
=
b
.
Prepare
(
config
)
warns
,
err
=
b
.
Prepare
(
config
)
if
len
(
warns
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
warns
)
}
if
err
==
nil
{
t
.
Fatal
(
"should have error"
)
}
...
...
@@ -529,7 +646,10 @@ func TestBuilderPrepare_SSHWaitTimeout(t *testing.T) {
// Test with a good one
config
[
"ssh_wait_timeout"
]
=
"5s"
b
=
Builder
{}
err
=
b
.
Prepare
(
config
)
warns
,
err
=
b
.
Prepare
(
config
)
if
len
(
warns
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
warns
)
}
if
err
!=
nil
{
t
.
Fatalf
(
"should not have error: %s"
,
err
)
}
...
...
@@ -541,7 +661,10 @@ func TestBuilderPrepare_QemuArgs(t *testing.T) {
// Test with empty
delete
(
config
,
"qemuargs"
)
err
:=
b
.
Prepare
(
config
)
warns
,
err
:=
b
.
Prepare
(
config
)
if
len
(
warns
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
warns
)
}
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
...
...
@@ -556,7 +679,10 @@ func TestBuilderPrepare_QemuArgs(t *testing.T) {
}
b
=
Builder
{}
err
=
b
.
Prepare
(
config
)
warns
,
err
=
b
.
Prepare
(
config
)
if
len
(
warns
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
warns
)
}
if
err
!=
nil
{
t
.
Fatalf
(
"should not have error: %s"
,
err
)
}
...
...
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