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
03321c7c
Commit
03321c7c
authored
Nov 02, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
command/fix: add fixer to auto set guest_additions_mode
parent
aee93096
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
151 additions
and
2 deletions
+151
-2
command/fix/command.go
command/fix/command.go
+1
-0
command/fix/fixer.go
command/fix/fixer.go
+3
-2
command/fix/fixer_virtualbox_gaattach.go
command/fix/fixer_virtualbox_gaattach.go
+59
-0
command/fix/fixer_virtualbox_gaattach_test.go
command/fix/fixer_virtualbox_gaattach_test.go
+88
-0
No files found.
command/fix/command.go
View file @
03321c7c
...
@@ -53,6 +53,7 @@ func (c Command) Run(env packer.Environment, args []string) int {
...
@@ -53,6 +53,7 @@ func (c Command) Run(env packer.Environment, args []string) int {
fixers
:=
[]
string
{
fixers
:=
[]
string
{
"iso-md5"
,
"iso-md5"
,
"createtime"
,
"createtime"
,
"virtualbox-gaattach"
,
}
}
input
:=
templateData
input
:=
templateData
...
...
command/fix/fixer.go
View file @
03321c7c
...
@@ -13,7 +13,8 @@ var Fixers map[string]Fixer
...
@@ -13,7 +13,8 @@ var Fixers map[string]Fixer
func
init
()
{
func
init
()
{
Fixers
=
map
[
string
]
Fixer
{
Fixers
=
map
[
string
]
Fixer
{
"iso-md5"
:
new
(
FixerISOMD5
),
"iso-md5"
:
new
(
FixerISOMD5
),
"createtime"
:
new
(
FixerCreateTime
),
"createtime"
:
new
(
FixerCreateTime
),
"virtualbox-gaattach"
:
new
(
FixerVirtualBoxGAAttach
),
}
}
}
}
command/fix/fixer_virtualbox_gaattach.go
0 → 100644
View file @
03321c7c
package
fix
import
(
"github.com/mitchellh/mapstructure"
)
// FixerVirtualBoxGAAttach changes the "guest_additions_attach" of a template
// to "guest_additions_mode".
type
FixerVirtualBoxGAAttach
struct
{}
func
(
FixerVirtualBoxGAAttach
)
Fix
(
input
map
[
string
]
interface
{})
(
map
[
string
]
interface
{},
error
)
{
// The type we'll decode into; we only care about builders
type
template
struct
{
Builders
[]
map
[
string
]
interface
{}
}
// Decode the input into our structure, if we can
var
tpl
template
if
err
:=
mapstructure
.
Decode
(
input
,
&
tpl
);
err
!=
nil
{
return
nil
,
err
}
for
_
,
builder
:=
range
tpl
.
Builders
{
builderTypeRaw
,
ok
:=
builder
[
"type"
]
if
!
ok
{
continue
}
builderType
,
ok
:=
builderTypeRaw
.
(
string
)
if
!
ok
{
continue
}
if
builderType
!=
"virtualbox"
{
continue
}
gaAttachRaw
,
ok
:=
builder
[
"guest_additions_attach"
]
if
!
ok
{
continue
}
gaAttach
,
ok
:=
gaAttachRaw
.
(
bool
)
if
!
ok
{
continue
}
gaMode
:=
"upload"
if
gaAttach
{
gaMode
=
"attach"
}
delete
(
builder
,
"guest_additions_attach"
)
builder
[
"guest_additions_mode"
]
=
gaMode
}
input
[
"builders"
]
=
tpl
.
Builders
return
input
,
nil
}
command/fix/fixer_virtualbox_gaattach_test.go
0 → 100644
View file @
03321c7c
package
fix
import
(
"reflect"
"testing"
)
func
TestFixerVirtualBoxGAAttach_Impl
(
t
*
testing
.
T
)
{
var
_
Fixer
=
new
(
FixerVirtualBoxGAAttach
)
}
func
TestFixerVirtualBoxGAAttach_Fix
(
t
*
testing
.
T
)
{
cases
:=
[]
struct
{
Input
map
[
string
]
interface
{}
Expected
map
[
string
]
interface
{}
}{
// No attach field
{
Input
:
map
[
string
]
interface
{}{
"type"
:
"virtualbox"
,
},
Expected
:
map
[
string
]
interface
{}{
"type"
:
"virtualbox"
,
},
},
// Attach field == false
{
Input
:
map
[
string
]
interface
{}{
"type"
:
"virtualbox"
,
"guest_additions_attach"
:
false
,
},
Expected
:
map
[
string
]
interface
{}{
"type"
:
"virtualbox"
,
"guest_additions_mode"
:
"upload"
,
},
},
// Attach field == true
{
Input
:
map
[
string
]
interface
{}{
"type"
:
"virtualbox"
,
"guest_additions_attach"
:
true
,
},
Expected
:
map
[
string
]
interface
{}{
"type"
:
"virtualbox"
,
"guest_additions_mode"
:
"attach"
,
},
},
// Attach field is not a bool
{
Input
:
map
[
string
]
interface
{}{
"type"
:
"virtualbox"
,
"guest_additions_attach"
:
"what"
,
},
Expected
:
map
[
string
]
interface
{}{
"type"
:
"virtualbox"
,
"guest_additions_attach"
:
"what"
,
},
},
}
for
_
,
tc
:=
range
cases
{
var
f
FixerVirtualBoxGAAttach
input
:=
map
[
string
]
interface
{}{
"builders"
:
[]
map
[
string
]
interface
{}{
tc
.
Input
},
}
expected
:=
map
[
string
]
interface
{}{
"builders"
:
[]
map
[
string
]
interface
{}{
tc
.
Expected
},
}
output
,
err
:=
f
.
Fix
(
input
)
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
if
!
reflect
.
DeepEqual
(
output
,
expected
)
{
t
.
Fatalf
(
"unexpected: %#v
\n
expected: %#v
\n
"
,
output
,
expected
)
}
}
}
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