ridley-connectors 2.0.1 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7cc8a35d12c2f0a211941000d82e951c738d1f0b
4
- data.tar.gz: 8793248c34607319be63abfbab2f0b5831f6ef2a
3
+ metadata.gz: e90348caa597256c09723c5a29428f75187dbb81
4
+ data.tar.gz: 3c6de11adb749a25c8873e3a061f6a1e33512010
5
5
  SHA512:
6
- metadata.gz: b6c08b024e392d443a050676e690e591342973c6fb105b4961f904cf2b1937eff4f2516751d6a2ad9d292ae58bbb2afc1456c675dc8d736e8d7b75aeae9813ac
7
- data.tar.gz: 74a3bba5e041055a7b2cfc02c38aff93132feeed3cbe4144d29f19f6c43c1897e9b9576f1a629339379aa01550d10d86673c5c3137a1a48d438dacde9f3a3919
6
+ metadata.gz: 7af3ff66ae8b1d47e67c8d10d382246432a550a8ef88f3c3c92fdf35619956554e3beb135ad40ba6759eb42be70eca5b656e24ea74a99e329ab141a1ee2913cc
7
+ data.tar.gz: a36958116a5abd3ea500eb33e73a7dbacde1efefd36426238a0dcabdc40c50cefc4a0a3384d8a9aea4b25fbc2d4fce4c76f444d139d133f5b671919cbf1e1f6f
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## v.2.1.0
2
+
3
+ * [#21](https://github.com/RiotGames/ridley-connectors/pull/21) Fix bootstrappers and pathing to files moved from Ridley
4
+ * [#22](https://github.com/RiotGames/ridley-connectors/pull/22) Added a new option to allow connector_for to pick a connector more intelligently
5
+
1
6
  ## v.2.0.1
2
7
 
3
8
  * [#18](https://github.com/RiotGames/ridley-connectors/pull/18) Move more connector-specific code out of ridley and into ridley-connectors
@@ -68,7 +68,7 @@ module Ridley
68
68
 
69
69
  # @return [Pathname]
70
70
  def templates_path
71
- Ridley.root.join('bootstrappers')
71
+ Ridley::Connectors.bootstrappers
72
72
  end
73
73
 
74
74
  # @return [String]
@@ -28,7 +28,7 @@ module Ridley
28
28
  # @return [Pathname]
29
29
  def template_file(filename = nil)
30
30
  return @template_file if filename.nil?
31
- @template_file = Ridley.scripts.join("#{filename}.erb")
31
+ @template_file = Ridley::Connectors.scripts.join("#{filename}.erb")
32
32
  end
33
33
  end
34
34
 
@@ -26,6 +26,9 @@ module Ridley
26
26
  PORT_CHECK_TIMEOUT = 3
27
27
  RETRY_COUNT = 3
28
28
 
29
+ DEFAULT_WINDOWS_CONNECTOR = "winrm"
30
+ DEFAULT_LINUX_CONNECTOR = "ssh"
31
+
29
32
  CONNECTOR_PORT_ERRORS = [
30
33
  Errno::ETIMEDOUT, Timeout::Error, SocketError,
31
34
  Errno::ECONNREFUSED, Errno::EHOSTUNREACH, Errno::EADDRNOTAVAIL,
@@ -60,6 +63,8 @@ module Ridley
60
63
  # * :user (String) a user that will login to each node and perform the bootstrap command on
61
64
  # * :password (String) the password for the user that will perform the bootstrap (required)
62
65
  # * :port (Fixnum) the winrm port to connect on the node the bootstrap will be performed on (5985)
66
+ # @option options [String] :connector
67
+ # a connector type to prefer
63
68
  #
64
69
  # @return [HostConnector::Response]
65
70
  def run(host, command, options = {})
@@ -102,6 +107,8 @@ module Ridley
102
107
  # * :user (String) a user that will login to each node and perform the bootstrap command on
103
108
  # * :password (String) the password for the user that will perform the bootstrap (required)
104
109
  # * :port (Fixnum) the winrm port to connect on the node the bootstrap will be performed on (5985)
110
+ # @option options [String] :connector
111
+ # a connector type to prefer
105
112
  #
106
113
  # @return [HostConnector::Response]
107
114
  def chef_client(host, options = {})
@@ -125,6 +132,8 @@ module Ridley
125
132
  # * :user (String) a user that will login to each node and perform the bootstrap command on
126
133
  # * :password (String) the password for the user that will perform the bootstrap (required)
127
134
  # * :port (Fixnum) the winrm port to connect on the node the bootstrap will be performed on (5985)
135
+ # @option options [String] :connector
136
+ # a connector type to prefer
128
137
  #
129
138
  # @return [HostConnector::Response]
130
139
  def put_secret(host, secret, options = {})
@@ -148,6 +157,8 @@ module Ridley
148
157
  # * :user (String) a user that will login to each node and perform the bootstrap command on
149
158
  # * :password (String) the password for the user that will perform the bootstrap (required)
150
159
  # * :port (Fixnum) the winrm port to connect on the node the bootstrap will be performed on (5985)
160
+ # @option options [String] :connector
161
+ # a connector type to prefer
151
162
  #
152
163
  # @return [HostConnector::Response]
153
164
  def ruby_script(host, command_lines, options = {})
@@ -173,6 +184,8 @@ module Ridley
173
184
  # * :user (String) a user that will login to each node and perform the bootstrap command on
174
185
  # * :password (String) the password for the user that will perform the bootstrap (required)
175
186
  # * :port (Fixnum) the winrm port to connect on the node the bootstrap will be performed on (5985)
187
+ # @option options [String] :connector
188
+ # a connector type to prefer
176
189
  #
177
190
  # @return [HostConnector::Response]
178
191
  def uninstall_chef(host, options = {})
@@ -188,6 +201,8 @@ module Ridley
188
201
  # * :timeout (Float) [5.0] timeout value for testing SSH connection
189
202
  # @option options [Hash] :winrm
190
203
  # * :port (Fixnum) the winrm port to connect on the node the bootstrap will be performed on (5985)
204
+ # @option options [String] :connector
205
+ # a connector type to prefer
191
206
  # @param block [Proc]
192
207
  # an optional block that is yielded the best HostConnector
193
208
  #
@@ -199,10 +214,12 @@ module Ridley
199
214
  options[:winrm][:port] ||= HostConnector::WinRM::DEFAULT_PORT
200
215
  options[:retries] ||= RETRY_COUNT
201
216
 
202
- if connector_port_open?(host, options[:winrm][:port], options[:winrm][:timeout], options[:retries])
217
+ connector = options[:connector]
218
+
219
+ if (connector == DEFAULT_WINDOWS_CONNECTOR || connector.nil?) && connector_port_open?(host, options[:winrm][:port], options[:winrm][:timeout], options[:retries])
203
220
  options.delete(:ssh)
204
221
  winrm
205
- elsif connector_port_open?(host, options[:ssh][:port], options[:ssh][:timeout], options[:retries])
222
+ elsif (connector == DEFAULT_LINUX_CONNECTOR || connector.nil?) && connector_port_open?(host, options[:ssh][:port], options[:ssh][:timeout], options[:retries])
206
223
  options.delete(:winrm)
207
224
  ssh
208
225
  else
@@ -95,10 +95,12 @@ module Ridley
95
95
  # host.
96
96
  #
97
97
  # @param [String] host
98
+ # @option options [String] :connector
99
+ # a connectory type to prefer
98
100
  #
99
101
  # @return [HostConnector::Response]
100
- def chef_run(host)
101
- host_commander.chef_client(host, ssh: ssh, winrm: winrm)
102
+ def chef_run(host, options = {})
103
+ host_commander.chef_client(host, ssh: ssh, winrm: winrm, connector: options[:connector])
102
104
  rescue Errors::HostConnectionError => ex
103
105
  abort(ex)
104
106
  end
@@ -107,10 +109,12 @@ module Ridley
107
109
  # the given host.
108
110
  #
109
111
  # @param [String] host
112
+ # @option options [String] :connector
113
+ # a connectory type to prefer
110
114
  #
111
115
  # @return [HostConnector::Response]
112
- def put_secret(host)
113
- host_commander.put_secret(host, encrypted_data_bag_secret, ssh: ssh, winrm: winrm)
116
+ def put_secret(host, options = {})
117
+ host_commander.put_secret(host, encrypted_data_bag_secret, ssh: ssh, winrm: winrm, connector: options[:connector])
114
118
  end
115
119
 
116
120
  # Executes an arbitrary ruby script using the best worker available
@@ -118,10 +122,12 @@ module Ridley
118
122
  #
119
123
  # @param [String] host
120
124
  # @param [Array<String>] command_lines
125
+ # @option options [String] :connector
126
+ # a connectory type to prefer
121
127
  #
122
128
  # @return [HostConnector::Response]
123
- def ruby_script(host, command_lines)
124
- host_commander.ruby_script(host, command_lines, ssh: ssh, winrm: winrm)
129
+ def ruby_script(host, command_lines, options = {})
130
+ host_commander.ruby_script(host, command_lines, ssh: ssh, winrm: winrm, connector: options[:connector])
125
131
  end
126
132
 
127
133
  # Executes the given command on a node using the best worker
@@ -131,8 +137,8 @@ module Ridley
131
137
  # @param [String] command
132
138
  #
133
139
  # @return [HostConnector::Response]
134
- def run(host, command)
135
- host_commander.run(host, command, ssh: ssh, winrm: winrm)
140
+ def run(host, command, options = {})
141
+ host_commander.run(host, command, ssh: ssh, winrm: winrm, connector: options[:connector])
136
142
  end
137
143
  alias_method :execute_command, :run
138
144
 
@@ -1,5 +1,5 @@
1
1
  module Ridley
2
2
  module Connectors
3
- VERSION = "2.0.1"
3
+ VERSION = "2.1.0"
4
4
  end
5
5
  end
@@ -3,10 +3,23 @@ require 'celluloid/io'
3
3
  require 'ridley'
4
4
 
5
5
  module Ridley
6
- class << self
7
- # @return [Pathname]
8
- def scripts
9
- root.join('scripts')
6
+ module Connectors
7
+ class << self
8
+
9
+ # @return [Pathname]
10
+ def root
11
+ @root ||= Pathname.new(File.expand_path('../', File.dirname(__FILE__)))
12
+ end
13
+
14
+ # @return [Pathname]
15
+ def scripts
16
+ root.join('scripts')
17
+ end
18
+
19
+ # @return [Pathname]
20
+ def bootstrappers
21
+ root.join('bootstrappers')
22
+ end
10
23
  end
11
24
  end
12
25
 
@@ -21,7 +21,7 @@ Gem::Specification.new do |s|
21
21
  s.add_dependency 'celluloid-io', '~> 0.16.0.pre'
22
22
  s.add_dependency 'erubis'
23
23
  s.add_dependency 'net-ssh'
24
- s.add_dependency 'ridley', '~> 3.0'
24
+ s.add_dependency 'ridley', '~> 3.1'
25
25
  s.add_dependency 'winrm', '~> 1.1.0'
26
26
 
27
27
  s.add_development_dependency 'buff-ruby_engine', '~> 0.1'
@@ -208,5 +208,43 @@ describe Ridley::HostCommander do
208
208
  subject.should_receive(:winrm)
209
209
  subject.connector_for(host, winrm: nil, ssh: nil)
210
210
  end
211
+
212
+ context "when a connector of winrm is given" do
213
+ let(:options) do
214
+ { ssh: { port: 22, timeout: 3 }, winrm: { port: 5985, timeout: 3 }, retries: 3, connector: "winrm" }
215
+ end
216
+ let(:winrm) { double }
217
+
218
+ it "should return winrm if winrm is open" do
219
+ subject.stub(:connector_port_open?).with(host, Ridley::HostConnector::WinRM::DEFAULT_PORT, anything, anything).and_return(true)
220
+ subject.stub(:winrm).and_return(winrm)
221
+ expect(subject.connector_for(host, options)).to eql(winrm)
222
+ end
223
+
224
+ it "should return nil if winrm is closed" do
225
+ subject.stub(:connector_port_open?).with(host, Ridley::HostConnector::WinRM::DEFAULT_PORT, anything, anything).and_return(false)
226
+ expect(subject.connector_for(host, options)).to be_nil
227
+ end
228
+ end
229
+
230
+ context "when a connector of ssh is given" do
231
+ let(:options) do
232
+ { ssh: { port: 22, timeout: 3 }, winrm: { port: 5985, timeout: 3 }, retries: 3, connector: "ssh" }
233
+ end
234
+ let(:ssh) { double }
235
+
236
+ it "should return ssh if ssh is open" do
237
+ subject.stub(:connector_port_open?).with(host, Ridley::HostConnector::SSH::DEFAULT_PORT, anything, anything).and_return(true)
238
+ subject.stub(:ssh).and_return(ssh)
239
+ subject.should_not_receive(:connector_port_open?).with(host, Ridley::HostConnector::WinRM::DEFAULT_PORT, anything, anything)
240
+ expect(subject.connector_for(host, options)).to eql(ssh)
241
+ end
242
+
243
+ it "should return nil if ssh is closed" do
244
+ subject.stub(:connector_port_open?).with(host, Ridley::HostConnector::SSH::DEFAULT_PORT, anything, anything).and_return(false)
245
+ subject.should_not_receive(:connector_port_open?).with(host, Ridley::HostConnector::WinRM::DEFAULT_PORT, anything, anything)
246
+ expect(subject.connector_for(host, options)).to be_nil
247
+ end
248
+ end
211
249
  end
212
250
  end
@@ -11,9 +11,11 @@ describe Ridley::NodeResource do
11
11
  encrypted_data_bag_secret: double('encrypted_data_bag_secret'),
12
12
  ssh: double('ssh'),
13
13
  winrm: double('winrm'),
14
- chef_version: double('chef_version')
14
+ chef_version: double('chef_version'),
15
+ connector: nil
15
16
  }
16
17
  end
18
+
17
19
  let(:instance) do
18
20
  inst = described_class.new(double, options)
19
21
  inst.stub(host_commander: host_commander)
@@ -21,21 +23,23 @@ describe Ridley::NodeResource do
21
23
  end
22
24
 
23
25
  describe "#bootstrap" do
26
+ let(:bootstrap_options) { options.delete(:connector); options }
27
+
24
28
  it "sends the message #bootstrap to the instance's host_commander" do
25
- host_commander.should_receive(:bootstrap).with(host, options)
29
+ host_commander.should_receive(:bootstrap).with(host, bootstrap_options)
26
30
  instance.bootstrap(host)
27
31
  end
28
32
 
29
33
  it "passes pre-configured options to #bootstrap" do
30
- host_commander.should_receive(:bootstrap).with(host, options)
34
+ host_commander.should_receive(:bootstrap).with(host, bootstrap_options)
31
35
  instance.bootstrap(host)
32
36
  end
33
37
  end
34
38
 
35
39
  describe "#chef_run" do
36
40
  it "sends the message #chef_client to the instance's host_commander" do
37
- host_commander.should_receive(:chef_client).with(host, ssh: instance.ssh, winrm: instance.winrm)
38
- instance.chef_run(host)
41
+ host_commander.should_receive(:chef_client).with(host, ssh: instance.ssh, winrm: instance.winrm, connector: nil)
42
+ instance.chef_run(host, options)
39
43
  end
40
44
  end
41
45
 
@@ -43,8 +47,8 @@ describe Ridley::NodeResource do
43
47
  let(:secret) { options[:encrypted_data_bag_secret] }
44
48
 
45
49
  it "sends the message #put_secret to the instance's host_commander" do
46
- host_commander.should_receive(:put_secret).with(host, secret, options.slice(:ssh, :winrm))
47
- instance.put_secret(host)
50
+ host_commander.should_receive(:put_secret).with(host, secret, options.slice(:ssh, :winrm, :connector))
51
+ instance.put_secret(host, options)
48
52
  end
49
53
  end
50
54
 
@@ -52,8 +56,8 @@ describe Ridley::NodeResource do
52
56
  let(:command_lines) { ["puts 'hello'", "puts 'there'"] }
53
57
 
54
58
  it "sends the message #ruby_script to the instance's host_commander" do
55
- host_commander.should_receive(:ruby_script).with(host, command_lines, ssh: instance.ssh, winrm: instance.winrm)
56
- instance.ruby_script(host, command_lines)
59
+ host_commander.should_receive(:ruby_script).with(host, command_lines, ssh: instance.ssh, winrm: instance.winrm, connector: nil)
60
+ instance.ruby_script(host, command_lines, options)
57
61
  end
58
62
  end
59
63
 
@@ -61,8 +65,8 @@ describe Ridley::NodeResource do
61
65
  let(:command) { "echo 'hello winrm_connectorld'" }
62
66
 
63
67
  it "sends the message #run to the instance's host_commander" do
64
- host_commander.should_receive(:run).with(host, command, ssh: instance.ssh, winrm: instance.winrm)
65
- instance.run(host, command)
68
+ host_commander.should_receive(:run).with(host, command, ssh: instance.ssh, winrm: instance.winrm, connector: nil)
69
+ instance.run(host, command, options)
66
70
  end
67
71
  end
68
72
 
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.0.1
4
+ version: 2.1.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-04-17 00:00:00.000000000 Z
12
+ date: 2014-04-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: celluloid
@@ -73,14 +73,14 @@ dependencies:
73
73
  requirements:
74
74
  - - ~>
75
75
  - !ruby/object:Gem::Version
76
- version: '3.0'
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
- version: '3.0'
83
+ version: '3.1'
84
84
  - !ruby/object:Gem::Dependency
85
85
  name: winrm
86
86
  requirement: !ruby/object:Gem::Requirement