ridley 1.7.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,57 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Ridley::HostConnector::SSH do
4
- subject { connector }
5
- let(:connector) { described_class.new }
6
-
7
- let(:host) { 'reset.riotgames.com' }
8
- let(:options) do
9
- {
10
- server_url: double('server_url'),
11
- validator_path: fixtures_path.join('reset.pem'),
12
- validator_client: double('validator_client'),
13
- encrypted_data_bag_secret: 'encrypted_data_bag_secret',
14
- ssh: Hash.new,
15
- chef_version: double('chef_version')
16
- }
17
- end
18
-
19
- describe "#bootstrap" do
20
- it "sends a #run message to self to bootstrap a node" do
21
- connector.should_receive(:run).with(host, anything, options)
22
- connector.bootstrap(host, options)
23
- end
24
- end
25
-
26
- describe "#chef_client" do
27
- it "sends a #run message to self to execute chef-client" do
28
- connector.should_receive(:run).with(host, "chef-client", options)
29
- connector.chef_client(host, options)
30
- end
31
- end
32
-
33
- describe "#put_secret" do
34
- let(:encrypted_data_bag_secret_path) { fixtures_path.join("encrypted_data_bag_secret").to_s }
35
- let(:secret) { File.read(encrypted_data_bag_secret_path).chomp }
36
-
37
- it "receives a run command with echo" do
38
- connector.should_receive(:run).with(host,
39
- "echo '#{secret}' > /etc/chef/encrypted_data_bag_secret; chmod 0600 /etc/chef/encrypted_data_bag_secret",
40
- options
41
- )
42
- connector.put_secret(host, secret, options)
43
- end
44
- end
45
-
46
- describe "#ruby_script" do
47
- let(:command_lines) { ["puts 'hello'", "puts 'there'"] }
48
-
49
- it "receives a ruby call with the command" do
50
- connector.should_receive(:run).with(host,
51
- "#{described_class::EMBEDDED_RUBY_PATH} -e \"puts 'hello';puts 'there'\"",
52
- options
53
- )
54
- connector.ruby_script(host, command_lines, options)
55
- end
56
- end
57
- end
@@ -1,67 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Ridley::HostConnector::WinRM::CommandUploader do
4
- let(:winrm_stub) {
5
- double('WinRM',
6
- run_cmd: run_cmd_data,
7
- powershell: nil
8
- )
9
- }
10
-
11
- subject { command_uploader }
12
-
13
- let(:command_uploader) { described_class.new(winrm_stub) }
14
- let(:command_string) { "a" * 2048 }
15
- let(:run_cmd_data) { { data: [{ stdout: "abc123" }] } }
16
- let(:command_file_name) { "my_command.bat" }
17
-
18
- its(:winrm) { should eq(winrm_stub) }
19
-
20
- before do
21
- command_uploader.stub(:get_file_path).and_return("")
22
- end
23
-
24
- describe "#upload" do
25
- let(:upload) { command_uploader.upload(command_string) }
26
-
27
- it "calls winrm to upload and convert the command" do
28
- winrm_stub.should_receive(:run_cmd).and_return(
29
- run_cmd_data,
30
- nil,
31
- run_cmd_data
32
- )
33
- winrm_stub.should_receive(:powershell)
34
-
35
- upload
36
- end
37
- end
38
-
39
- describe "#command" do
40
- subject { command }
41
- let(:command) { command_uploader.command }
42
-
43
- before do
44
- command_uploader.stub command_file_name: command_file_name
45
- end
46
-
47
- it { should eq("cmd.exe /C #{command_file_name}") }
48
- end
49
-
50
- describe "#cleanup" do
51
- subject { cleanup }
52
-
53
- let(:cleanup) { command_uploader.cleanup }
54
- let(:base64_file_name) { "my_base64_file" }
55
-
56
- before do
57
- command_uploader.stub command_file_name: command_file_name
58
- command_uploader.stub base64_file_name: base64_file_name
59
- end
60
-
61
- it "cleans up the windows temp dir" do
62
- winrm_stub.should_receive(:run_cmd).with("del #{base64_file_name} /F /Q")
63
- winrm_stub.should_receive(:run_cmd).with("del #{command_file_name} /F /Q")
64
- cleanup
65
- end
66
- end
67
- end
@@ -1,145 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Ridley::HostConnector::WinRM do
4
- subject { connector }
5
- let(:connector) { described_class.new }
6
- let(:host) { 'reset.riotgames.com' }
7
- let(:options) do
8
- {
9
- server_url: double('server_url'),
10
- validator_path: fixtures_path.join('reset.pem'),
11
- validator_client: double('validator_client'),
12
- encrypted_data_bag_secret: 'encrypted_data_bag_secret',
13
- winrm: Hash.new,
14
- chef_version: double('chef_version')
15
- }
16
- end
17
-
18
- before { described_class::CommandUploader.stub(:new).and_return(double('command_uploader')) }
19
-
20
- describe "#get_command" do
21
- subject(:get_command) { connector.get_command(command, command_uploader_stub) }
22
-
23
- let(:command) { "echo %TEMP%" }
24
- let(:command_uploader_stub) { double('CommandUploader') }
25
-
26
- it { should eq(command) }
27
-
28
- context "when a command is more than 2047 characters" do
29
- let(:command) { "a" * 2048 }
30
-
31
- it "uploads and returns a command" do
32
- described_class::CommandUploader.stub(new: command_uploader_stub)
33
-
34
- command_uploader_stub.should_receive :upload
35
- command_uploader_stub.stub command: "my command"
36
- command_uploader_stub.stub(:cleanup)
37
-
38
- get_command.should eq("my command")
39
- end
40
- end
41
- end
42
-
43
- describe "#run" do
44
- subject(:result) { connector.run(host, command, options) }
45
- let(:command) { "dir" }
46
- let(:command_uploader_stub) { double('CommandUploader', cleanup: true) }
47
- let(:stdout) { "stdout" }
48
- let(:stderr) { nil }
49
- let(:winrm_stub) { double }
50
-
51
- before do
52
- described_class::CommandUploader.stub(:new).and_return(command_uploader_stub)
53
- connector.stub(:winrm).and_return(winrm_stub)
54
- winrm_stub.stub(:run_cmd).and_yield(stdout, stderr).and_return(exitcode: 0)
55
- end
56
-
57
- context "when the exit_code is 0" do
58
- it "returns a non-error HostConnector::Response" do
59
- expect(result).to be_a(Ridley::HostConnector::Response)
60
- expect(result).to_not be_error
61
- end
62
-
63
- it "sets the response's stdout message" do
64
- expect(result.stdout).to eq("stdout")
65
- end
66
- end
67
-
68
- context "when the exit_code is not 0" do
69
- let(:stderr) { "stderr" }
70
-
71
- before do
72
- winrm_stub.stub(:run_cmd).and_yield(stdout, stderr).and_return(exitcode: 1)
73
- end
74
-
75
- it "returns an error HostConnector::Response with an error" do
76
- expect(result).to be_a(Ridley::HostConnector::Response)
77
- expect(result).to be_error
78
- end
79
-
80
- it "sets the response's stderr message" do
81
- expect(result.stderr).to eq("stderr")
82
- end
83
- end
84
-
85
- context "when a WinRM::WinRMHTTPTransportError error is raised" do
86
- let(:stderr) { "error" }
87
- before { winrm_stub.stub(:run_cmd).and_yield(stdout, stderr).and_raise(::WinRM::WinRMHTTPTransportError) }
88
-
89
- it "returns an error HostConnector::Response with an error" do
90
- expect(result).to be_a(Ridley::HostConnector::Response)
91
- expect(result).to be_error
92
- end
93
-
94
- it "sets the response's stderr message to the exception's message" do
95
- expect(result.stderr).to eql("WinRM::WinRMHTTPTransportError")
96
- end
97
- end
98
- end
99
-
100
- describe "#bootstrap" do
101
- it "sends a #run message to self to bootstrap a node" do
102
- connector.should_receive(:run).with(host, anything, options)
103
- connector.bootstrap(host, options)
104
- end
105
- end
106
-
107
- describe "#chef_client" do
108
- subject(:chef_client) { connector.chef_client(host, options) }
109
-
110
- it "receives a command to run chef-client" do
111
- connector.should_receive(:run).with(host, "chef-client", options)
112
-
113
- chef_client
114
- end
115
- end
116
-
117
- describe "#put_secret" do
118
- subject(:put_secret) { connector.put_secret(host, secret, options) }
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
- connector.should_receive(:run).with(host,
124
- "echo #{secret} > C:\\chef\\encrypted_data_bag_secret",
125
- options
126
- )
127
-
128
- put_secret
129
- end
130
- end
131
-
132
- describe "#ruby_script" do
133
- subject(:ruby_script) { connector.ruby_script(host, command_lines, options) }
134
- let(:command_lines) { ["puts 'hello'", "puts 'there'"] }
135
-
136
- it "receives a ruby call with the command" do
137
- connector.should_receive(:run).with(host,
138
- "#{described_class::EMBEDDED_RUBY_PATH} -e \"puts 'hello';puts 'there'\"",
139
- options
140
- )
141
-
142
- ruby_script
143
- end
144
- end
145
- end
@@ -1,50 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Ridley::HostConnector::Base do
4
- subject { Class.new(Ridley::HostConnector::Base).new }
5
-
6
- let(:host) { double('host') }
7
- let(:options) { Hash.new }
8
-
9
- describe "#run" do
10
- let(:command) { double('command') }
11
-
12
- it "raises a RuntimeError" do
13
- expect { subject.run(host, command, options) }.to raise_error(RuntimeError)
14
- end
15
- end
16
-
17
- describe "#bootstrap" do
18
- it "raises a RuntimeError" do
19
- expect { subject.bootstrap(host, options) }.to raise_error(RuntimeError)
20
- end
21
- end
22
-
23
- describe "#chef_client" do
24
- it "raises a RuntimeError" do
25
- expect { subject.chef_client(host, options) }.to raise_error(RuntimeError)
26
- end
27
- end
28
-
29
- describe "#put_secret" do
30
- let(:secret) { double('secret') }
31
-
32
- it "raises a RuntimeError" do
33
- expect { subject.put_secret(host, secret, options) }.to raise_error(RuntimeError)
34
- end
35
- end
36
-
37
- describe "#ruby_script" do
38
- let(:command_lines) { double('command-lines') }
39
-
40
- it "raises a RuntimeError" do
41
- expect { subject.ruby_script(host, command_lines, options) }.to raise_error(RuntimeError)
42
- end
43
- end
44
-
45
- describe "#uninstall_chef" do
46
- it "raises a RuntimeError" do
47
- expect { subject.uninstall_chef(host, options) }.to raise_error(RuntimeError)
48
- end
49
- end
50
- end