ridley-connectors 2.1.0 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/.travis.yml +1 -0
- data/CHANGELOG.md +4 -0
- data/lib/ridley-connectors/host_commander.rb +43 -3
- data/lib/ridley-connectors/version.rb +1 -1
- data/spec/support/errors.rb +3 -0
- data/spec/unit/ridley-connectors/host_commander_spec.rb +80 -6
- metadata +24 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 301f0d55380eefdcc12152a5e943643c67af77aa
|
4
|
+
data.tar.gz: 5e1f3ac6e959b50a8f62d0ff7e76c0c20ce55c9a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4780c2b719f082bc9e4cda5bf8b2154c0f670ce6a78d6c8d27246643e7c8b469642b6e9cdab54f91c8779c6e2073fa84a2fd51705d97a052690259a8a353cd51
|
7
|
+
data.tar.gz: c732f970be05ea14f0a396e165c5ffad48a81bb6df3914995474064d62e372d639d490e83942fc315efeecfc4130ec220d522efea0ed36eef9e368185ed94214
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.1.1
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
## v.2.1.1
|
2
|
+
|
3
|
+
* [#24](https://github.com/RiotGames/ridley-connectors/pull/24) Fix a bug with Timeout.rb unable to interrupt Socket connections (mostly JRuby)
|
4
|
+
|
1
5
|
## v.2.1.0
|
2
6
|
|
3
7
|
* [#21](https://github.com/RiotGames/ridley-connectors/pull/21) Fix bootstrappers and pathing to files moved from Ridley
|
@@ -259,17 +259,17 @@ module Ridley
|
|
259
259
|
# the host to attempt to connect to
|
260
260
|
# @param [Fixnum] port
|
261
261
|
# the port to attempt to connect on
|
262
|
-
# @param [Float]
|
262
|
+
# @param [Float] timeout ({PORT_CHECK_TIMEOUT})
|
263
263
|
# the number of seconds to wait
|
264
264
|
# @param [Int] retries ({RETRY_COUNT})
|
265
265
|
# the number of times to retry the connection before counting it unavailable
|
266
266
|
#
|
267
267
|
# @return [Boolean]
|
268
|
-
def connector_port_open?(host, port,
|
268
|
+
def connector_port_open?(host, port, timeout = PORT_CHECK_TIMEOUT, retries = RETRY_COUNT)
|
269
269
|
@retry_count = retries
|
270
270
|
begin
|
271
271
|
defer {
|
272
|
-
|
272
|
+
connectable?(host, port, timeout || PORT_CHECK_TIMEOUT)
|
273
273
|
}
|
274
274
|
rescue *CONNECTOR_PORT_ERRORS => ex
|
275
275
|
@retry_count -= 1
|
@@ -281,6 +281,46 @@ module Ridley
|
|
281
281
|
end
|
282
282
|
end
|
283
283
|
|
284
|
+
# Check if a port on a host is able to be connected, failing if the timeout transpires.
|
285
|
+
#
|
286
|
+
# @param [String] host
|
287
|
+
# the host to attempt to connect to
|
288
|
+
# @param [Fixnum] port
|
289
|
+
# the port to attempt to connect on
|
290
|
+
# @param [Fixnum] timeout ({PORT_CHECK_TIMEOUT})
|
291
|
+
#
|
292
|
+
# @return [Boolean]
|
293
|
+
def connectable?(host, port, timeout = PORT_CHECK_TIMEOUT)
|
294
|
+
addr = Socket.getaddrinfo(host, nil)
|
295
|
+
sockaddr = Socket.pack_sockaddr_in(port, addr[0][3])
|
296
|
+
socket = Socket.new(Socket.const_get(addr[0][0]), Socket::SOCK_STREAM, 0)
|
297
|
+
socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
|
298
|
+
|
299
|
+
success = false
|
300
|
+
begin
|
301
|
+
socket.connect_nonblock(sockaddr)
|
302
|
+
success = true
|
303
|
+
rescue ::IO::WaitWritable
|
304
|
+
if ::IO.select(nil, [socket], nil, timeout || PORT_CHECK_TIMEOUT)
|
305
|
+
begin
|
306
|
+
socket.connect_nonblock(sockaddr)
|
307
|
+
success = true
|
308
|
+
rescue Errno::EISCONN
|
309
|
+
success = true
|
310
|
+
rescue
|
311
|
+
begin
|
312
|
+
socket.close
|
313
|
+
rescue Errno::EBADF
|
314
|
+
# socket is not open
|
315
|
+
end
|
316
|
+
end
|
317
|
+
else
|
318
|
+
socket.close
|
319
|
+
end
|
320
|
+
end
|
321
|
+
success
|
322
|
+
end
|
323
|
+
|
284
324
|
def finalize_callback
|
285
325
|
@connector_supervisor.async.terminate if @connector_supervisor && @connector_supervisor.alive?
|
286
326
|
end
|
@@ -171,10 +171,9 @@ describe Ridley::HostCommander do
|
|
171
171
|
context "when connector_port_open? experiences an error" do
|
172
172
|
let(:socket) { double(close: true) }
|
173
173
|
|
174
|
-
|
175
|
-
before do
|
174
|
+
it "executes retry logic" do
|
176
175
|
@times_called = 0
|
177
|
-
|
176
|
+
subject.should_receive(:connectable?).twice.and_return do
|
178
177
|
@times_called += 1
|
179
178
|
if @times_called == 1
|
180
179
|
raise Errno::ETIMEDOUT
|
@@ -182,10 +181,7 @@ describe Ridley::HostCommander do
|
|
182
181
|
socket
|
183
182
|
end
|
184
183
|
end
|
185
|
-
end
|
186
184
|
|
187
|
-
it "executes retry logic" do
|
188
|
-
expect(Celluloid::IO::TCPSocket).to receive(:new).twice
|
189
185
|
subject.connector_for(host)
|
190
186
|
end
|
191
187
|
end
|
@@ -247,4 +243,82 @@ describe Ridley::HostCommander do
|
|
247
243
|
end
|
248
244
|
end
|
249
245
|
end
|
246
|
+
|
247
|
+
describe "#connectable?" do
|
248
|
+
let(:port) { 1234 }
|
249
|
+
|
250
|
+
before do
|
251
|
+
Socket
|
252
|
+
.stub(:getaddrinfo)
|
253
|
+
.with(host, nil)
|
254
|
+
.and_return [["AF_INET", 0, "33.33.33.10", "33.33.33.10", 2, 2, 17],
|
255
|
+
["AF_INET", 0, "33.33.33.10", "33.33.33.10", 2, 1, 6]]
|
256
|
+
end
|
257
|
+
|
258
|
+
context "when the target is accessible" do
|
259
|
+
before do
|
260
|
+
calls = 0
|
261
|
+
Socket.any_instance.stub(:connect_nonblock).and_return do
|
262
|
+
calls += 1
|
263
|
+
if calls == 1
|
264
|
+
raise WaitWritableError.new
|
265
|
+
end
|
266
|
+
raise Errno::EISCONN.new
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
270
|
+
it "should return true when a connection is initiated" do
|
271
|
+
::IO.stub(:select).and_return ["an array!"]
|
272
|
+
|
273
|
+
expect(subject.send(:connectable?, host, port)).to be_true
|
274
|
+
end
|
275
|
+
|
276
|
+
it "should return true when a connection is initiated and an explicit nil is passed as the timeout" do
|
277
|
+
::IO.stub(:select).with(anything, anything, anything, Ridley::HostCommander::PORT_CHECK_TIMEOUT).and_return ["an array!"]
|
278
|
+
|
279
|
+
expect(subject.send(:connectable?, host, port, nil)).to be_true
|
280
|
+
end
|
281
|
+
|
282
|
+
it "should return false when select times out" do
|
283
|
+
::IO.stub(:select).and_return nil
|
284
|
+
|
285
|
+
expect(subject.send(:connectable?, host, port)).to be_false
|
286
|
+
end
|
287
|
+
|
288
|
+
it "should return true when the connection does not have to wait" do
|
289
|
+
Socket.any_instance.stub(:connect_nonblock).and_return 0
|
290
|
+
|
291
|
+
expect(subject.send(:connectable?, host, port)).to be_true
|
292
|
+
end
|
293
|
+
end
|
294
|
+
|
295
|
+
Ridley::HostCommander::CONNECTOR_PORT_ERRORS.each do |error|
|
296
|
+
context "when the target causes #{error}" do
|
297
|
+
before do
|
298
|
+
calls = 0
|
299
|
+
Socket.any_instance.stub(:connect_nonblock).and_return do
|
300
|
+
calls += 1
|
301
|
+
if calls == 1
|
302
|
+
raise WaitWritableError.new
|
303
|
+
end
|
304
|
+
raise error.new
|
305
|
+
end
|
306
|
+
|
307
|
+
::IO.stub(:select).and_return []
|
308
|
+
end
|
309
|
+
|
310
|
+
context "should return false" do
|
311
|
+
it "" do
|
312
|
+
expect(subject.send(:connectable?, host, port)).to be_false
|
313
|
+
end
|
314
|
+
|
315
|
+
it "when the socket close throws EBAFD" do
|
316
|
+
Socket.any_instance.stub(:close).and_return { raise Errno::EBADF.new }
|
317
|
+
|
318
|
+
expect(subject.send(:connectable?, host, port)).to be_false
|
319
|
+
end
|
320
|
+
end
|
321
|
+
end
|
322
|
+
end
|
323
|
+
end
|
250
324
|
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: 2.1.
|
4
|
+
version: 2.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jamie Winsor
|
@@ -9,104 +9,104 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-04-
|
12
|
+
date: 2014-04-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: celluloid
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- - ~>
|
18
|
+
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
20
|
version: 0.16.0.pre
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
|
-
- - ~>
|
25
|
+
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: 0.16.0.pre
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: celluloid-io
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
|
-
- - ~>
|
32
|
+
- - "~>"
|
33
33
|
- !ruby/object:Gem::Version
|
34
34
|
version: 0.16.0.pre
|
35
35
|
type: :runtime
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
|
-
- - ~>
|
39
|
+
- - "~>"
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: 0.16.0.pre
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: erubis
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
|
-
- -
|
46
|
+
- - ">="
|
47
47
|
- !ruby/object:Gem::Version
|
48
48
|
version: '0'
|
49
49
|
type: :runtime
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
|
-
- -
|
53
|
+
- - ">="
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: '0'
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
57
|
name: net-ssh
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
59
59
|
requirements:
|
60
|
-
- -
|
60
|
+
- - ">="
|
61
61
|
- !ruby/object:Gem::Version
|
62
62
|
version: '0'
|
63
63
|
type: :runtime
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
|
-
- -
|
67
|
+
- - ">="
|
68
68
|
- !ruby/object:Gem::Version
|
69
69
|
version: '0'
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: ridley
|
72
72
|
requirement: !ruby/object:Gem::Requirement
|
73
73
|
requirements:
|
74
|
-
- - ~>
|
74
|
+
- - "~>"
|
75
75
|
- !ruby/object:Gem::Version
|
76
76
|
version: '3.1'
|
77
77
|
type: :runtime
|
78
78
|
prerelease: false
|
79
79
|
version_requirements: !ruby/object:Gem::Requirement
|
80
80
|
requirements:
|
81
|
-
- - ~>
|
81
|
+
- - "~>"
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
version: '3.1'
|
84
84
|
- !ruby/object:Gem::Dependency
|
85
85
|
name: winrm
|
86
86
|
requirement: !ruby/object:Gem::Requirement
|
87
87
|
requirements:
|
88
|
-
- - ~>
|
88
|
+
- - "~>"
|
89
89
|
- !ruby/object:Gem::Version
|
90
90
|
version: 1.1.0
|
91
91
|
type: :runtime
|
92
92
|
prerelease: false
|
93
93
|
version_requirements: !ruby/object:Gem::Requirement
|
94
94
|
requirements:
|
95
|
-
- - ~>
|
95
|
+
- - "~>"
|
96
96
|
- !ruby/object:Gem::Version
|
97
97
|
version: 1.1.0
|
98
98
|
- !ruby/object:Gem::Dependency
|
99
99
|
name: buff-ruby_engine
|
100
100
|
requirement: !ruby/object:Gem::Requirement
|
101
101
|
requirements:
|
102
|
-
- - ~>
|
102
|
+
- - "~>"
|
103
103
|
- !ruby/object:Gem::Version
|
104
104
|
version: '0.1'
|
105
105
|
type: :development
|
106
106
|
prerelease: false
|
107
107
|
version_requirements: !ruby/object:Gem::Requirement
|
108
108
|
requirements:
|
109
|
-
- - ~>
|
109
|
+
- - "~>"
|
110
110
|
- !ruby/object:Gem::Version
|
111
111
|
version: '0.1'
|
112
112
|
description: A Connector API for talking to nodes managed by Chef
|
@@ -117,9 +117,9 @@ executables: []
|
|
117
117
|
extensions: []
|
118
118
|
extra_rdoc_files: []
|
119
119
|
files:
|
120
|
-
- .gitignore
|
121
|
-
- .ruby-version
|
122
|
-
- .travis.yml
|
120
|
+
- ".gitignore"
|
121
|
+
- ".ruby-version"
|
122
|
+
- ".travis.yml"
|
123
123
|
- CHANGELOG.md
|
124
124
|
- Gemfile
|
125
125
|
- Guardfile
|
@@ -153,6 +153,7 @@ files:
|
|
153
153
|
- spec/fixtures/my-fake.pem
|
154
154
|
- spec/spec_helper.rb
|
155
155
|
- spec/support/actor_mocking.rb
|
156
|
+
- spec/support/errors.rb
|
156
157
|
- spec/support/spec_helpers.rb
|
157
158
|
- spec/unit/ridley-connectors/bootstrap_context/unix_spec.rb
|
158
159
|
- spec/unit/ridley-connectors/bootstrap_context/windows_spec.rb
|
@@ -176,17 +177,17 @@ require_paths:
|
|
176
177
|
- lib
|
177
178
|
required_ruby_version: !ruby/object:Gem::Requirement
|
178
179
|
requirements:
|
179
|
-
- -
|
180
|
+
- - ">="
|
180
181
|
- !ruby/object:Gem::Version
|
181
182
|
version: 1.9.1
|
182
183
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
183
184
|
requirements:
|
184
|
-
- -
|
185
|
+
- - ">="
|
185
186
|
- !ruby/object:Gem::Version
|
186
187
|
version: '0'
|
187
188
|
requirements: []
|
188
189
|
rubyforge_project:
|
189
|
-
rubygems_version: 2.
|
190
|
+
rubygems_version: 2.2.2
|
190
191
|
signing_key:
|
191
192
|
specification_version: 4
|
192
193
|
summary: A Connector API for talking to nodes managed by Chef
|
@@ -195,6 +196,7 @@ test_files:
|
|
195
196
|
- spec/fixtures/my-fake.pem
|
196
197
|
- spec/spec_helper.rb
|
197
198
|
- spec/support/actor_mocking.rb
|
199
|
+
- spec/support/errors.rb
|
198
200
|
- spec/support/spec_helpers.rb
|
199
201
|
- spec/unit/ridley-connectors/bootstrap_context/unix_spec.rb
|
200
202
|
- spec/unit/ridley-connectors/bootstrap_context/windows_spec.rb
|