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
5aec3f67
Commit
5aec3f67
authored
May 04, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer/rpc: Remote environments
parent
255b9476
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
149 additions
and
19 deletions
+149
-19
packer/rpc/command_test.go
packer/rpc/command_test.go
+1
-17
packer/rpc/environment.go
packer/rpc/environment.go
+59
-2
packer/rpc/environment_test.go
packer/rpc/environment_test.go
+85
-0
packer/rpc/server.go
packer/rpc/server.go
+4
-0
No files found.
packer/rpc/command_test.go
View file @
5aec3f67
package
rpc
import
(
"bytes"
"cgl.tideland.biz/asserts"
"github.com/mitchellh/packer/packer"
"net"
...
...
@@ -26,21 +25,6 @@ func (tc *TestCommand) Synopsis() string {
return
"foo"
}
func
testEnvironment
()
packer
.
Environment
{
config
:=
&
packer
.
EnvironmentConfig
{}
config
.
Ui
=
&
packer
.
ReaderWriterUi
{
new
(
bytes
.
Buffer
),
new
(
bytes
.
Buffer
),
}
env
,
err
:=
packer
.
NewEnvironment
(
config
)
if
err
!=
nil
{
panic
(
err
)
}
return
env
}
// This starts a RPC server for the given command listening on the
// given address. The RPC server is ready when "readyChan" receives a message
// and the RPC server will quit when "stopChan" receives a message.
...
...
@@ -102,7 +86,7 @@ func TestRPCCommand(t *testing.T) {
clientComm
:=
&
ClientCommand
{
client
}
runArgs
:=
[]
string
{
"foo"
,
"bar"
}
testEnv
:=
testEnvironment
()
testEnv
:=
&
testEnvironment
{}
exitCode
:=
clientComm
.
Run
(
testEnv
,
runArgs
)
synopsis
:=
clientComm
.
Synopsis
()
...
...
packer/rpc/environment.go
View file @
5aec3f67
...
...
@@ -5,9 +5,9 @@ import (
"net/rpc"
)
// A Environment
Client
is an implementation of the packer.Environment interface
// A Environment is an implementation of the packer.Environment interface
// where the actual environment is executed over an RPC connection.
type
Environment
Client
struct
{
type
Environment
struct
{
client
*
rpc
.
Client
}
...
...
@@ -16,3 +16,60 @@ type EnvironmentClient struct {
type
EnvironmentServer
struct
{
env
packer
.
Environment
}
type
EnvironmentCliArgs
struct
{
Args
[]
string
}
func
(
e
*
Environment
)
BuilderFactory
()
packer
.
BuilderFactory
{
var
reply
string
e
.
client
.
Call
(
"Environment.BuilderFactory"
,
new
(
interface
{}),
&
reply
)
// TODO: error handling
client
,
_
:=
rpc
.
Dial
(
"tcp"
,
reply
)
return
&
BuilderFactory
{
client
}
}
func
(
e
*
Environment
)
Cli
(
args
[]
string
)
(
result
int
)
{
rpcArgs
:=
&
EnvironmentCliArgs
{
args
}
e
.
client
.
Call
(
"Environment.Cli"
,
rpcArgs
,
&
result
)
return
}
func
(
e
*
Environment
)
Ui
()
packer
.
Ui
{
var
reply
string
e
.
client
.
Call
(
"Environment.Ui"
,
new
(
interface
{}),
&
reply
)
// TODO: error handling
client
,
_
:=
rpc
.
Dial
(
"tcp"
,
reply
)
return
&
Ui
{
client
}
}
func
(
e
*
EnvironmentServer
)
BuilderFactory
(
args
*
interface
{},
reply
*
string
)
error
{
bf
:=
e
.
env
.
BuilderFactory
()
// Wrap that up into a server, and server a single connection back
server
:=
NewServer
()
server
.
RegisterBuilderFactory
(
bf
)
server
.
StartSingle
()
*
reply
=
server
.
Address
()
return
nil
}
func
(
e
*
EnvironmentServer
)
Cli
(
args
*
EnvironmentCliArgs
,
reply
*
int
)
error
{
*
reply
=
e
.
env
.
Cli
(
args
.
Args
)
return
nil
}
func
(
e
*
EnvironmentServer
)
Ui
(
args
*
interface
{},
reply
*
string
)
error
{
ui
:=
e
.
env
.
Ui
()
// Wrap it
server
:=
NewServer
()
server
.
RegisterUi
(
ui
)
server
.
StartSingle
()
*
reply
=
server
.
Address
()
return
nil
}
packer/rpc/environment_test.go
0 → 100644
View file @
5aec3f67
package
rpc
import
(
"cgl.tideland.biz/asserts"
"github.com/mitchellh/packer/packer"
"net/rpc"
"testing"
)
var
testEnvBF
=
&
testBuilderFactory
{}
var
testEnvUi
=
&
testUi
{}
type
testEnvironment
struct
{
bfCalled
bool
cliCalled
bool
cliArgs
[]
string
uiCalled
bool
}
func
(
e
*
testEnvironment
)
BuilderFactory
()
packer
.
BuilderFactory
{
e
.
bfCalled
=
true
return
testEnvBF
}
func
(
e
*
testEnvironment
)
Cli
(
args
[]
string
)
int
{
e
.
cliCalled
=
true
e
.
cliArgs
=
args
return
42
}
func
(
e
*
testEnvironment
)
Ui
()
packer
.
Ui
{
e
.
uiCalled
=
true
return
testEnvUi
}
func
TestEnvironmentRPC
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
// Create the interface to test
e
:=
&
testEnvironment
{}
// Start the server
server
:=
NewServer
()
server
.
RegisterEnvironment
(
e
)
server
.
Start
()
defer
server
.
Stop
()
// Create the client over RPC and run some methods to verify it works
client
,
err
:=
rpc
.
Dial
(
"tcp"
,
server
.
Address
())
assert
.
Nil
(
err
,
"should be able to connect"
)
// Test BuilderFactory
eClient
:=
&
Environment
{
client
}
bf
:=
eClient
.
BuilderFactory
()
assert
.
True
(
e
.
bfCalled
,
"BuilderFactory should be called"
)
// Test calls on the factory
_
=
bf
.
CreateBuilder
(
"foo"
)
assert
.
True
(
testEnvBF
.
createCalled
,
"create should be called on BF"
)
// Test Cli
cliArgs
:=
[]
string
{
"foo"
,
"bar"
}
result
:=
eClient
.
Cli
(
cliArgs
)
assert
.
True
(
e
.
cliCalled
,
"CLI should be called"
)
assert
.
Equal
(
e
.
cliArgs
,
cliArgs
,
"args should match"
)
assert
.
Equal
(
result
,
42
,
"result shuld be 42"
)
// Test Ui
ui
:=
eClient
.
Ui
()
assert
.
True
(
e
.
uiCalled
,
"Ui should've been called"
)
// Test calls on the Ui
ui
.
Say
(
"format"
)
assert
.
True
(
testEnvUi
.
sayCalled
,
"Say should be called"
)
assert
.
Equal
(
testEnvUi
.
sayFormat
,
"format"
,
"format should match"
)
}
func
TestEnvironment_ImplementsEnvironment
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
var
realVar
packer
.
Environment
e
:=
&
Environment
{
nil
}
assert
.
Implementor
(
e
,
&
realVar
,
"should be an Environment"
)
}
packer/rpc/server.go
View file @
5aec3f67
...
...
@@ -41,6 +41,10 @@ func (s *Server) RegisterBuilderFactory(b packer.BuilderFactory) {
s
.
server
.
RegisterName
(
"BuilderFactory"
,
&
BuilderFactoryServer
{
b
})
}
func
(
s
*
Server
)
RegisterEnvironment
(
e
packer
.
Environment
)
{
s
.
server
.
RegisterName
(
"Environment"
,
&
EnvironmentServer
{
e
})
}
func
(
s
*
Server
)
RegisterUi
(
ui
packer
.
Ui
)
{
s
.
server
.
RegisterName
(
"Ui"
,
&
UiServer
{
ui
})
}
...
...
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