ridley-connectors 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,116 @@
1
+ require 'spec_helper'
2
+
3
+ describe Ridley::BootstrapContext::Windows do
4
+ let(:options) do
5
+ {
6
+ server_url: "https://api.opscode.com/organizations/vialstudios",
7
+ validator_client: "chef-validator",
8
+ validator_path: fixtures_path.join("my-fake.pem").to_s,
9
+ encrypted_data_bag_secret: File.read(fixtures_path.join("my-fake.pem")),
10
+ chef_version: "11.4.0"
11
+ }
12
+ end
13
+
14
+ describe "ClassMethods" do
15
+ subject { described_class }
16
+
17
+ describe "::new" do
18
+ context "when a chef_version is passed through" do
19
+ it "sets the chef_version attribute to the same value" do
20
+ subject.new(options).chef_version.should eq("11.4.0")
21
+ end
22
+ end
23
+
24
+ context "when the chef_version is not passed through" do
25
+ it "sets the chef_version to 'latest'" do
26
+ options.delete(:chef_version)
27
+ subject.new(options).chef_version.should eq("latest")
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+ subject { described_class.new(options) }
34
+
35
+ describe "MixinMethods" do
36
+ describe "#templates_path" do
37
+ it "returns a pathname" do
38
+ subject.templates_path.should be_a(Pathname)
39
+ end
40
+ end
41
+
42
+ describe "#first_boot" do
43
+ it "returns a string" do
44
+ subject.first_boot.should be_a(String)
45
+ end
46
+ end
47
+
48
+ describe "#encrypted_data_bag_secret" do
49
+ it "returns a string" do
50
+ subject.encrypted_data_bag_secret.should be_a(String)
51
+ end
52
+ end
53
+
54
+ describe "#validation_key" do
55
+ it "returns a string" do
56
+ subject.validation_key.should be_a(String)
57
+ end
58
+ end
59
+
60
+ describe "template" do
61
+ it "returns a string" do
62
+ subject.template.should be_a(Erubis::Eruby)
63
+ end
64
+ end
65
+ end
66
+
67
+ describe "#boot_command" do
68
+ it "returns a string" do
69
+ subject.boot_command.should be_a(String)
70
+ end
71
+ end
72
+
73
+ describe "#chef_run" do
74
+ it "returns a string" do
75
+ subject.chef_run.should be_a(String)
76
+ end
77
+ end
78
+
79
+ describe "#chef_config" do
80
+ it "returns a string" do
81
+ subject.chef_config.should be_a(String)
82
+ end
83
+ end
84
+
85
+ describe "#env_path" do
86
+ it "returns a string" do
87
+ expect(subject.env_path).to be_a(String)
88
+ end
89
+ end
90
+
91
+ describe "#default_template" do
92
+ it "returns a string" do
93
+ subject.default_template.should be_a(String)
94
+ end
95
+ end
96
+
97
+ describe "#bootstrap_directory" do
98
+ it "returns a string" do
99
+ subject.bootstrap_directory.should be_a(String)
100
+ end
101
+ end
102
+
103
+ describe "#escape_and_echo" do
104
+ let(:output) { "foo()" }
105
+
106
+ it "adds 'echo.' to the beginning of each line and escapes special batch characters" do
107
+ subject.escape_and_echo(output).should eq("echo.foo^(^)")
108
+ end
109
+ end
110
+
111
+ describe "#windows_wget_powershell" do
112
+ it "returns a string" do
113
+ subject.windows_wget_powershell.should be_a(String)
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+
3
+ describe Ridley::BootstrapContext::Base do
4
+ let(:host) { "reset.riotgames.com" }
5
+ let(:options) do
6
+ {
7
+ server_url: "https://api.opscode.com/organizations/vialstudios",
8
+ validator_client: "chef-validator",
9
+ validator_path: fixtures_path.join("my-fake.pem").to_s,
10
+ encrypted_data_bag_secret: File.read(fixtures_path.join("my-fake.pem")),
11
+ chef_version: "11.4.0"
12
+ }
13
+ end
14
+
15
+ describe "ClassMethods" do
16
+ subject { described_class }
17
+
18
+ describe ":included" do
19
+ context "when a class includes Ridley::BootstrapBinding" do
20
+ it "should have a validate_options class method`" do
21
+ subject.methods.should include(:validate_options)
22
+ end
23
+ end
24
+ end
25
+
26
+ describe ":validate_options" do
27
+ context "when server_url is not specified" do
28
+ let(:options) { Hash.new }
29
+
30
+ it "raises an ArgumentError" do
31
+ expect {
32
+ subject.validate_options(options)
33
+ }.to raise_error(Ridley::Errors::ArgumentError)
34
+ end
35
+ end
36
+ end
37
+
38
+ context "when validator_path is not specified" do
39
+ let(:options) do
40
+ {
41
+ server_url: "https://api.opscode.com/organizations/vialstudios"
42
+ }
43
+ end
44
+
45
+ it "raises an ArgumentError" do
46
+ expect {
47
+ subject.validate_options(options)
48
+ }.to raise_error(Ridley::Errors::ArgumentError)
49
+ end
50
+ end
51
+ end
52
+ end
@@ -26,7 +26,7 @@ describe Ridley::Client do
26
26
 
27
27
  it "assigns a 'winrm' attribute from the given 'winrm' option" do
28
28
  described_class.new(config).winrm.should eql({user: "fake", password: "password2", port: "5986"})
29
- end
29
+ end
30
30
  end
31
31
  end
32
32
  end
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+
3
+ describe Ridley::CommandContext::Base do
4
+ let(:command_context) { described_class.new }
5
+
6
+ describe "ClassMethods" do
7
+ describe "::template_file" do
8
+ let(:template_file) { described_class.template_file(filename) }
9
+ let(:filename) { "test" }
10
+
11
+ context "when a filename is provided" do
12
+ it "sets and returns a class variable" do
13
+ expect(template_file).to be_a(Pathname)
14
+ expect(template_file.to_path).to end_with("scripts/test.erb")
15
+ end
16
+ end
17
+ end
18
+ end
19
+
20
+ describe "#command" do
21
+ let(:command) { command_context.command }
22
+ let(:template) { double(:evaluate => nil) }
23
+
24
+ before do
25
+ command_context.stub(:template).and_return(template)
26
+ end
27
+
28
+ it "attempts to evaluate the template" do
29
+ command
30
+ expect(template).to have_received(:evaluate)
31
+ end
32
+ end
33
+ end
34
+
35
+ describe Ridley::CommandContext::Unix do
36
+ let(:unix) { described_class.new(options) }
37
+
38
+ describe "#command" do
39
+ context "when sudo is true" do
40
+ let(:command) { unix.command }
41
+ let(:template) { double(:evaluate => command_string) }
42
+ let(:options) do
43
+ {sudo: true}
44
+ end
45
+ let(:command_string) { "echo 'hi'" }
46
+
47
+ before do
48
+ unix.stub(:template).and_return(template)
49
+ end
50
+
51
+ it "prepends sudo to the command" do
52
+ expect(command).to eql("sudo echo 'hi'")
53
+ end
54
+ end
55
+ end
56
+ end
@@ -167,6 +167,29 @@ describe Ridley::HostCommander do
167
167
  end
168
168
 
169
169
  describe "#connector_for" do
170
+
171
+ context "when connector_port_open? experiences an error" do
172
+ let(:socket) { double(close: true) }
173
+
174
+
175
+ before do
176
+ @times_called = 0
177
+ Celluloid::IO::TCPSocket.stub(:new).and_return do
178
+ @times_called += 1
179
+ if @times_called == 1
180
+ raise Errno::ETIMEDOUT
181
+ else
182
+ socket
183
+ end
184
+ end
185
+ end
186
+
187
+ it "executes retry logic" do
188
+ expect(Celluloid::IO::TCPSocket).to receive(:new).twice
189
+ subject.connector_for(host)
190
+ end
191
+ end
192
+
170
193
  it "should return winrm if winrm is open" do
171
194
  subject.stub(:connector_port_open?).with(host, Ridley::HostConnector::WinRM::DEFAULT_PORT, anything, anything).and_return(true)
172
195
  subject.should_receive(:winrm)
@@ -21,29 +21,6 @@ describe Ridley::HostConnector::WinRM do
21
21
  ::WinRM::WinRMWebService.stub(:new).and_return(double(:set_timeout => nil, :run_cmd => {exitcode: 0}))
22
22
  end
23
23
 
24
- describe "#get_command" do
25
- subject(:get_command) { connector.get_command(command, command_uploader_stub) }
26
-
27
- let(:command) { "echo %TEMP%" }
28
- let(:command_uploader_stub) { double('CommandUploader') }
29
-
30
- it { should eq(command) }
31
-
32
- context "when a command is more than 2047 characters" do
33
- let(:command) { "a" * 2048 }
34
-
35
- it "uploads and returns a command" do
36
- described_class::CommandUploader.stub(new: command_uploader_stub)
37
-
38
- command_uploader_stub.should_receive :upload
39
- command_uploader_stub.stub command: "my command"
40
- command_uploader_stub.stub(:cleanup)
41
-
42
- get_command.should eq("my command")
43
- end
44
- end
45
- end
46
-
47
24
  describe "#run" do
48
25
  subject(:result) { connector.run(host, command, options) }
49
26
  let(:command) { "dir" }
@@ -58,6 +35,37 @@ describe Ridley::HostConnector::WinRM do
58
35
  winrm_stub.stub(:run_cmd).and_yield(stdout, stderr).and_return(exitcode: 0)
59
36
  end
60
37
 
38
+ context "when the command is forced" do
39
+ let(:command_uploader) { double(upload: nil, command: command, cleanup: true) }
40
+ let(:command) { "a forced-to-upload command" }
41
+ let(:options) do
42
+ { force_batch_file: true }
43
+ end
44
+
45
+ before do
46
+ Ridley::HostConnector::WinRM::CommandUploader.stub(:new).and_return(command_uploader)
47
+ end
48
+
49
+ it "uploads the command" do
50
+ expect(winrm_stub).to receive(:run_cmd).with("a forced-to-upload command")
51
+ result
52
+ end
53
+ end
54
+
55
+ context "when the command is too long" do
56
+ let(:command_uploader) { double(upload: nil, command: command, cleanup: true) }
57
+ let(:command) { "a" * 2048 }
58
+
59
+ before do
60
+ Ridley::HostConnector::WinRM::CommandUploader.stub(:new).and_return(command_uploader)
61
+ end
62
+
63
+ it "uploads the command" do
64
+ expect(winrm_stub).to receive(:run_cmd).with("a" * 2048)
65
+ result
66
+ end
67
+ end
68
+
61
69
  context "when the exit_code is 0" do
62
70
  it "returns a non-error HostConnector::Response" do
63
71
  expect(result).to be_a(Ridley::HostConnector::Response)
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: 2.0.0
4
+ version: 2.0.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-04-07 00:00:00.000000000 Z
12
+ date: 2014-04-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: celluloid
@@ -39,6 +39,20 @@ dependencies:
39
39
  - - ~>
40
40
  - !ruby/object:Gem::Version
41
41
  version: 0.16.0.pre
42
+ - !ruby/object:Gem::Dependency
43
+ name: erubis
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
42
56
  - !ruby/object:Gem::Dependency
43
57
  name: net-ssh
44
58
  requirement: !ruby/object:Gem::Requirement
@@ -112,9 +126,18 @@ files:
112
126
  - LICENSE
113
127
  - README.md
114
128
  - Thorfile
129
+ - bootstrappers/unix_omnibus.erb
130
+ - bootstrappers/windows_omnibus.erb
115
131
  - lib/ridley-connectors.rb
132
+ - lib/ridley-connectors/bootstrap_context.rb
133
+ - lib/ridley-connectors/bootstrap_context/unix.rb
134
+ - lib/ridley-connectors/bootstrap_context/windows.rb
116
135
  - lib/ridley-connectors/chef_objects/node_object.rb
117
136
  - lib/ridley-connectors/client.rb
137
+ - lib/ridley-connectors/command_context.rb
138
+ - lib/ridley-connectors/command_context/unix_uninstall.rb
139
+ - lib/ridley-connectors/command_context/windows_uninstall.rb
140
+ - lib/ridley-connectors/errors.rb
118
141
  - lib/ridley-connectors/host_commander.rb
119
142
  - lib/ridley-connectors/host_connector.rb
120
143
  - lib/ridley-connectors/host_connector/response.rb
@@ -124,13 +147,19 @@ files:
124
147
  - lib/ridley-connectors/resources/node_resource.rb
125
148
  - lib/ridley-connectors/version.rb
126
149
  - ridley-connectors.gemspec
150
+ - scripts/unix_uninstall_omnibus.erb
151
+ - scripts/windows_uninstall_omnibus.erb
127
152
  - spec/fixtures/encrypted_data_bag_secret
128
153
  - spec/fixtures/my-fake.pem
129
154
  - spec/spec_helper.rb
130
155
  - spec/support/actor_mocking.rb
131
156
  - spec/support/spec_helpers.rb
157
+ - spec/unit/ridley-connectors/bootstrap_context/unix_spec.rb
158
+ - spec/unit/ridley-connectors/bootstrap_context/windows_spec.rb
159
+ - spec/unit/ridley-connectors/bootstrap_context_spec.rb
132
160
  - spec/unit/ridley-connectors/chef_objects/node_object_spec.rb
133
161
  - spec/unit/ridley-connectors/client_spec.rb
162
+ - spec/unit/ridley-connectors/command_context_spec.rb
134
163
  - spec/unit/ridley-connectors/host_commander_spec.rb
135
164
  - spec/unit/ridley-connectors/host_connector/ssh_spec.rb
136
165
  - spec/unit/ridley-connectors/host_connector/winrm/command_uploader_spec.rb
@@ -157,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
157
186
  version: '0'
158
187
  requirements: []
159
188
  rubyforge_project:
160
- rubygems_version: 2.0.7
189
+ rubygems_version: 2.0.3
161
190
  signing_key:
162
191
  specification_version: 4
163
192
  summary: A Connector API for talking to nodes managed by Chef
@@ -167,8 +196,12 @@ test_files:
167
196
  - spec/spec_helper.rb
168
197
  - spec/support/actor_mocking.rb
169
198
  - spec/support/spec_helpers.rb
199
+ - spec/unit/ridley-connectors/bootstrap_context/unix_spec.rb
200
+ - spec/unit/ridley-connectors/bootstrap_context/windows_spec.rb
201
+ - spec/unit/ridley-connectors/bootstrap_context_spec.rb
170
202
  - spec/unit/ridley-connectors/chef_objects/node_object_spec.rb
171
203
  - spec/unit/ridley-connectors/client_spec.rb
204
+ - spec/unit/ridley-connectors/command_context_spec.rb
172
205
  - spec/unit/ridley-connectors/host_commander_spec.rb
173
206
  - spec/unit/ridley-connectors/host_connector/ssh_spec.rb
174
207
  - spec/unit/ridley-connectors/host_connector/winrm/command_uploader_spec.rb