right_agent 0.6.2 → 0.6.3
Sign up to get free protection for your applications and to get access to all the features.
@@ -22,10 +22,11 @@
|
|
22
22
|
|
23
23
|
module RightScale
|
24
24
|
|
25
|
-
# Run commands exposed by an agent
|
26
|
-
# External processes can send commands through a socket with the specified port
|
25
|
+
# Run commands exposed by an agent.
|
26
|
+
# External processes can send commands through a socket with the specified port.
|
27
|
+
# Command runner accepts connections and deserializes commands using YAML.
|
28
|
+
# Each command is expected to be a hash containing the :name and :options keys.
|
27
29
|
class CommandRunner
|
28
|
-
|
29
30
|
class << self
|
30
31
|
# (Integer) Port command runner is listening on
|
31
32
|
attr_reader :listen_port
|
@@ -34,8 +35,7 @@ module RightScale
|
|
34
35
|
attr_reader :cookie
|
35
36
|
end
|
36
37
|
|
37
|
-
#
|
38
|
-
# Each command is expected to be a hash containing the :name and :options keys
|
38
|
+
# Start a command runner listening on a local TCP port.
|
39
39
|
#
|
40
40
|
# === Parameters
|
41
41
|
# socket_port(Integer):: Base socket port on which to listen for connection,
|
@@ -43,6 +43,11 @@ module RightScale
|
|
43
43
|
# identity(String):: Agent identity
|
44
44
|
# commands(Hash):: Commands exposed by agent
|
45
45
|
#
|
46
|
+
# === Block
|
47
|
+
# If a block is provided, this method will yield after all setup has been completed,
|
48
|
+
# passing its PidFile to the block. This provides a customization hook, e.g. for
|
49
|
+
# changing the pid file's access mode or ownership.
|
50
|
+
#
|
46
51
|
# === Return
|
47
52
|
# cmd_options[:cookie](String):: Command protocol cookie
|
48
53
|
# cmd_options[:listen_port](Integer):: Command server listen port
|
@@ -52,6 +57,7 @@ module RightScale
|
|
52
57
|
def self.start(socket_port, identity, commands)
|
53
58
|
cmd_options = nil
|
54
59
|
@listen_port = socket_port
|
60
|
+
|
55
61
|
begin
|
56
62
|
CommandIO.instance.listen(socket_port) do |c, conn|
|
57
63
|
begin
|
@@ -77,6 +83,7 @@ module RightScale
|
|
77
83
|
pid_file = PidFile.new(identity)
|
78
84
|
if pid_file.exists?
|
79
85
|
pid_file.set_command_options(cmd_options)
|
86
|
+
yield(pid_file) if block_given?
|
80
87
|
else
|
81
88
|
Log.warning("Failed to update listen port in PID file - no pid file found for agent with identity #{identity}")
|
82
89
|
end
|
@@ -29,18 +29,18 @@ module RightScale
|
|
29
29
|
include Serializable
|
30
30
|
|
31
31
|
attr_accessor :uuid, :username, :public_key, :public_keys, :common_name,
|
32
|
-
:superuser, :expires_at, :
|
32
|
+
:superuser, :expires_at, :profile_data
|
33
33
|
|
34
34
|
# Initialize fields from given arguments
|
35
35
|
def initialize(*args)
|
36
|
-
@uuid
|
37
|
-
@username
|
38
|
-
@public_key
|
39
|
-
@common_name
|
40
|
-
@superuser
|
41
|
-
@expires_at
|
42
|
-
@public_keys
|
43
|
-
@
|
36
|
+
@uuid = args[0]
|
37
|
+
@username = args[1]
|
38
|
+
@public_key = args[2]
|
39
|
+
@common_name = args[3] || ''
|
40
|
+
@superuser = args[4] || false
|
41
|
+
@expires_at = Time.at(args[5]) if args[5] && (args[5] != 0) # nil -> 0 because of expires_at.to_i below
|
42
|
+
@public_keys = args[6]
|
43
|
+
@profile_data = args[7]
|
44
44
|
|
45
45
|
# we now expect an array of public_keys to be passed while supporting the
|
46
46
|
# singular public_key as a legacy member. when serialized back from a
|
@@ -57,7 +57,7 @@ module RightScale
|
|
57
57
|
|
58
58
|
# Array of serialized fields given to constructor
|
59
59
|
def serialized_members
|
60
|
-
[ @uuid, @username, @public_key, @common_name, @superuser, @expires_at.to_i, @public_keys, @
|
60
|
+
[ @uuid, @username, @public_key, @common_name, @superuser, @expires_at.to_i, @public_keys, @profile_data ]
|
61
61
|
end
|
62
62
|
|
63
63
|
end
|
data/lib/right_agent/pid_file.rb
CHANGED
data/right_agent.gemspec
CHANGED
@@ -24,7 +24,7 @@ require 'rubygems'
|
|
24
24
|
|
25
25
|
Gem::Specification.new do |spec|
|
26
26
|
spec.name = 'right_agent'
|
27
|
-
spec.version = '0.6.
|
27
|
+
spec.version = '0.6.3'
|
28
28
|
spec.authors = ['Lee Kirchhoff', 'Raphael Simon', 'Tony Spataro']
|
29
29
|
spec.email = 'lee@rightscale.com'
|
30
30
|
spec.homepage = 'https://github.com/rightscale/right_agent'
|
@@ -48,6 +48,30 @@ describe RightScale::CommandRunner do
|
|
48
48
|
@socket_port = TEST_SOCKET_PORT
|
49
49
|
end
|
50
50
|
|
51
|
+
context :start do
|
52
|
+
before(:each) do
|
53
|
+
@pid_file = flexmock(RightScale::PidFile)
|
54
|
+
@pid_file.should_receive(:exists?).and_return(true)
|
55
|
+
@pid_file.should_receive(:set_command_options).and_return(true)
|
56
|
+
flexmock(RightScale::PidFile).should_receive(:new).and_return(@pid_file)
|
57
|
+
end
|
58
|
+
|
59
|
+
context 'when a block is provided' do
|
60
|
+
before(:each) do
|
61
|
+
@block = Proc.new do |pid_file|
|
62
|
+
@callback_pid_file = pid_file
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'should yield its PidFile' do
|
67
|
+
commands = { :test => lambda { |opt, _| } }
|
68
|
+
flexmock(RightScale::CommandIO).should_receive(:instance).and_return(RightScale::CommandIOMock.instance)
|
69
|
+
RightScale::CommandRunner.start(@socket_port, RightScale::AgentIdentity.generate, commands, &@block)
|
70
|
+
@callback_pid_file.should == @pid_file
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
51
75
|
it 'should handle invalid formats' do
|
52
76
|
flexmock(RightScale::CommandIO.instance).should_receive(:listen).and_yield(['invalid yaml'])
|
53
77
|
flexmock(RightScale::Log).should_receive(:info).once
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: right_agent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 1
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 6
|
9
|
-
-
|
10
|
-
version: 0.6.
|
9
|
+
- 3
|
10
|
+
version: 0.6.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Lee Kirchhoff
|
@@ -17,14 +17,11 @@ autorequire:
|
|
17
17
|
bindir: bin
|
18
18
|
cert_chain: []
|
19
19
|
|
20
|
-
date: 2011-11-
|
20
|
+
date: 2011-11-21 00:00:00 -08:00
|
21
21
|
default_executable:
|
22
22
|
dependencies:
|
23
23
|
- !ruby/object:Gem::Dependency
|
24
|
-
|
25
|
-
type: :runtime
|
26
|
-
name: right_support
|
27
|
-
version_requirements: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
28
25
|
none: false
|
29
26
|
requirements:
|
30
27
|
- - ~>
|
@@ -34,12 +31,12 @@ dependencies:
|
|
34
31
|
- 1
|
35
32
|
- 0
|
36
33
|
version: "1.0"
|
37
|
-
|
38
|
-
- !ruby/object:Gem::Dependency
|
34
|
+
name: right_support
|
39
35
|
prerelease: false
|
40
36
|
type: :runtime
|
41
|
-
|
42
|
-
|
37
|
+
version_requirements: *id001
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
43
40
|
none: false
|
44
41
|
requirements:
|
45
42
|
- - "="
|
@@ -50,12 +47,12 @@ dependencies:
|
|
50
47
|
- 7
|
51
48
|
- 5
|
52
49
|
version: 0.7.5
|
53
|
-
|
54
|
-
- !ruby/object:Gem::Dependency
|
50
|
+
name: amqp
|
55
51
|
prerelease: false
|
56
52
|
type: :runtime
|
57
|
-
|
58
|
-
|
53
|
+
version_requirements: *id002
|
54
|
+
- !ruby/object:Gem::Dependency
|
55
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
59
56
|
none: false
|
60
57
|
requirements:
|
61
58
|
- - ~>
|
@@ -65,12 +62,12 @@ dependencies:
|
|
65
62
|
- 1
|
66
63
|
- 4
|
67
64
|
version: "1.4"
|
68
|
-
|
69
|
-
- !ruby/object:Gem::Dependency
|
65
|
+
name: json
|
70
66
|
prerelease: false
|
71
67
|
type: :runtime
|
72
|
-
|
73
|
-
|
68
|
+
version_requirements: *id003
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
74
71
|
none: false
|
75
72
|
requirements:
|
76
73
|
- - ~>
|
@@ -81,12 +78,12 @@ dependencies:
|
|
81
78
|
- 12
|
82
79
|
- 10
|
83
80
|
version: 0.12.10
|
84
|
-
|
85
|
-
- !ruby/object:Gem::Dependency
|
81
|
+
name: eventmachine
|
86
82
|
prerelease: false
|
87
83
|
type: :runtime
|
88
|
-
|
89
|
-
|
84
|
+
version_requirements: *id004
|
85
|
+
- !ruby/object:Gem::Dependency
|
86
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
90
87
|
none: false
|
91
88
|
requirements:
|
92
89
|
- - ~>
|
@@ -97,12 +94,12 @@ dependencies:
|
|
97
94
|
- 0
|
98
95
|
- 11
|
99
96
|
version: 1.0.11
|
100
|
-
|
101
|
-
- !ruby/object:Gem::Dependency
|
97
|
+
name: right_popen
|
102
98
|
prerelease: false
|
103
99
|
type: :runtime
|
104
|
-
|
105
|
-
|
100
|
+
version_requirements: *id005
|
101
|
+
- !ruby/object:Gem::Dependency
|
102
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
106
103
|
none: false
|
107
104
|
requirements:
|
108
105
|
- - "="
|
@@ -113,7 +110,10 @@ dependencies:
|
|
113
110
|
- 4
|
114
111
|
- 4
|
115
112
|
version: 0.4.4
|
116
|
-
|
113
|
+
name: msgpack
|
114
|
+
prerelease: false
|
115
|
+
type: :runtime
|
116
|
+
version_requirements: *id006
|
117
117
|
description: |
|
118
118
|
RightAgent provides a foundation for running an agent on a server to interface
|
119
119
|
in a secure fashion with other agents in the RightScale system. A RightAgent
|