knife-windows 0.5.10 → 0.5.12
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.
- data/.rspec +3 -0
- data/Gemfile +6 -0
- data/Rakefile +14 -0
- data/lib/chef/knife/bootstrap/windows-chef-client-msi.erb +87 -8
- data/lib/chef/knife/bootstrap_windows_base.rb +2 -2
- data/lib/chef/knife/bootstrap_windows_ssh.rb +1 -1
- data/lib/chef/knife/bootstrap_windows_winrm.rb +3 -1
- data/lib/chef/knife/core/windows_bootstrap_context.rb +27 -0
- data/lib/chef/knife/winrm.rb +11 -2
- data/lib/knife-windows/version.rb +1 -1
- data/spec/functional/bootstrap_download_spec.rb +115 -0
- data/spec/spec_helper.rb +63 -0
- data/spec/unit/knife/winrm_spec.rb +65 -0
- metadata +40 -54
data/.rspec
ADDED
data/Gemfile
CHANGED
data/Rakefile
CHANGED
|
@@ -1,2 +1,16 @@
|
|
|
1
1
|
require 'bundler'
|
|
2
2
|
Bundler::GemHelper.install_tasks
|
|
3
|
+
|
|
4
|
+
begin
|
|
5
|
+
require 'rspec/core/rake_task'
|
|
6
|
+
|
|
7
|
+
task :default => :spec
|
|
8
|
+
|
|
9
|
+
desc "Run all specs in spec directory"
|
|
10
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
|
11
|
+
t.pattern = 'spec/**/*_spec.rb'
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
rescue LoadError
|
|
15
|
+
STDERR.puts "\n*** RSpec not available. (sudo) gem install rspec to run unit tests. ***\n\n"
|
|
16
|
+
end
|
|
@@ -16,33 +16,112 @@
|
|
|
16
16
|
@rem limitations under the License.
|
|
17
17
|
@rem
|
|
18
18
|
|
|
19
|
+
@setlocal
|
|
20
|
+
|
|
19
21
|
<%= "SETX HTTP_PROXY \"#{knife_config[:bootstrap_proxy]}\"" if knife_config[:bootstrap_proxy] %>
|
|
20
|
-
mkdir
|
|
22
|
+
mkdir <%= bootstrap_directory %>
|
|
21
23
|
|
|
22
|
-
>
|
|
24
|
+
> <%= bootstrap_directory %>\wget.vbs (
|
|
23
25
|
<%= win_wget %>
|
|
24
26
|
)
|
|
25
27
|
|
|
28
|
+
> <%= bootstrap_directory %>\wget.ps1 (
|
|
29
|
+
<%= win_wget_ps %>
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
@rem Determine the version and the architecture
|
|
33
|
+
|
|
34
|
+
FOR /F "tokens=1-8 delims=.[] " %%A IN ('ver') DO (
|
|
35
|
+
@set WinMajor=%%D
|
|
36
|
+
@set WinMinor=%%E
|
|
37
|
+
@set WinBuild=%%F
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
goto Version%WinMajor%.%WinMinor%
|
|
41
|
+
|
|
42
|
+
@rem If this is an unknown version of windows set the default
|
|
43
|
+
@set MACHINE_OS=2008r2
|
|
44
|
+
goto architecture
|
|
45
|
+
|
|
46
|
+
:Version6.0
|
|
47
|
+
@set MACHINE_OS=2008
|
|
48
|
+
goto architecture
|
|
49
|
+
|
|
50
|
+
:Version5.2
|
|
51
|
+
@set MACHINE_OS=2003r2
|
|
52
|
+
goto architecture
|
|
53
|
+
|
|
54
|
+
:Version6.1
|
|
55
|
+
@set MACHINE_OS=2008r2
|
|
56
|
+
goto architecture
|
|
57
|
+
|
|
58
|
+
:Version6.2
|
|
59
|
+
@set MACHINE_OS=2012
|
|
60
|
+
goto architecture
|
|
61
|
+
|
|
62
|
+
:architecture
|
|
63
|
+
|
|
64
|
+
goto Architecture%PROCESSOR_ARCHITECTURE%
|
|
65
|
+
|
|
66
|
+
@rem If this is an unknown architecture set the default
|
|
67
|
+
@set MACHINE_ARCH=i686
|
|
68
|
+
goto install
|
|
69
|
+
|
|
70
|
+
:Architecturex86
|
|
71
|
+
@set MACHINE_ARCH=i686
|
|
72
|
+
goto install
|
|
73
|
+
|
|
74
|
+
:Architectureamd64
|
|
75
|
+
@set MACHINE_ARCH=x86_64
|
|
76
|
+
goto install
|
|
77
|
+
|
|
78
|
+
:install
|
|
26
79
|
@rem Install Chef using chef-client MSI installer
|
|
27
|
-
cscript /nologo C:\chef\wget.vbs /url:http://www.opscode.com/chef/install.msi /path:%TEMP%\chef-client-latest.msi
|
|
28
|
-
msiexec /qb /i %TEMP%\chef-client-latest.msi
|
|
29
80
|
|
|
30
|
-
|
|
81
|
+
@set "REMOTE_SOURCE_MSI_URL=https://www.opscode.com/chef/download?p=windows&pv=%MACHINE_OS%&m=%MACHINE_ARCH%"
|
|
82
|
+
@set "LOCAL_DESTINATION_MSI_PATH=<%= local_download_path %>"
|
|
83
|
+
@set "FALLBACK_QUERY_STRING=&DownloadContext=PowerShell"
|
|
84
|
+
|
|
85
|
+
cscript /nologo <%= bootstrap_directory %>\wget.vbs /url:"%REMOTE_SOURCE_MSI_URL%" /path:"%LOCAL_DESTINATION_MSI_PATH%"
|
|
86
|
+
|
|
87
|
+
@rem Work around issues found in Windows Server 2012 around job objects not respecting WSMAN memory quotas
|
|
88
|
+
@rem that cause the MSI download process to exceed the quota even when it is increased by administrators.
|
|
89
|
+
@rem Retry the download using a more memory-efficient mechanism that only works if PowerShell is available.
|
|
90
|
+
@if ERRORLEVEL 1 (
|
|
91
|
+
echo Warning: Failed to download "%REMOTE_SOURCE_MSI_URL%" to "%LOCAL_DESTINATION_MSI_PATH%"
|
|
92
|
+
echo Warning: Retrying download with PowerShell if available
|
|
93
|
+
if EXIST "%LOCAL_DESTINATION_MSI_PATH%" del /f /q "%LOCAL_DESTINATION_MSI_PATH%"
|
|
94
|
+
@powershell -ExecutionPolicy Unrestricted -NoProfile -NonInteractive "& '<%= bootstrap_directory %>\wget.ps1' '%REMOTE_SOURCE_MSI_URL%%FALLBACK_QUERY_STRING%' '%LOCAL_DESTINATION_MSI_PATH%'"
|
|
95
|
+
|
|
96
|
+
if NOT ERRORLEVEL 1 (
|
|
97
|
+
echo Download succeeded
|
|
98
|
+
) else (
|
|
99
|
+
echo Failed to download "%REMOTE_SOURCE_MSI_URL%"
|
|
100
|
+
echo Subsequent attempt to install the downloaded MSI is likely to fail
|
|
101
|
+
)
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
<%= install_chef %>
|
|
105
|
+
|
|
106
|
+
@endlocal
|
|
107
|
+
|
|
108
|
+
> <%= bootstrap_directory %>\validation.pem (
|
|
31
109
|
<%= validation_key %>
|
|
32
110
|
)
|
|
33
111
|
|
|
34
112
|
<% if @config[:encrypted_data_bag_secret] -%>
|
|
35
|
-
>
|
|
113
|
+
> <%= bootstrap_directory %>\encrypted_data_bag_secret (
|
|
36
114
|
<%= encrypted_data_bag_secret %>
|
|
37
115
|
)
|
|
38
116
|
<% end -%>
|
|
39
117
|
|
|
40
|
-
>
|
|
118
|
+
> <%= bootstrap_directory %>\client.rb (
|
|
41
119
|
<%= config_content %>
|
|
42
120
|
)
|
|
43
121
|
|
|
44
|
-
>
|
|
122
|
+
> <%= bootstrap_directory %>\first-boot.json (
|
|
45
123
|
<%= run_list %>
|
|
46
124
|
)
|
|
47
125
|
|
|
48
126
|
<%= start_chef %>
|
|
127
|
+
|
|
@@ -136,14 +136,14 @@ class Chef
|
|
|
136
136
|
# we have to run the remote commands in 2047 char chunks
|
|
137
137
|
create_bootstrap_bat_command do |command_chunk, chunk_num|
|
|
138
138
|
begin
|
|
139
|
-
run_command("cmd.exe /C echo \"Rendering '#{bootstrap_bat_file}' chunk #{chunk_num}\" && #{command_chunk}")
|
|
139
|
+
run_command("cmd.exe /C echo \"Rendering '#{bootstrap_bat_file}' chunk #{chunk_num}\" && #{command_chunk}")
|
|
140
140
|
rescue SystemExit => e
|
|
141
141
|
raise unless e.success?
|
|
142
142
|
end
|
|
143
143
|
end
|
|
144
144
|
|
|
145
145
|
# execute the bootstrap.bat file
|
|
146
|
-
run_command(bootstrap_command)
|
|
146
|
+
run_command(bootstrap_command)
|
|
147
147
|
end
|
|
148
148
|
|
|
149
149
|
def bootstrap_command
|
|
@@ -17,7 +17,9 @@
|
|
|
17
17
|
#
|
|
18
18
|
|
|
19
19
|
require 'chef/knife/bootstrap_windows_base'
|
|
20
|
+
require 'chef/knife/winrm'
|
|
20
21
|
require 'chef/knife/winrm_base'
|
|
22
|
+
require 'chef/knife/bootstrap'
|
|
21
23
|
|
|
22
24
|
class Chef
|
|
23
25
|
class Knife
|
|
@@ -51,7 +53,7 @@ class Chef
|
|
|
51
53
|
winrm.config[:ca_trust_file] = Chef::Config[:knife][:ca_trust_file] if Chef::Config[:knife][:ca_trust_file]
|
|
52
54
|
winrm.config[:manual] = true
|
|
53
55
|
winrm.config[:winrm_port] = locate_config_value(:winrm_port)
|
|
54
|
-
winrm
|
|
56
|
+
winrm.run
|
|
55
57
|
end
|
|
56
58
|
|
|
57
59
|
end
|
|
@@ -136,6 +136,33 @@ WGET
|
|
|
136
136
|
escape_and_echo(win_wget)
|
|
137
137
|
end
|
|
138
138
|
|
|
139
|
+
def win_wget_ps
|
|
140
|
+
win_wget_ps = <<-WGET_PS
|
|
141
|
+
param(
|
|
142
|
+
[String] $remoteUrl,
|
|
143
|
+
[String] $localPath
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
$webClient = new-object System.Net.WebClient;
|
|
147
|
+
|
|
148
|
+
$webClient.DownloadFile($remoteUrl, $localPath);
|
|
149
|
+
WGET_PS
|
|
150
|
+
|
|
151
|
+
escape_and_echo(win_wget_ps)
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
def install_chef
|
|
155
|
+
install_chef = 'msiexec /qb /i "%LOCAL_DESTINATION_MSI_PATH%"'
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
def bootstrap_directory
|
|
159
|
+
bootstrap_directory = "C:\\chef"
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
def local_download_path
|
|
163
|
+
local_download_path = "%TEMP%\\chef-client-latest.msi"
|
|
164
|
+
end
|
|
165
|
+
|
|
139
166
|
# escape WIN BATCH special chars
|
|
140
167
|
# and prefixes each line with an
|
|
141
168
|
# echo
|
data/lib/chef/knife/winrm.rb
CHANGED
|
@@ -89,7 +89,16 @@ class Chef
|
|
|
89
89
|
end
|
|
90
90
|
r
|
|
91
91
|
end
|
|
92
|
-
|
|
92
|
+
if list.length == 0
|
|
93
|
+
if @action_nodes.length == 0
|
|
94
|
+
ui.fatal("No nodes returned from search!")
|
|
95
|
+
else
|
|
96
|
+
ui.fatal("#{@action_nodes.length} #{@action_nodes.length > 1 ? "nodes":"node"} found, " +
|
|
97
|
+
"but does not have the required attribute (#{config[:attribute]}) to establish the connection. " +
|
|
98
|
+
"Try setting another attribute to open the connection using --attribute.")
|
|
99
|
+
end
|
|
100
|
+
exit 10
|
|
101
|
+
end
|
|
93
102
|
session_from_list(list)
|
|
94
103
|
end
|
|
95
104
|
|
|
@@ -238,7 +247,7 @@ class Chef
|
|
|
238
247
|
end
|
|
239
248
|
|
|
240
249
|
session.close
|
|
241
|
-
|
|
250
|
+
@exit_code || 0
|
|
242
251
|
end
|
|
243
252
|
rescue WinRM::WinRMHTTPTransportError => e
|
|
244
253
|
case e.message
|
|
@@ -0,0 +1,115 @@
|
|
|
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
|
+
end
|
|
54
|
+
|
|
55
|
+
after(:all) do
|
|
56
|
+
# Clear the temp directory upon exit
|
|
57
|
+
if Dir.exists?(@temp_directory)
|
|
58
|
+
FileUtils::remove_dir(@temp_directory)
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
describe "running on any version of the Windows OS", :windows_only do
|
|
63
|
+
before do
|
|
64
|
+
@mock_bootstrap_context = Chef::Knife::Core::WindowsBootstrapContext.new({ }, nil, { })
|
|
65
|
+
|
|
66
|
+
# Stub the bootstrap context and prevent config related sections
|
|
67
|
+
# to be populated, chef installation and first chef run
|
|
68
|
+
@mock_bootstrap_context.stub(:validation_key).and_return("echo.validation_key")
|
|
69
|
+
@mock_bootstrap_context.stub(:encrypted_data_bag_secret).and_return("echo.encrypted_data_bag_secret")
|
|
70
|
+
@mock_bootstrap_context.stub(:config_content).and_return("echo.config_content")
|
|
71
|
+
@mock_bootstrap_context.stub(:start_chef).and_return("echo.echo start_chef_command")
|
|
72
|
+
@mock_bootstrap_context.stub(:run_list).and_return("echo.run_list")
|
|
73
|
+
@mock_bootstrap_context.stub(:install_chef).and_return("echo.echo install_chef_command")
|
|
74
|
+
|
|
75
|
+
# Change the directorires where bootstrap files will be created
|
|
76
|
+
@mock_bootstrap_context.stub(:bootstrap_directory).and_return(@temp_directory.gsub(::File::SEPARATOR, ::File::ALT_SEPARATOR))
|
|
77
|
+
@mock_bootstrap_context.stub(:local_download_path).and_return(@local_file_download_destination.gsub(::File::SEPARATOR, ::File::ALT_SEPARATOR))
|
|
78
|
+
|
|
79
|
+
# Prevent password prompt during bootstrap process
|
|
80
|
+
@mock_winrm = Chef::Knife::Winrm.new
|
|
81
|
+
@mock_winrm.stub(:get_password).and_return(nil)
|
|
82
|
+
Chef::Knife::Winrm.stub(:new).and_return(@mock_winrm)
|
|
83
|
+
|
|
84
|
+
Chef::Knife::Core::WindowsBootstrapContext.stub(:new).and_return(@mock_bootstrap_context)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
it "downloads the chef-client MSI during winrm bootstrap" do
|
|
88
|
+
clean_test_case
|
|
89
|
+
|
|
90
|
+
bootstrap_context = Chef::Knife::BootstrapWindowsWinrm.new([ "127.0.0.1" ])
|
|
91
|
+
|
|
92
|
+
# Execute the commands locally that would normally be executed via WinRM
|
|
93
|
+
bootstrap_context.stub(:run_command) do |command|
|
|
94
|
+
system(command)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
bootstrap_context.run
|
|
98
|
+
|
|
99
|
+
# Download should succeed
|
|
100
|
+
download_succeeded?.should == true
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def download_succeeded?
|
|
105
|
+
File.exists?(@local_file_download_destination) && ! File.zero?(@local_file_download_destination)
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
# Remove file artifiacts generated by individual test cases
|
|
109
|
+
def clean_test_case
|
|
110
|
+
if File.exists?(@local_file_download_destination)
|
|
111
|
+
File.delete(@local_file_download_destination)
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
end
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
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.treat_symbols_as_metadata_keys_with_true_values = true
|
|
59
|
+
|
|
60
|
+
config.filter_run_excluding :windows_only => true unless windows?
|
|
61
|
+
config.filter_run_excluding :windows_2012_only => true unless windows2012?
|
|
62
|
+
end
|
|
63
|
+
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Author:: Bryan McLellan <btm@opscode.com>
|
|
3
|
+
# Copyright:: Copyright (c) 2013 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 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
|
+
Chef::Knife::Winrm.load_deps
|
|
22
|
+
|
|
23
|
+
describe Chef::Knife::Winrm do
|
|
24
|
+
before(:all) do
|
|
25
|
+
@original_config = Chef::Config.hash_dup
|
|
26
|
+
@original_knife_config = Chef::Config[:knife].dup
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
after(:all) do
|
|
30
|
+
Chef::Config.configuration = @original_config
|
|
31
|
+
Chef::Config[:knife] = @original_knife_config
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
before do
|
|
35
|
+
@knife = Chef::Knife::Winrm.new
|
|
36
|
+
@knife.config[:attribute] = "fqdn"
|
|
37
|
+
@node_foo = Chef::Node.new
|
|
38
|
+
@node_foo.automatic_attrs[:fqdn] = "foo.example.org"
|
|
39
|
+
@node_foo.automatic_attrs[:ipaddress] = "10.0.0.1"
|
|
40
|
+
@node_bar = Chef::Node.new
|
|
41
|
+
@node_bar.automatic_attrs[:fqdn] = "bar.example.org"
|
|
42
|
+
@node_bar.automatic_attrs[:ipaddress] = "10.0.0.2"
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
describe "#configure_session" do
|
|
46
|
+
before do
|
|
47
|
+
@query = mock("Chef::Search::Query")
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
context "when there are some hosts found but they do not have an attribute to connect with" do
|
|
51
|
+
before do
|
|
52
|
+
@query.stub!(:search).and_return([[@node_foo, @node_bar]])
|
|
53
|
+
@node_foo.automatic_attrs[:fqdn] = nil
|
|
54
|
+
@node_bar.automatic_attrs[:fqdn] = nil
|
|
55
|
+
Chef::Search::Query.stub!(:new).and_return(@query)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it "should raise a specific error (KNIFE-222)" do
|
|
59
|
+
@knife.ui.should_receive(:fatal).with(/does not have the required attribute/)
|
|
60
|
+
@knife.should_receive(:exit).with(10)
|
|
61
|
+
@knife.configure_session
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
metadata
CHANGED
|
@@ -1,50 +1,44 @@
|
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: knife-windows
|
|
3
|
-
version: !ruby/object:Gem::Version
|
|
4
|
-
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.5.12
|
|
5
5
|
prerelease:
|
|
6
|
-
segments:
|
|
7
|
-
- 0
|
|
8
|
-
- 5
|
|
9
|
-
- 10
|
|
10
|
-
version: 0.5.10
|
|
11
6
|
platform: ruby
|
|
12
|
-
authors:
|
|
7
|
+
authors:
|
|
13
8
|
- Seth Chisamore
|
|
14
9
|
autorequire:
|
|
15
10
|
bindir: bin
|
|
16
11
|
cert_chain: []
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
- !ruby/object:Gem::Dependency
|
|
12
|
+
date: 2013-01-25 00:00:00.000000000 Z
|
|
13
|
+
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
21
15
|
name: em-winrm
|
|
22
|
-
|
|
23
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
|
24
17
|
none: false
|
|
25
|
-
requirements:
|
|
26
|
-
- -
|
|
27
|
-
- !ruby/object:Gem::Version
|
|
28
|
-
hash: 3
|
|
29
|
-
segments:
|
|
30
|
-
- 0
|
|
31
|
-
- 5
|
|
32
|
-
- 4
|
|
18
|
+
requirements:
|
|
19
|
+
- - '='
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
33
21
|
version: 0.5.4
|
|
34
22
|
type: :runtime
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
+
none: false
|
|
26
|
+
requirements:
|
|
27
|
+
- - '='
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: 0.5.4
|
|
30
|
+
description: Plugin that adds functionality to Chef's Knife CLI for configuring/interacting
|
|
31
|
+
with nodes running Microsoft Windows
|
|
32
|
+
email:
|
|
38
33
|
- schisamo@opscode.com
|
|
39
34
|
executables: []
|
|
40
|
-
|
|
41
35
|
extensions: []
|
|
42
|
-
|
|
43
|
-
extra_rdoc_files:
|
|
36
|
+
extra_rdoc_files:
|
|
44
37
|
- README.rdoc
|
|
45
38
|
- LICENSE
|
|
46
|
-
files:
|
|
39
|
+
files:
|
|
47
40
|
- .gitignore
|
|
41
|
+
- .rspec
|
|
48
42
|
- CHANGELOG
|
|
49
43
|
- Gemfile
|
|
50
44
|
- LICENSE
|
|
@@ -60,40 +54,32 @@ files:
|
|
|
60
54
|
- lib/chef/knife/winrm.rb
|
|
61
55
|
- lib/chef/knife/winrm_base.rb
|
|
62
56
|
- lib/knife-windows/version.rb
|
|
57
|
+
- spec/functional/bootstrap_download_spec.rb
|
|
58
|
+
- spec/spec_helper.rb
|
|
59
|
+
- spec/unit/knife/winrm_spec.rb
|
|
63
60
|
homepage: https://github.com/opscode/knife-windows
|
|
64
61
|
licenses: []
|
|
65
|
-
|
|
66
62
|
post_install_message:
|
|
67
63
|
rdoc_options: []
|
|
68
|
-
|
|
69
|
-
require_paths:
|
|
64
|
+
require_paths:
|
|
70
65
|
- lib
|
|
71
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
72
67
|
none: false
|
|
73
|
-
requirements:
|
|
74
|
-
- -
|
|
75
|
-
- !ruby/object:Gem::Version
|
|
76
|
-
hash: 49
|
|
77
|
-
segments:
|
|
78
|
-
- 1
|
|
79
|
-
- 9
|
|
80
|
-
- 1
|
|
68
|
+
requirements:
|
|
69
|
+
- - ! '>='
|
|
70
|
+
- !ruby/object:Gem::Version
|
|
81
71
|
version: 1.9.1
|
|
82
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
83
73
|
none: false
|
|
84
|
-
requirements:
|
|
85
|
-
- -
|
|
86
|
-
- !ruby/object:Gem::Version
|
|
87
|
-
|
|
88
|
-
segments:
|
|
89
|
-
- 0
|
|
90
|
-
version: "0"
|
|
74
|
+
requirements:
|
|
75
|
+
- - ! '>='
|
|
76
|
+
- !ruby/object:Gem::Version
|
|
77
|
+
version: '0'
|
|
91
78
|
requirements: []
|
|
92
|
-
|
|
93
79
|
rubyforge_project:
|
|
94
|
-
rubygems_version: 1.8.
|
|
80
|
+
rubygems_version: 1.8.21
|
|
95
81
|
signing_key:
|
|
96
82
|
specification_version: 3
|
|
97
|
-
summary: Plugin that adds functionality to Chef's Knife CLI for configuring/interacting
|
|
83
|
+
summary: Plugin that adds functionality to Chef's Knife CLI for configuring/interacting
|
|
84
|
+
with nodes running Microsoft Windows
|
|
98
85
|
test_files: []
|
|
99
|
-
|