ridley 1.0.0.rc3 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ridley.rb +1 -0
- data/lib/ridley/connection.rb +13 -14
- data/lib/ridley/host_commander.rb +20 -25
- data/lib/ridley/resource.rb +1 -1
- data/lib/ridley/resources/node_resource.rb +2 -1
- data/lib/ridley/version.rb +1 -1
- data/ridley.gemspec +1 -0
- data/spec/unit/ridley/host_commander_spec.rb +20 -55
- data/spec/unit/ridley/resources/node_resource_spec.rb +2 -2
- metadata +23 -4
data/lib/ridley.rb
CHANGED
data/lib/ridley/connection.rb
CHANGED
@@ -6,6 +6,7 @@ require 'zlib'
|
|
6
6
|
module Ridley
|
7
7
|
class Connection < Faraday::Connection
|
8
8
|
include Celluloid
|
9
|
+
task_class TaskThread
|
9
10
|
|
10
11
|
VALID_OPTIONS = [
|
11
12
|
:retries,
|
@@ -100,7 +101,7 @@ module Ridley
|
|
100
101
|
# Override Faraday::Connection#run_request to catch exceptions from {Ridley::Middleware} that
|
101
102
|
# we expect. Caught exceptions are re-raised with Celluloid#abort so we don't crash the connection.
|
102
103
|
def run_request(*args)
|
103
|
-
|
104
|
+
super
|
104
105
|
rescue Errors::HTTPError => ex
|
105
106
|
abort ex
|
106
107
|
rescue Faraday::Error::ConnectionFailed => ex
|
@@ -140,22 +141,20 @@ module Ridley
|
|
140
141
|
local = Tempfile.new('ridley-stream')
|
141
142
|
local.binmode
|
142
143
|
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
body = Zlib::Inflate.inflate(body)
|
152
|
-
end
|
153
|
-
local.write(body)
|
144
|
+
retryable(tries: retries, on: OpenURI::HTTPError, sleep: retry_interval) do
|
145
|
+
open(target, 'rb', headers) do |remote|
|
146
|
+
body = remote.read
|
147
|
+
case remote.content_encoding
|
148
|
+
when ['gzip']
|
149
|
+
body = Zlib::GzipReader.new(StringIO.new(body), encoding: 'ASCII-8BIT').read
|
150
|
+
when ['deflate']
|
151
|
+
body = Zlib::Inflate.inflate(body)
|
154
152
|
end
|
153
|
+
local.write(body)
|
155
154
|
end
|
155
|
+
end
|
156
156
|
|
157
|
-
|
158
|
-
}
|
157
|
+
local.flush
|
159
158
|
|
160
159
|
FileUtils.mv(local.path, destination)
|
161
160
|
rescue OpenURI::HTTPError => ex
|
@@ -1,6 +1,3 @@
|
|
1
|
-
require 'socket'
|
2
|
-
require 'timeout'
|
3
|
-
|
4
1
|
module Ridley
|
5
2
|
class ConnectorSupervisor < ::Celluloid::SupervisionGroup
|
6
3
|
# @param [Celluloid::Registry] registry
|
@@ -12,25 +9,6 @@ module Ridley
|
|
12
9
|
end
|
13
10
|
|
14
11
|
class HostCommander
|
15
|
-
class << self
|
16
|
-
# Checks to see if the given port is open for TCP connections
|
17
|
-
# on the given host.
|
18
|
-
#
|
19
|
-
# @param [String] host
|
20
|
-
# the host to attempt to connect to
|
21
|
-
# @param [Fixnum] port
|
22
|
-
# the port to attempt to connect on
|
23
|
-
# @param [Float] timeout
|
24
|
-
# the number of seconds to wait (default: {PORT_CHECK_TIMEOUT})
|
25
|
-
#
|
26
|
-
# @return [Boolean]
|
27
|
-
def connector_port_open?(host, port, timeout = nil)
|
28
|
-
Timeout.timeout(timeout || PORT_CHECK_TIMEOUT) { TCPSocket.new(host, port).close; true }
|
29
|
-
rescue Timeout::Error, SocketError, Errno::ECONNREFUSED, Errno::EHOSTUNREACH, Errno::EADDRNOTAVAIL => ex
|
30
|
-
false
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
12
|
include Celluloid
|
35
13
|
include Ridley::Logging
|
36
14
|
|
@@ -183,7 +161,7 @@ module Ridley
|
|
183
161
|
def execute(method, host, *args)
|
184
162
|
options = args.last.is_a?(Hash) ? args.pop : Hash.new
|
185
163
|
|
186
|
-
connector_for(host, options).send(method, host, *args, options)
|
164
|
+
defer { connector_for(host, options).send(method, host, *args, options) }
|
187
165
|
rescue Errors::HostConnectionError => ex
|
188
166
|
abort(ex)
|
189
167
|
end
|
@@ -206,10 +184,10 @@ module Ridley
|
|
206
184
|
options[:ssh][:port] ||= HostConnector::SSH::DEFAULT_PORT
|
207
185
|
options[:winrm][:port] ||= HostConnector::WinRM::DEFAULT_PORT
|
208
186
|
|
209
|
-
if
|
187
|
+
if connector_port_open?(host, options[:winrm][:port])
|
210
188
|
options.delete(:ssh)
|
211
189
|
winrm
|
212
|
-
elsif
|
190
|
+
elsif connector_port_open?(host, options[:ssh][:port], options[:ssh][:timeout])
|
213
191
|
options.delete(:winrm)
|
214
192
|
ssh
|
215
193
|
else
|
@@ -217,6 +195,23 @@ module Ridley
|
|
217
195
|
end
|
218
196
|
end
|
219
197
|
|
198
|
+
# Checks to see if the given port is open for TCP connections
|
199
|
+
# on the given host.
|
200
|
+
#
|
201
|
+
# @param [String] host
|
202
|
+
# the host to attempt to connect to
|
203
|
+
# @param [Fixnum] port
|
204
|
+
# the port to attempt to connect on
|
205
|
+
# @param [Float] wait_time ({PORT_CHECK_TIMEOUT})
|
206
|
+
# the number of seconds to wait
|
207
|
+
#
|
208
|
+
# @return [Boolean]
|
209
|
+
def connector_port_open?(host, port, wait_time = nil)
|
210
|
+
timeout(wait_time || PORT_CHECK_TIMEOUT) { Celluloid::IO::TCPSocket.new(host, port).close; true }
|
211
|
+
rescue Timeout::Error, SocketError, Errno::ECONNREFUSED, Errno::EHOSTUNREACH, Errno::EADDRNOTAVAIL => ex
|
212
|
+
false
|
213
|
+
end
|
214
|
+
|
220
215
|
def finalize_callback
|
221
216
|
@connector_supervisor.terminate if @connector_supervisor && @connector_supervisor.alive?
|
222
217
|
end
|
data/lib/ridley/resource.rb
CHANGED
@@ -109,7 +109,7 @@ module Ridley
|
|
109
109
|
raise Errors::HTTPUnknownMethod, "unknown http method: #{method}"
|
110
110
|
end
|
111
111
|
|
112
|
-
|
112
|
+
connection.send(method, *args)
|
113
113
|
rescue Errors::HTTPError, Errors::ClientError => ex
|
114
114
|
abort(ex)
|
115
115
|
end
|
@@ -133,9 +133,10 @@ module Ridley
|
|
133
133
|
# @param [String] command
|
134
134
|
#
|
135
135
|
# @return [Array<Symbol, HostConnector::Response>]
|
136
|
-
def
|
136
|
+
def run(host, command)
|
137
137
|
host_commander.run(host, command, ssh: ssh, winrm: winrm)
|
138
138
|
end
|
139
|
+
alias_method :execute_command, :run
|
139
140
|
|
140
141
|
# Merges the given data with the the data of the target node on the remote
|
141
142
|
#
|
data/lib/ridley/version.rb
CHANGED
data/ridley.gemspec
CHANGED
@@ -20,6 +20,7 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.add_runtime_dependency 'addressable'
|
21
21
|
s.add_runtime_dependency 'chozo', '>= 0.6.0'
|
22
22
|
s.add_runtime_dependency 'celluloid', '~> 0.14.0'
|
23
|
+
s.add_runtime_dependency 'celluloid-io', '~> 0.14.0'
|
23
24
|
s.add_runtime_dependency 'erubis'
|
24
25
|
s.add_runtime_dependency 'faraday', '>= 0.8.4'
|
25
26
|
s.add_runtime_dependency 'hashie', '>= 2.0.2'
|
@@ -1,41 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Ridley::HostCommander do
|
4
|
-
describe "ClassMethods" do
|
5
|
-
subject { described_class }
|
6
|
-
|
7
|
-
describe "::connector_port_open?" do
|
8
|
-
let(:host) { "127.0.0.1" }
|
9
|
-
let(:port) { 22 }
|
10
|
-
let(:socket) { double(close: nil) }
|
11
|
-
|
12
|
-
before { TCPSocket.stub(:new).and_return(socket) }
|
13
|
-
|
14
|
-
subject(:result) { described_class.connector_port_open?(host, port) }
|
15
|
-
|
16
|
-
context "when a port is open" do
|
17
|
-
it { should be_true }
|
18
|
-
|
19
|
-
it "closes the opened socket" do
|
20
|
-
socket.should_receive(:close)
|
21
|
-
result
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
context "when a port is closed" do
|
26
|
-
before { TCPSocket.stub(:new).and_raise(Errno::ECONNREFUSED) }
|
27
|
-
|
28
|
-
it { should be_false }
|
29
|
-
end
|
30
|
-
|
31
|
-
context "when host is unreachable" do
|
32
|
-
before { TCPSocket.stub(:new).and_raise(SocketError) }
|
33
|
-
|
34
|
-
it { should be_false }
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
4
|
subject { described_class.new }
|
40
5
|
|
41
6
|
describe "#run" do
|
@@ -47,8 +12,8 @@ describe Ridley::HostCommander do
|
|
47
12
|
|
48
13
|
context "when communicating to a unix node" do
|
49
14
|
before do
|
50
|
-
|
51
|
-
|
15
|
+
subject.stub(:connector_port_open?).with(host, options[:winrm][:port]).and_return(false)
|
16
|
+
subject.stub(:connector_port_open?).with(host, options[:ssh][:port], anything).and_return(true)
|
52
17
|
end
|
53
18
|
|
54
19
|
it "sends a #run message to the ssh host connector" do
|
@@ -60,8 +25,8 @@ describe Ridley::HostCommander do
|
|
60
25
|
|
61
26
|
context "when communicating to a windows node" do
|
62
27
|
before do
|
63
|
-
|
64
|
-
|
28
|
+
subject.stub(:connector_port_open?).with(host, options[:winrm][:port]).and_return(true)
|
29
|
+
subject.stub(:connector_port_open?).with(host, options[:ssh][:port], anything).and_return(false)
|
65
30
|
end
|
66
31
|
|
67
32
|
it "sends a #run message to the ssh host connector" do
|
@@ -80,8 +45,8 @@ describe Ridley::HostCommander do
|
|
80
45
|
|
81
46
|
context "when communicating to a unix node" do
|
82
47
|
before do
|
83
|
-
|
84
|
-
|
48
|
+
subject.stub(:connector_port_open?).with(host, options[:winrm][:port]).and_return(false)
|
49
|
+
subject.stub(:connector_port_open?).with(host, options[:ssh][:port], anything).and_return(true)
|
85
50
|
end
|
86
51
|
|
87
52
|
it "sends a #bootstrap message to the ssh host connector" do
|
@@ -93,8 +58,8 @@ describe Ridley::HostCommander do
|
|
93
58
|
|
94
59
|
context "when communicating to a windows node" do
|
95
60
|
before do
|
96
|
-
|
97
|
-
|
61
|
+
subject.stub(:connector_port_open?).with(host, options[:winrm][:port]).and_return(true)
|
62
|
+
subject.stub(:connector_port_open?).with(host, options[:ssh][:port], anything).and_return(false)
|
98
63
|
end
|
99
64
|
|
100
65
|
it "sends a #bootstrap message to the ssh host connector" do
|
@@ -113,8 +78,8 @@ describe Ridley::HostCommander do
|
|
113
78
|
|
114
79
|
context "when communicating to a unix node" do
|
115
80
|
before do
|
116
|
-
|
117
|
-
|
81
|
+
subject.stub(:connector_port_open?).with(host, options[:winrm][:port]).and_return(false)
|
82
|
+
subject.stub(:connector_port_open?).with(host, options[:ssh][:port], anything).and_return(true)
|
118
83
|
end
|
119
84
|
|
120
85
|
it "sends a #chef_client message to the ssh host connector" do
|
@@ -126,8 +91,8 @@ describe Ridley::HostCommander do
|
|
126
91
|
|
127
92
|
context "when communicating to a windows node" do
|
128
93
|
before do
|
129
|
-
|
130
|
-
|
94
|
+
subject.stub(:connector_port_open?).with(host, options[:winrm][:port]).and_return(true)
|
95
|
+
subject.stub(:connector_port_open?).with(host, options[:ssh][:port], anything).and_return(false)
|
131
96
|
end
|
132
97
|
|
133
98
|
it "sends a #chef_client message to the ssh host connector" do
|
@@ -147,8 +112,8 @@ describe Ridley::HostCommander do
|
|
147
112
|
|
148
113
|
context "when communicating to a unix node" do
|
149
114
|
before do
|
150
|
-
|
151
|
-
|
115
|
+
subject.stub(:connector_port_open?).with(host, options[:winrm][:port]).and_return(false)
|
116
|
+
subject.stub(:connector_port_open?).with(host, options[:ssh][:port], anything).and_return(true)
|
152
117
|
end
|
153
118
|
|
154
119
|
it "sends a #put_secret message to the ssh host connector" do
|
@@ -160,8 +125,8 @@ describe Ridley::HostCommander do
|
|
160
125
|
|
161
126
|
context "when communicating to a windows node" do
|
162
127
|
before do
|
163
|
-
|
164
|
-
|
128
|
+
subject.stub(:connector_port_open?).with(host, options[:winrm][:port]).and_return(true)
|
129
|
+
subject.stub(:connector_port_open?).with(host, options[:ssh][:port], anything).and_return(false)
|
165
130
|
end
|
166
131
|
|
167
132
|
it "sends a #put_secret message to the ssh host connector" do
|
@@ -181,8 +146,8 @@ describe Ridley::HostCommander do
|
|
181
146
|
|
182
147
|
context "when communicating to a unix node" do
|
183
148
|
before do
|
184
|
-
|
185
|
-
|
149
|
+
subject.stub(:connector_port_open?).with(host, options[:winrm][:port]).and_return(false)
|
150
|
+
subject.stub(:connector_port_open?).with(host, options[:ssh][:port], anything).and_return(true)
|
186
151
|
end
|
187
152
|
|
188
153
|
it "sends a #ruby_script message to the ssh host connector" do
|
@@ -194,8 +159,8 @@ describe Ridley::HostCommander do
|
|
194
159
|
|
195
160
|
context "when communicating to a windows node" do
|
196
161
|
before do
|
197
|
-
|
198
|
-
|
162
|
+
subject.stub(:connector_port_open?).with(host, options[:winrm][:port]).and_return(true)
|
163
|
+
subject.stub(:connector_port_open?).with(host, options[:ssh][:port], anything).and_return(false)
|
199
164
|
end
|
200
165
|
|
201
166
|
it "sends a #ruby_script message to the ssh host connector" do
|
@@ -58,12 +58,12 @@ describe Ridley::NodeResource do
|
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
-
describe "#
|
61
|
+
describe "#run" do
|
62
62
|
let(:command) { "echo 'hello world'" }
|
63
63
|
|
64
64
|
it "sends the message #run to the instance's host_commander" do
|
65
65
|
host_commander.should_receive(:run).with(host, command, ssh: instance.ssh, winrm: instance.winrm)
|
66
|
-
instance.
|
66
|
+
instance.run(host, command)
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
metadata
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ridley
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Jamie Winsor
|
@@ -60,6 +60,22 @@ dependencies:
|
|
60
60
|
- - ~>
|
61
61
|
- !ruby/object:Gem::Version
|
62
62
|
version: 0.14.0
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: celluloid-io
|
65
|
+
requirement: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ~>
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: 0.14.0
|
71
|
+
type: :runtime
|
72
|
+
prerelease: false
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ~>
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: 0.14.0
|
63
79
|
- !ruby/object:Gem::Dependency
|
64
80
|
name: erubis
|
65
81
|
requirement: !ruby/object:Gem::Requirement
|
@@ -369,9 +385,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
369
385
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
370
386
|
none: false
|
371
387
|
requirements:
|
372
|
-
- - ! '
|
388
|
+
- - ! '>='
|
373
389
|
- !ruby/object:Gem::Version
|
374
|
-
version:
|
390
|
+
version: '0'
|
391
|
+
segments:
|
392
|
+
- 0
|
393
|
+
hash: 422593322150565092
|
375
394
|
requirements: []
|
376
395
|
rubyforge_project:
|
377
396
|
rubygems_version: 1.8.23
|