knife-windows 0.8.2 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -13
- data/.gitignore +1 -0
- data/.travis.yml +16 -2
- data/CHANGELOG.md +38 -4
- data/DOC_CHANGES.md +331 -15
- data/Gemfile +2 -1
- data/README.md +306 -71
- data/RELEASE_NOTES.md +63 -43
- data/Rakefile +9 -4
- data/appveyor.yml +42 -0
- data/ci.gemfile +15 -0
- data/knife-windows.gemspec +6 -4
- data/lib/chef/knife/bootstrap/windows-chef-client-msi.erb +96 -71
- data/lib/chef/knife/bootstrap_windows_base.rb +219 -37
- data/lib/chef/knife/bootstrap_windows_ssh.rb +22 -5
- data/lib/chef/knife/bootstrap_windows_winrm.rb +24 -24
- data/lib/chef/knife/core/windows_bootstrap_context.rb +146 -12
- data/lib/chef/knife/knife_windows_base.rb +33 -0
- data/lib/chef/knife/windows_cert_generate.rb +155 -0
- data/lib/chef/knife/windows_cert_install.rb +68 -0
- data/lib/chef/knife/windows_helper.rb +3 -1
- data/lib/chef/knife/windows_listener_create.rb +107 -0
- data/lib/chef/knife/winrm.rb +103 -206
- data/lib/chef/knife/winrm_base.rb +30 -11
- data/lib/chef/knife/winrm_knife_base.rb +218 -0
- data/lib/chef/knife/winrm_session.rb +81 -0
- data/lib/chef/knife/winrm_shared_options.rb +47 -0
- data/lib/chef/knife/wsman_endpoint.rb +44 -0
- data/lib/chef/knife/wsman_test.rb +96 -0
- data/lib/knife-windows/path_helper.rb +234 -0
- data/lib/knife-windows/version.rb +1 -1
- data/spec/assets/win_template_rendered_with_bootstrap_install_command.txt +217 -0
- data/spec/assets/win_template_rendered_without_bootstrap_install_command.txt +329 -0
- data/spec/assets/win_template_unrendered.txt +246 -0
- data/spec/functional/bootstrap_download_spec.rb +129 -35
- data/spec/spec_helper.rb +28 -1
- data/spec/unit/knife/bootstrap_options_spec.rb +150 -0
- data/spec/unit/knife/bootstrap_template_spec.rb +27 -26
- data/spec/unit/knife/bootstrap_windows_winrm_spec.rb +166 -32
- data/spec/unit/knife/core/windows_bootstrap_context_spec.rb +151 -0
- data/spec/unit/knife/windows_cert_generate_spec.rb +90 -0
- data/spec/unit/knife/windows_cert_install_spec.rb +51 -0
- data/spec/unit/knife/windows_listener_create_spec.rb +76 -0
- data/spec/unit/knife/winrm_session_spec.rb +56 -0
- data/spec/unit/knife/winrm_spec.rb +403 -118
- data/spec/unit/knife/wsman_test_spec.rb +176 -0
- metadata +67 -21
|
@@ -25,7 +25,7 @@ require 'tmpdir'
|
|
|
25
25
|
# Windows nodes. The test modifies the Windows batch file generated
|
|
26
26
|
# from an erb template in the plugin source in order to enable execution
|
|
27
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
|
|
28
|
+
# The test relies on knowledge of the fields of the template itself and
|
|
29
29
|
# also on knowledge of the contents and structure of the Windows batch
|
|
30
30
|
# file generated by the template.
|
|
31
31
|
#
|
|
@@ -34,7 +34,7 @@ require 'tmpdir'
|
|
|
34
34
|
# occur, the bootstrap code should be refactored to explicitly expose
|
|
35
35
|
# the download funcitonality separately from other tasks to make the
|
|
36
36
|
# test more robust.
|
|
37
|
-
describe 'Knife::Windows::Core msi download functionality for knife Windows winrm bootstrap template' do
|
|
37
|
+
describe 'Knife::Windows::Core msi download functionality for knife Windows winrm bootstrap template' do
|
|
38
38
|
|
|
39
39
|
before(:all) do
|
|
40
40
|
# Since we're always running 32-bit Ruby, fix the
|
|
@@ -43,7 +43,7 @@ describe 'Knife::Windows::Core msi download functionality for knife Windows winr
|
|
|
43
43
|
if ENV["PROCESSOR_ARCHITEW6432"]
|
|
44
44
|
ENV["PROCESSOR_ARCHITECTURE"] = ENV["PROCESSOR_ARCHITEW6432"]
|
|
45
45
|
end
|
|
46
|
-
|
|
46
|
+
|
|
47
47
|
# All file artifacts from this test will be written into this directory
|
|
48
48
|
@temp_directory = Dir.mktmpdir("bootstrap_test")
|
|
49
49
|
|
|
@@ -51,8 +51,8 @@ describe 'Knife::Windows::Core msi download functionality for knife Windows winr
|
|
|
51
51
|
# the downloaded msi
|
|
52
52
|
@local_file_download_destination = "#{@temp_directory}/chef-client-latest.msi"
|
|
53
53
|
|
|
54
|
-
source_code_directory = File.dirname(__FILE__)
|
|
55
|
-
@template_file_path ="#{source_code_directory}/../../lib/chef/knife/bootstrap/windows-chef-client-msi.erb"
|
|
54
|
+
source_code_directory = File.dirname(__FILE__)
|
|
55
|
+
@template_file_path ="#{source_code_directory}/../../lib/chef/knife/bootstrap/windows-chef-client-msi.erb"
|
|
56
56
|
end
|
|
57
57
|
|
|
58
58
|
after(:all) do
|
|
@@ -63,48 +63,50 @@ describe 'Knife::Windows::Core msi download functionality for knife Windows winr
|
|
|
63
63
|
end
|
|
64
64
|
|
|
65
65
|
describe "running on any version of the Windows OS", :windows_only do
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
let(:mock_bootstrap_context) { Chef::Knife::Core::WindowsBootstrapContext.new({ }, nil, { :knife => {} }) }
|
|
67
|
+
let(:mock_winrm) { Chef::Knife::Winrm.new }
|
|
68
68
|
|
|
69
|
+
before do
|
|
69
70
|
# Stub the bootstrap context and prevent config related sections
|
|
70
71
|
# from being populated, i.e. chef installation and first chef
|
|
71
72
|
# run sections
|
|
72
|
-
allow(
|
|
73
|
-
allow(
|
|
74
|
-
allow(
|
|
75
|
-
allow(
|
|
76
|
-
allow(
|
|
77
|
-
allow(
|
|
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")
|
|
78
79
|
|
|
79
80
|
# Change the directories where bootstrap files will be created
|
|
80
|
-
allow(
|
|
81
|
-
allow(
|
|
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))
|
|
82
83
|
|
|
83
84
|
# Prevent password prompt during bootstrap process
|
|
84
|
-
|
|
85
|
-
allow(
|
|
86
|
-
allow(Chef::Knife::Winrm).to receive(:new).and_return(@mock_winrm)
|
|
85
|
+
allow(mock_winrm).to receive(:get_password).and_return(nil)
|
|
86
|
+
allow(Chef::Knife::Winrm).to receive(:new).and_return(mock_winrm)
|
|
87
87
|
|
|
88
|
-
allow(Chef::Knife::Core::WindowsBootstrapContext).to receive(:new).and_return(
|
|
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'}
|
|
89
90
|
end
|
|
90
91
|
|
|
91
|
-
it "downloads the chef-client MSI during winrm bootstrap" do
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
winrm_bootstrapper = Chef::Knife::BootstrapWindowsWinrm.new([ "127.0.0.1" ])
|
|
96
|
-
allow(winrm_bootstrapper).to receive(:wait_for_remote_response)
|
|
97
|
-
winrm_bootstrapper.config[:template_file] = @template_file_path
|
|
92
|
+
it "downloads the chef-client MSI from the default location during winrm bootstrap" do
|
|
93
|
+
run_download_scenario
|
|
94
|
+
end
|
|
98
95
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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
|
|
102
101
|
end
|
|
102
|
+
end
|
|
103
103
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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
|
|
108
110
|
end
|
|
109
111
|
end
|
|
110
112
|
|
|
@@ -118,5 +120,97 @@ describe 'Knife::Windows::Core msi download functionality for knife Windows winr
|
|
|
118
120
|
File.delete(@local_file_download_destination)
|
|
119
121
|
end
|
|
120
122
|
end
|
|
121
|
-
|
|
122
|
-
|
|
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
|
+
winrm_bootstrapper.config[:template_file] = @template_file_path
|
|
137
|
+
|
|
138
|
+
# Execute the commands locally that would normally be executed via WinRM
|
|
139
|
+
allow(winrm_bootstrapper).to receive(:run_command) do |command|
|
|
140
|
+
system(command)
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
winrm_bootstrapper.run
|
|
144
|
+
|
|
145
|
+
# Download should succeed
|
|
146
|
+
expect(download_succeeded?).to be true
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
describe "bootstrap_install_command functionality through WinRM protocol", :if_chef_11 => true, :chef_lt_12_5_only => true do
|
|
151
|
+
context "bootstrap_install_command option is not specified" do
|
|
152
|
+
let(:bootstrap) { Chef::Knife::BootstrapWindowsWinrm.new([]) }
|
|
153
|
+
before do
|
|
154
|
+
@template_input = sample_data('win_template_unrendered.txt')
|
|
155
|
+
@template_output = sample_data('win_template_rendered_without_bootstrap_install_command.txt')
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
it "bootstrap_install_command option is not rendered in the windows-chef-client-msi.erb template as its value is nil" do
|
|
159
|
+
expect(bootstrap.send(:render_template,@template_input)).to eq(
|
|
160
|
+
@template_output)
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
context "bootstrap_install_command option is specified" do
|
|
165
|
+
let(:bootstrap) { Chef::Knife::BootstrapWindowsWinrm.new(['--bootstrap-install-command', 'chef-client -o recipe[cbk1::rec2]']) }
|
|
166
|
+
before do
|
|
167
|
+
bootstrap.config[:bootstrap_install_command] = "chef-client -o recipe[cbk1::rec2]"
|
|
168
|
+
@template_input = sample_data('win_template_unrendered.txt')
|
|
169
|
+
@template_output = sample_data('win_template_rendered_with_bootstrap_install_command.txt')
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
it "bootstrap_install_command option is rendered in the windows-chef-client-msi.erb template" do
|
|
173
|
+
expect(bootstrap.send(:render_template,@template_input)).to eq(
|
|
174
|
+
@template_output)
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
after do
|
|
178
|
+
bootstrap.config.delete(:bootstrap_install_command)
|
|
179
|
+
Chef::Config[:knife].delete(:bootstrap_install_command)
|
|
180
|
+
end
|
|
181
|
+
end
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
describe "bootstrap_install_command functionality through SSH protocol", :if_chef_11 => true, :chef_lt_12_5_only => true do
|
|
185
|
+
context "bootstrap_install_command option is not specified" do
|
|
186
|
+
let(:bootstrap) { Chef::Knife::BootstrapWindowsSsh.new([]) }
|
|
187
|
+
before do
|
|
188
|
+
@template_input = sample_data('win_template_unrendered.txt')
|
|
189
|
+
@template_output = sample_data('win_template_rendered_without_bootstrap_install_command.txt')
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
it "bootstrap_install_command option is not rendered in the windows-chef-client-msi.erb template as its value is nil" do
|
|
193
|
+
expect(bootstrap.send(:render_template,@template_input)).to eq(
|
|
194
|
+
@template_output)
|
|
195
|
+
end
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
context "bootstrap_install_command option is specified" do
|
|
199
|
+
let(:bootstrap) { Chef::Knife::BootstrapWindowsSsh.new(['--bootstrap-install-command', 'chef-client -o recipe[cbk1::rec2]']) }
|
|
200
|
+
before do
|
|
201
|
+
bootstrap.config[:bootstrap_install_command] = "chef-client -o recipe[cbk1::rec2]"
|
|
202
|
+
@template_input = sample_data('win_template_unrendered.txt')
|
|
203
|
+
@template_output = sample_data('win_template_rendered_with_bootstrap_install_command.txt')
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
it "bootstrap_install_command option is rendered in the windows-chef-client-msi.erb template" do
|
|
207
|
+
expect(bootstrap.send(:render_template,@template_input)).to eq(
|
|
208
|
+
@template_output)
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
after do
|
|
212
|
+
bootstrap.config.delete(:bootstrap_install_command)
|
|
213
|
+
Chef::Config[:knife].delete(:bootstrap_install_command)
|
|
214
|
+
end
|
|
215
|
+
end
|
|
216
|
+
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -23,6 +23,8 @@ end
|
|
|
23
23
|
|
|
24
24
|
require_relative '../lib/chef/knife/core/windows_bootstrap_context'
|
|
25
25
|
require_relative '../lib/chef/knife/bootstrap_windows_winrm'
|
|
26
|
+
require_relative '../lib/chef/knife/bootstrap_windows_ssh'
|
|
27
|
+
require_relative '../lib/chef/knife/wsman_test'
|
|
26
28
|
|
|
27
29
|
if windows?
|
|
28
30
|
require 'ruby-wmi'
|
|
@@ -30,7 +32,7 @@ end
|
|
|
30
32
|
|
|
31
33
|
def windows2012?
|
|
32
34
|
is_win2k12 = false
|
|
33
|
-
|
|
35
|
+
|
|
34
36
|
if windows?
|
|
35
37
|
this_operating_system = WMI::Win32_OperatingSystem.find(:first)
|
|
36
38
|
os_version = this_operating_system.send('Version')
|
|
@@ -53,9 +55,34 @@ def windows2012?
|
|
|
53
55
|
is_win2k12
|
|
54
56
|
end
|
|
55
57
|
|
|
58
|
+
def chef_gte_12?
|
|
59
|
+
Chef::VERSION.split('.').first.to_i >= 12
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def chef_gte_12_5?
|
|
63
|
+
Chef::VERSION.split('.')[0..1].join('.').to_f >= 12.5
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def chef_lt_12?
|
|
67
|
+
Chef::VERSION.split('.').first.to_i < 12
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def chef_eq_11?
|
|
71
|
+
Chef::VERSION.split('.').first.to_i == 11
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def sample_data(file_name)
|
|
75
|
+
file = File.expand_path(File.dirname("spec/assets/*"))+"/#{file_name}"
|
|
76
|
+
File.read(file)
|
|
77
|
+
end
|
|
56
78
|
|
|
57
79
|
RSpec.configure do |config|
|
|
58
80
|
config.filter_run_excluding :windows_only => true unless windows?
|
|
59
81
|
config.filter_run_excluding :windows_2012_only => true unless windows2012?
|
|
82
|
+
config.filter_run_excluding :chef_gte_12_only => true unless chef_gte_12?
|
|
83
|
+
config.filter_run_excluding :chef_gte_12_5_only => true unless chef_gte_12_5?
|
|
84
|
+
config.filter_run_excluding :chef_lt_12_5_only => true if chef_gte_12_5?
|
|
85
|
+
config.filter_run_excluding :chef_lt_12_only => true unless chef_lt_12?
|
|
86
|
+
config.filter_run_excluding :if_chef_11 => true if chef_eq_11?
|
|
60
87
|
end
|
|
61
88
|
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Author:: Kartik Null Cating-Subramanian(<ksubramanian@chef.io>)
|
|
3
|
+
# Copyright:: Copyright (c) 2015 Chef Software, 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 implied.
|
|
15
|
+
# See the License for the specific language governing permissions and
|
|
16
|
+
# limitations under the License.
|
|
17
|
+
#
|
|
18
|
+
|
|
19
|
+
require 'spec_helper'
|
|
20
|
+
|
|
21
|
+
describe Chef::Knife::Bootstrap, :chef_gte_12_5_only do
|
|
22
|
+
before(:all) do
|
|
23
|
+
Chef::Config.reset
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
let(:bootstrap) { Chef::Knife::Bootstrap.new }
|
|
27
|
+
let(:win_bootstrap) { nil }
|
|
28
|
+
let(:opt_map) { {} }
|
|
29
|
+
let(:ref_ignore) { [] }
|
|
30
|
+
let(:win_ignore) { [] }
|
|
31
|
+
|
|
32
|
+
def compare_property(sym)
|
|
33
|
+
win_bootstrap.options.each do |win_key, win_val|
|
|
34
|
+
unless win_ignore.include?(win_key) || opt_map.include?(win_key) then
|
|
35
|
+
actual = win_val[sym]
|
|
36
|
+
expected = bootstrap.options[win_key][sym]
|
|
37
|
+
expect(actual).to eq(expected),
|
|
38
|
+
"#{win_key} flag's #{sym} property doesn't match
|
|
39
|
+
|
|
40
|
+
expected: #{expected}
|
|
41
|
+
got: #{actual}"
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
shared_examples 'compare_options' do
|
|
47
|
+
it 'contains the option flags' do
|
|
48
|
+
opt_map.default_proc = proc { |map, key| key }
|
|
49
|
+
filtered_keys = (win_bootstrap.options.keys - win_ignore).map! { |key| opt_map[key] }
|
|
50
|
+
|
|
51
|
+
expect(filtered_keys).to match_array(bootstrap.options.keys - ref_ignore)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
it 'uses the same long-name' do
|
|
55
|
+
compare_property(:long)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it 'uses the same short-name' do
|
|
59
|
+
compare_property(:short)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
it 'uses the same description' do
|
|
63
|
+
compare_property(:description)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
it 'uses the same default value' do
|
|
67
|
+
compare_property(:default)
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
context 'when compared to BootstrapWindowsWinrm' do
|
|
72
|
+
let(:win_bootstrap) { Chef::Knife::BootstrapWindowsWinrm.new }
|
|
73
|
+
|
|
74
|
+
# opt_map: Hash of symbols in windows mapping to symbols in core. Name checks are
|
|
75
|
+
# ignored for these.
|
|
76
|
+
let(:opt_map) { {
|
|
77
|
+
:msi_url => :bootstrap_url,
|
|
78
|
+
:encrypted_data_bag_secret => :secret,
|
|
79
|
+
:encrypted_data_bag_secret_file => :secret_file,
|
|
80
|
+
:winrm_user => :ssh_user,
|
|
81
|
+
:winrm_password => :ssh_password,
|
|
82
|
+
:winrm_port => :ssh_port,
|
|
83
|
+
:winrm_ssl_verify_mode => :host_key_verify,
|
|
84
|
+
:bootstrap_install_command => :bootstrap_install_command,
|
|
85
|
+
}}
|
|
86
|
+
|
|
87
|
+
# ref_ignore: Options in core that are not implemented here.
|
|
88
|
+
let(:ref_ignore) { [
|
|
89
|
+
# These are irrelevant to WinRM.
|
|
90
|
+
:bootstrap_curl_options,
|
|
91
|
+
:bootstrap_wget_options,
|
|
92
|
+
:forward_agent,
|
|
93
|
+
:ssh_gateway,
|
|
94
|
+
:use_sudo,
|
|
95
|
+
:use_sudo_password,
|
|
96
|
+
:encrypt, # irrelevant during bootstrap
|
|
97
|
+
:policy_name, # NYI, issue https://github.com/chef/knife-windows/issues/295
|
|
98
|
+
:policy_group, #https://github.com/chef/knife-windows/issues/295
|
|
99
|
+
]}
|
|
100
|
+
|
|
101
|
+
# win_ignore: Options in windows that aren't relevant to core.
|
|
102
|
+
let(:win_ignore) { [
|
|
103
|
+
:attribute,
|
|
104
|
+
:auth_timeout,
|
|
105
|
+
:ca_trust_file,
|
|
106
|
+
:install_as_service,
|
|
107
|
+
:kerberos_keytab_file,
|
|
108
|
+
:kerberos_realm,
|
|
109
|
+
:kerberos_service,
|
|
110
|
+
:manual,
|
|
111
|
+
:session_timeout,
|
|
112
|
+
:winrm_authentication_protocol,
|
|
113
|
+
:winrm_transport,
|
|
114
|
+
] }
|
|
115
|
+
|
|
116
|
+
include_examples 'compare_options'
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
context 'when compared to BootstrapWindowsSsh' do
|
|
120
|
+
let(:win_bootstrap) { Chef::Knife::BootstrapWindowsSsh.new }
|
|
121
|
+
|
|
122
|
+
# opt_map: Hash of symbols in windows mapping to symbols in core. Name checks are
|
|
123
|
+
# ignored for these.
|
|
124
|
+
let(:opt_map) { {
|
|
125
|
+
:msi_url => :bootstrap_url,
|
|
126
|
+
:encrypted_data_bag_secret => :secret,
|
|
127
|
+
:encrypted_data_bag_secret_file => :secret_file,
|
|
128
|
+
:bootstrap_install_command => :bootstrap_install_command,
|
|
129
|
+
}}
|
|
130
|
+
# ref_ignore: Options in core that are not implemented here.
|
|
131
|
+
let(:ref_ignore) { [
|
|
132
|
+
:bootstrap_curl_options,
|
|
133
|
+
:bootstrap_wget_options,
|
|
134
|
+
:use_sudo,
|
|
135
|
+
:use_sudo_password,
|
|
136
|
+
:encrypt, # irrelevant during bootstrap
|
|
137
|
+
:policy_name, # NYI, issue https://github.com/chef/knife-windows/issues/295
|
|
138
|
+
:policy_group, #https://github.com/chef/knife-windows/issues/295
|
|
139
|
+
]}
|
|
140
|
+
# win_ignore: Options in windows that aren't relevant to core.
|
|
141
|
+
let(:win_ignore) { [
|
|
142
|
+
:auth_timeout,
|
|
143
|
+
:install_as_service,
|
|
144
|
+
:host_key_verification, # Deprecated - remove this when the flag is removed.
|
|
145
|
+
] }
|
|
146
|
+
|
|
147
|
+
include_examples 'compare_options'
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
end
|
|
@@ -20,25 +20,17 @@ TEMPLATE_FILE = File.expand_path(File.dirname(__FILE__)) + "/../../../lib/chef/k
|
|
|
20
20
|
|
|
21
21
|
require 'spec_helper'
|
|
22
22
|
|
|
23
|
-
describe
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
download_url.include?("%MACHINE_OS%") && download_url.include?("%MACHINE_ARCH%")
|
|
33
|
-
end
|
|
34
|
-
it "should download specific version of MSI if supplied" do
|
|
35
|
-
download_url_ext= template_file_lines.find {|l| l.include?("url +=")}
|
|
36
|
-
download_url_ext.include?("[:bootstrap_version]")
|
|
37
|
-
end
|
|
23
|
+
describe Chef::Knife::BootstrapWindowsWinrm do
|
|
24
|
+
let(:template_file) { TEMPLATE_FILE }
|
|
25
|
+
let(:options) { [] }
|
|
26
|
+
let(:rendered_template) do
|
|
27
|
+
knife.instance_variable_set("@template_file", template_file)
|
|
28
|
+
knife.parse_options(options)
|
|
29
|
+
# Avoid referencing a validation keyfile we won't find during #render_template
|
|
30
|
+
template = IO.read(template_file).chomp
|
|
31
|
+
knife.render_template(template)
|
|
38
32
|
end
|
|
39
|
-
end
|
|
40
33
|
|
|
41
|
-
describe Chef::Knife::BootstrapWindowsWinrm do
|
|
42
34
|
before(:all) do
|
|
43
35
|
@original_config = Chef::Config.hash_dup
|
|
44
36
|
@original_knife_config = Chef::Config[:knife].dup
|
|
@@ -54,7 +46,7 @@ describe Chef::Knife::BootstrapWindowsWinrm do
|
|
|
54
46
|
@knife = Chef::Knife::BootstrapWindowsWinrm.new
|
|
55
47
|
# Merge default settings in.
|
|
56
48
|
@knife.merge_configs
|
|
57
|
-
@knife.config[:template_file] =
|
|
49
|
+
@knife.config[:template_file] = template_file
|
|
58
50
|
@stdout = StringIO.new
|
|
59
51
|
allow(@knife.ui).to receive(:stdout).and_return(@stdout)
|
|
60
52
|
@stderr = StringIO.new
|
|
@@ -64,14 +56,6 @@ describe Chef::Knife::BootstrapWindowsWinrm do
|
|
|
64
56
|
describe "specifying no_proxy with various entries" do
|
|
65
57
|
subject(:knife) { described_class.new }
|
|
66
58
|
let(:options){ ["--bootstrap-proxy", "", "--bootstrap-no-proxy", setting] }
|
|
67
|
-
let(:template_file) { TEMPLATE_FILE }
|
|
68
|
-
let(:rendered_template) do
|
|
69
|
-
knife.instance_variable_set("@template_file", template_file)
|
|
70
|
-
knife.parse_options(options)
|
|
71
|
-
# Avoid referencing a validation keyfile we won't find during #render_template
|
|
72
|
-
template_string = knife.read_template.gsub(/^.*[Vv]alidation_key.*$/, '')
|
|
73
|
-
knife.render_template(template_string)
|
|
74
|
-
end
|
|
75
59
|
|
|
76
60
|
context "via --bootstrap-no-proxy" do
|
|
77
61
|
let(:setting) { "api.opscode.com" }
|
|
@@ -88,4 +72,21 @@ describe Chef::Knife::BootstrapWindowsWinrm do
|
|
|
88
72
|
end
|
|
89
73
|
end
|
|
90
74
|
end
|
|
75
|
+
|
|
76
|
+
describe "specifying --msi-url" do
|
|
77
|
+
subject(:knife) { described_class.new }
|
|
78
|
+
|
|
79
|
+
context "with explicitly provided --msi-url" do
|
|
80
|
+
let(:options) { ["--msi-url", "file:///something.msi"] }
|
|
81
|
+
|
|
82
|
+
it "bootstrap batch file must fetch from provided url" do
|
|
83
|
+
expect(rendered_template).to match(%r{.*REMOTE_SOURCE_MSI_URL=file:///something\.msi.*})
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
context "with no provided --msi-url" do
|
|
87
|
+
it "bootstrap batch file must fetch from provided url" do
|
|
88
|
+
expect(rendered_template).to match(%r{.*REMOTE_SOURCE_MSI_URL=https://www\.chef\.io/.*})
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
|
91
92
|
end
|