ridley 0.10.0.rc1 → 0.10.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
- data/bootstrappers/windows_omnibus.erb +1 -22
- data/lib/ridley/bootstrap_bindings/windows_template_binding.rb +0 -53
- data/lib/ridley/bootstrapper.rb +13 -10
- data/lib/ridley/bootstrapper/context.rb +2 -1
- data/lib/ridley/errors.rb +3 -0
- data/lib/ridley/host_connector.rb +21 -16
- data/lib/ridley/host_connector/ssh/worker.rb +40 -2
- data/lib/ridley/host_connector/winrm.rb +1 -0
- data/lib/ridley/host_connector/winrm/command_uploader.rb +90 -0
- data/lib/ridley/host_connector/winrm/worker.rb +67 -47
- data/lib/ridley/resources/environment_resource.rb +1 -1
- data/lib/ridley/resources/node_resource.rb +106 -19
- data/lib/ridley/version.rb +1 -1
- data/spec/unit/ridley/bootstrap_bindings/windows_template_binding_spec.rb +0 -6
- data/spec/unit/ridley/bootstrapper_spec.rb +23 -3
- data/spec/unit/ridley/host_connector/ssh/worker_spec.rb +49 -7
- data/spec/unit/ridley/host_connector/ssh_spec.rb +4 -3
- data/spec/unit/ridley/host_connector/winrm/command_uploader_spec.rb +67 -0
- data/spec/unit/ridley/host_connector/winrm/worker_spec.rb +67 -21
- data/spec/unit/ridley/host_connector/winrm_spec.rb +5 -0
- data/spec/unit/ridley/host_connector_spec.rb +39 -10
- data/spec/unit/ridley/resources/node_resource_spec.rb +171 -4
- metadata +5 -2
@@ -10,6 +10,11 @@ describe Ridley::HostConnector::WinRM do
|
|
10
10
|
let(:node_two) do
|
11
11
|
Ridley::NodeResource.new(connection, automatic: { cloud: { public_hostname: "33.33.33.11" } })
|
12
12
|
end
|
13
|
+
let(:command_uploader) { double('command_uploader', cleanup: nil) }
|
14
|
+
|
15
|
+
before do
|
16
|
+
Ridley::HostConnector::WinRM::CommandUploader.stub(:new).and_return(command_uploader)
|
17
|
+
end
|
13
18
|
|
14
19
|
describe "ClassMethods" do
|
15
20
|
subject { Ridley::HostConnector::WinRM }
|
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Ridley::HostConnector do
|
4
|
-
|
5
4
|
subject do
|
6
5
|
described_class
|
7
6
|
end
|
@@ -14,29 +13,50 @@ describe Ridley::HostConnector do
|
|
14
13
|
described_class::DEFAULT_WINRM_PORT.should eq(5985)
|
15
14
|
end
|
16
15
|
|
17
|
-
describe "#connector_port_open" do
|
18
|
-
let(:host) {"127.0.0.1"}
|
19
|
-
let(:port) {22}
|
20
|
-
let(:socket) {double(:new => true, :close => nil)}
|
16
|
+
describe "#connector_port_open?" do
|
17
|
+
let(:host) { "127.0.0.1" }
|
18
|
+
let(:port) { 22 }
|
19
|
+
let(:socket) { double(:new => true, :close => nil) }
|
21
20
|
|
22
21
|
context "when a port is open" do
|
23
|
-
|
22
|
+
before do
|
24
23
|
TCPSocket.stub(:new).and_return(socket)
|
25
|
-
|
24
|
+
end
|
25
|
+
|
26
|
+
it "returns true" do
|
27
|
+
subject.connector_port_open?(host, port).should eql(true)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "closes the opened socket" do
|
31
|
+
socket.should_receive(:close)
|
32
|
+
subject.connector_port_open?(host, port)
|
26
33
|
end
|
27
34
|
end
|
28
35
|
|
29
36
|
context "when a port is closed" do
|
30
|
-
|
37
|
+
before do
|
31
38
|
TCPSocket.stub(:new).and_raise(Errno::ECONNREFUSED)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "returns false" do
|
32
42
|
subject.connector_port_open?(host, port).should eq(false)
|
33
43
|
end
|
34
44
|
end
|
45
|
+
|
46
|
+
context "when host is unreachable" do
|
47
|
+
before do
|
48
|
+
TCPSocket.stub(:new).and_raise(SocketError)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "returns false" do
|
52
|
+
subject.connector_port_open?(host, port).should eql(false)
|
53
|
+
end
|
54
|
+
end
|
35
55
|
end
|
36
56
|
|
37
57
|
describe "#best_connector_for" do
|
38
58
|
let(:host) {"127.0.0.1"}
|
39
|
-
|
59
|
+
|
40
60
|
context "when an SSH port is open" do
|
41
61
|
it "returns Ridley::HostConnector::SSH" do
|
42
62
|
subject.stub(:connector_port_open?).and_return(true)
|
@@ -59,6 +79,15 @@ describe Ridley::HostConnector do
|
|
59
79
|
}.to raise_error(Ridley::Errors::HostConnectionError)
|
60
80
|
end
|
61
81
|
end
|
82
|
+
|
83
|
+
context "when a block is provided" do
|
84
|
+
it "yields the best HostConnector to the block" do
|
85
|
+
subject.stub(:connector_port_open?).and_return(true)
|
86
|
+
subject.best_connector_for(host) do |yielded|
|
87
|
+
yielded.should eq(Ridley::HostConnector::SSH)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
62
91
|
end
|
63
92
|
|
64
93
|
describe "#parse_port_options" do
|
@@ -72,7 +101,7 @@ describe Ridley::HostConnector do
|
|
72
101
|
}
|
73
102
|
}
|
74
103
|
end
|
75
|
-
|
104
|
+
|
76
105
|
context "when :ssh has a key for :port" do
|
77
106
|
it "returns the value of port instead of the default" do
|
78
107
|
subject.parse_port_options(options).should include(1234)
|
@@ -10,13 +10,21 @@ describe Ridley::NodeResource do
|
|
10
10
|
ssh: {
|
11
11
|
user: "reset",
|
12
12
|
password: "lol"
|
13
|
-
}
|
13
|
+
},
|
14
|
+
winrm: {
|
15
|
+
user: "Administrator",
|
16
|
+
password: "secret"
|
17
|
+
},
|
18
|
+
encrypted_data_bag_secret_path: nil
|
14
19
|
)
|
15
20
|
end
|
21
|
+
let(:host) { "33.33.33.10" }
|
16
22
|
|
17
23
|
describe "ClassMethods" do
|
18
24
|
subject { Ridley::NodeResource }
|
19
25
|
|
26
|
+
let(:worker) { double('worker', alive?: true, terminate: nil) }
|
27
|
+
|
20
28
|
describe "::bootstrap" do
|
21
29
|
let(:boot_options) do
|
22
30
|
{
|
@@ -36,6 +44,133 @@ describe Ridley::NodeResource do
|
|
36
44
|
end
|
37
45
|
end
|
38
46
|
|
47
|
+
describe "::chef_run" do
|
48
|
+
subject { chef_run }
|
49
|
+
let(:chef_run) { described_class.chef_run(connection, host) }
|
50
|
+
let(:response) { [:ok, double('response', stdout: 'success_message')] }
|
51
|
+
|
52
|
+
before do
|
53
|
+
Ridley::NodeResource.stub(:configured_worker_for).and_return(worker)
|
54
|
+
worker.stub(:chef_client).and_return(response)
|
55
|
+
end
|
56
|
+
|
57
|
+
it { should eq(response) }
|
58
|
+
|
59
|
+
context "when it executes unsuccessfully" do
|
60
|
+
let(:response) { [:error, double('response', stderr: 'failure_message')] }
|
61
|
+
|
62
|
+
it {should eq(response)}
|
63
|
+
end
|
64
|
+
|
65
|
+
it "terminates the worker" do
|
66
|
+
worker.should_receive(:terminate)
|
67
|
+
chef_run
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "::put_secret" do
|
72
|
+
subject { put_secret }
|
73
|
+
let(:put_secret) { described_class.put_secret(connection, host, secret_path)}
|
74
|
+
let(:response) { [:ok, double('response', stdout: 'success_message')] }
|
75
|
+
let(:secret_path) { fixtures_path.join("reset.pem").to_s }
|
76
|
+
|
77
|
+
before do
|
78
|
+
Ridley::NodeResource.stub(:configured_worker_for).and_return(worker)
|
79
|
+
worker.stub(:put_secret).and_return(response)
|
80
|
+
end
|
81
|
+
|
82
|
+
it { should eq(response) }
|
83
|
+
|
84
|
+
context "when it executes unsuccessfully" do
|
85
|
+
let(:response) { [:error, double('response', stderr: 'failure_message')] }
|
86
|
+
|
87
|
+
it { should eq(response) }
|
88
|
+
end
|
89
|
+
|
90
|
+
it "terminates the worker" do
|
91
|
+
worker.should_receive(:terminate)
|
92
|
+
put_secret
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
describe "::ruby_script" do
|
97
|
+
subject { ruby_script }
|
98
|
+
let(:ruby_script) { described_class.ruby_script(connection, host, command_lines) }
|
99
|
+
let(:response) { [:ok, double('response', stdout: 'success_message')] }
|
100
|
+
let(:command_lines) { ["puts 'hello'", "puts 'there'"] }
|
101
|
+
|
102
|
+
before do
|
103
|
+
Ridley::NodeResource.stub(:configured_worker_for).and_return(worker)
|
104
|
+
worker.stub(:ruby_script).and_return(response)
|
105
|
+
end
|
106
|
+
|
107
|
+
it { should eq(response) }
|
108
|
+
|
109
|
+
context "when it executes unsuccessfully" do
|
110
|
+
let(:response) { [:error, double('response', stderr: 'failure_message')] }
|
111
|
+
|
112
|
+
it { should eq(response) }
|
113
|
+
end
|
114
|
+
|
115
|
+
it "terminates the worker" do
|
116
|
+
worker.should_receive(:terminate)
|
117
|
+
ruby_script
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
describe "::execute_command" do
|
122
|
+
subject { execute_command }
|
123
|
+
|
124
|
+
let(:execute_command) { described_class.execute_command(connection, host, command) }
|
125
|
+
let(:response) { [:ok, double('response', stdout: 'success_message')] }
|
126
|
+
let(:command) { "echo 'hello world'" }
|
127
|
+
|
128
|
+
before do
|
129
|
+
Ridley::NodeResource.stub(:configured_worker_for).and_return(worker)
|
130
|
+
worker.stub(:run).and_return(response)
|
131
|
+
end
|
132
|
+
|
133
|
+
it { should eq(response) }
|
134
|
+
|
135
|
+
context "when it executes unsuccessfully" do
|
136
|
+
let(:response) { [:error, double('response', stderr: 'failure_message')] }
|
137
|
+
|
138
|
+
it { should eq(response) }
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
describe "::configured_worker_for" do
|
143
|
+
subject { configured_worker_for }
|
144
|
+
|
145
|
+
let(:configured_worker_for) { described_class.send(:configured_worker_for, connection, host) }
|
146
|
+
|
147
|
+
context "when the best connector is SSH" do
|
148
|
+
before do
|
149
|
+
Ridley::HostConnector.stub(:best_connector_for).and_yield(Ridley::HostConnector::SSH)
|
150
|
+
end
|
151
|
+
|
152
|
+
it "returns an SSH worker instance" do
|
153
|
+
configured_worker_for.should be_a(Ridley::HostConnector::SSH::Worker)
|
154
|
+
end
|
155
|
+
|
156
|
+
its(:user) { should eq("reset") }
|
157
|
+
end
|
158
|
+
|
159
|
+
context "when the best connector is WinRM" do
|
160
|
+
before do
|
161
|
+
Ridley::HostConnector.stub(:best_connector_for).and_yield(Ridley::HostConnector::WinRM)
|
162
|
+
Ridley::HostConnector::WinRM::CommandUploader.stub(:new)
|
163
|
+
end
|
164
|
+
|
165
|
+
it "returns a WinRm worker instance" do
|
166
|
+
configured_worker_for.should be_a(Ridley::HostConnector::WinRM::Worker)
|
167
|
+
end
|
168
|
+
|
169
|
+
its(:user) { should eq("Administrator") }
|
170
|
+
its(:password) { should eq("secret") }
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
39
174
|
describe "::merge_data" do
|
40
175
|
it "finds the target node and sends it the merge_data message" do
|
41
176
|
data = double('data')
|
@@ -48,7 +183,8 @@ describe Ridley::NodeResource do
|
|
48
183
|
end
|
49
184
|
end
|
50
185
|
|
51
|
-
subject {
|
186
|
+
subject { node_resource }
|
187
|
+
let(:node_resource) { Ridley::NodeResource.new(connection) }
|
52
188
|
|
53
189
|
describe "#set_chef_attribute" do
|
54
190
|
it "sets an normal node attribute at the nested path" do
|
@@ -242,11 +378,42 @@ describe Ridley::NodeResource do
|
|
242
378
|
end
|
243
379
|
|
244
380
|
describe "#chef_client" do
|
245
|
-
|
381
|
+
subject { chef_client }
|
382
|
+
let(:chef_client) { node_resource.chef_client }
|
383
|
+
let(:worker) { double('worker', chef_client: response) }
|
384
|
+
let(:response) { [:ok, Ridley::HostConnector::Response.new(host)] }
|
385
|
+
|
386
|
+
before do
|
387
|
+
Ridley::HostConnector.stub(:best_connector_for).and_yield(Ridley::HostConnector::SSH)
|
388
|
+
Ridley::HostConnector::SSH.stub(:start).and_yield(worker)
|
389
|
+
end
|
390
|
+
|
391
|
+
it "returns a HostConnector::Response" do
|
392
|
+
|
393
|
+
chef_client.should be_a(Ridley::HostConnector::Response)
|
394
|
+
end
|
246
395
|
end
|
247
396
|
|
248
397
|
describe "#put_secret" do
|
249
|
-
|
398
|
+
subject { put_secret }
|
399
|
+
let(:put_secret) { node_resource.put_secret }
|
400
|
+
let(:worker) { double('worker', put_secret: response) }
|
401
|
+
let(:response) { [:ok, Ridley::HostConnector::Response.new(host)] }
|
402
|
+
|
403
|
+
before do
|
404
|
+
Ridley::HostConnector.stub(:best_connector_for).and_yield(Ridley::HostConnector::SSH)
|
405
|
+
Ridley::HostConnector::SSH.stub(:start).and_yield(worker)
|
406
|
+
end
|
407
|
+
|
408
|
+
context "when the client does not have an encrypted file" do
|
409
|
+
it "returns nil" do
|
410
|
+
put_secret.should be_nil
|
411
|
+
end
|
412
|
+
end
|
413
|
+
|
414
|
+
it "returns a HostConnector::Response" do
|
415
|
+
pending
|
416
|
+
end
|
250
417
|
end
|
251
418
|
|
252
419
|
describe "#merge_data" do
|
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: 0.10.0.
|
4
|
+
version: 0.10.0.rc2
|
5
5
|
prerelease: 7
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-04-
|
12
|
+
date: 2013-04-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
@@ -321,6 +321,7 @@ files:
|
|
321
321
|
- lib/ridley/host_connector/ssh.rb
|
322
322
|
- lib/ridley/host_connector/ssh/worker.rb
|
323
323
|
- lib/ridley/host_connector/winrm.rb
|
324
|
+
- lib/ridley/host_connector/winrm/command_uploader.rb
|
324
325
|
- lib/ridley/host_connector/winrm/worker.rb
|
325
326
|
- lib/ridley/log.rb
|
326
327
|
- lib/ridley/logging.rb
|
@@ -391,6 +392,7 @@ files:
|
|
391
392
|
- spec/unit/ridley/host_connector/response_set_spec.rb
|
392
393
|
- spec/unit/ridley/host_connector/ssh/worker_spec.rb
|
393
394
|
- spec/unit/ridley/host_connector/ssh_spec.rb
|
395
|
+
- spec/unit/ridley/host_connector/winrm/command_uploader_spec.rb
|
394
396
|
- spec/unit/ridley/host_connector/winrm/worker_spec.rb
|
395
397
|
- spec/unit/ridley/host_connector/winrm_spec.rb
|
396
398
|
- spec/unit/ridley/host_connector_spec.rb
|
@@ -478,6 +480,7 @@ test_files:
|
|
478
480
|
- spec/unit/ridley/host_connector/response_set_spec.rb
|
479
481
|
- spec/unit/ridley/host_connector/ssh/worker_spec.rb
|
480
482
|
- spec/unit/ridley/host_connector/ssh_spec.rb
|
483
|
+
- spec/unit/ridley/host_connector/winrm/command_uploader_spec.rb
|
481
484
|
- spec/unit/ridley/host_connector/winrm/worker_spec.rb
|
482
485
|
- spec/unit/ridley/host_connector/winrm_spec.rb
|
483
486
|
- spec/unit/ridley/host_connector_spec.rb
|