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
0b61e506
Commit
0b61e506
authored
Nov 02, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer/rpc: implement new warnings interfaces
parent
336051e3
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
69 additions
and
28 deletions
+69
-28
packer/rpc/build.go
packer/rpc/build.go
+16
-6
packer/rpc/build_test.go
packer/rpc/build_test.go
+34
-13
packer/rpc/builder.go
packer/rpc/builder.go
+17
-7
packer/rpc/builder_test.go
packer/rpc/builder_test.go
+2
-2
No files found.
packer/rpc/build.go
View file @
0b61e506
...
...
@@ -21,6 +21,11 @@ type BuildRunArgs struct {
UiRPCAddress
string
}
type
BuildPrepareResponse
struct
{
Warnings
[]
string
Error
error
}
func
Build
(
client
*
rpc
.
Client
)
*
build
{
return
&
build
{
client
}
}
...
...
@@ -30,12 +35,13 @@ func (b *build) Name() (result string) {
return
}
func
(
b
*
build
)
Prepare
(
v
map
[
string
]
string
)
(
err
error
)
{
if
cerr
:=
b
.
client
.
Call
(
"Build.Prepare"
,
v
,
&
err
);
cerr
!=
nil
{
return
cerr
func
(
b
*
build
)
Prepare
(
v
map
[
string
]
string
)
([]
string
,
error
)
{
var
resp
BuildPrepareResponse
if
cerr
:=
b
.
client
.
Call
(
"Build.Prepare"
,
v
,
&
resp
);
cerr
!=
nil
{
return
nil
,
cerr
}
return
return
resp
.
Warnings
,
resp
.
Error
}
func
(
b
*
build
)
Run
(
ui
packer
.
Ui
,
cache
packer
.
Cache
)
([]
packer
.
Artifact
,
error
)
{
...
...
@@ -86,8 +92,12 @@ func (b *BuildServer) Name(args *interface{}, reply *string) error {
return
nil
}
func
(
b
*
BuildServer
)
Prepare
(
v
map
[
string
]
string
,
reply
*
error
)
error
{
*
reply
=
b
.
build
.
Prepare
(
v
)
func
(
b
*
BuildServer
)
Prepare
(
v
map
[
string
]
string
,
resp
*
BuildPrepareResponse
)
error
{
warnings
,
err
:=
b
.
build
.
Prepare
(
v
)
*
resp
=
BuildPrepareResponse
{
Warnings
:
warnings
,
Error
:
err
,
}
return
nil
}
...
...
packer/rpc/build_test.go
View file @
0b61e506
...
...
@@ -4,21 +4,23 @@ import (
"errors"
"github.com/mitchellh/packer/packer"
"net/rpc"
"reflect"
"testing"
)
var
testBuildArtifact
=
&
testArtifact
{}
type
testBuild
struct
{
nameCalled
bool
prepareCalled
bool
prepareVars
map
[
string
]
string
runCalled
bool
runCache
packer
.
Cache
runUi
packer
.
Ui
setDebugCalled
bool
setForceCalled
bool
cancelCalled
bool
nameCalled
bool
prepareCalled
bool
prepareVars
map
[
string
]
string
prepareWarnings
[]
string
runCalled
bool
runCache
packer
.
Cache
runUi
packer
.
Ui
setDebugCalled
bool
setForceCalled
bool
cancelCalled
bool
errRunResult
bool
}
...
...
@@ -28,10 +30,10 @@ func (b *testBuild) Name() string {
return
"name"
}
func
(
b
*
testBuild
)
Prepare
(
v
map
[
string
]
string
)
error
{
func
(
b
*
testBuild
)
Prepare
(
v
map
[
string
]
string
)
([]
string
,
error
)
{
b
.
prepareCalled
=
true
b
.
prepareVars
=
v
return
nil
return
b
.
prepareWarnings
,
nil
}
func
(
b
*
testBuild
)
Run
(
ui
packer
.
Ui
,
cache
packer
.
Cache
)
([]
packer
.
Artifact
,
error
)
{
...
...
@@ -58,7 +60,7 @@ func (b *testBuild) Cancel() {
b
.
cancelCalled
=
true
}
func
TestBuildRPC
(
t
*
testing
.
T
)
{
func
buildRPCClient
(
t
*
testing
.
T
)
(
*
testBuild
,
packer
.
Build
)
{
// Create the interface to test
b
:=
new
(
testBuild
)
...
...
@@ -72,7 +74,11 @@ func TestBuildRPC(t *testing.T) {
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
bClient
:=
Build
(
client
)
return
b
,
Build
(
client
)
}
func
TestBuild
(
t
*
testing
.
T
)
{
b
,
bClient
:=
buildRPCClient
(
t
)
// Test Name
bClient
.
Name
()
...
...
@@ -157,6 +163,21 @@ func TestBuildRPC(t *testing.T) {
}
}
func
TestBuildPrepare_Warnings
(
t
*
testing
.
T
)
{
b
,
bClient
:=
buildRPCClient
(
t
)
expected
:=
[]
string
{
"foo"
}
b
.
prepareWarnings
=
expected
warnings
,
err
:=
bClient
.
Prepare
(
nil
)
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
if
!
reflect
.
DeepEqual
(
warnings
,
expected
)
{
t
.
Fatalf
(
"bad: %#v"
,
warnings
)
}
}
func
TestBuild_ImplementsBuild
(
t
*
testing
.
T
)
{
var
_
packer
.
Build
=
Build
(
nil
)
}
packer/rpc/builder.go
View file @
0b61e506
...
...
@@ -29,6 +29,11 @@ type BuilderRunArgs struct {
ResponseAddress
string
}
type
BuilderPrepareResponse
struct
{
Warnings
[]
string
Error
error
}
type
BuilderRunResponse
struct
{
Err
error
RPCAddress
string
...
...
@@ -38,13 +43,14 @@ func Builder(client *rpc.Client) *builder {
return
&
builder
{
client
}
}
func
(
b
*
builder
)
Prepare
(
config
...
interface
{})
(
err
error
)
{
cerr
:=
b
.
client
.
Call
(
"Builder.Prepare"
,
&
BuilderPrepareArgs
{
config
},
&
err
)
func
(
b
*
builder
)
Prepare
(
config
...
interface
{})
([]
string
,
error
)
{
var
resp
BuilderPrepareResponse
cerr
:=
b
.
client
.
Call
(
"Builder.Prepare"
,
&
BuilderPrepareArgs
{
config
},
&
resp
)
if
cerr
!=
nil
{
err
=
cerr
return
nil
,
cerr
}
return
return
resp
.
Warnings
,
resp
.
Error
}
func
(
b
*
builder
)
Run
(
ui
packer
.
Ui
,
hook
packer
.
Hook
,
cache
packer
.
Cache
)
(
packer
.
Artifact
,
error
)
{
...
...
@@ -108,12 +114,16 @@ func (b *builder) Cancel() {
}
}
func
(
b
*
BuilderServer
)
Prepare
(
args
*
BuilderPrepareArgs
,
reply
*
error
)
error
{
err
:=
b
.
builder
.
Prepare
(
args
.
Configs
...
)
func
(
b
*
BuilderServer
)
Prepare
(
args
*
BuilderPrepareArgs
,
reply
*
BuilderPrepareResponse
)
error
{
warnings
,
err
:=
b
.
builder
.
Prepare
(
args
.
Configs
...
)
if
err
!=
nil
{
*
reply
=
NewBasicError
(
err
)
err
=
NewBasicError
(
err
)
}
*
reply
=
BuilderPrepareResponse
{
Warnings
:
warnings
,
Error
:
err
,
}
return
nil
}
...
...
packer/rpc/builder_test.go
View file @
0b61e506
...
...
@@ -23,10 +23,10 @@ type testBuilder struct {
nilRunResult
bool
}
func
(
b
*
testBuilder
)
Prepare
(
config
...
interface
{})
error
{
func
(
b
*
testBuilder
)
Prepare
(
config
...
interface
{})
([]
string
,
error
)
{
b
.
prepareCalled
=
true
b
.
prepareConfig
=
config
return
nil
return
nil
,
nil
}
func
(
b
*
testBuilder
)
Run
(
ui
packer
.
Ui
,
hook
packer
.
Hook
,
cache
packer
.
Cache
)
(
packer
.
Artifact
,
error
)
{
...
...
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