ridley-connectors 1.6.0 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/ridley-connectors/host_commander.rb +17 -8
- data/lib/ridley-connectors/version.rb +1 -1
- data/spec/unit/ridley-connectors/host_commander_spec.rb +30 -30
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 599c5217df3e7254b4578d86c7ea5d2cff2642d2
|
|
4
|
+
data.tar.gz: dd25c405a8e4d04d49841830d2d052ed4149a126
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 586525058a7a8db6d445f7a613a70099b6751b9d3d4958f631e680b70b58f69b97fb2ba90ec773145c4e2c063b9be9ed795e073571eacaeef009c82f04e0e907
|
|
7
|
+
data.tar.gz: b66f344b598132790cf6b927f54af4763100a27e9bc358ac79d50b3e549152b5af9145fad8ced11c99672ff76f13bacc21c60cc4bd72530db4d262c5ecbe47bf
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
## v.1.7.0
|
|
2
|
+
|
|
3
|
+
* [#15](https://github.com/RiotGames/ridley-connectors/pull/15) Add retries to ssh and winrm connections
|
|
4
|
+
|
|
1
5
|
## v.1.6.0
|
|
2
6
|
* [#14](https://github.com/RiotGames/ridley-connectors/pull/14) Create
|
|
3
7
|
a pool of WinRM / SSH actors, configurable with options(:connector\_pool\_size)
|
|
@@ -19,6 +19,7 @@ module Ridley
|
|
|
19
19
|
include Ridley::Logging
|
|
20
20
|
|
|
21
21
|
PORT_CHECK_TIMEOUT = 3
|
|
22
|
+
RETRY_COUNT = 3
|
|
22
23
|
|
|
23
24
|
finalizer :finalize_callback
|
|
24
25
|
|
|
@@ -181,11 +182,12 @@ module Ridley
|
|
|
181
182
|
options[:winrm] ||= Hash.new
|
|
182
183
|
options[:ssh][:port] ||= HostConnector::SSH::DEFAULT_PORT
|
|
183
184
|
options[:winrm][:port] ||= HostConnector::WinRM::DEFAULT_PORT
|
|
185
|
+
options[:retries] ||= RETRY_COUNT
|
|
184
186
|
|
|
185
|
-
if connector_port_open?(host, options[:winrm][:port])
|
|
187
|
+
if connector_port_open?(host, options[:winrm][:port], options[:winrm][:timeout], options[:retries])
|
|
186
188
|
options.delete(:ssh)
|
|
187
189
|
winrm
|
|
188
|
-
elsif connector_port_open?(host, options[:ssh][:port], options[:ssh][:timeout])
|
|
190
|
+
elsif connector_port_open?(host, options[:ssh][:port], options[:ssh][:timeout], options[:retries])
|
|
189
191
|
options.delete(:winrm)
|
|
190
192
|
ssh
|
|
191
193
|
else
|
|
@@ -214,14 +216,21 @@ module Ridley
|
|
|
214
216
|
# the port to attempt to connect on
|
|
215
217
|
# @param [Float] wait_time ({PORT_CHECK_TIMEOUT})
|
|
216
218
|
# the number of seconds to wait
|
|
219
|
+
# @param [Int] retries ({RETRY_COUNT})
|
|
220
|
+
# the number of times to retry the connection before counting it unavailable
|
|
217
221
|
#
|
|
218
222
|
# @return [Boolean]
|
|
219
|
-
def connector_port_open?(host, port, wait_time = nil)
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
223
|
+
def connector_port_open?(host, port, wait_time = nil, retries = RETRY_COUNT)
|
|
224
|
+
@retry_count = retries
|
|
225
|
+
begin
|
|
226
|
+
defer {
|
|
227
|
+
Timeout.timeout(wait_time || PORT_CHECK_TIMEOUT) { Celluloid::IO::TCPSocket.new(host, port).close; true }
|
|
228
|
+
}
|
|
229
|
+
rescue Errno::ETIMEDOUT, Timeout::Error, SocketError, Errno::ECONNREFUSED, Errno::EHOSTUNREACH, Errno::EADDRNOTAVAIL => ex
|
|
230
|
+
@retry_count -= 1
|
|
231
|
+
retry if @retry_count > 0
|
|
232
|
+
false
|
|
233
|
+
end
|
|
225
234
|
end
|
|
226
235
|
|
|
227
236
|
def finalize_callback
|
|
@@ -7,13 +7,13 @@ describe Ridley::HostCommander do
|
|
|
7
7
|
describe "#run" do
|
|
8
8
|
let(:command) { "ls" }
|
|
9
9
|
let(:options) do
|
|
10
|
-
{ ssh: { port: 22 }, winrm: { port: 5985 } }
|
|
10
|
+
{ ssh: { port: 22, timeout: 3 }, winrm: { port: 5985, timeout: 3 }, retries: 3 }
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
context "when communicating to a unix node" do
|
|
14
14
|
before do
|
|
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)
|
|
15
|
+
subject.stub(:connector_port_open?).with(host, options[:winrm][:port], anything, anything).and_return(false)
|
|
16
|
+
subject.stub(:connector_port_open?).with(host, options[:ssh][:port], anything, anything).and_return(true)
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
it "sends a #run message to the ssh host connector" do
|
|
@@ -24,8 +24,8 @@ describe Ridley::HostCommander do
|
|
|
24
24
|
|
|
25
25
|
context "when communicating to a windows node" do
|
|
26
26
|
before do
|
|
27
|
-
subject.stub(:connector_port_open?).with(host, options[:winrm][:port]).and_return(true)
|
|
28
|
-
subject.stub(:connector_port_open?).with(host, options[:ssh][:port], anything).and_return(false)
|
|
27
|
+
subject.stub(:connector_port_open?).with(host, options[:winrm][:port], anything, anything).and_return(true)
|
|
28
|
+
subject.stub(:connector_port_open?).with(host, options[:ssh][:port], anything, anything).and_return(false)
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
it "sends a #run message to the ssh host connector" do
|
|
@@ -38,13 +38,13 @@ describe Ridley::HostCommander do
|
|
|
38
38
|
|
|
39
39
|
describe "#bootstrap" do
|
|
40
40
|
let(:options) do
|
|
41
|
-
{ ssh: { port: 22 }, winrm: { port: 5985 } }
|
|
41
|
+
{ ssh: { port: 22, timeout: 3 }, winrm: { port: 5985, timeout: 3 }, retries: 3 }
|
|
42
42
|
end
|
|
43
43
|
|
|
44
44
|
context "when communicating to a unix node" do
|
|
45
45
|
before do
|
|
46
|
-
subject.stub(:connector_port_open?).with(host, options[:winrm][:port]).and_return(false)
|
|
47
|
-
subject.stub(:connector_port_open?).with(host, options[:ssh][:port], anything).and_return(true)
|
|
46
|
+
subject.stub(:connector_port_open?).with(host, options[:winrm][:port], anything, anything).and_return(false)
|
|
47
|
+
subject.stub(:connector_port_open?).with(host, options[:ssh][:port], anything, anything).and_return(true)
|
|
48
48
|
end
|
|
49
49
|
|
|
50
50
|
it "sends a #bootstrap message to the ssh host connector" do
|
|
@@ -56,8 +56,8 @@ describe Ridley::HostCommander do
|
|
|
56
56
|
|
|
57
57
|
context "when communicating to a windows node" do
|
|
58
58
|
before do
|
|
59
|
-
subject.stub(:connector_port_open?).with(host, options[:winrm][:port]).and_return(true)
|
|
60
|
-
subject.stub(:connector_port_open?).with(host, options[:ssh][:port], anything).and_return(false)
|
|
59
|
+
subject.stub(:connector_port_open?).with(host, options[:winrm][:port], anything, anything).and_return(true)
|
|
60
|
+
subject.stub(:connector_port_open?).with(host, options[:ssh][:port], anything, anything).and_return(false)
|
|
61
61
|
end
|
|
62
62
|
|
|
63
63
|
it "sends a #bootstrap message to the winrm host connector" do
|
|
@@ -70,13 +70,13 @@ describe Ridley::HostCommander do
|
|
|
70
70
|
|
|
71
71
|
describe "#chef_client" do
|
|
72
72
|
let(:options) do
|
|
73
|
-
{ ssh: { port: 22 }, winrm: { port: 5985 } }
|
|
73
|
+
{ ssh: { port: 22, timeout: 3 }, winrm: { port: 5985, timeout: 3 }, retries: 3 }
|
|
74
74
|
end
|
|
75
75
|
|
|
76
76
|
context "when communicating to a unix node" do
|
|
77
77
|
before do
|
|
78
|
-
subject.stub(:connector_port_open?).with(host, options[:winrm][:port]).and_return(false)
|
|
79
|
-
subject.stub(:connector_port_open?).with(host, options[:ssh][:port], anything).and_return(true)
|
|
78
|
+
subject.stub(:connector_port_open?).with(host, options[:winrm][:port], anything, anything).and_return(false)
|
|
79
|
+
subject.stub(:connector_port_open?).with(host, options[:ssh][:port], anything, anything).and_return(true)
|
|
80
80
|
end
|
|
81
81
|
|
|
82
82
|
it "sends a #chef_client message to the ssh host connector" do
|
|
@@ -88,8 +88,8 @@ describe Ridley::HostCommander do
|
|
|
88
88
|
|
|
89
89
|
context "when communicating to a windows node" do
|
|
90
90
|
before do
|
|
91
|
-
subject.stub(:connector_port_open?).with(host, options[:winrm][:port]).and_return(true)
|
|
92
|
-
subject.stub(:connector_port_open?).with(host, options[:ssh][:port], anything).and_return(false)
|
|
91
|
+
subject.stub(:connector_port_open?).with(host, options[:winrm][:port], anything, anything).and_return(true)
|
|
92
|
+
subject.stub(:connector_port_open?).with(host, options[:ssh][:port], anything, anything).and_return(false)
|
|
93
93
|
end
|
|
94
94
|
|
|
95
95
|
it "sends a #chef_client message to the ssh host connector" do
|
|
@@ -103,13 +103,13 @@ describe Ridley::HostCommander do
|
|
|
103
103
|
describe "#put_secret" do
|
|
104
104
|
let(:secret) { "something_secret" }
|
|
105
105
|
let(:options) do
|
|
106
|
-
{ ssh: { port: 22 }, winrm: { port: 5985 } }
|
|
106
|
+
{ ssh: { port: 22, timeout: 3 }, winrm: { port: 5985, timeout: 3 }, retries: 3 }
|
|
107
107
|
end
|
|
108
108
|
|
|
109
109
|
context "when communicating to a unix node" do
|
|
110
110
|
before do
|
|
111
|
-
subject.stub(:connector_port_open?).with(host, options[:winrm][:port]).and_return(false)
|
|
112
|
-
subject.stub(:connector_port_open?).with(host, options[:ssh][:port], anything).and_return(true)
|
|
111
|
+
subject.stub(:connector_port_open?).with(host, options[:winrm][:port], anything, anything).and_return(false)
|
|
112
|
+
subject.stub(:connector_port_open?).with(host, options[:ssh][:port], anything, anything).and_return(true)
|
|
113
113
|
end
|
|
114
114
|
|
|
115
115
|
it "sends a #put_secret message to the ssh host connector" do
|
|
@@ -121,8 +121,8 @@ describe Ridley::HostCommander do
|
|
|
121
121
|
|
|
122
122
|
context "when communicating to a windows node" do
|
|
123
123
|
before do
|
|
124
|
-
subject.stub(:connector_port_open?).with(host, options[:winrm][:port]).and_return(true)
|
|
125
|
-
subject.stub(:connector_port_open?).with(host, options[:ssh][:port], anything).and_return(false)
|
|
124
|
+
subject.stub(:connector_port_open?).with(host, options[:winrm][:port], anything, anything).and_return(true)
|
|
125
|
+
subject.stub(:connector_port_open?).with(host, options[:ssh][:port], anything, anything).and_return(false)
|
|
126
126
|
end
|
|
127
127
|
|
|
128
128
|
it "sends a #put_secret message to the ssh host connector" do
|
|
@@ -136,13 +136,13 @@ describe Ridley::HostCommander do
|
|
|
136
136
|
describe "#ruby_script" do
|
|
137
137
|
let(:command_lines) { ["line one"] }
|
|
138
138
|
let(:options) do
|
|
139
|
-
{ ssh: { port: 22 }, winrm: { port: 5985 } }
|
|
139
|
+
{ ssh: { port: 22, timeout: 3 }, winrm: { port: 5985, timeout: 3 }, retries: 3 }
|
|
140
140
|
end
|
|
141
141
|
|
|
142
142
|
context "when communicating to a unix node" do
|
|
143
143
|
before do
|
|
144
|
-
subject.stub(:connector_port_open?).with(host, options[:winrm][:port]).and_return(false)
|
|
145
|
-
subject.stub(:connector_port_open?).with(host, options[:ssh][:port], anything).and_return(true)
|
|
144
|
+
subject.stub(:connector_port_open?).with(host, options[:winrm][:port], anything, anything).and_return(false)
|
|
145
|
+
subject.stub(:connector_port_open?).with(host, options[:ssh][:port], anything, anything).and_return(true)
|
|
146
146
|
end
|
|
147
147
|
|
|
148
148
|
it "sends a #ruby_script message to the ssh host connector" do
|
|
@@ -154,8 +154,8 @@ describe Ridley::HostCommander do
|
|
|
154
154
|
|
|
155
155
|
context "when communicating to a windows node" do
|
|
156
156
|
before do
|
|
157
|
-
subject.stub(:connector_port_open?).with(host, options[:winrm][:port]).and_return(true)
|
|
158
|
-
subject.stub(:connector_port_open?).with(host, options[:ssh][:port], anything).and_return(false)
|
|
157
|
+
subject.stub(:connector_port_open?).with(host, options[:winrm][:port], anything, anything).and_return(true)
|
|
158
|
+
subject.stub(:connector_port_open?).with(host, options[:ssh][:port], anything, anything).and_return(false)
|
|
159
159
|
end
|
|
160
160
|
|
|
161
161
|
it "sends a #ruby_script message to the ssh host connector" do
|
|
@@ -168,20 +168,20 @@ describe Ridley::HostCommander do
|
|
|
168
168
|
|
|
169
169
|
describe "#connector_for" do
|
|
170
170
|
it "should return winrm if winrm is open" do
|
|
171
|
-
subject.stub(:connector_port_open?).with(host, Ridley::HostConnector::WinRM::DEFAULT_PORT).and_return(true)
|
|
171
|
+
subject.stub(:connector_port_open?).with(host, Ridley::HostConnector::WinRM::DEFAULT_PORT, anything, anything).and_return(true)
|
|
172
172
|
subject.should_receive(:winrm)
|
|
173
173
|
subject.connector_for(host)
|
|
174
174
|
end
|
|
175
175
|
|
|
176
|
-
it "should return
|
|
177
|
-
subject.stub(:connector_port_open?).with(host, Ridley::HostConnector::WinRM::DEFAULT_PORT).and_return(false)
|
|
178
|
-
subject.stub(:connector_port_open?).with(host, Ridley::HostConnector::SSH::DEFAULT_PORT,
|
|
176
|
+
it "should return ssh if winrm is closed" do
|
|
177
|
+
subject.stub(:connector_port_open?).with(host, Ridley::HostConnector::WinRM::DEFAULT_PORT, anything, anything).and_return(false)
|
|
178
|
+
subject.stub(:connector_port_open?).with(host, Ridley::HostConnector::SSH::DEFAULT_PORT, anything, anything).and_return(true)
|
|
179
179
|
subject.should_receive(:ssh)
|
|
180
180
|
subject.connector_for(host)
|
|
181
181
|
end
|
|
182
182
|
|
|
183
183
|
it "should still set the default ports if an explicit nil is passed in" do
|
|
184
|
-
subject.stub(:connector_port_open?).with(host, Ridley::HostConnector::WinRM::DEFAULT_PORT).and_return(true)
|
|
184
|
+
subject.stub(:connector_port_open?).with(host, Ridley::HostConnector::WinRM::DEFAULT_PORT, anything, anything).and_return(true)
|
|
185
185
|
subject.should_receive(:winrm)
|
|
186
186
|
subject.connector_for(host, winrm: nil, ssh: nil)
|
|
187
187
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ridley-connectors
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.7.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jamie Winsor
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2014-03-
|
|
12
|
+
date: 2014-03-31 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: celluloid
|