ridley 1.2.3 → 1.2.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +5 -3
- data/lib/ridley/errors.rb +12 -0
- data/lib/ridley/host_commander.rb +30 -29
- data/lib/ridley/host_connector/winrm.rb +5 -1
- data/lib/ridley/resources/node_resource.rb +25 -1
- data/lib/ridley/version.rb +1 -1
- data/spec/unit/ridley/resources/node_resource_spec.rb +71 -0
- metadata +3 -3
data/.travis.yml
CHANGED
@@ -1,11 +1,13 @@
|
|
1
|
-
script: "bundle exec thor spec
|
1
|
+
script: "bundle exec thor spec:$TEST_SUITE"
|
2
2
|
language: ruby
|
3
|
+
env:
|
4
|
+
- TEST_SUITE=unit
|
5
|
+
- TEST_SUITE=acceptance
|
3
6
|
rvm:
|
4
7
|
- 1.9.2
|
5
8
|
- 1.9.3
|
6
9
|
- 2.0.0
|
7
10
|
- jruby-19mode
|
8
|
-
|
9
11
|
matrix:
|
10
12
|
allow_failures:
|
11
|
-
- rvm: jruby-19mode
|
13
|
+
- rvm: jruby-19mode
|
data/lib/ridley/errors.rb
CHANGED
@@ -50,6 +50,18 @@ module Ridley
|
|
50
50
|
|
51
51
|
class RemoteCommandError < RidleyError; end
|
52
52
|
class RemoteScriptError < RemoteCommandError; end
|
53
|
+
class CommandNotProvided < RemoteCommandError
|
54
|
+
attr_reader :connector_type
|
55
|
+
|
56
|
+
# @params [Symbol] connector_type
|
57
|
+
def initialize(connector_type)
|
58
|
+
@connector_type = connector_type
|
59
|
+
end
|
60
|
+
|
61
|
+
def to_s
|
62
|
+
"No command provided in #{connector_type.inspect}, however the #{connector_type.inspect} connector was selected."
|
63
|
+
end
|
64
|
+
end
|
53
65
|
|
54
66
|
# Exception thrown when the maximum amount of requests is exceeded.
|
55
67
|
class RedirectLimitReached < RidleyError
|
@@ -156,6 +156,36 @@ module Ridley
|
|
156
156
|
execute(__method__, host, options)
|
157
157
|
end
|
158
158
|
|
159
|
+
# Finds and returns the best HostConnector for a given host
|
160
|
+
#
|
161
|
+
# @param [String] host
|
162
|
+
# the host to attempt to connect to
|
163
|
+
# @option options [Hash] :ssh
|
164
|
+
# * :port (Fixnum) the ssh port to connect on the node the bootstrap will be performed on (22)
|
165
|
+
# * :timeout (Float) [5.0] timeout value for testing SSH connection
|
166
|
+
# @option options [Hash] :winrm
|
167
|
+
# * :port (Fixnum) the winrm port to connect on the node the bootstrap will be performed on (5985)
|
168
|
+
# @param block [Proc]
|
169
|
+
# an optional block that is yielded the best HostConnector
|
170
|
+
#
|
171
|
+
# @return [HostConnector::SSH, HostConnector::WinRM]
|
172
|
+
def connector_for(host, options = {})
|
173
|
+
options = options.reverse_merge(ssh: Hash.new, winrm: Hash.new)
|
174
|
+
options[:ssh][:port] ||= HostConnector::SSH::DEFAULT_PORT
|
175
|
+
options[:winrm][:port] ||= HostConnector::WinRM::DEFAULT_PORT
|
176
|
+
|
177
|
+
if connector_port_open?(host, options[:winrm][:port])
|
178
|
+
options.delete(:ssh)
|
179
|
+
winrm
|
180
|
+
elsif connector_port_open?(host, options[:ssh][:port], options[:ssh][:timeout])
|
181
|
+
options.delete(:winrm)
|
182
|
+
ssh
|
183
|
+
else
|
184
|
+
raise Errors::HostConnectionError, "No connector ports open on '#{host}'"
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
|
159
189
|
private
|
160
190
|
|
161
191
|
def execute(method, host, *args)
|
@@ -166,35 +196,6 @@ module Ridley
|
|
166
196
|
abort(ex)
|
167
197
|
end
|
168
198
|
|
169
|
-
# Finds and returns the best HostConnector for a given host
|
170
|
-
#
|
171
|
-
# @param [String] host
|
172
|
-
# the host to attempt to connect to
|
173
|
-
# @option options [Hash] :ssh
|
174
|
-
# * :port (Fixnum) the ssh port to connect on the node the bootstrap will be performed on (22)
|
175
|
-
# * :timeout (Float) [5.0] timeout value for testing SSH connection
|
176
|
-
# @option options [Hash] :winrm
|
177
|
-
# * :port (Fixnum) the winrm port to connect on the node the bootstrap will be performed on (5985)
|
178
|
-
# @param block [Proc]
|
179
|
-
# an optional block that is yielded the best HostConnector
|
180
|
-
#
|
181
|
-
# @return [HostConnector::SSH, HostConnector::WinRM]
|
182
|
-
def connector_for(host, options = {})
|
183
|
-
options = options.reverse_merge(ssh: Hash.new, winrm: Hash.new)
|
184
|
-
options[:ssh][:port] ||= HostConnector::SSH::DEFAULT_PORT
|
185
|
-
options[:winrm][:port] ||= HostConnector::WinRM::DEFAULT_PORT
|
186
|
-
|
187
|
-
if connector_port_open?(host, options[:winrm][:port])
|
188
|
-
options.delete(:ssh)
|
189
|
-
winrm
|
190
|
-
elsif connector_port_open?(host, options[:ssh][:port], options[:ssh][:timeout])
|
191
|
-
options.delete(:winrm)
|
192
|
-
ssh
|
193
|
-
else
|
194
|
-
raise Errors::HostConnectionError, "No connector ports open on '#{host}'"
|
195
|
-
end
|
196
|
-
end
|
197
|
-
|
198
199
|
# Checks to see if the given port is open for TCP connections
|
199
200
|
# on the given host.
|
200
201
|
#
|
@@ -80,7 +80,11 @@ module Ridley
|
|
80
80
|
end
|
81
81
|
end
|
82
82
|
ensure
|
83
|
-
|
83
|
+
begin
|
84
|
+
command_uploaders.map(&:cleanup)
|
85
|
+
rescue ::WinRM::WinRMHTTPTransportError => ex
|
86
|
+
log.info "Error cleaning up leftover Powershell scripts on some hosts"
|
87
|
+
end
|
84
88
|
end
|
85
89
|
|
86
90
|
# Returns the command if it does not break the WinRM command length
|
@@ -132,12 +132,36 @@ module Ridley
|
|
132
132
|
# @param [String] host
|
133
133
|
# @param [String] command
|
134
134
|
#
|
135
|
-
# @return [
|
135
|
+
# @return [HostConnector::Response]
|
136
136
|
def run(host, command)
|
137
137
|
host_commander.run(host, command, ssh: ssh, winrm: winrm)
|
138
138
|
end
|
139
139
|
alias_method :execute_command, :run
|
140
140
|
|
141
|
+
# Executes the given command on a node using a platform specific
|
142
|
+
# command.
|
143
|
+
#
|
144
|
+
# @param [String] host
|
145
|
+
# @param [Hash] commands
|
146
|
+
#
|
147
|
+
# @example
|
148
|
+
# platform_specific_run("host.example.com", linux: "hostname -f", windows: "echo %COMPUTERNAME%")
|
149
|
+
#
|
150
|
+
# @return [HostConnector::Response]
|
151
|
+
def platform_specific_run(host, commands)
|
152
|
+
case (type = host_commander.connector_for(host, ssh: ssh, winrm: winrm))
|
153
|
+
when HostConnector::SSH
|
154
|
+
raise Errors::CommandNotProvided.new(:ssh) unless commands[:ssh] and !commands[:ssh].empty?
|
155
|
+
run(host, commands[:ssh])
|
156
|
+
when HostConnector::WinRM
|
157
|
+
raise Errors::CommandNotProvided.new(:winrm) unless commands[:winrm] and !commands[:winrm].empty?
|
158
|
+
run(host, commands[:winrm])
|
159
|
+
else
|
160
|
+
raise RuntimeError, "#{type.class.to_s} is not a supported connector for #{self.class}##{__method__}"
|
161
|
+
end
|
162
|
+
end
|
163
|
+
alias_method :execute_platform_specific_command, :platform_specific_run
|
164
|
+
|
141
165
|
# Merges the given data with the the data of the target node on the remote
|
142
166
|
#
|
143
167
|
# @param [Ridley::NodeResource, String] target
|
data/lib/ridley/version.rb
CHANGED
@@ -67,6 +67,77 @@ describe Ridley::NodeResource do
|
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
|
+
describe "#platform_specific_run" do
|
71
|
+
let(:ssh_command) { "hostname -f" }
|
72
|
+
let(:winrm_command) { "echo %COMPUTERNAME%" }
|
73
|
+
let(:ssh_connector) { Ridley::HostConnector::SSH.new }
|
74
|
+
let(:winrm_connector) { Ridley::HostConnector::WinRM.new }
|
75
|
+
let(:unsupported_connector) { Object.new }
|
76
|
+
|
77
|
+
describe "expecting the ssh connector" do
|
78
|
+
before do
|
79
|
+
host_commander.stub(:connector_for).and_return ssh_connector
|
80
|
+
end
|
81
|
+
it "sends the ssh command" do
|
82
|
+
instance.should_receive(:run).with(host, ssh_command)
|
83
|
+
instance.platform_specific_run(host, ssh: ssh_command, winrm: winrm_command)
|
84
|
+
end
|
85
|
+
|
86
|
+
it "raises an error if no command is provided for the ssh connector when the ssh connector is used" do
|
87
|
+
expect {
|
88
|
+
instance.platform_specific_run(host, winrm: winrm_command)
|
89
|
+
}.to raise_error(Ridley::Errors::CommandNotProvided)
|
90
|
+
end
|
91
|
+
|
92
|
+
it "raises an error if an empty command is provided for the ssh connector when the ssh connector is used" do
|
93
|
+
expect {
|
94
|
+
instance.platform_specific_run(host, ssh: "", winrm: winrm_command)
|
95
|
+
}.to raise_error(Ridley::Errors::CommandNotProvided)
|
96
|
+
end
|
97
|
+
|
98
|
+
it "raises an error if a nil command is provided for the ssh connector when the ssh connector is used" do
|
99
|
+
expect {
|
100
|
+
instance.platform_specific_run(host, ssh: nil, winrm: winrm_command)
|
101
|
+
}.to raise_error(Ridley::Errors::CommandNotProvided)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
describe "expecting the winrm connector" do
|
106
|
+
before do
|
107
|
+
host_commander.stub(:connector_for).and_return winrm_connector
|
108
|
+
end
|
109
|
+
it "sends the ssh command if the connector is winrm" do
|
110
|
+
instance.should_receive(:run).with(host, winrm_command)
|
111
|
+
instance.platform_specific_run(host, ssh: ssh_command, winrm: winrm_command)
|
112
|
+
end
|
113
|
+
|
114
|
+
it "raises an error if no command is provided for the winrm connector when the winrm connector is used" do
|
115
|
+
expect {
|
116
|
+
instance.platform_specific_run(host, ssh: ssh_command)
|
117
|
+
}.to raise_error(Ridley::Errors::CommandNotProvided)
|
118
|
+
end
|
119
|
+
|
120
|
+
it "raises an error if an empty is provided for the winrm connector when the winrm connector is used" do
|
121
|
+
expect {
|
122
|
+
instance.platform_specific_run(host, ssh: ssh_command, winrm: "")
|
123
|
+
}.to raise_error(Ridley::Errors::CommandNotProvided)
|
124
|
+
end
|
125
|
+
|
126
|
+
it "raises a nil command is provided for the winrm connector when the winrm connector is used" do
|
127
|
+
expect {
|
128
|
+
instance.platform_specific_run(host, ssh: ssh_command, winrm: nil)
|
129
|
+
}.to raise_error(Ridley::Errors::CommandNotProvided)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
it "raises a RuntimeError if an unsupported connector is used" do
|
134
|
+
host_commander.stub(:connector_for).and_return unsupported_connector
|
135
|
+
expect {
|
136
|
+
instance.platform_specific_run(host, ssh: ssh_command, winrm: winrm_command)
|
137
|
+
}.to raise_error(RuntimeError)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
70
141
|
describe "#merge_data" do
|
71
142
|
let(:node_name) { "rspec-test" }
|
72
143
|
let(:run_list) { [ "recipe[one]", "recipe[two]" ] }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ridley
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-06-
|
13
|
+
date: 2013-06-29 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: addressable
|
@@ -454,7 +454,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
454
454
|
version: '0'
|
455
455
|
segments:
|
456
456
|
- 0
|
457
|
-
hash: -
|
457
|
+
hash: -3781892320161055859
|
458
458
|
requirements: []
|
459
459
|
rubyforge_project:
|
460
460
|
rubygems_version: 1.8.23
|