knife-windows 0.5.15 → 0.6.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.
@@ -1,99 +1,99 @@
1
- #
2
- # Author:: Seth Chisamore (<schisamo@opscode.com>)
3
- # Copyright:: Copyright (c) 2011 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 'chef/knife'
20
- require 'chef/encrypted_data_bag_item'
21
- require 'kconv'
22
-
23
- class Chef
24
- class Knife
25
- module WinrmBase
26
-
27
- # :nodoc:
28
- # Would prefer to do this in a rational way, but can't be done b/c of
29
- # Mixlib::CLI's design :(
30
- def self.included(includer)
31
- includer.class_eval do
32
-
33
- deps do
34
- require 'readline'
35
- require 'chef/json_compat'
36
- end
37
-
38
- option :winrm_user,
39
- :short => "-x USERNAME",
40
- :long => "--winrm-user USERNAME",
41
- :description => "The WinRM username",
42
- :default => "Administrator",
43
- :proc => Proc.new { |key| Chef::Config[:knife][:winrm_user] = key }
44
-
45
- option :winrm_password,
46
- :short => "-P PASSWORD",
47
- :long => "--winrm-password PASSWORD",
48
- :description => "The WinRM password",
49
- :proc => Proc.new { |key| Chef::Config[:knife][:winrm_password] = key }
50
-
51
- option :winrm_port,
52
- :short => "-p PORT",
53
- :long => "--winrm-port PORT",
54
- :description => "The WinRM port, by default this is 5985",
55
- :default => "5985",
56
- :proc => Proc.new { |key| Chef::Config[:knife][:winrm_port] = key }
57
-
58
- option :identity_file,
59
- :short => "-i IDENTITY_FILE",
60
- :long => "--identity-file IDENTITY_FILE",
61
- :description => "The SSH identity file used for authentication"
62
-
63
- option :winrm_transport,
64
- :short => "-t TRANSPORT",
65
- :long => "--winrm-transport TRANSPORT",
66
- :description => "The WinRM transport type. valid choices are [ssl, plaintext]",
67
- :default => 'plaintext',
68
- :proc => Proc.new { |transport| Chef::Config[:knife][:winrm_transport] = transport }
69
-
70
- option :kerberos_keytab_file,
71
- :short => "-i KEYTAB_FILE",
72
- :long => "--keytab-file KEYTAB_FILE",
73
- :description => "The Kerberos keytab file used for authentication",
74
- :proc => Proc.new { |keytab| Chef::Config[:knife][:kerberos_keytab_file] = keytab }
75
-
76
- option :kerberos_realm,
77
- :short => "-R KERBEROS_REALM",
78
- :long => "--kerberos-realm KERBEROS_REALM",
79
- :description => "The Kerberos realm used for authentication",
80
- :proc => Proc.new { |realm| Chef::Config[:knife][:kerberos_realm] = realm }
81
-
82
- option :kerberos_service,
83
- :short => "-S KERBEROS_SERVICE",
84
- :long => "--kerberos-service KERBEROS_SERVICE",
85
- :description => "The Kerberos service used for authentication",
86
- :proc => Proc.new { |service| Chef::Config[:knife][:kerberos_service] = service }
87
-
88
- option :ca_trust_file,
89
- :short => "-f CA_TRUST_FILE",
90
- :long => "--ca-trust-file CA_TRUST_FILE",
91
- :description => "The Certificate Authority (CA) trust file used for SSL transport",
92
- :proc => Proc.new { |trust| Chef::Config[:knife][:ca_trust_file] = trust }
93
-
94
- end
95
- end
96
-
97
- end
98
- end
99
- end
1
+ #
2
+ # Author:: Seth Chisamore (<schisamo@opscode.com>)
3
+ # Copyright:: Copyright (c) 2011 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 'chef/knife'
20
+ require 'chef/encrypted_data_bag_item'
21
+ require 'kconv'
22
+
23
+ class Chef
24
+ class Knife
25
+ module WinrmBase
26
+
27
+ # :nodoc:
28
+ # Would prefer to do this in a rational way, but can't be done b/c of
29
+ # Mixlib::CLI's design :(
30
+ def self.included(includer)
31
+ includer.class_eval do
32
+
33
+ deps do
34
+ require 'readline'
35
+ require 'chef/json_compat'
36
+ end
37
+
38
+ option :winrm_user,
39
+ :short => "-x USERNAME",
40
+ :long => "--winrm-user USERNAME",
41
+ :description => "The WinRM username",
42
+ :default => "Administrator",
43
+ :proc => Proc.new { |key| Chef::Config[:knife][:winrm_user] = key }
44
+
45
+ option :winrm_password,
46
+ :short => "-P PASSWORD",
47
+ :long => "--winrm-password PASSWORD",
48
+ :description => "The WinRM password",
49
+ :proc => Proc.new { |key| Chef::Config[:knife][:winrm_password] = key }
50
+
51
+ option :winrm_port,
52
+ :short => "-p PORT",
53
+ :long => "--winrm-port PORT",
54
+ :description => "The WinRM port, by default this is 5985",
55
+ :default => "5985",
56
+ :proc => Proc.new { |key| Chef::Config[:knife][:winrm_port] = key }
57
+
58
+ option :identity_file,
59
+ :short => "-i IDENTITY_FILE",
60
+ :long => "--identity-file IDENTITY_FILE",
61
+ :description => "The SSH identity file used for authentication"
62
+
63
+ option :winrm_transport,
64
+ :short => "-t TRANSPORT",
65
+ :long => "--winrm-transport TRANSPORT",
66
+ :description => "The WinRM transport type. valid choices are [ssl, plaintext]",
67
+ :default => 'plaintext',
68
+ :proc => Proc.new { |transport| Chef::Config[:knife][:winrm_transport] = transport }
69
+
70
+ option :kerberos_keytab_file,
71
+ :short => "-i KEYTAB_FILE",
72
+ :long => "--keytab-file KEYTAB_FILE",
73
+ :description => "The Kerberos keytab file used for authentication",
74
+ :proc => Proc.new { |keytab| Chef::Config[:knife][:kerberos_keytab_file] = keytab }
75
+
76
+ option :kerberos_realm,
77
+ :short => "-R KERBEROS_REALM",
78
+ :long => "--kerberos-realm KERBEROS_REALM",
79
+ :description => "The Kerberos realm used for authentication",
80
+ :proc => Proc.new { |realm| Chef::Config[:knife][:kerberos_realm] = realm }
81
+
82
+ option :kerberos_service,
83
+ :short => "-S KERBEROS_SERVICE",
84
+ :long => "--kerberos-service KERBEROS_SERVICE",
85
+ :description => "The Kerberos service used for authentication",
86
+ :proc => Proc.new { |service| Chef::Config[:knife][:kerberos_service] = service }
87
+
88
+ option :ca_trust_file,
89
+ :short => "-f CA_TRUST_FILE",
90
+ :long => "--ca-trust-file CA_TRUST_FILE",
91
+ :description => "The Certificate Authority (CA) trust file used for SSL transport",
92
+ :proc => Proc.new { |trust| Chef::Config[:knife][:ca_trust_file] = trust }
93
+
94
+ end
95
+ end
96
+
97
+ end
98
+ end
99
+ end
@@ -1,6 +1,6 @@
1
- module Knife
2
- module Windows
3
- VERSION = "0.5.15"
4
- MAJOR, MINOR, TINY = VERSION.split('.')
5
- end
6
- end
1
+ module Knife
2
+ module Windows
3
+ VERSION = "0.6.0"
4
+ MAJOR, MINOR, TINY = VERSION.split('.')
5
+ end
6
+ end
@@ -1,120 +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
- before do
67
- @mock_bootstrap_context = Chef::Knife::Core::WindowsBootstrapContext.new({ }, nil, { })
68
-
69
- # Stub the bootstrap context and prevent config related sections
70
- # from being populated, i.e. chef installation and first chef
71
- # run sections
72
- @mock_bootstrap_context.stub(:validation_key).and_return("echo.validation_key")
73
- @mock_bootstrap_context.stub(:encrypted_data_bag_secret).and_return("echo.encrypted_data_bag_secret")
74
- @mock_bootstrap_context.stub(:config_content).and_return("echo.config_content")
75
- @mock_bootstrap_context.stub(:start_chef).and_return("echo.echo start_chef_command")
76
- @mock_bootstrap_context.stub(:run_list).and_return("echo.run_list")
77
- @mock_bootstrap_context.stub(:install_chef).and_return("echo.echo install_chef_command")
78
-
79
- # Change the directories where bootstrap files will be created
80
- @mock_bootstrap_context.stub(:bootstrap_directory).and_return(@temp_directory.gsub(::File::SEPARATOR, ::File::ALT_SEPARATOR))
81
- @mock_bootstrap_context.stub(:local_download_path).and_return(@local_file_download_destination.gsub(::File::SEPARATOR, ::File::ALT_SEPARATOR))
82
-
83
- # Prevent password prompt during bootstrap process
84
- @mock_winrm = Chef::Knife::Winrm.new
85
- @mock_winrm.stub(:get_password).and_return(nil)
86
- Chef::Knife::Winrm.stub(:new).and_return(@mock_winrm)
87
-
88
- Chef::Knife::Core::WindowsBootstrapContext.stub(:new).and_return(@mock_bootstrap_context)
89
- end
90
-
91
- it "downloads the chef-client MSI during winrm bootstrap" do
92
- clean_test_case
93
-
94
- winrm_bootstrapper = Chef::Knife::BootstrapWindowsWinrm.new([ "127.0.0.1" ])
95
- winrm_bootstrapper.config[:template_file] = @template_file_path
96
-
97
- # Execute the commands locally that would normally be executed via WinRM
98
- winrm_bootstrapper.stub(:run_command) do |command|
99
- system(command)
100
- end
101
-
102
- winrm_bootstrapper.run
103
-
104
- # Download should succeed
105
- download_succeeded?.should == true
106
- end
107
- end
108
-
109
- def download_succeeded?
110
- File.exists?(@local_file_download_destination) && ! File.zero?(@local_file_download_destination)
111
- end
112
-
113
- # Remove file artifacts generated by individual test cases
114
- def clean_test_case
115
- if File.exists?(@local_file_download_destination)
116
- File.delete(@local_file_download_destination)
117
- end
118
- end
119
-
120
- 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
+ before do
67
+ @mock_bootstrap_context = Chef::Knife::Core::WindowsBootstrapContext.new({ }, nil, { :knife => {} })
68
+
69
+ # Stub the bootstrap context and prevent config related sections
70
+ # from being populated, i.e. chef installation and first chef
71
+ # run sections
72
+ @mock_bootstrap_context.stub(:validation_key).and_return("echo.validation_key")
73
+ @mock_bootstrap_context.stub(:encrypted_data_bag_secret).and_return("echo.encrypted_data_bag_secret")
74
+ @mock_bootstrap_context.stub(:config_content).and_return("echo.config_content")
75
+ @mock_bootstrap_context.stub(:start_chef).and_return("echo.echo start_chef_command")
76
+ @mock_bootstrap_context.stub(:run_list).and_return("echo.run_list")
77
+ @mock_bootstrap_context.stub(:install_chef).and_return("echo.echo install_chef_command")
78
+
79
+ # Change the directories where bootstrap files will be created
80
+ @mock_bootstrap_context.stub(:bootstrap_directory).and_return(@temp_directory.gsub(::File::SEPARATOR, ::File::ALT_SEPARATOR))
81
+ @mock_bootstrap_context.stub(:local_download_path).and_return(@local_file_download_destination.gsub(::File::SEPARATOR, ::File::ALT_SEPARATOR))
82
+
83
+ # Prevent password prompt during bootstrap process
84
+ @mock_winrm = Chef::Knife::Winrm.new
85
+ @mock_winrm.stub(:get_password).and_return(nil)
86
+ Chef::Knife::Winrm.stub(:new).and_return(@mock_winrm)
87
+
88
+ Chef::Knife::Core::WindowsBootstrapContext.stub(: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
+ winrm_bootstrapper.stub(: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
+ winrm_bootstrapper.stub(:run_command) do |command|
101
+ system(command)
102
+ end
103
+
104
+ winrm_bootstrapper.run
105
+
106
+ # Download should succeed
107
+ download_succeeded?.should == 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