knife-windows 0.8.5 → 0.8.6.rc.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +4 -4
- data/.travis.yml +6 -6
- data/CHANGELOG.md +48 -48
- data/DOC_CHANGES.md +23 -23
- data/Gemfile +11 -11
- data/LICENSE +201 -201
- data/README.md +161 -161
- data/RELEASE_NOTES.md +26 -26
- data/Rakefile +16 -16
- data/features/knife_help.feature +20 -20
- data/features/support/env.rb +5 -5
- data/knife-windows.gemspec +26 -26
- data/lib/chef/knife/bootstrap/windows-chef-client-msi.erb +227 -227
- data/lib/chef/knife/bootstrap_windows_base.rb +222 -222
- data/lib/chef/knife/bootstrap_windows_ssh.rb +93 -93
- data/lib/chef/knife/bootstrap_windows_winrm.rb +102 -102
- data/lib/chef/knife/core/windows_bootstrap_context.rb +311 -307
- data/lib/chef/knife/windows_helper.rb +34 -34
- data/lib/chef/knife/winrm.rb +315 -315
- data/lib/chef/knife/winrm_base.rb +99 -99
- data/lib/knife-windows/path_helper.rb +157 -157
- data/lib/knife-windows/version.rb +6 -6
- data/spec/functional/bootstrap_download_spec.rb +122 -122
- data/spec/spec_helper.rb +61 -61
- data/spec/unit/knife/bootstrap_template_spec.rb +92 -92
- data/spec/unit/knife/bootstrap_windows_winrm_spec.rb +106 -106
- data/spec/unit/knife/core/windows_bootstrap_context_spec.rb +54 -54
- data/spec/unit/knife/winrm_spec.rb +219 -219
- metadata +28 -20
@@ -1,6 +1,6 @@
|
|
1
|
-
module Knife
|
2
|
-
module Windows
|
3
|
-
VERSION = "0.8.
|
4
|
-
MAJOR, MINOR, TINY = VERSION.split('.')
|
5
|
-
end
|
6
|
-
end
|
1
|
+
module Knife
|
2
|
+
module Windows
|
3
|
+
VERSION = "0.8.6.rc.0"
|
4
|
+
MAJOR, MINOR, TINY = VERSION.split('.')
|
5
|
+
end
|
6
|
+
end
|
@@ -1,122 +1,122 @@
|
|
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(:encrypted_data_bag_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).to receive(:get_password).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
|
-
end
|
90
|
-
|
91
|
-
it "downloads the chef-client MSI during winrm bootstrap" do
|
92
|
-
|
93
|
-
clean_test_case
|
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
|
98
|
-
|
99
|
-
# Execute the commands locally that would normally be executed via WinRM
|
100
|
-
allow(winrm_bootstrapper).to receive(:run_command) do |command|
|
101
|
-
system(command)
|
102
|
-
end
|
103
|
-
|
104
|
-
winrm_bootstrapper.run
|
105
|
-
|
106
|
-
# Download should succeed
|
107
|
-
expect(download_succeeded?).to be true
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
def download_succeeded?
|
112
|
-
File.exists?(@local_file_download_destination) && ! File.zero?(@local_file_download_destination)
|
113
|
-
end
|
114
|
-
|
115
|
-
# Remove file artifacts generated by individual test cases
|
116
|
-
def clean_test_case
|
117
|
-
if File.exists?(@local_file_download_destination)
|
118
|
-
File.delete(@local_file_download_destination)
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
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(:encrypted_data_bag_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).to receive(:get_password).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
|
+
end
|
90
|
+
|
91
|
+
it "downloads the chef-client MSI during winrm bootstrap" do
|
92
|
+
|
93
|
+
clean_test_case
|
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
|
98
|
+
|
99
|
+
# Execute the commands locally that would normally be executed via WinRM
|
100
|
+
allow(winrm_bootstrapper).to receive(:run_command) do |command|
|
101
|
+
system(command)
|
102
|
+
end
|
103
|
+
|
104
|
+
winrm_bootstrapper.run
|
105
|
+
|
106
|
+
# Download should succeed
|
107
|
+
expect(download_succeeded?).to be true
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def download_succeeded?
|
112
|
+
File.exists?(@local_file_download_destination) && ! File.zero?(@local_file_download_destination)
|
113
|
+
end
|
114
|
+
|
115
|
+
# Remove file artifacts generated by individual test cases
|
116
|
+
def clean_test_case
|
117
|
+
if File.exists?(@local_file_download_destination)
|
118
|
+
File.delete(@local_file_download_destination)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,61 +1,61 @@
|
|
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
|
-
def windows?
|
21
|
-
!!(RUBY_PLATFORM =~ /mswin|mingw|windows/)
|
22
|
-
end
|
23
|
-
|
24
|
-
require_relative '../lib/chef/knife/core/windows_bootstrap_context'
|
25
|
-
require_relative '../lib/chef/knife/bootstrap_windows_winrm'
|
26
|
-
|
27
|
-
if windows?
|
28
|
-
require 'ruby-wmi'
|
29
|
-
end
|
30
|
-
|
31
|
-
def windows2012?
|
32
|
-
is_win2k12 = false
|
33
|
-
|
34
|
-
if windows?
|
35
|
-
this_operating_system = WMI::Win32_OperatingSystem.find(:first)
|
36
|
-
os_version = this_operating_system.send('Version')
|
37
|
-
|
38
|
-
# The operating system version is a string in the following form
|
39
|
-
# that can be split into components based on the '.' delimiter:
|
40
|
-
# MajorVersionNumber.MinorVersionNumber.BuildNumber
|
41
|
-
os_version_components = os_version.split('.')
|
42
|
-
|
43
|
-
if os_version_components.length < 2
|
44
|
-
raise 'WMI returned a Windows version from Win32_OperatingSystem.Version ' +
|
45
|
-
'with an unexpected format. The Windows version could not be determined.'
|
46
|
-
end
|
47
|
-
|
48
|
-
# Windows 6.2 is Windows Server 2012, so test the major and
|
49
|
-
# minor version components
|
50
|
-
is_win2k12 = os_version_components[0] == '6' && os_version_components[1] == '2'
|
51
|
-
end
|
52
|
-
|
53
|
-
is_win2k12
|
54
|
-
end
|
55
|
-
|
56
|
-
|
57
|
-
RSpec.configure do |config|
|
58
|
-
config.filter_run_excluding :windows_only => true unless windows?
|
59
|
-
config.filter_run_excluding :windows_2012_only => true unless windows2012?
|
60
|
-
end
|
61
|
-
|
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
|
+
def windows?
|
21
|
+
!!(RUBY_PLATFORM =~ /mswin|mingw|windows/)
|
22
|
+
end
|
23
|
+
|
24
|
+
require_relative '../lib/chef/knife/core/windows_bootstrap_context'
|
25
|
+
require_relative '../lib/chef/knife/bootstrap_windows_winrm'
|
26
|
+
|
27
|
+
if windows?
|
28
|
+
require 'ruby-wmi'
|
29
|
+
end
|
30
|
+
|
31
|
+
def windows2012?
|
32
|
+
is_win2k12 = false
|
33
|
+
|
34
|
+
if windows?
|
35
|
+
this_operating_system = WMI::Win32_OperatingSystem.find(:first)
|
36
|
+
os_version = this_operating_system.send('Version')
|
37
|
+
|
38
|
+
# The operating system version is a string in the following form
|
39
|
+
# that can be split into components based on the '.' delimiter:
|
40
|
+
# MajorVersionNumber.MinorVersionNumber.BuildNumber
|
41
|
+
os_version_components = os_version.split('.')
|
42
|
+
|
43
|
+
if os_version_components.length < 2
|
44
|
+
raise 'WMI returned a Windows version from Win32_OperatingSystem.Version ' +
|
45
|
+
'with an unexpected format. The Windows version could not be determined.'
|
46
|
+
end
|
47
|
+
|
48
|
+
# Windows 6.2 is Windows Server 2012, so test the major and
|
49
|
+
# minor version components
|
50
|
+
is_win2k12 = os_version_components[0] == '6' && os_version_components[1] == '2'
|
51
|
+
end
|
52
|
+
|
53
|
+
is_win2k12
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
RSpec.configure do |config|
|
58
|
+
config.filter_run_excluding :windows_only => true unless windows?
|
59
|
+
config.filter_run_excluding :windows_2012_only => true unless windows2012?
|
60
|
+
end
|
61
|
+
|
@@ -1,92 +1,92 @@
|
|
1
|
-
#
|
2
|
-
# Author:: Chirag Jog (<chirag@clogeny.com>)
|
3
|
-
# Copyright:: Copyright (c) 2013 Chirag Jog
|
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
|
-
TEMPLATE_FILE = File.expand_path(File.dirname(__FILE__)) + "/../../../lib/chef/knife/bootstrap/windows-chef-client-msi.erb"
|
20
|
-
|
21
|
-
require 'spec_helper'
|
22
|
-
|
23
|
-
describe "While Windows Bootstrapping" do
|
24
|
-
context "the default Windows bootstrapping template" do
|
25
|
-
bootstrap = Chef::Knife::BootstrapWindowsWinrm.new
|
26
|
-
bootstrap.config[:template_file] = TEMPLATE_FILE
|
27
|
-
|
28
|
-
template = bootstrap.load_template
|
29
|
-
template_file_lines = template.split('\n')
|
30
|
-
it "should download Platform specific MSI" do
|
31
|
-
download_url=template_file_lines.find {|l| l.include?("url=")}
|
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
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
describe Chef::Knife::BootstrapWindowsWinrm do
|
42
|
-
before(:all) do
|
43
|
-
@original_config = Chef::Config.hash_dup
|
44
|
-
@original_knife_config = Chef::Config[:knife].dup
|
45
|
-
end
|
46
|
-
|
47
|
-
after(:all) do
|
48
|
-
Chef::Config.configuration = @original_config
|
49
|
-
Chef::Config[:knife] = @original_knife_config
|
50
|
-
end
|
51
|
-
|
52
|
-
before(:each) do
|
53
|
-
Chef::Log.logger = Logger.new(StringIO.new)
|
54
|
-
@knife = Chef::Knife::BootstrapWindowsWinrm.new
|
55
|
-
# Merge default settings in.
|
56
|
-
@knife.merge_configs
|
57
|
-
@knife.config[:template_file] = TEMPLATE_FILE
|
58
|
-
@stdout = StringIO.new
|
59
|
-
allow(@knife.ui).to receive(:stdout).and_return(@stdout)
|
60
|
-
@stderr = StringIO.new
|
61
|
-
allow(@knife.ui).to receive(:stderr).and_return(@stderr)
|
62
|
-
end
|
63
|
-
|
64
|
-
describe "specifying no_proxy with various entries" do
|
65
|
-
subject(:knife) { described_class.new }
|
66
|
-
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 = IO.read(template_file).chomp
|
73
|
-
template_string = template.gsub(/^.*[Vv]alidation_key.*$/, '')
|
74
|
-
knife.render_template(template_string)
|
75
|
-
end
|
76
|
-
|
77
|
-
context "via --bootstrap-no-proxy" do
|
78
|
-
let(:setting) { "api.opscode.com" }
|
79
|
-
|
80
|
-
it "renders the client.rb with a single FQDN no_proxy entry" do
|
81
|
-
expect(rendered_template).to match(%r{.*no_proxy\s*\"api.opscode.com\".*})
|
82
|
-
end
|
83
|
-
end
|
84
|
-
context "via --bootstrap-no-proxy multiple" do
|
85
|
-
let(:setting) { "api.opscode.com,172.16.10.*" }
|
86
|
-
|
87
|
-
it "renders the client.rb with comma-separated FQDN and wildcard IP address no_proxy entries" do
|
88
|
-
expect(rendered_template).to match(%r{.*no_proxy\s*"api.opscode.com,172.16.10.\*".*})
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
1
|
+
#
|
2
|
+
# Author:: Chirag Jog (<chirag@clogeny.com>)
|
3
|
+
# Copyright:: Copyright (c) 2013 Chirag Jog
|
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
|
+
TEMPLATE_FILE = File.expand_path(File.dirname(__FILE__)) + "/../../../lib/chef/knife/bootstrap/windows-chef-client-msi.erb"
|
20
|
+
|
21
|
+
require 'spec_helper'
|
22
|
+
|
23
|
+
describe "While Windows Bootstrapping" do
|
24
|
+
context "the default Windows bootstrapping template" do
|
25
|
+
bootstrap = Chef::Knife::BootstrapWindowsWinrm.new
|
26
|
+
bootstrap.config[:template_file] = TEMPLATE_FILE
|
27
|
+
|
28
|
+
template = bootstrap.load_template
|
29
|
+
template_file_lines = template.split('\n')
|
30
|
+
it "should download Platform specific MSI" do
|
31
|
+
download_url=template_file_lines.find {|l| l.include?("url=")}
|
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
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe Chef::Knife::BootstrapWindowsWinrm do
|
42
|
+
before(:all) do
|
43
|
+
@original_config = Chef::Config.hash_dup
|
44
|
+
@original_knife_config = Chef::Config[:knife].dup
|
45
|
+
end
|
46
|
+
|
47
|
+
after(:all) do
|
48
|
+
Chef::Config.configuration = @original_config
|
49
|
+
Chef::Config[:knife] = @original_knife_config
|
50
|
+
end
|
51
|
+
|
52
|
+
before(:each) do
|
53
|
+
Chef::Log.logger = Logger.new(StringIO.new)
|
54
|
+
@knife = Chef::Knife::BootstrapWindowsWinrm.new
|
55
|
+
# Merge default settings in.
|
56
|
+
@knife.merge_configs
|
57
|
+
@knife.config[:template_file] = TEMPLATE_FILE
|
58
|
+
@stdout = StringIO.new
|
59
|
+
allow(@knife.ui).to receive(:stdout).and_return(@stdout)
|
60
|
+
@stderr = StringIO.new
|
61
|
+
allow(@knife.ui).to receive(:stderr).and_return(@stderr)
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "specifying no_proxy with various entries" do
|
65
|
+
subject(:knife) { described_class.new }
|
66
|
+
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 = IO.read(template_file).chomp
|
73
|
+
template_string = template.gsub(/^.*[Vv]alidation_key.*$/, '')
|
74
|
+
knife.render_template(template_string)
|
75
|
+
end
|
76
|
+
|
77
|
+
context "via --bootstrap-no-proxy" do
|
78
|
+
let(:setting) { "api.opscode.com" }
|
79
|
+
|
80
|
+
it "renders the client.rb with a single FQDN no_proxy entry" do
|
81
|
+
expect(rendered_template).to match(%r{.*no_proxy\s*\"api.opscode.com\".*})
|
82
|
+
end
|
83
|
+
end
|
84
|
+
context "via --bootstrap-no-proxy multiple" do
|
85
|
+
let(:setting) { "api.opscode.com,172.16.10.*" }
|
86
|
+
|
87
|
+
it "renders the client.rb with comma-separated FQDN and wildcard IP address no_proxy entries" do
|
88
|
+
expect(rendered_template).to match(%r{.*no_proxy\s*"api.opscode.com,172.16.10.\*".*})
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|