ridley-connectors 1.2.0 → 1.2.1

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: d377ab3a3c31432e8159a2211ed1d9bd3594bef1
4
- data.tar.gz: 59ed27aaa0c2ac8693364c9da424993cf90db674
3
+ metadata.gz: 8931876ade720f3abe20d2e445e71104241df5a1
4
+ data.tar.gz: 4980b60e12f779d067baea1cf83dc7d700c7d996
5
5
  SHA512:
6
- metadata.gz: 0bfa41714c7a6d903ac7e900b2334757c88b012c162eab16ba9d89155bfbfe12a89739e89da244c0b5321c650dfaffb8cbe2aae52a25e89f14baefb54b315e26
7
- data.tar.gz: bb63aa0722d6810dcad2a2251afdd2d407255dd312972d28872550994060597563b36d17926f2e7230eeaf5617ef764ceb195a0364f478091eb66cf4aeb04173
6
+ metadata.gz: 55fe74b96c38964ee8ccb8dbc51863bdd802deaeb95a75f607dab2c2b67eb4a3c65a35a678b46cb5221b30111f52e77e96efe1a807727a4166c572f7ae57d59d
7
+ data.tar.gz: 4416bbcb1b1dfc7ad830fa41fbcebab58a2ab1655d508a41cd2dfc14d57d2ddee116afaa0c4571c3de1c0042b4e5f06b031519f1615fc4559851d22274ef8f17
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## v.1.2.1
2
+
3
+ * [#8](https://github.com/RiotGames/ridley-connectors/pull/8) Add a flag to execute Ruby scripts on Windows machines using a batch file
4
+ * [#9](https://github.com/RiotGames/ridley-connectors/pull/9) Fix a bug where a nil value for SSH or WinRM config would cause a NoMethodError
5
+
1
6
  ## v.1.2.0
2
7
 
3
8
  * Bumping internal dependency on Ridley to at least 2.4.2
@@ -170,7 +170,8 @@ module Ridley
170
170
  #
171
171
  # @return [HostConnector::SSH, HostConnector::WinRM]
172
172
  def connector_for(host, options = {})
173
- options = options.reverse_merge(ssh: Hash.new, winrm: Hash.new)
173
+ options[:ssh] ||= Hash.new
174
+ options[:winrm] ||= Hash.new
174
175
  options[:ssh][:port] ||= HostConnector::SSH::DEFAULT_PORT
175
176
  options[:winrm][:port] ||= HostConnector::WinRM::DEFAULT_PORT
176
177
 
@@ -29,6 +29,8 @@ module Ridley
29
29
  # * :user (String) a user that will login to each node and perform the bootstrap command on
30
30
  # * :password (String) the password for the user that will perform the bootstrap (required)
31
31
  # * :port (Fixnum) the winrm port to connect on the node the bootstrap will be performed on (5985)
32
+ # @option options [TrueClass, FalseClass] :force_batch_file
33
+ # Always use a batch file to run the command regardless of command length.
32
34
  #
33
35
  # @return [HostConnector::Response]
34
36
  def run(host, command, options = {})
@@ -49,7 +51,7 @@ module Ridley
49
51
  HostConnector::Response.new(host).tap do |response|
50
52
  begin
51
53
  command_uploaders << command_uploader = CommandUploader.new(connection)
52
- command = get_command(command, command_uploader)
54
+ command = get_command(command, command_uploader, force_batch_file: options[:force_batch_file])
53
55
 
54
56
  log.info "Running WinRM command: '#{command}' on: '#{host}' as: '#{user}'"
55
57
 
@@ -93,10 +95,14 @@ module Ridley
93
95
  # limit. Otherwise, we return an execution of the command as a batch file.
94
96
  #
95
97
  # @param command [String]
98
+ # @param options [Hash]
99
+ #
100
+ # @option options [TrueClass, FalseClass] :force_batch_file
101
+ # Always use a batch file to run the command regardless of command length.
96
102
  #
97
103
  # @return [String]
98
- def get_command(command, command_uploader)
99
- if command.length < CommandUploader::CHUNK_LIMIT
104
+ def get_command(command, command_uploader, options = {})
105
+ if !options[:force_batch_file] && command.length < CommandUploader::CHUNK_LIMIT
100
106
  command
101
107
  else
102
108
  log.debug "Detected a command that was longer than #{CommandUploader::CHUNK_LIMIT} characters. " +
@@ -159,7 +165,10 @@ module Ridley
159
165
  run(host, command, options)
160
166
  end
161
167
 
162
- # Execute line(s) of Ruby code on a node using Chef's embedded Ruby
168
+ # Execute line(s) of Ruby code on a node using Chef's embedded
169
+ # Ruby. This will always run via a batch file due to WinRM
170
+ # having difficulty handling long ruby scripts being passed via
171
+ # ruby -e.
163
172
  #
164
173
  # @param [String] host
165
174
  # the host to perform the action on
@@ -174,7 +183,7 @@ module Ridley
174
183
  # @return [HostConnector::Response]
175
184
  def ruby_script(host, command_lines, options = {})
176
185
  command = "#{EMBEDDED_RUBY_PATH} -e \"#{command_lines.join(';')}\""
177
- run(host, command, options)
186
+ run(host, command, options.merge(force_batch_file: true))
178
187
  end
179
188
 
180
189
  # Uninstall Chef from a node
@@ -1,5 +1,5 @@
1
1
  module Ridley
2
2
  module Connectors
3
- VERSION = '1.2.0'
3
+ VERSION = '1.2.1'
4
4
  end
5
5
  end
@@ -2,9 +2,9 @@ require 'spec_helper'
2
2
 
3
3
  describe Ridley::HostCommander do
4
4
  subject { described_class.new }
5
+ let(:host) { "fake.riotgames.com" }
5
6
 
6
7
  describe "#run" do
7
- let(:host) { "fake.riotgames.com" }
8
8
  let(:command) { "ls" }
9
9
  let(:options) do
10
10
  { ssh: { port: 22 }, winrm: { port: 5985 } }
@@ -18,7 +18,6 @@ describe Ridley::HostCommander do
18
18
 
19
19
  it "sends a #run message to the ssh host connector" do
20
20
  subject.send(:ssh).should_receive(:run).with(host, command, options)
21
-
22
21
  subject.run(host, command, options)
23
22
  end
24
23
  end
@@ -38,7 +37,6 @@ describe Ridley::HostCommander do
38
37
  end
39
38
 
40
39
  describe "#bootstrap" do
41
- let(:host) { "fake.riotgames.com" }
42
40
  let(:options) do
43
41
  { ssh: { port: 22 }, winrm: { port: 5985 } }
44
42
  end
@@ -71,7 +69,6 @@ describe Ridley::HostCommander do
71
69
  end
72
70
 
73
71
  describe "#chef_client" do
74
- let(:host) { "fake.riotgames.com" }
75
72
  let(:options) do
76
73
  { ssh: { port: 22 }, winrm: { port: 5985 } }
77
74
  end
@@ -104,7 +101,6 @@ describe Ridley::HostCommander do
104
101
  end
105
102
 
106
103
  describe "#put_secret" do
107
- let(:host) { "fake.riotgames.com" }
108
104
  let(:secret) { "something_secret" }
109
105
  let(:options) do
110
106
  { ssh: { port: 22 }, winrm: { port: 5985 } }
@@ -138,7 +134,6 @@ describe Ridley::HostCommander do
138
134
  end
139
135
 
140
136
  describe "#ruby_script" do
141
- let(:host) { "fake.riotgames.com" }
142
137
  let(:command_lines) { ["line one"] }
143
138
  let(:options) do
144
139
  { ssh: { port: 22 }, winrm: { port: 5985 } }
@@ -170,4 +165,25 @@ describe Ridley::HostCommander do
170
165
  end
171
166
  end
172
167
  end
168
+
169
+ describe "#connector_for" do
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)
172
+ subject.should_receive(:winrm)
173
+ subject.connector_for(host)
174
+ end
175
+
176
+ it "should return winrm if winrm is open" do
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, nil).and_return(true)
179
+ subject.should_receive(:ssh)
180
+ subject.connector_for(host)
181
+ end
182
+
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)
185
+ subject.should_receive(:winrm)
186
+ subject.connector_for(host, winrm: nil, ssh: nil)
187
+ end
188
+ end
173
189
  end
@@ -99,6 +99,16 @@ describe Ridley::HostConnector::WinRM do
99
99
  expect(result.stderr).to eql("WinRM::WinRMHTTPTransportError")
100
100
  end
101
101
  end
102
+
103
+ context "when the force_batch_file is true" do
104
+ let(:options_with_force_batch_file) { options.merge(force_batch_file: true) }
105
+ subject(:result) { connector.run(host, command, options_with_force_batch_file) }
106
+ it "should always use a command uploader when a force_batch_file is set to true" do
107
+ command_uploader_stub.should_receive(:upload).with(command)
108
+ command_uploader_stub.should_receive(:command).and_return(command)
109
+ result
110
+ end
111
+ end
102
112
  end
103
113
 
104
114
  describe "#bootstrap" do
@@ -156,7 +166,7 @@ describe Ridley::HostConnector::WinRM do
156
166
  it "receives a ruby call with the command" do
157
167
  connector.should_receive(:run).with(host,
158
168
  "#{described_class::EMBEDDED_RUBY_PATH} -e \"puts 'hello';puts 'there'\"",
159
- options
169
+ options.merge(force_batch_file: true)
160
170
  )
161
171
 
162
172
  ruby_script
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.2.0
4
+ version: 1.2.1
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-01-29 00:00:00.000000000 Z
12
+ date: 2014-02-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: celluloid