knife-windows 1.2.1 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +5 -5
- data/.travis.yml +26 -23
- data/CHANGELOG.md +108 -104
- data/DOC_CHANGES.md +14 -14
- data/Gemfile +12 -12
- data/LICENSE +201 -201
- data/README.md +385 -376
- data/RELEASE_NOTES.md +34 -34
- data/Rakefile +21 -21
- data/appveyor.yml +42 -42
- data/ci.gemfile +15 -15
- data/features/knife_help.feature +20 -20
- data/features/support/env.rb +5 -5
- data/knife-windows.gemspec +25 -25
- data/lib/chef/knife/bootstrap/windows-chef-client-msi.erb +247 -247
- data/lib/chef/knife/bootstrap_windows_base.rb +415 -415
- data/lib/chef/knife/bootstrap_windows_ssh.rb +115 -115
- data/lib/chef/knife/bootstrap_windows_winrm.rb +95 -95
- data/lib/chef/knife/core/windows_bootstrap_context.rb +366 -366
- data/lib/chef/knife/knife_windows_base.rb +33 -33
- data/lib/chef/knife/windows_cert_generate.rb +155 -155
- data/lib/chef/knife/windows_cert_install.rb +68 -68
- data/lib/chef/knife/windows_helper.rb +36 -36
- data/lib/chef/knife/windows_listener_create.rb +107 -107
- data/lib/chef/knife/winrm.rb +122 -122
- data/lib/chef/knife/winrm_base.rb +117 -113
- data/lib/chef/knife/winrm_knife_base.rb +303 -298
- data/lib/chef/knife/winrm_session.rb +86 -86
- data/lib/chef/knife/winrm_shared_options.rb +47 -47
- data/lib/chef/knife/wsman_endpoint.rb +44 -44
- data/lib/chef/knife/wsman_test.rb +117 -117
- data/lib/knife-windows/path_helper.rb +234 -234
- data/lib/knife-windows/version.rb +6 -6
- data/spec/assets/win_template_rendered_with_bootstrap_install_command.txt +217 -217
- data/spec/assets/win_template_rendered_with_bootstrap_install_command_on_12_5_client.txt +217 -217
- data/spec/assets/win_template_rendered_without_bootstrap_install_command.txt +329 -329
- data/spec/assets/win_template_rendered_without_bootstrap_install_command_on_12_5_client.txt +329 -329
- data/spec/assets/win_template_unrendered.txt +246 -246
- data/spec/functional/bootstrap_download_spec.rb +234 -234
- data/spec/spec_helper.rb +93 -93
- data/spec/unit/knife/bootstrap_options_spec.rb +155 -154
- data/spec/unit/knife/bootstrap_template_spec.rb +92 -92
- data/spec/unit/knife/bootstrap_windows_winrm_spec.rb +295 -295
- data/spec/unit/knife/core/windows_bootstrap_context_spec.rb +177 -177
- data/spec/unit/knife/windows_cert_generate_spec.rb +90 -90
- data/spec/unit/knife/windows_cert_install_spec.rb +51 -51
- data/spec/unit/knife/windows_listener_create_spec.rb +76 -76
- data/spec/unit/knife/winrm_session_spec.rb +64 -64
- data/spec/unit/knife/winrm_spec.rb +516 -516
- data/spec/unit/knife/wsman_test_spec.rb +201 -201
- metadata +4 -4
@@ -1,234 +1,234 @@
|
|
1
|
-
#
|
2
|
-
# Author:: Adam Edwards (<adamed@opscode.com>)
|
3
|
-
# Copyright:: Copyright (c) 2012 Opscode, Inc.
|
4
|
-
# License:: Apache License, Version 2.0
|
5
|
-
#
|
6
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
-
# you may not use this file except in compliance with the License.
|
8
|
-
# You may obtain a copy of the License at
|
9
|
-
#
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
15
|
-
# implied.
|
16
|
-
# See the License for the specific language governing permissions and
|
17
|
-
# limitations under the License.
|
18
|
-
#
|
19
|
-
|
20
|
-
require 'spec_helper'
|
21
|
-
require 'tmpdir'
|
22
|
-
|
23
|
-
# These test cases exercise the Knife::Windows knife plugin's ability
|
24
|
-
# to download a bootstrap msi as part of the bootstrap process on
|
25
|
-
# Windows nodes. The test modifies the Windows batch file generated
|
26
|
-
# from an erb template in the plugin source in order to enable execution
|
27
|
-
# of only the download functionality contained in the bootstrap template.
|
28
|
-
# The test relies on knowledge of the fields of the template itself and
|
29
|
-
# also on knowledge of the contents and structure of the Windows batch
|
30
|
-
# file generated by the template.
|
31
|
-
#
|
32
|
-
# Note that if the bootstrap template changes substantially, the tests
|
33
|
-
# should fail and will require re-implementation. If such changes
|
34
|
-
# occur, the bootstrap code should be refactored to explicitly expose
|
35
|
-
# the download funcitonality separately from other tasks to make the
|
36
|
-
# test more robust.
|
37
|
-
describe 'Knife::Windows::Core msi download functionality for knife Windows winrm bootstrap template' do
|
38
|
-
|
39
|
-
before(:all) do
|
40
|
-
# Since we're always running 32-bit Ruby, fix the
|
41
|
-
# PROCESSOR_ARCHITECTURE environment variable.
|
42
|
-
|
43
|
-
if ENV["PROCESSOR_ARCHITEW6432"]
|
44
|
-
ENV["PROCESSOR_ARCHITECTURE"] = ENV["PROCESSOR_ARCHITEW6432"]
|
45
|
-
end
|
46
|
-
|
47
|
-
# All file artifacts from this test will be written into this directory
|
48
|
-
@temp_directory = Dir.mktmpdir("bootstrap_test")
|
49
|
-
|
50
|
-
# Location to which the download script will be modified to write
|
51
|
-
# the downloaded msi
|
52
|
-
@local_file_download_destination = "#{@temp_directory}/chef-client-latest.msi"
|
53
|
-
|
54
|
-
source_code_directory = File.dirname(__FILE__)
|
55
|
-
@template_file_path ="#{source_code_directory}/../../lib/chef/knife/bootstrap/windows-chef-client-msi.erb"
|
56
|
-
end
|
57
|
-
|
58
|
-
after(:all) do
|
59
|
-
# Clear the temp directory upon exit
|
60
|
-
if Dir.exists?(@temp_directory)
|
61
|
-
FileUtils::remove_dir(@temp_directory)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
describe "running on any version of the Windows OS", :windows_only do
|
66
|
-
let(:mock_bootstrap_context) { Chef::Knife::Core::WindowsBootstrapContext.new({ }, nil, { :knife => {} }) }
|
67
|
-
let(:mock_winrm) { Chef::Knife::Winrm.new }
|
68
|
-
|
69
|
-
before do
|
70
|
-
# Stub the bootstrap context and prevent config related sections
|
71
|
-
# from being populated, i.e. chef installation and first chef
|
72
|
-
# run sections
|
73
|
-
allow(mock_bootstrap_context).to receive(:validation_key).and_return("echo.validation_key")
|
74
|
-
allow(mock_bootstrap_context).to receive(:secret).and_return("echo.encrypted_data_bag_secret")
|
75
|
-
allow(mock_bootstrap_context).to receive(:config_content).and_return("echo.config_content")
|
76
|
-
allow(mock_bootstrap_context).to receive(:start_chef).and_return("echo.echo start_chef_command")
|
77
|
-
allow(mock_bootstrap_context).to receive(:run_list).and_return("echo.run_list")
|
78
|
-
allow(mock_bootstrap_context).to receive(:install_chef).and_return("echo.echo install_chef_command")
|
79
|
-
|
80
|
-
# Change the directories where bootstrap files will be created
|
81
|
-
allow(mock_bootstrap_context).to receive(:bootstrap_directory).and_return(@temp_directory.gsub(::File::SEPARATOR, ::File::ALT_SEPARATOR))
|
82
|
-
allow(mock_bootstrap_context).to receive(:local_download_path).and_return(@local_file_download_destination.gsub(::File::SEPARATOR, ::File::ALT_SEPARATOR))
|
83
|
-
|
84
|
-
# Prevent password prompt during bootstrap process
|
85
|
-
allow(mock_winrm.ui).to receive(:ask).and_return(nil)
|
86
|
-
allow(Chef::Knife::Winrm).to receive(:new).and_return(mock_winrm)
|
87
|
-
|
88
|
-
allow(Chef::Knife::Core::WindowsBootstrapContext).to receive(:new).and_return(mock_bootstrap_context)
|
89
|
-
Chef::Config[:knife] = {:winrm_transport => 'plaintext', :chef_node_name => 'foo.example.com', :winrm_authentication_protocol => 'negotiate'}
|
90
|
-
end
|
91
|
-
|
92
|
-
it "downloads the chef-client MSI from the default location during winrm bootstrap" do
|
93
|
-
run_download_scenario
|
94
|
-
end
|
95
|
-
|
96
|
-
context "when provided a custom msi_url to fetch from" do
|
97
|
-
let(:mock_bootstrap_context) { Chef::Knife::Core::WindowsBootstrapContext.new(
|
98
|
-
{ :msi_url => "file:///C:/Windows/System32/xcopy.exe" }, nil, { :knife => {} }) }
|
99
|
-
it "downloads the chef-client MSI from a custom path during winrm bootstrap" do
|
100
|
-
run_download_scenario
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
context "when provided a custom msi_url with space in path to fetch from" do
|
105
|
-
let(:mock_bootstrap_context) { Chef::Knife::Core::WindowsBootstrapContext.new(
|
106
|
-
{ :msi_url => "file:///C:/Program Files/Windows NT/Accessories/wordpad.exe" }, nil, { :knife => {} }) }
|
107
|
-
it "downloads the chef-client MSI from a custom path with spaces during winrm bootstrap" do
|
108
|
-
run_download_scenario
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
def download_succeeded?
|
114
|
-
File.exists?(@local_file_download_destination) && ! File.zero?(@local_file_download_destination)
|
115
|
-
end
|
116
|
-
|
117
|
-
# Remove file artifacts generated by individual test cases
|
118
|
-
def clean_test_case
|
119
|
-
if File.exists?(@local_file_download_destination)
|
120
|
-
File.delete(@local_file_download_destination)
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
def run_download_scenario
|
125
|
-
clean_test_case
|
126
|
-
|
127
|
-
winrm_bootstrapper = Chef::Knife::BootstrapWindowsWinrm.new([ "127.0.0.1" ])
|
128
|
-
|
129
|
-
if chef_gte_12?
|
130
|
-
winrm_bootstrapper.client_builder = instance_double("Chef::Knife::Bootstrap::ClientBuilder", :run => nil, :client_path => nil)
|
131
|
-
elsif chef_lt_12?
|
132
|
-
allow(File).to receive(:exist?).with(File.expand_path(Chef::Config[:validation_key])).and_return(true)
|
133
|
-
end
|
134
|
-
|
135
|
-
allow(winrm_bootstrapper).to receive(:wait_for_remote_response)
|
136
|
-
allow(winrm_bootstrapper).to receive(:validate_options!)
|
137
|
-
allow(winrm_bootstrapper.ui).to receive(:ask).and_return(nil)
|
138
|
-
winrm_bootstrapper.config[:template_file] = @template_file_path
|
139
|
-
winrm_bootstrapper.config[:run_list] = []
|
140
|
-
# Execute the commands locally that would normally be executed via WinRM
|
141
|
-
allow(winrm_bootstrapper).to receive(:run_command) do |command|
|
142
|
-
system(command)
|
143
|
-
end
|
144
|
-
|
145
|
-
winrm_bootstrapper.run
|
146
|
-
|
147
|
-
# Download should succeed
|
148
|
-
expect(download_succeeded?).to be true
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
describe "bootstrap_install_command functionality through WinRM protocol", :if_chef_11 => true do
|
153
|
-
context "bootstrap_install_command option is not specified" do
|
154
|
-
let(:bootstrap) { Chef::Knife::BootstrapWindowsWinrm.new([]) }
|
155
|
-
before do
|
156
|
-
@template_input = sample_data('win_template_unrendered.txt')
|
157
|
-
@template_output = sample_data('win_template_rendered_without_bootstrap_install_command.txt')
|
158
|
-
end
|
159
|
-
|
160
|
-
it "bootstrap_install_command option is not rendered in the windows-chef-client-msi.erb template as its value is nil", :chef_lt_12_5_only => true do
|
161
|
-
expect(bootstrap.send(:render_template,@template_input)).to eq(
|
162
|
-
@template_output)
|
163
|
-
end
|
164
|
-
|
165
|
-
context "when running chef-client 12.5.0 or greater", :chef_gte_12_5_only => true do
|
166
|
-
let(:template_12_5_output) { sample_data('win_template_rendered_without_bootstrap_install_command_on_12_5_client.txt') }
|
167
|
-
it "bootstrap_install_command option is not rendered in the windows-chef-client-msi.erb template as its value is nil" do
|
168
|
-
expect(bootstrap.send(:render_template,@template_input)).to eq(
|
169
|
-
template_12_5_output)
|
170
|
-
end
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
|
-
context "bootstrap_install_command option is specified" do
|
175
|
-
let(:bootstrap) { Chef::Knife::BootstrapWindowsWinrm.new(['--bootstrap-install-command', 'chef-client -o recipe[cbk1::rec2]']) }
|
176
|
-
before do
|
177
|
-
bootstrap.config[:bootstrap_install_command] = "chef-client -o recipe[cbk1::rec2]"
|
178
|
-
@template_input = sample_data('win_template_unrendered.txt')
|
179
|
-
@template_output = sample_data('win_template_rendered_with_bootstrap_install_command.txt')
|
180
|
-
end
|
181
|
-
|
182
|
-
it "bootstrap_install_command option is rendered in the windows-chef-client-msi.erb template", :chef_lt_12_5_only => true do
|
183
|
-
expect(bootstrap.send(:render_template,@template_input)).to eq(
|
184
|
-
@template_output)
|
185
|
-
end
|
186
|
-
|
187
|
-
context "when running chef-client 12.5.0 or greater", :chef_gte_12_5_only => true do
|
188
|
-
let(:template_12_5_output) { sample_data('win_template_rendered_with_bootstrap_install_command_on_12_5_client.txt') }
|
189
|
-
it "bootstrap_install_command option is rendered in the windows-chef-client-msi.erb template" do
|
190
|
-
expect(bootstrap.send(:render_template,@template_input)).to eq(
|
191
|
-
template_12_5_output)
|
192
|
-
end
|
193
|
-
end
|
194
|
-
|
195
|
-
after do
|
196
|
-
bootstrap.config.delete(:bootstrap_install_command)
|
197
|
-
Chef::Config[:knife].delete(:bootstrap_install_command)
|
198
|
-
end
|
199
|
-
end
|
200
|
-
end
|
201
|
-
|
202
|
-
describe "bootstrap_install_command functionality through SSH protocol", :if_chef_11 => true, :chef_lt_12_5_only => true do
|
203
|
-
context "bootstrap_install_command option is not specified" do
|
204
|
-
let(:bootstrap) { Chef::Knife::BootstrapWindowsSsh.new([]) }
|
205
|
-
before do
|
206
|
-
@template_input = sample_data('win_template_unrendered.txt')
|
207
|
-
@template_output = sample_data('win_template_rendered_without_bootstrap_install_command.txt')
|
208
|
-
end
|
209
|
-
|
210
|
-
it "bootstrap_install_command option is not rendered in the windows-chef-client-msi.erb template as its value is nil" do
|
211
|
-
expect(bootstrap.send(:render_template,@template_input)).to eq(
|
212
|
-
@template_output)
|
213
|
-
end
|
214
|
-
end
|
215
|
-
|
216
|
-
context "bootstrap_install_command option is specified" do
|
217
|
-
let(:bootstrap) { Chef::Knife::BootstrapWindowsSsh.new(['--bootstrap-install-command', 'chef-client -o recipe[cbk1::rec2]']) }
|
218
|
-
before do
|
219
|
-
bootstrap.config[:bootstrap_install_command] = "chef-client -o recipe[cbk1::rec2]"
|
220
|
-
@template_input = sample_data('win_template_unrendered.txt')
|
221
|
-
@template_output = sample_data('win_template_rendered_with_bootstrap_install_command.txt')
|
222
|
-
end
|
223
|
-
|
224
|
-
it "bootstrap_install_command option is rendered in the windows-chef-client-msi.erb template" do
|
225
|
-
expect(bootstrap.send(:render_template,@template_input)).to eq(
|
226
|
-
@template_output)
|
227
|
-
end
|
228
|
-
|
229
|
-
after do
|
230
|
-
bootstrap.config.delete(:bootstrap_install_command)
|
231
|
-
Chef::Config[:knife].delete(:bootstrap_install_command)
|
232
|
-
end
|
233
|
-
end
|
234
|
-
end
|
1
|
+
#
|
2
|
+
# Author:: Adam Edwards (<adamed@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2012 Opscode, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
15
|
+
# implied.
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
18
|
+
#
|
19
|
+
|
20
|
+
require 'spec_helper'
|
21
|
+
require 'tmpdir'
|
22
|
+
|
23
|
+
# These test cases exercise the Knife::Windows knife plugin's ability
|
24
|
+
# to download a bootstrap msi as part of the bootstrap process on
|
25
|
+
# Windows nodes. The test modifies the Windows batch file generated
|
26
|
+
# from an erb template in the plugin source in order to enable execution
|
27
|
+
# of only the download functionality contained in the bootstrap template.
|
28
|
+
# The test relies on knowledge of the fields of the template itself and
|
29
|
+
# also on knowledge of the contents and structure of the Windows batch
|
30
|
+
# file generated by the template.
|
31
|
+
#
|
32
|
+
# Note that if the bootstrap template changes substantially, the tests
|
33
|
+
# should fail and will require re-implementation. If such changes
|
34
|
+
# occur, the bootstrap code should be refactored to explicitly expose
|
35
|
+
# the download funcitonality separately from other tasks to make the
|
36
|
+
# test more robust.
|
37
|
+
describe 'Knife::Windows::Core msi download functionality for knife Windows winrm bootstrap template' do
|
38
|
+
|
39
|
+
before(:all) do
|
40
|
+
# Since we're always running 32-bit Ruby, fix the
|
41
|
+
# PROCESSOR_ARCHITECTURE environment variable.
|
42
|
+
|
43
|
+
if ENV["PROCESSOR_ARCHITEW6432"]
|
44
|
+
ENV["PROCESSOR_ARCHITECTURE"] = ENV["PROCESSOR_ARCHITEW6432"]
|
45
|
+
end
|
46
|
+
|
47
|
+
# All file artifacts from this test will be written into this directory
|
48
|
+
@temp_directory = Dir.mktmpdir("bootstrap_test")
|
49
|
+
|
50
|
+
# Location to which the download script will be modified to write
|
51
|
+
# the downloaded msi
|
52
|
+
@local_file_download_destination = "#{@temp_directory}/chef-client-latest.msi"
|
53
|
+
|
54
|
+
source_code_directory = File.dirname(__FILE__)
|
55
|
+
@template_file_path ="#{source_code_directory}/../../lib/chef/knife/bootstrap/windows-chef-client-msi.erb"
|
56
|
+
end
|
57
|
+
|
58
|
+
after(:all) do
|
59
|
+
# Clear the temp directory upon exit
|
60
|
+
if Dir.exists?(@temp_directory)
|
61
|
+
FileUtils::remove_dir(@temp_directory)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "running on any version of the Windows OS", :windows_only do
|
66
|
+
let(:mock_bootstrap_context) { Chef::Knife::Core::WindowsBootstrapContext.new({ }, nil, { :knife => {} }) }
|
67
|
+
let(:mock_winrm) { Chef::Knife::Winrm.new }
|
68
|
+
|
69
|
+
before do
|
70
|
+
# Stub the bootstrap context and prevent config related sections
|
71
|
+
# from being populated, i.e. chef installation and first chef
|
72
|
+
# run sections
|
73
|
+
allow(mock_bootstrap_context).to receive(:validation_key).and_return("echo.validation_key")
|
74
|
+
allow(mock_bootstrap_context).to receive(:secret).and_return("echo.encrypted_data_bag_secret")
|
75
|
+
allow(mock_bootstrap_context).to receive(:config_content).and_return("echo.config_content")
|
76
|
+
allow(mock_bootstrap_context).to receive(:start_chef).and_return("echo.echo start_chef_command")
|
77
|
+
allow(mock_bootstrap_context).to receive(:run_list).and_return("echo.run_list")
|
78
|
+
allow(mock_bootstrap_context).to receive(:install_chef).and_return("echo.echo install_chef_command")
|
79
|
+
|
80
|
+
# Change the directories where bootstrap files will be created
|
81
|
+
allow(mock_bootstrap_context).to receive(:bootstrap_directory).and_return(@temp_directory.gsub(::File::SEPARATOR, ::File::ALT_SEPARATOR))
|
82
|
+
allow(mock_bootstrap_context).to receive(:local_download_path).and_return(@local_file_download_destination.gsub(::File::SEPARATOR, ::File::ALT_SEPARATOR))
|
83
|
+
|
84
|
+
# Prevent password prompt during bootstrap process
|
85
|
+
allow(mock_winrm.ui).to receive(:ask).and_return(nil)
|
86
|
+
allow(Chef::Knife::Winrm).to receive(:new).and_return(mock_winrm)
|
87
|
+
|
88
|
+
allow(Chef::Knife::Core::WindowsBootstrapContext).to receive(:new).and_return(mock_bootstrap_context)
|
89
|
+
Chef::Config[:knife] = {:winrm_transport => 'plaintext', :chef_node_name => 'foo.example.com', :winrm_authentication_protocol => 'negotiate'}
|
90
|
+
end
|
91
|
+
|
92
|
+
it "downloads the chef-client MSI from the default location during winrm bootstrap" do
|
93
|
+
run_download_scenario
|
94
|
+
end
|
95
|
+
|
96
|
+
context "when provided a custom msi_url to fetch from" do
|
97
|
+
let(:mock_bootstrap_context) { Chef::Knife::Core::WindowsBootstrapContext.new(
|
98
|
+
{ :msi_url => "file:///C:/Windows/System32/xcopy.exe" }, nil, { :knife => {} }) }
|
99
|
+
it "downloads the chef-client MSI from a custom path during winrm bootstrap" do
|
100
|
+
run_download_scenario
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
context "when provided a custom msi_url with space in path to fetch from" do
|
105
|
+
let(:mock_bootstrap_context) { Chef::Knife::Core::WindowsBootstrapContext.new(
|
106
|
+
{ :msi_url => "file:///C:/Program Files/Windows NT/Accessories/wordpad.exe" }, nil, { :knife => {} }) }
|
107
|
+
it "downloads the chef-client MSI from a custom path with spaces during winrm bootstrap" do
|
108
|
+
run_download_scenario
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def download_succeeded?
|
114
|
+
File.exists?(@local_file_download_destination) && ! File.zero?(@local_file_download_destination)
|
115
|
+
end
|
116
|
+
|
117
|
+
# Remove file artifacts generated by individual test cases
|
118
|
+
def clean_test_case
|
119
|
+
if File.exists?(@local_file_download_destination)
|
120
|
+
File.delete(@local_file_download_destination)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def run_download_scenario
|
125
|
+
clean_test_case
|
126
|
+
|
127
|
+
winrm_bootstrapper = Chef::Knife::BootstrapWindowsWinrm.new([ "127.0.0.1" ])
|
128
|
+
|
129
|
+
if chef_gte_12?
|
130
|
+
winrm_bootstrapper.client_builder = instance_double("Chef::Knife::Bootstrap::ClientBuilder", :run => nil, :client_path => nil)
|
131
|
+
elsif chef_lt_12?
|
132
|
+
allow(File).to receive(:exist?).with(File.expand_path(Chef::Config[:validation_key])).and_return(true)
|
133
|
+
end
|
134
|
+
|
135
|
+
allow(winrm_bootstrapper).to receive(:wait_for_remote_response)
|
136
|
+
allow(winrm_bootstrapper).to receive(:validate_options!)
|
137
|
+
allow(winrm_bootstrapper.ui).to receive(:ask).and_return(nil)
|
138
|
+
winrm_bootstrapper.config[:template_file] = @template_file_path
|
139
|
+
winrm_bootstrapper.config[:run_list] = []
|
140
|
+
# Execute the commands locally that would normally be executed via WinRM
|
141
|
+
allow(winrm_bootstrapper).to receive(:run_command) do |command|
|
142
|
+
system(command)
|
143
|
+
end
|
144
|
+
|
145
|
+
winrm_bootstrapper.run
|
146
|
+
|
147
|
+
# Download should succeed
|
148
|
+
expect(download_succeeded?).to be true
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
describe "bootstrap_install_command functionality through WinRM protocol", :if_chef_11 => true do
|
153
|
+
context "bootstrap_install_command option is not specified" do
|
154
|
+
let(:bootstrap) { Chef::Knife::BootstrapWindowsWinrm.new([]) }
|
155
|
+
before do
|
156
|
+
@template_input = sample_data('win_template_unrendered.txt')
|
157
|
+
@template_output = sample_data('win_template_rendered_without_bootstrap_install_command.txt')
|
158
|
+
end
|
159
|
+
|
160
|
+
it "bootstrap_install_command option is not rendered in the windows-chef-client-msi.erb template as its value is nil", :chef_lt_12_5_only => true do
|
161
|
+
expect(bootstrap.send(:render_template,@template_input)).to eq(
|
162
|
+
@template_output)
|
163
|
+
end
|
164
|
+
|
165
|
+
context "when running chef-client 12.5.0 or greater", :chef_gte_12_5_only => true do
|
166
|
+
let(:template_12_5_output) { sample_data('win_template_rendered_without_bootstrap_install_command_on_12_5_client.txt') }
|
167
|
+
it "bootstrap_install_command option is not rendered in the windows-chef-client-msi.erb template as its value is nil" do
|
168
|
+
expect(bootstrap.send(:render_template,@template_input)).to eq(
|
169
|
+
template_12_5_output)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
context "bootstrap_install_command option is specified" do
|
175
|
+
let(:bootstrap) { Chef::Knife::BootstrapWindowsWinrm.new(['--bootstrap-install-command', 'chef-client -o recipe[cbk1::rec2]']) }
|
176
|
+
before do
|
177
|
+
bootstrap.config[:bootstrap_install_command] = "chef-client -o recipe[cbk1::rec2]"
|
178
|
+
@template_input = sample_data('win_template_unrendered.txt')
|
179
|
+
@template_output = sample_data('win_template_rendered_with_bootstrap_install_command.txt')
|
180
|
+
end
|
181
|
+
|
182
|
+
it "bootstrap_install_command option is rendered in the windows-chef-client-msi.erb template", :chef_lt_12_5_only => true do
|
183
|
+
expect(bootstrap.send(:render_template,@template_input)).to eq(
|
184
|
+
@template_output)
|
185
|
+
end
|
186
|
+
|
187
|
+
context "when running chef-client 12.5.0 or greater", :chef_gte_12_5_only => true do
|
188
|
+
let(:template_12_5_output) { sample_data('win_template_rendered_with_bootstrap_install_command_on_12_5_client.txt') }
|
189
|
+
it "bootstrap_install_command option is rendered in the windows-chef-client-msi.erb template" do
|
190
|
+
expect(bootstrap.send(:render_template,@template_input)).to eq(
|
191
|
+
template_12_5_output)
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
after do
|
196
|
+
bootstrap.config.delete(:bootstrap_install_command)
|
197
|
+
Chef::Config[:knife].delete(:bootstrap_install_command)
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
describe "bootstrap_install_command functionality through SSH protocol", :if_chef_11 => true, :chef_lt_12_5_only => true do
|
203
|
+
context "bootstrap_install_command option is not specified" do
|
204
|
+
let(:bootstrap) { Chef::Knife::BootstrapWindowsSsh.new([]) }
|
205
|
+
before do
|
206
|
+
@template_input = sample_data('win_template_unrendered.txt')
|
207
|
+
@template_output = sample_data('win_template_rendered_without_bootstrap_install_command.txt')
|
208
|
+
end
|
209
|
+
|
210
|
+
it "bootstrap_install_command option is not rendered in the windows-chef-client-msi.erb template as its value is nil" do
|
211
|
+
expect(bootstrap.send(:render_template,@template_input)).to eq(
|
212
|
+
@template_output)
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
context "bootstrap_install_command option is specified" do
|
217
|
+
let(:bootstrap) { Chef::Knife::BootstrapWindowsSsh.new(['--bootstrap-install-command', 'chef-client -o recipe[cbk1::rec2]']) }
|
218
|
+
before do
|
219
|
+
bootstrap.config[:bootstrap_install_command] = "chef-client -o recipe[cbk1::rec2]"
|
220
|
+
@template_input = sample_data('win_template_unrendered.txt')
|
221
|
+
@template_output = sample_data('win_template_rendered_with_bootstrap_install_command.txt')
|
222
|
+
end
|
223
|
+
|
224
|
+
it "bootstrap_install_command option is rendered in the windows-chef-client-msi.erb template" do
|
225
|
+
expect(bootstrap.send(:render_template,@template_input)).to eq(
|
226
|
+
@template_output)
|
227
|
+
end
|
228
|
+
|
229
|
+
after do
|
230
|
+
bootstrap.config.delete(:bootstrap_install_command)
|
231
|
+
Chef::Config[:knife].delete(:bootstrap_install_command)
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|