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
d823d255
Commit
d823d255
authored
Jun 18, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer/rpc: Support PostProcessor
parent
540fac64
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
184 additions
and
0 deletions
+184
-0
packer/rpc/post_processor.go
packer/rpc/post_processor.go
+91
-0
packer/rpc/post_processor_test.go
packer/rpc/post_processor_test.go
+87
-0
packer/rpc/server.go
packer/rpc/server.go
+6
-0
No files found.
packer/rpc/post_processor.go
0 → 100644
View file @
d823d255
package
rpc
import
(
"github.com/mitchellh/packer/packer"
"net/rpc"
)
// An implementation of packer.PostProcessor where the PostProcessor is actually
// executed over an RPC connection.
type
postProcessor
struct
{
client
*
rpc
.
Client
}
// PostProcessorServer wraps a packer.PostProcessor implementation and makes it
// exportable as part of a Golang RPC server.
type
PostProcessorServer
struct
{
p
packer
.
PostProcessor
}
type
PostProcessorProcessResponse
struct
{
Err
error
RPCAddress
string
}
func
PostProcessor
(
client
*
rpc
.
Client
)
*
postProcessor
{
return
&
postProcessor
{
client
}
}
func
(
p
*
postProcessor
)
Configure
(
raw
interface
{})
(
err
error
)
{
if
cerr
:=
p
.
client
.
Call
(
"PostProcessor.Configure"
,
&
raw
,
&
err
);
cerr
!=
nil
{
err
=
cerr
}
return
}
func
(
p
*
postProcessor
)
PostProcess
(
a
packer
.
Artifact
)
(
packer
.
Artifact
,
error
)
{
server
:=
rpc
.
NewServer
()
RegisterArtifact
(
server
,
a
)
var
response
PostProcessorProcessResponse
if
err
:=
p
.
client
.
Call
(
"PostProcessor.PostProcess"
,
serveSingleConn
(
server
),
&
response
);
err
!=
nil
{
return
nil
,
err
}
if
response
.
Err
!=
nil
{
return
nil
,
response
.
Err
}
if
response
.
RPCAddress
==
""
{
return
nil
,
nil
}
client
,
err
:=
rpc
.
Dial
(
"tcp"
,
response
.
RPCAddress
)
if
err
!=
nil
{
return
nil
,
err
}
return
Artifact
(
client
),
nil
}
func
(
p
*
PostProcessorServer
)
Configure
(
raw
*
interface
{},
reply
*
error
)
error
{
*
reply
=
p
.
p
.
Configure
(
*
raw
)
return
nil
}
func
(
p
*
PostProcessorServer
)
PostProcess
(
address
string
,
reply
*
PostProcessorProcessResponse
)
error
{
client
,
err
:=
rpc
.
Dial
(
"tcp"
,
address
)
if
err
!=
nil
{
return
err
}
responseAddress
:=
""
artifact
,
err
:=
p
.
p
.
PostProcess
(
Artifact
(
client
))
if
err
==
nil
&&
artifact
!=
nil
{
server
:=
rpc
.
NewServer
()
RegisterArtifact
(
server
,
artifact
)
responseAddress
=
serveSingleConn
(
server
)
}
if
err
!=
nil
{
err
=
NewBasicError
(
err
)
}
*
reply
=
PostProcessorProcessResponse
{
Err
:
err
,
RPCAddress
:
responseAddress
,
}
return
nil
}
packer/rpc/post_processor_test.go
0 → 100644
View file @
d823d255
package
rpc
import
(
"github.com/mitchellh/packer/packer"
"net/rpc"
"testing"
)
var
testPostProcessorArtifact
=
new
(
testArtifact
)
type
TestPostProcessor
struct
{
configCalled
bool
configVal
interface
{}
ppCalled
bool
ppArtifact
packer
.
Artifact
}
func
(
pp
*
TestPostProcessor
)
Configure
(
v
interface
{})
error
{
pp
.
configCalled
=
true
pp
.
configVal
=
v
return
nil
}
func
(
pp
*
TestPostProcessor
)
PostProcess
(
a
packer
.
Artifact
)
(
packer
.
Artifact
,
error
)
{
pp
.
ppCalled
=
true
pp
.
ppArtifact
=
a
return
testPostProcessorArtifact
,
nil
}
func
TestPostProcessorRPC
(
t
*
testing
.
T
)
{
// Create the interface to test
p
:=
new
(
TestPostProcessor
)
// Start the server
server
:=
rpc
.
NewServer
()
RegisterPostProcessor
(
server
,
p
)
address
:=
serveSingleConn
(
server
)
// Create the client over RPC and run some methods to verify it works
client
,
err
:=
rpc
.
Dial
(
"tcp"
,
address
)
if
err
!=
nil
{
t
.
Fatalf
(
"Error connecting to rpc: %s"
,
err
)
}
// Test Configure
config
:=
42
pClient
:=
PostProcessor
(
client
)
err
=
pClient
.
Configure
(
config
)
if
err
!=
nil
{
t
.
Fatalf
(
"error: %s"
,
err
)
}
if
!
p
.
configCalled
{
t
.
Fatal
(
"config should be called"
)
}
if
p
.
configVal
!=
42
{
t
.
Fatalf
(
"unknown config value: %#v"
,
p
.
configVal
)
}
// Test PostProcess
a
:=
new
(
testArtifact
)
artifact
,
err
:=
pClient
.
PostProcess
(
a
)
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
if
!
p
.
ppCalled
{
t
.
Fatal
(
"postprocess should be called"
)
}
if
p
.
ppArtifact
.
BuilderId
()
!=
"bid"
{
t
.
Fatal
(
"unknown artifact"
)
}
if
artifact
.
BuilderId
()
!=
"bid"
{
t
.
Fatal
(
"unknown result artifact"
)
}
}
func
TestPostProcessor_Implements
(
t
*
testing
.
T
)
{
var
raw
interface
{}
raw
=
PostProcessor
(
nil
)
if
_
,
ok
:=
raw
.
(
packer
.
PostProcessor
);
!
ok
{
t
.
Fatal
(
"not a postprocessor"
)
}
}
packer/rpc/server.go
View file @
d823d255
...
...
@@ -53,6 +53,12 @@ func RegisterHook(s *rpc.Server, hook packer.Hook) {
s
.
RegisterName
(
"Hook"
,
&
HookServer
{
hook
})
}
// Registers the appropriate endpoing on an RPC server to serve a
// PostProcessor.
func
RegisterPostProcessor
(
s
*
rpc
.
Server
,
p
packer
.
PostProcessor
)
{
s
.
RegisterName
(
"PostProcessor"
,
&
PostProcessorServer
{
p
})
}
// Registers the appropriate endpoint on an RPC server to serve a packer.Provisioner
func
RegisterProvisioner
(
s
*
rpc
.
Server
,
p
packer
.
Provisioner
)
{
s
.
RegisterName
(
"Provisioner"
,
&
ProvisionerServer
{
p
})
...
...
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