knife-windows 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +5 -5
  3. data/.travis.yml +20 -20
  4. data/CHANGELOG.md +87 -83
  5. data/DOC_CHANGES.md +20 -20
  6. data/Gemfile +12 -12
  7. data/LICENSE +201 -201
  8. data/README.md +396 -396
  9. data/RELEASE_NOTES.md +34 -34
  10. data/Rakefile +21 -21
  11. data/appveyor.yml +42 -42
  12. data/ci.gemfile +15 -15
  13. data/features/knife_help.feature +20 -20
  14. data/features/support/env.rb +5 -5
  15. data/knife-windows.gemspec +28 -28
  16. data/lib/chef/knife/bootstrap/windows-chef-client-msi.erb +247 -247
  17. data/lib/chef/knife/bootstrap_windows_base.rb +407 -401
  18. data/lib/chef/knife/bootstrap_windows_ssh.rb +110 -110
  19. data/lib/chef/knife/bootstrap_windows_winrm.rb +95 -102
  20. data/lib/chef/knife/core/windows_bootstrap_context.rb +362 -362
  21. data/lib/chef/knife/knife_windows_base.rb +33 -33
  22. data/lib/chef/knife/windows_cert_generate.rb +155 -155
  23. data/lib/chef/knife/windows_cert_install.rb +68 -68
  24. data/lib/chef/knife/windows_helper.rb +36 -36
  25. data/lib/chef/knife/windows_listener_create.rb +107 -107
  26. data/lib/chef/knife/winrm.rb +122 -212
  27. data/lib/chef/knife/winrm_base.rb +118 -118
  28. data/lib/chef/knife/winrm_knife_base.rb +309 -218
  29. data/lib/chef/knife/winrm_session.rb +82 -82
  30. data/lib/chef/knife/winrm_shared_options.rb +47 -47
  31. data/lib/chef/knife/wsman_endpoint.rb +44 -44
  32. data/lib/chef/knife/wsman_test.rb +95 -95
  33. data/lib/knife-windows/path_helper.rb +234 -234
  34. data/lib/knife-windows/version.rb +6 -6
  35. data/spec/assets/win_template_rendered_with_bootstrap_install_command.txt +217 -217
  36. data/spec/assets/win_template_rendered_with_bootstrap_install_command_on_12_5_client.txt +217 -217
  37. data/spec/assets/win_template_rendered_without_bootstrap_install_command.txt +329 -329
  38. data/spec/assets/win_template_rendered_without_bootstrap_install_command_on_12_5_client.txt +329 -329
  39. data/spec/assets/win_template_unrendered.txt +246 -246
  40. data/spec/functional/bootstrap_download_spec.rb +234 -233
  41. data/spec/spec_helper.rb +88 -88
  42. data/spec/unit/knife/bootstrap_options_spec.rb +148 -146
  43. data/spec/unit/knife/bootstrap_template_spec.rb +92 -92
  44. data/spec/unit/knife/bootstrap_windows_winrm_spec.rb +259 -243
  45. data/spec/unit/knife/core/windows_bootstrap_context_spec.rb +151 -151
  46. data/spec/unit/knife/windows_cert_generate_spec.rb +90 -90
  47. data/spec/unit/knife/windows_cert_install_spec.rb +51 -51
  48. data/spec/unit/knife/windows_listener_create_spec.rb +76 -76
  49. data/spec/unit/knife/winrm_session_spec.rb +73 -73
  50. data/spec/unit/knife/winrm_spec.rb +551 -504
  51. data/spec/unit/knife/wsman_test_spec.rb +178 -175
  52. metadata +3 -23
data/spec/spec_helper.rb CHANGED
@@ -1,88 +1,88 @@
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
- require_relative '../lib/chef/knife/bootstrap_windows_ssh'
27
- require_relative '../lib/chef/knife/wsman_test'
28
-
29
- if windows?
30
- require 'ruby-wmi'
31
- end
32
-
33
- def windows2012?
34
- is_win2k12 = false
35
-
36
- if windows?
37
- this_operating_system = WMI::Win32_OperatingSystem.find(:first)
38
- os_version = this_operating_system.send('Version')
39
-
40
- # The operating system version is a string in the following form
41
- # that can be split into components based on the '.' delimiter:
42
- # MajorVersionNumber.MinorVersionNumber.BuildNumber
43
- os_version_components = os_version.split('.')
44
-
45
- if os_version_components.length < 2
46
- raise 'WMI returned a Windows version from Win32_OperatingSystem.Version ' +
47
- 'with an unexpected format. The Windows version could not be determined.'
48
- end
49
-
50
- # Windows 6.2 is Windows Server 2012, so test the major and
51
- # minor version components
52
- is_win2k12 = os_version_components[0] == '6' && os_version_components[1] == '2'
53
- end
54
-
55
- is_win2k12
56
- end
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
78
-
79
- RSpec.configure do |config|
80
- config.filter_run_excluding :windows_only => true unless windows?
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?
87
- end
88
-
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
+ require_relative '../lib/chef/knife/bootstrap_windows_ssh'
27
+ require_relative '../lib/chef/knife/wsman_test'
28
+
29
+ if windows?
30
+ require 'ruby-wmi'
31
+ end
32
+
33
+ def windows2012?
34
+ is_win2k12 = false
35
+
36
+ if windows?
37
+ this_operating_system = WMI::Win32_OperatingSystem.find(:first)
38
+ os_version = this_operating_system.send('Version')
39
+
40
+ # The operating system version is a string in the following form
41
+ # that can be split into components based on the '.' delimiter:
42
+ # MajorVersionNumber.MinorVersionNumber.BuildNumber
43
+ os_version_components = os_version.split('.')
44
+
45
+ if os_version_components.length < 2
46
+ raise 'WMI returned a Windows version from Win32_OperatingSystem.Version ' +
47
+ 'with an unexpected format. The Windows version could not be determined.'
48
+ end
49
+
50
+ # Windows 6.2 is Windows Server 2012, so test the major and
51
+ # minor version components
52
+ is_win2k12 = os_version_components[0] == '6' && os_version_components[1] == '2'
53
+ end
54
+
55
+ is_win2k12
56
+ end
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
78
+
79
+ RSpec.configure do |config|
80
+ config.filter_run_excluding :windows_only => true unless windows?
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?
87
+ end
88
+
@@ -1,146 +1,148 @@
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
- ]}
98
-
99
- # win_ignore: Options in windows that aren't relevant to core.
100
- let(:win_ignore) { [
101
- :attribute,
102
- :auth_timeout,
103
- :ca_trust_file,
104
- :install_as_service,
105
- :kerberos_keytab_file,
106
- :kerberos_realm,
107
- :kerberos_service,
108
- :manual,
109
- :session_timeout,
110
- :winrm_authentication_protocol,
111
- :winrm_transport,
112
- ] }
113
-
114
- include_examples 'compare_options'
115
- end
116
-
117
- context 'when compared to BootstrapWindowsSsh' do
118
- let(:win_bootstrap) { Chef::Knife::BootstrapWindowsSsh.new }
119
-
120
- # opt_map: Hash of symbols in windows mapping to symbols in core. Name checks are
121
- # ignored for these.
122
- let(:opt_map) { {
123
- :msi_url => :bootstrap_url,
124
- :encrypted_data_bag_secret => :secret,
125
- :encrypted_data_bag_secret_file => :secret_file,
126
- :bootstrap_install_command => :bootstrap_install_command,
127
- }}
128
- # ref_ignore: Options in core that are not implemented here.
129
- let(:ref_ignore) { [
130
- :bootstrap_curl_options,
131
- :bootstrap_wget_options,
132
- :use_sudo,
133
- :use_sudo_password,
134
- :encrypt, # irrelevant during bootstrap
135
- ]}
136
- # win_ignore: Options in windows that aren't relevant to core.
137
- let(:win_ignore) { [
138
- :auth_timeout,
139
- :install_as_service,
140
- :host_key_verification, # Deprecated - remove this when the flag is removed.
141
- ] }
142
-
143
- include_examples 'compare_options'
144
- end
145
-
146
- end
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
+ :preserve_home,
94
+ :ssh_gateway,
95
+ :use_sudo,
96
+ :use_sudo_password,
97
+ :encrypt, # irrelevant during bootstrap
98
+ ]}
99
+
100
+ # win_ignore: Options in windows that aren't relevant to core.
101
+ let(:win_ignore) { [
102
+ :attribute,
103
+ :auth_timeout,
104
+ :ca_trust_file,
105
+ :install_as_service,
106
+ :kerberos_keytab_file,
107
+ :kerberos_realm,
108
+ :kerberos_service,
109
+ :manual,
110
+ :session_timeout,
111
+ :winrm_authentication_protocol,
112
+ :winrm_transport,
113
+ ] }
114
+
115
+ include_examples 'compare_options'
116
+ end
117
+
118
+ context 'when compared to BootstrapWindowsSsh' do
119
+ let(:win_bootstrap) { Chef::Knife::BootstrapWindowsSsh.new }
120
+
121
+ # opt_map: Hash of symbols in windows mapping to symbols in core. Name checks are
122
+ # ignored for these.
123
+ let(:opt_map) { {
124
+ :msi_url => :bootstrap_url,
125
+ :encrypted_data_bag_secret => :secret,
126
+ :encrypted_data_bag_secret_file => :secret_file,
127
+ :bootstrap_install_command => :bootstrap_install_command,
128
+ }}
129
+ # ref_ignore: Options in core that are not implemented here.
130
+ let(:ref_ignore) { [
131
+ :bootstrap_curl_options,
132
+ :bootstrap_wget_options,
133
+ :preserve_home,
134
+ :use_sudo,
135
+ :use_sudo_password,
136
+ :encrypt, # irrelevant during bootstrap
137
+ ]}
138
+ # win_ignore: Options in windows that aren't relevant to core.
139
+ let(:win_ignore) { [
140
+ :auth_timeout,
141
+ :install_as_service,
142
+ :host_key_verification, # Deprecated - remove this when the flag is removed.
143
+ ] }
144
+
145
+ include_examples 'compare_options'
146
+ end
147
+
148
+ end