ridley 0.12.4 → 1.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. data/Gemfile +1 -1
  2. data/lib/ridley.rb +3 -3
  3. data/lib/ridley/bootstrap_context.rb +100 -0
  4. data/lib/ridley/bootstrap_context/unix.rb +74 -0
  5. data/lib/ridley/bootstrap_context/windows.rb +120 -0
  6. data/lib/ridley/chef_objects/node_object.rb +8 -5
  7. data/lib/ridley/host_commander.rb +207 -0
  8. data/lib/ridley/host_connector.rb +49 -87
  9. data/lib/ridley/host_connector/ssh.rb +153 -39
  10. data/lib/ridley/host_connector/winrm.rb +164 -39
  11. data/lib/ridley/resources/node_resource.rb +52 -56
  12. data/lib/ridley/version.rb +1 -1
  13. data/ridley.gemspec +0 -2
  14. data/spec/spec_helper.rb +4 -4
  15. data/spec/support/chef_server.rb +9 -3
  16. data/spec/unit/ridley/{bootstrap_bindings/unix_template_binding_spec.rb → bootstrap_context/unix_spec.rb} +2 -2
  17. data/spec/unit/ridley/{bootstrap_bindings/windows_template_binding_spec.rb → bootstrap_context/windows_spec.rb} +2 -2
  18. data/spec/unit/ridley/{mixin/bootstrap_binding_spec.rb → bootstrap_context_spec.rb} +2 -6
  19. data/spec/unit/ridley/host_commander_spec.rb +208 -0
  20. data/spec/unit/ridley/host_connector/ssh_spec.rb +37 -31
  21. data/spec/unit/ridley/host_connector/winrm_spec.rb +124 -31
  22. data/spec/unit/ridley/host_connector_spec.rb +23 -147
  23. data/spec/unit/ridley/resources/node_resource_spec.rb +55 -115
  24. metadata +17 -66
  25. data/lib/ridley/bootstrap_bindings.rb +0 -3
  26. data/lib/ridley/bootstrap_bindings/unix_template_binding.rb +0 -108
  27. data/lib/ridley/bootstrap_bindings/windows_template_binding.rb +0 -163
  28. data/lib/ridley/bootstrapper.rb +0 -89
  29. data/lib/ridley/bootstrapper/context.rb +0 -81
  30. data/lib/ridley/host_connector/response_set.rb +0 -98
  31. data/lib/ridley/host_connector/ssh/worker.rb +0 -135
  32. data/lib/ridley/host_connector/winrm/worker.rb +0 -159
  33. data/lib/ridley/log.rb +0 -10
  34. data/lib/ridley/mixin/bootstrap_binding.rb +0 -77
  35. data/spec/unit/ridley/bootstrapper/context_spec.rb +0 -45
  36. data/spec/unit/ridley/bootstrapper_spec.rb +0 -96
  37. data/spec/unit/ridley/host_connector/response_set_spec.rb +0 -112
  38. data/spec/unit/ridley/host_connector/ssh/worker_spec.rb +0 -57
  39. data/spec/unit/ridley/host_connector/winrm/worker_spec.rb +0 -139
@@ -1,57 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Ridley::HostConnector::SSH::Worker do
4
- subject { ssh_worker }
5
- let(:ssh_worker) { described_class.new(host, options) }
6
-
7
- let(:host) { 'reset.riotgames.com' }
8
- let(:options) { {} }
9
-
10
- describe "#sudo" do
11
- subject { ssh_worker.sudo }
12
-
13
- it { should be_false }
14
-
15
- context "with sudo" do
16
- let(:options) { { ssh: { sudo: true } } }
17
-
18
- it { should be_true }
19
- end
20
- end
21
-
22
- describe "#chef_client" do
23
- subject(:chef_client) { ssh_worker.chef_client }
24
-
25
- it { should be_a(Array) }
26
-
27
- context "with sudo" do
28
- let(:options) { { ssh: { sudo: true } } }
29
-
30
- it "sends a run command with sudo" do
31
- ssh_worker.should_receive(:run).with("sudo chef-client")
32
- chef_client
33
- end
34
- end
35
- end
36
-
37
- describe "#put_secret" do
38
- subject(:put_secret) { ssh_worker.put_secret(secret) }
39
- let(:encrypted_data_bag_secret_path) { fixtures_path.join("encrypted_data_bag_secret").to_s }
40
- let(:secret) { File.read(encrypted_data_bag_secret_path).chomp }
41
-
42
- it "receives a run command with echo" do
43
- ssh_worker.should_receive(:run).with("echo '#{secret}' > /etc/chef/encrypted_data_bag_secret; chmod 0600 /etc/chef/encrypted_data_bag_secret")
44
- put_secret
45
- end
46
- end
47
-
48
- describe "#ruby_script" do
49
- subject(:ruby_script) { ssh_worker.ruby_script(command_lines) }
50
- let(:command_lines) { ["puts 'hello'", "puts 'there'"] }
51
-
52
- it "receives a ruby call with the command" do
53
- ssh_worker.should_receive(:run).with("#{described_class::EMBEDDED_RUBY_PATH} -e \"puts 'hello';puts 'there'\"")
54
- ruby_script
55
- end
56
- end
57
- end
@@ -1,139 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Ridley::HostConnector::WinRM::Worker do
4
- subject { winrm_worker }
5
- let(:winrm_worker) { described_class.new(host, options) }
6
- let(:host) { 'reset.riotgames.com' }
7
- let(:options) { {} }
8
-
9
- before do
10
- Ridley::HostConnector::WinRM::CommandUploader.stub(:new).and_return(double('command_uploader'))
11
- end
12
-
13
- describe "#winrm_port" do
14
- subject(:winrm_port) { winrm_worker.winrm_port }
15
-
16
- it { should eq(Ridley::HostConnector::DEFAULT_WINRM_PORT) }
17
-
18
- context "when overridden" do
19
- let(:options) { { winrm: { port: 1234 } } }
20
-
21
- it { should eq(1234) }
22
- end
23
- end
24
-
25
- describe "#winrm" do
26
- subject { winrm_worker.winrm }
27
-
28
- it "returns a WinRM::WinRMWebService" do
29
- expect(subject).to be_a(::WinRM::WinRMWebService)
30
- end
31
- end
32
-
33
- describe "#get_command" do
34
- subject(:get_command) { winrm_worker.get_command(command, command_uploader_stub) }
35
-
36
- let(:command) { "echo %TEMP%" }
37
- let(:command_uploader_stub) { double('CommandUploader') }
38
-
39
- it { should eq(command) }
40
-
41
- context "when a command is more than 2047 characters" do
42
- let(:command) { "a" * 2048 }
43
-
44
- it "uploads and returns a command" do
45
- Ridley::HostConnector::WinRM::CommandUploader.stub new: command_uploader_stub
46
-
47
- command_uploader_stub.should_receive :upload
48
- command_uploader_stub.stub command: "my command"
49
- command_uploader_stub.stub(:cleanup)
50
-
51
- get_command.should eq("my command")
52
- end
53
- end
54
- end
55
-
56
- describe "#run" do
57
- subject(:run) { winrm_worker.run(command) }
58
- let(:command) { "dir" }
59
- let(:command_uploader_stub) { double('CommandUploader') }
60
- let(:stdout) { "stdout" }
61
- let(:stderr) { nil }
62
- let(:winrm_stub) { double }
63
-
64
- before do
65
- Ridley::HostConnector::WinRM::CommandUploader.stub(:new).and_return(command_uploader_stub)
66
- winrm_worker.stub(:winrm).and_return(winrm_stub)
67
- winrm_stub.stub(:run_cmd).and_yield(stdout, stderr).and_return({exitcode: 0})
68
- end
69
-
70
- context "when the exit_code is 0" do
71
- it "returns an :ok with the response" do
72
- status, response = run
73
- expect(status).to eq(:ok)
74
- expect(response.stdout).to eq("stdout")
75
- end
76
- end
77
-
78
- context "when the exit_code is not 0" do
79
- let(:stderr) { "stderr" }
80
-
81
- before do
82
- winrm_stub.stub(:run_cmd).and_yield(stdout, stderr).and_return({exitcode: 1})
83
- end
84
-
85
- it "returns an :error with the response" do
86
- status, response = run
87
- expect(status).to eq(:error)
88
- expect(response.stderr).to eq("stderr")
89
- end
90
- end
91
-
92
- context "when an error is raised" do
93
- let(:stderr) { "error" }
94
-
95
- before do
96
- winrm_stub.stub(:run_cmd).and_yield(stdout, stderr).and_raise("error")
97
- end
98
-
99
- it "returns an :error with the response" do
100
- status, response = run
101
- expect(status).to eq(:error)
102
- expect(response.stderr).to eq("error")
103
- end
104
- end
105
- end
106
-
107
- describe "#chef_client" do
108
- subject(:chef_client) { winrm_worker.chef_client }
109
-
110
- it "receives a command to run chef-client" do
111
- winrm_worker.should_receive(:run).with("chef-client")
112
-
113
- chef_client
114
- end
115
- end
116
-
117
- describe "#put_secret" do
118
- subject(:put_secret) { winrm_worker.put_secret(secret) }
119
- let(:encrypted_data_bag_secret_path) { fixtures_path.join("encrypted_data_bag_secret").to_s }
120
- let(:secret) { File.read(encrypted_data_bag_secret_path).chomp }
121
-
122
- it "receives a command to copy the secret" do
123
- winrm_worker.should_receive(:run).with("echo #{secret} > C:\\chef\\encrypted_data_bag_secret")
124
-
125
- put_secret
126
- end
127
- end
128
-
129
- describe "#ruby_script" do
130
- subject(:ruby_script) { winrm_worker.ruby_script(command_lines) }
131
- let(:command_lines) { ["puts 'hello'", "puts 'there'"] }
132
-
133
- it "receives a ruby call with the command" do
134
- winrm_worker.should_receive(:run).with("#{described_class::EMBEDDED_RUBY_PATH} -e \"puts 'hello';puts 'there'\"")
135
-
136
- ruby_script
137
- end
138
- end
139
- end