knife-windows 0.6.0 → 0.8.2

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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- N2UyYTQ5NDQwMTQ2Yzc2MTVkZDI3OGFiMTVjMjEyMmIxMmUxMWVkMw==
4
+ M2QyMmEwMTg1NGM2ZWEyNzdhYjFhMzE3YWI0NDY1NjcxNzU3NzgxNQ==
5
5
  data.tar.gz: !binary |-
6
- Nzk5OTk2NmYwYzBiNjQ3NGZiZmYyMjAxOGNjYmE1OWVhYzg4M2NiMw==
6
+ MmU3YWEzNjFhMWJjYTY2NzlkY2Q3NWMzMDYyZTMwMDNkYWZkZDNmOQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MzdlNDUwY2QyMGIwYzAzZmRlYjY0YmM4YjkxMmZjOGZkYjM0Yzg2YmQ5MWNh
10
- NDkwOGFlODhiZDRlZDc1NjZjMjY3YTA4YTRiNjJkMDQ5YmFmY2I1MDVmZTNi
11
- YTUyZGQ3M2Q4Njk4OWM0NGVhMDNhMTdlOTlmMjJjZjI4OGM0Y2M=
9
+ YTI3MTczYWRmNzBjZDg5MTMyMjA4NjdlMWNiMTdhNDEyYjhhZmE0NTI5NjA2
10
+ YTU0Mjk3OWY2NmMyZjM5MTcyNDI4NzFiZWUwMmRmMTUyNDI2MGJiOTFhMDJi
11
+ NGJhYmQ1NzMxMzIyN2IyMzU1ODZkZTczMzE2YTA0MWExM2RiNTA=
12
12
  data.tar.gz: !binary |-
13
- MDgzZWFlNzQ3OWI3MjNkOWEyZmNlNmYyYTM4NTA0ZjYzOTJmZjc4MTQwMGVi
14
- ZWZkYTY2YmE5MmNhNThiYmY5MTZmMWM3NmM5Y2M2NmY3NGFlOTJhM2ExYjU1
15
- NTBhZTUxYjVmNzEyYmY1OTRmYjA3MWIyNDhkYmNhNTg2ODYzMjY=
13
+ ZmVmMTEwZTU4NjdmOWI2NmE4MTczYTM1YmRhNjAxMjY3NWIzZDUwYmIwYmE5
14
+ ODk5NmMzYzZjNzBkZDMxY2I3ZGEwODU2YTk0ZDJhNWRjMWYwZTk3YTQ3MmRi
15
+ NWFkZTVlYTUxNTRkNjgxNTVmNTU5Nzg5ZTliNjNlNmExZTgwNjM=
data/.rspec CHANGED
@@ -1,3 +1,3 @@
1
- --color
2
- -fs
3
-
1
+ --color
2
+ -fdocumentation
3
+
data/CHANGELOG.md CHANGED
@@ -1,10 +1,20 @@
1
1
  # knife-windows Change Log
2
2
 
3
3
  ## Unreleased changes
4
+ None.
4
5
 
5
- None
6
+ ## Latest release: 0.8.2
7
+ * [knife-windows #108](https://github.com/opscode/knife-windows/issues/108) Error: Unencrypted communication not supported if remote server does not require encryption
6
8
 
7
- ## Last Release: 0.6.0 (05/08/2014)
9
+ ## Latest release: 0.8.0
10
+ * [knife-windows #98](https://github.com/opscode/knife-windows/issues/98) Get winrm command exit code if it is not expected
11
+ * [knife-windows #96](https://github.com/opscode/knife-windows/issues/96) Fix break from OS patch KB2918614
12
+ * Remove the 'instance data' method of creating EC2 servers
13
+ * Update winrm-s dependency along with em-winrm and winrm dependencies
14
+ * Return failure codes from knife winrm even when `returns` is not set
15
+ * Support Windows negotiate authentication protocol when running knife on Windows
16
+
17
+ ## Release: 0.6.0 (05/08/2014)
8
18
 
9
19
  * [KNIFE-386](https://tickets.opscode.com/browse/KNIFE-386) Wait for a valid command response before bootstrapping over WinRM
10
20
  * [KNIFE-394](https://tickets.opscode.com/browse/KNIFE-394) Update em-winrm dependency
data/DOC_CHANGES.md CHANGED
@@ -6,37 +6,18 @@ Example Doc Change:
6
6
  Description of the required change.
7
7
  -->
8
8
 
9
- # knife-windows 0.6.0 doc changes:
10
-
11
- ### `--auth-timeout` option for bootstrap
12
- The `knife windows bootstrap` command has a new `--auth-timeout` option that
13
- takes a number of minutes as an argument. After the command has detected that
14
- the node to be bootstrapped has opened a port for the desired transport (e.g.
15
- WinRM), the command then tries to successfully execute a remote test command
16
- on the system to verify authentication and will retry for the number of minutes specified in the
17
- `--auth-timeout` option if an authentication error is received. This is
18
- particularly useful for nodes hosted by cloud providers that may open up ports before user
19
- identities that can be authenticated are configured on the system, or if the
20
- authentication subsystem's readiness lags that of transport readiness.
21
-
22
- If the `--auth-timeout` option is not specified, the default retry period is
23
- 25 minutes.
24
-
25
- This value is currently only honored when bootstrapping using the WinRM
26
- transport and is ignored when bootstrapping via ssh.
27
-
28
- ### New configuration option for `knife winrm`: `:suppress_auth_failure`
29
- The option `:suppress_auth_failure` may be configured in `knife.rb` to alter
30
- the behavior of the `knife winrm` subcommand's behavior when authentication
31
- fails:
32
-
33
- * When this option is not specified (the default case) or is configured as `false`, the `knife winrm`
34
- subcommand will return a process exit code of `100` if the command is able to
35
- connect to the WinRM transport on the remote system but fails to authenticate.
36
- * When this option is set to `true`, the exit status in the authentication
37
- failure case is `0`.
38
-
39
- The default behavior is retained for compatibility reasons. The ability to
40
- override it via the `:suppress_auth_failure` option is useful for automation that uses the `knife winrm` subcommand
41
- and needs to implement customized retry behavior when authentication fails.
42
-
9
+ # knife-windows 0.8.2 doc changes
10
+
11
+ ### Negotiate / NTLM authentication support
12
+ If you are running `knife-windows` subcommands from a Windows workstation, you
13
+ should not specify a username argument that includes a domain name (i.e. a
14
+ name formatted like `domain\user`) unless the remote host has WinRM's
15
+ `AllowUnencrypted` setting set to `$false` (the default setting on Windows if
16
+ the `winrm quickconfig` command was used to enable WinRM). If you've modified
17
+ the host to set this to `$true` instead of its default value and you run
18
+ subcommands from a Windows workstation where the username specified to
19
+ `knife-windows` contains a domain, the command will fail with an
20
+ authentication error. To avoid this, omit the domain name (this will only work
21
+ if the system is not joined to a domain, i.e. you were specifying the local
22
+ workstation as the domain), or set `AllowUnencrypted` to `$false` which is a
23
+ more secure setting.
data/Gemfile CHANGED
@@ -4,7 +4,7 @@ source "https://rubygems.org"
4
4
  gemspec
5
5
 
6
6
  group :test do
7
- gem "rspec"
7
+ gem "rspec", '~> 3.0'
8
8
  gem "ruby-wmi"
9
9
  gem "chef"
10
10
  gem 'rake'
data/README.md ADDED
@@ -0,0 +1,161 @@
1
+ Knife Windows Plugin
2
+ ====================
3
+
4
+ This plugin adds additional functionality to the Chef Knife CLI tool for
5
+ configuring/interacting with nodes running Microsoft Windows. The subcommands
6
+ should function on any system running Ruby 1.9.1+ but nodes being configured
7
+ via these subcommands require Windows Remote Management (WinRM) 1.0+.WinRM
8
+ allows you to call native objects in Windows. This includes, but is not
9
+ limited to, running batch scripts, powershell scripts and fetching WMI
10
+ variables. For more information on WinRM, please visit
11
+ [Microsoft's WinRM site](http://msdn.microsoft.com/en-us/library/aa384426(v=VS.85).aspx).
12
+ You will want to familiarize yourself with (certain key aspects) of WinRM
13
+ because you will be writing scripts / running commands with this tool to get
14
+ you from specific point A to specific point B.
15
+
16
+ WinRM is built into Windows 7 and Windows Server 2008+. It can also be easily installed on older version of Windows, including:
17
+
18
+ * Windows Server 2003
19
+ * Windows Vista
20
+
21
+ More information can be found on [Microsoft Support article 968930](http://support.microsoft.com/?kbid=968930).
22
+
23
+ ## Subcommands
24
+
25
+ This plugin provides the following Knife subcommands. Specific command options can be found by invoking the subcommand with a `--help` flag
26
+
27
+ ### knife winrm
28
+
29
+ The `winrm` subcommand allows you to invoke commands in parallel on a subset of the nodes in your infrastructure. The `winrm` subcommand uses the same syntax as the [search subcommand](http://wiki.opscode.com/display/chef/Search); you could could find the uptime of all your web servers using the command:
30
+
31
+ knife winrm "role:web" "net stats srv" -x Administrator -P 'super_secret_password'
32
+
33
+ Or force a chef run:
34
+
35
+ knife winrm 'ec2-50-xx-xx-124.compute-1.amazonaws.com' 'chef-client -c c:/chef/client.rb' -m -x Administrator -P 'super_secret_password'
36
+ ec2-50-xx-xx-124.compute-1.amazonaws.com [Fri, 04 Mar 2011 22:00:49 +0000] INFO: Starting Chef Run (Version 0.9.12)
37
+ ec2-50-xx-xx-124.compute-1.amazonaws.com [Fri, 04 Mar 2011 22:00:50 +0000] WARN: Node ip-0A502FFB has an empty run list.
38
+ ec2-50-xx-xx-124.compute-1.amazonaws.com [Fri, 04 Mar 2011 22:00:53 +0000] INFO: Chef Run complete in 4.383966 seconds
39
+ ec2-50-xx-xx-124.compute-1.amazonaws.com [Fri, 04 Mar 2011 22:00:53 +0000] INFO: cleaning the checksum cache
40
+ ec2-50-xx-xx-124.compute-1.amazonaws.com [Fri, 04 Mar 2011 22:00:53 +0000] INFO: Running report handlers
41
+ ec2-50-xx-xx-124.compute-1.amazonaws.com [Fri, 04 Mar 2011 22:00:53 +0000] INFO: Report handlers complete
42
+
43
+ This subcommand operates in a manner similar to [knife ssh](http://wiki.opscode.com/display/chef/Knife#Knife-SSHSubcommand)...just leveraging the WinRM protocol for communication. It also include's `knife ssh`'s "[interactive session mode](http://wiki.opscode.com/display/chef/Knife#Knife-InteractiveMode)"
44
+
45
+ ### knife bootstrap windows winrm
46
+
47
+ Performs a Chef Bootstrap (via the WinRM protocol) on the target node. The goal of the bootstrap is to get Chef installed on the target system so it can run Chef Client with a Chef Server. The main assumption is a baseline OS installation exists. It is primarily intended for Chef Client systems that talk to a Chef server.
48
+
49
+ This subcommand operates in a manner similar to [knife bootstrap](http://wiki.opscode.com/display/chef/Knife+Bootstrap)...just leveraging the WinRM protocol for communication. An initial run_list for the node can also be passed to the subcommand. Example usage:
50
+
51
+ knife bootstrap windows winrm ec2-50-xx-xx-124.compute-1.amazonaws.com -r 'role[webserver],role[production]' -x Administrator -P 'super_secret_password'
52
+
53
+ ### knife bootstrap windows ssh
54
+
55
+ Performs a Chef Bootstrap (via the SSH protocol) on the target node. The goal of the bootstrap is to get Chef installed on the target system so it can run Chef Client with a Chef Server. The main assumption is a baseline OS installation exists. It is primarily intended for Chef Client systems that talk to a Chef server.
56
+
57
+ This subcommand assumes the SSH session will use the Windows native cmd.exe command shell vs a bash shell through an emulated cygwin layer. Most popular Windows based SSHd daemons like [freeSSHd](http://www.freesshd.com/) and [WinSSHD](http://www.bitvise.com/winsshd) behave this way.
58
+
59
+ An initial run_list for the node can also be passed to the subcommand. Example usage:
60
+
61
+ knife bootstrap windows ssh ec2-50-xx-xx-124.compute-1.amazonaws.com -r 'role[webserver],role[production]' -x Administrator -i ~/.ssh/id_rsa
62
+
63
+ ## BOOTSTRAP TEMPLATES:
64
+
65
+ This gem provides the bootstrap template `windows-chef-client-msi`.
66
+
67
+ ### windows-chef-client-msi
68
+
69
+ This bootstrap template does the following:
70
+
71
+ * Installs the latest version of Chef (and all dependencies) using the `chef-client` msi.
72
+ * Writes the validation.pem per the local knife configuration.
73
+ * Writes a default config file for Chef (`C:\chef\client.rb`) using values from the `knife.rb`.
74
+ * Creates a JSON attributes file containing the specified run list and run Chef.
75
+
76
+ This is the default bootstrap template used by both the `windows bootstrap` subcommands.
77
+
78
+ ## REQUIREMENTS/SETUP:
79
+
80
+ ### Ruby
81
+
82
+ Ruby 1.9.1+ is needed.
83
+
84
+ ### Chef Version
85
+
86
+ Knife plugins require >= Chef 0.10. More details about Knife plugins can be [found on the Chef wiki](http://wiki.opscode.com/display/chef/Knife+Plugins).
87
+
88
+ ## Nodes
89
+
90
+ **NOTE**: Before any WinRM related knife subcommands will function correctly a node's WinRM installation must be configured correctly. The below settings should be added to your base server image (AMI) or passed in using some sort of user-data mechanism provided by your cloud provider.
91
+
92
+ A server running WinRM must also be configured properly to allow outside connections and the entire network path from the knife workstation to the server. The easiest way to accomplish this is to use [WinRM's quick configuration option](http://msdn.microsoft.com/en-us/library/aa384372(v=vs.85).aspx#quick_default_configuration):
93
+
94
+ winrm quickconfig -q
95
+
96
+ The Chef and Ohai gem installations (that occur during bootstrap) take more
97
+ memory than the default 150MB WinRM allocates per shell -- this can slow down
98
+ bootstrap. Optionally increase the memory limit to 300MB with the following command:
99
+
100
+ winrm set winrm/config/winrs @{MaxMemoryPerShellMB="300"}
101
+
102
+ Bootstrap commands can take longer than the WinRM default 60 seconds to
103
+ complete, optionally increase to 30 minutes if bootstrap terminates a command prematurely:
104
+
105
+ winrm set winrm/config @{MaxTimeoutms="1800000"}
106
+
107
+ WinRM supports both the HTTP and HTTPS transports and the following
108
+ authentication schemes: Kerberos, Digest, Certificate and Basic. The details
109
+ of these authentication transports are outside of the scope of this README but
110
+ details can be found on the
111
+ [WinRM configuration guide](http://msdn.microsoft.com/en-us/library/aa384372(v=vs.85).aspx).
112
+ Currently, this plugin support Kerberos and Basic authentication schemes on
113
+ all platform versions. The negotiate protocol which allows NTLM is fully
114
+ supported when `knife windows bootstrap` is executed on a Windows system; if
115
+ it is executed on a non-Windows system, certificate authentication or Kerberos
116
+ should be used instead via the `:kerberos_service` and related options of the subcommands.
117
+
118
+ **NOTE**: In order to use NTLM / Negotiate to authenticate as the user
119
+ specified by the `--winrm-user` (`-x`) option, you must include the user's
120
+ Windows domain when specifying the user name using the format `domain\user`
121
+ where the backslash ('`\`') character separates the user from the domain. If
122
+ an account local to the node is being used to access, `.` may be used as the domain:
123
+
124
+ knife bootstrap windows winrm web1.cloudapp.net -r 'server::web' -x 'proddomain\webuser' -P 'super_secret_password'
125
+ knife bootstrap windows winrm db1.cloudapp.net -r 'server::db' -x '.\localadmin' -P 'super_secret_password'
126
+
127
+ For development and testing purposes, unencrypted traffic with Basic authentication can make it easier to test connectivity:
128
+
129
+ winrm set winrm/config/service @{AllowUnencrypted="true"}
130
+ winrm set winrm/config/service/auth @{Basic="true"}
131
+
132
+ ## Troubleshooting
133
+
134
+ * When I run the winrm command I get: "Error: Invalid use of command line. Type "winrm -?" for help."
135
+ You're running the winrm command from PowerShell and you need to put the key/value pair in single quotes. For example:
136
+
137
+ winrm set winrm/config/winrs '@{MaxMemoryPerShellMB="512"}'
138
+
139
+ ## CONTRIBUTING:
140
+
141
+ Please file bugs against the KNIFE_WINDOWS project at https://github.com/opscode/knife-windows/issues.
142
+
143
+ More information on the contribution process for Opscode projects can be found in the [Chef Contributions document](http://docs.opscode.com/community_contributions.html).
144
+
145
+ # LICENSE:
146
+
147
+ Author:: Seth Chisamore (<schisamo@opscode.com>)
148
+ Copyright:: Copyright (c) 2014 Opscode, Inc.
149
+ License:: Apache License, Version 2.0
150
+
151
+ Licensed under the Apache License, Version 2.0 (the "License");
152
+ you may not use this file except in compliance with the License.
153
+ You may obtain a copy of the License at
154
+
155
+ http://www.apache.org/licenses/LICENSE-2.0
156
+
157
+ Unless required by applicable law or agreed to in writing, software
158
+ distributed under the License is distributed on an "AS IS" BASIS,
159
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
160
+ See the License for the specific language governing permissions and
161
+ limitations under the License.
data/RELEASE_NOTES.md CHANGED
@@ -6,35 +6,57 @@ Example Note:
6
6
  ## Example Heading
7
7
  Details about the thing that changed that needs to get included in the Release Notes in markdown.
8
8
  -->
9
- # knife-windows 0.6.0 release notes:
10
- This release of knife-windows addresses issues with reliability of winrm
11
- readiness detection during Windows bootstrap, exit codes in command execution
12
- scenarios, and gem dependencies.
13
-
14
- Special thanks to **Okezie Eze** for the helpful bug report in KNIFE-386.
15
- Issues with `knife-windows` should be reported in the ticketing system at
16
- https://tickets.opscode.com/browse/KNIFE. Learn more about how you can
17
- contribute features and bug fixes to `knife-windows` at https://wiki.opscode.com/display/chef/How+to+Contribute.
18
-
19
- ## Features added in knife-windows 0.6.0
20
-
21
- ### `--auth-timeout` option for bootstrap
22
- The `knife windows bootstrap` command has an `--auth-timeout` option that
23
- takes as an argument a number of minutes that specifies the time period during
24
- which to retry authentication attempts to WinRM when boostrapping a remote
25
- node via WinRM. By default, the value is 25 minutes. This retry behavior during bootstrap addresses issues that arise on
26
- some cloud providers where the authentication system is not ready until
27
- some time after WinRM is ready.
9
+ # knife-windows 0.8.2 release notes:
10
+ This release of knife-windows addresses a regression in knife-windows 0.8.0
11
+ from previous releases where `knife winrm` and `knife bootstrap windows`
12
+ commands fail due to inability to authenticate:
13
+ [knife-windows #108](https://github.com/opscode/knife-windows/issues/108).
28
14
 
29
- ## knife-windows on RubyGems and Github
30
- https://rubygems.org/gems/knife-windows
31
- https://github.com/opscode/knife-windows
15
+ You can install the fix for this issue by upgrading to this new version using
16
+ the `gem` command:
17
+
18
+ gem install knife-windows --pre
19
+
20
+ A thank you goes to **Richard Lavey** for reporting [knife-windows #108](https://github.com/opscode/knife-windows/issues/108).
21
+
22
+ ## Impact of [knife-windows #108](https://github.com/opscode/knife-windows/issues/108)
23
+
24
+ [knife-windows #108](https://github.com/opscode/knife-windows/issues/108) will affect a given user if all of the following are true:
25
+
26
+ * You are running `knife-windows` subcommands on a Windows workstation
27
+ * The remote node you're interacting with via `knife-windows` has a WinRM
28
+ configuration with the `WSMan:\localhost\Service\AllowUnencrypted` (in
29
+ PowerShell's WinRM settings drive provider)
30
+
31
+ In this situation, you will receive an authentication error message from
32
+ the `knife winrm` or `knife bootstrap windows` command such as
33
+ `Error: Unencrypted communication not supported`. To resolve this error,
34
+ simply install this version of the gem as described earlier.
35
+
36
+ If you are running the `knife` commands from a non-Windows operating system,
37
+ [knife-windows #108](https://github.com/opscode/knife-windows/issues/108) does
38
+ not affect you, so you don't need to upgrade just for this issue.
32
39
 
33
- ## Issues fixed in knife-windows 0.6.0
34
- * [KNIFE-386](https://tickets.opscode.com/browse/KNIFE-386) Wait for a valid command response before bootstrapping over WinRM
35
- * [KNIFE-394](https://tickets.opscode.com/browse/KNIFE-394) Update em-winrm dependency
36
- * [KNIFE-450](https://tickets.opscode.com/browse/KNIFE-450) Set knife winrm command exit status on exception and command failure
40
+ ## Reporting issues and contributing
37
41
 
38
- ## knife-windows breaking changes:
42
+ `knife-windows` issues like the one addressed in this release should be
43
+ reported in the ticketing system at https://github.com/opscode/knife-windows/issues. You can learn more about how to contribute features and bug fixes to `knife-windows` in the [Chef Contributions document](http://docs.opscode.com/community_contributions.html).
39
44
 
45
+ ## Features added in knife-windows 0.8.2
40
46
  None.
47
+
48
+ ## Issues fixed in knife-windows 0.8.2
49
+ [knife-windows #108](https://github.com/opscode/knife-windows/issues/108) Error: Unencrypted communication not supported if remote server does not require encryption
50
+
51
+ The fix in this release will cause a behavior change from the 0.8.0 release:
52
+
53
+ * As described in the [documentation changes](https://github.com/opscode/knife-windows/blob/0.8.0/DOC_CHANGES.md) for the 0.8.0 release of the `knife-windows`, the negotiate authentication
54
+ protocol will only be used in this 0.8.2 release if a domain is specified (you can specify '.' as
55
+ the domain if you want to use the local workstation as the domain). Due to a
56
+ defect in the 0.8.0 release, the negotiate protocol was being used even when
57
+ the domain was not specified.
58
+
59
+ ## knife-windows on RubyGems and Github
60
+ https://rubygems.org/gems/knife-windows
61
+ https://github.com/opscode/knife-windows
62
+
@@ -6,16 +6,18 @@ Gem::Specification.new do |s|
6
6
  s.name = "knife-windows"
7
7
  s.version = Knife::Windows::VERSION
8
8
  s.platform = Gem::Platform::RUBY
9
- s.has_rdoc = true
10
- s.extra_rdoc_files = ["README.rdoc", "LICENSE" ]
11
9
  s.authors = ["Seth Chisamore"]
12
10
  s.email = ["schisamo@opscode.com"]
11
+ s.license = "Apache-2.0"
13
12
  s.homepage = "https://github.com/opscode/knife-windows"
14
13
  s.summary = %q{Plugin that adds functionality to Chef's Knife CLI for configuring/interacting with nodes running Microsoft Windows}
15
14
  s.description = s.summary
16
15
 
17
16
  s.required_ruby_version = ">= 1.9.1"
18
- s.add_dependency "em-winrm", "~> 0.5", ">= 0.5.4"
17
+ s.add_dependency "winrm-s", "~> 0.2"
18
+ s.add_dependency "em-winrm", "~> 0.6"
19
+
20
+ s.add_development_dependency 'pry'
19
21
 
20
22
  s.files = `git ls-files`.split("\n")
21
23
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -96,8 +96,8 @@ class Chef
96
96
 
97
97
  option :auth_timeout,
98
98
  :long => "--auth-timeout MINUTES",
99
- :description => "The maximum time in minutes to wait to for authentication over the transport to the node to succeed. The default value is 25 minutes.",
100
- :default => 25
99
+ :description => "The maximum time in minutes to wait to for authentication over the transport to the node to succeed. The default value is 2 minutes.",
100
+ :default => 2
101
101
  end
102
102
  end
103
103
 
@@ -41,6 +41,7 @@ class Chef
41
41
  bootstrap
42
42
  end
43
43
 
44
+
44
45
  def run_command(command = '')
45
46
  winrm = Chef::Knife::Winrm.new
46
47
  winrm.name_args = [ server_name, command ]
@@ -54,7 +55,11 @@ class Chef
54
55
  winrm.config[:manual] = true
55
56
  winrm.config[:winrm_port] = locate_config_value(:winrm_port)
56
57
  winrm.config[:suppress_auth_failure] = true
57
- winrm.config[:returns] = nil
58
+
59
+ #If you turn off the return flag, then winrm.run won't atually check and
60
+ #return the error
61
+ #codes. Otherwise, it ignores the return value of the server call.
62
+ winrm.config[:returns] = "0"
58
63
  winrm.run
59
64
  end
60
65
 
@@ -149,7 +149,9 @@ WGET_PS
149
149
  end
150
150
 
151
151
  def install_chef
152
- install_chef = 'msiexec /qn /log "%CHEF_CLIENT_MSI_LOG_PATH%" /i "%LOCAL_DESTINATION_MSI_PATH%"'
152
+ # The normal install command uses regular double quotes in
153
+ # the install command, so request such a string from install_command
154
+ install_chef = install_command('"') + "\n" + fallback_install_task_command
153
155
  end
154
156
 
155
157
  def bootstrap_directory
@@ -171,6 +173,54 @@ WGET_PS
171
173
  def escape_and_echo(file_contents)
172
174
  file_contents.gsub(/^(.*)$/, 'echo.\1').gsub(/([(<|>)^])/, '^\1')
173
175
  end
176
+
177
+ private
178
+
179
+ def install_command(executor_quote)
180
+ "msiexec /qn /log #{executor_quote}%CHEF_CLIENT_MSI_LOG_PATH%#{executor_quote} /i #{executor_quote}%LOCAL_DESTINATION_MSI_PATH%#{executor_quote}"
181
+ end
182
+
183
+ def fallback_install_task_command
184
+ # This command will be executed by schtasks.exe in the batch
185
+ # code below. To handle tasks that contain arguments that
186
+ # need to be double quoted, schtasks allows the use of single
187
+ # quotes that will later be converted to double quotes
188
+ command = install_command('\'')
189
+ <<-EOH
190
+ @set MSIERRORCODE=!ERRORLEVEL!
191
+ @if ERRORLEVEL 1 (
192
+ @echo WARNING: Failed to install Chef Client MSI package in remote context with status code !MSIERRORCODE!.
193
+ @echo WARNING: This may be due to a defect in operating system update KB2918614: http://support.microsoft.com/kb/2918614
194
+ @set OLDLOGLOCATION="%CHEF_CLIENT_MSI_LOG_PATH%-fail.log"
195
+ @move "%CHEF_CLIENT_MSI_LOG_PATH%" "!OLDLOGLOCATION!" > NUL
196
+ @echo WARNING: Saving installation log of failure at !OLDLOGLOCATION!
197
+ @echo WARNING: Retrying installation with local context...
198
+ @schtasks /create /f /sc once /st 00:00:00 /tn chefclientbootstraptask /ru SYSTEM /rl HIGHEST /tr \"cmd /c #{command} & sleep 2 & waitfor /s %computername% /si chefclientinstalldone\"
199
+
200
+ @if ERRORLEVEL 1 (
201
+ @echo ERROR: Failed to create Chef Client installation scheduled task with status code !ERRORLEVEL! > "&2"
202
+ ) else (
203
+ @echo Successfully created scheduled task to install Chef Client.
204
+ @schtasks /run /tn chefclientbootstraptask
205
+ @if ERRORLEVEL 1 (
206
+ @echo ERROR: Failed to execut Chef Client installation scheduled task with status code !ERRORLEVEL!. > "&2"
207
+ ) else (
208
+ @echo Successfully started Chef Client installation scheduled task.
209
+ @echo Waiting for installation to complete -- this may take a few minutes...
210
+ waitfor chefclientinstalldone /t 600
211
+ if ERRORLEVEL 1 (
212
+ @echo ERROR: Timed out waiting for Chef Client package to install
213
+ ) else (
214
+ @echo Finished waiting for Chef Client package to install.
215
+ )
216
+ @schtasks /delete /f /tn chefclientbootstraptask > NUL
217
+ )
218
+ )
219
+ ) else (
220
+ @echo Successfully installed Chef Client package.
221
+ )
222
+ EOH
223
+ end
174
224
  end
175
225
  end
176
226
  end
@@ -44,9 +44,7 @@ class Chef
44
44
  option :returns,
45
45
  :long => "--returns CODES",
46
46
  :description => "A comma delimited list of return codes which indicate success",
47
- :default => nil,
48
- :proc => Proc.new { |codes|
49
- Chef::Config[:knife][:returns] = codes.split(',').collect {|item| item.to_i} }
47
+ :default => "0"
50
48
 
51
49
  option :manual,
52
50
  :short => "-m",
@@ -55,6 +53,7 @@ class Chef
55
53
  :description => "QUERY is a space separated list of servers",
56
54
  :default => false
57
55
 
56
+
58
57
  def session
59
58
  session_opts = {}
60
59
  session_opts[:logger] = Chef::Log.logger if Chef::Log.level == :debug
@@ -75,6 +74,12 @@ class Chef
75
74
 
76
75
  end
77
76
 
77
+ def success_return_codes
78
+ #Redundant if the CLI options parsing occurs
79
+ return [0] unless config[:returns]
80
+ return config[:returns].split(',').collect {|item| item.to_i}
81
+ end
82
+
78
83
  # TODO: Copied from Knife::Core:GenericPresenter. Should be extracted
79
84
  def extract_nested_value(data, nested_value_spec)
80
85
  nested_value_spec.split(".").each do |attr|
@@ -96,6 +101,7 @@ class Chef
96
101
  end
97
102
 
98
103
  def configure_session
104
+
99
105
  list = case config[:manual]
100
106
  when true
101
107
  @name_args[0].split(" ")
@@ -136,7 +142,10 @@ class Chef
136
142
  session_opts[:operation_timeout] = 1800 # 30 min OperationTimeout for long bootstraps fix for KNIFE_WINDOWS-8
137
143
 
138
144
  ## If you have a \\ in your name you need to use NTLM domain authentication
139
- if session_opts[:user].split("\\").length.eql?(2)
145
+ username_contains_domain = session_opts[:user].split("\\").length.eql?(2)
146
+
147
+ if username_contains_domain
148
+ # We cannot use basic_auth for domain authentication
140
149
  session_opts[:basic_auth_only] = false
141
150
  else
142
151
  session_opts[:basic_auth_only] = true
@@ -147,11 +156,19 @@ class Chef
147
156
  session_opts[:basic_auth_only] = false
148
157
  else
149
158
  session_opts[:transport] = (Chef::Config[:knife][:winrm_transport] || config[:winrm_transport]).to_sym
150
- session_opts[:disable_sspi] = true
159
+
160
+ if Chef::Platform.windows? && session_opts[:transport] == :plaintext && username_contains_domain
161
+ ui.warn("Switching to Negotiate authentication, Basic does not support Domain Authentication")
162
+ # windows - force only encrypted communication
163
+ require 'winrm-s'
164
+ session_opts[:transport] = :sspinegotiate
165
+ session_opts[:disable_sspi] = false
166
+ else
167
+ session_opts[:disable_sspi] = true
168
+ end
151
169
  if session_opts[:user] and
152
170
  (not session_opts[:password])
153
171
  session_opts[:password] = Chef::Config[:knife][:winrm_password] = config[:winrm_password] = get_password
154
-
155
172
  end
156
173
  end
157
174
 
@@ -240,8 +257,9 @@ class Chef
240
257
  def check_for_errors!(exit_codes)
241
258
 
242
259
  exit_codes.each do |host, value|
243
- unless Chef::Config[:knife][:returns].include? value.to_i
244
- @exit_code = 1
260
+ Chef::Log.debug("Exit code found: #{value}")
261
+ unless success_return_codes.include? value.to_i
262
+ @exit_code = value.to_i
245
263
  ui.error "Failed to execute command on #{host} return code #{value}"
246
264
  end
247
265
  end
@@ -249,6 +267,7 @@ class Chef
249
267
  end
250
268
 
251
269
  def run
270
+
252
271
  STDOUT.sync = STDERR.sync = true
253
272
 
254
273
  begin
@@ -1,6 +1,6 @@
1
1
  module Knife
2
2
  module Windows
3
- VERSION = "0.6.0"
3
+ VERSION = "0.8.2"
4
4
  MAJOR, MINOR, TINY = VERSION.split('.')
5
5
  end
6
6
  end
@@ -69,23 +69,23 @@ describe 'Knife::Windows::Core msi download functionality for knife Windows winr
69
69
  # Stub the bootstrap context and prevent config related sections
70
70
  # from being populated, i.e. chef installation and first chef
71
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")
72
+ allow(@mock_bootstrap_context).to receive(:validation_key).and_return("echo.validation_key")
73
+ allow(@mock_bootstrap_context).to receive(:encrypted_data_bag_secret).and_return("echo.encrypted_data_bag_secret")
74
+ allow(@mock_bootstrap_context).to receive(:config_content).and_return("echo.config_content")
75
+ allow(@mock_bootstrap_context).to receive(:start_chef).and_return("echo.echo start_chef_command")
76
+ allow(@mock_bootstrap_context).to receive(:run_list).and_return("echo.run_list")
77
+ allow(@mock_bootstrap_context).to receive(:install_chef).and_return("echo.echo install_chef_command")
78
78
 
79
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))
80
+ allow(@mock_bootstrap_context).to receive(:bootstrap_directory).and_return(@temp_directory.gsub(::File::SEPARATOR, ::File::ALT_SEPARATOR))
81
+ allow(@mock_bootstrap_context).to receive(:local_download_path).and_return(@local_file_download_destination.gsub(::File::SEPARATOR, ::File::ALT_SEPARATOR))
82
82
 
83
83
  # Prevent password prompt during bootstrap process
84
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)
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
- Chef::Knife::Core::WindowsBootstrapContext.stub(:new).and_return(@mock_bootstrap_context)
88
+ allow(Chef::Knife::Core::WindowsBootstrapContext).to receive(:new).and_return(@mock_bootstrap_context)
89
89
  end
90
90
 
91
91
  it "downloads the chef-client MSI during winrm bootstrap" do
@@ -93,18 +93,18 @@ describe 'Knife::Windows::Core msi download functionality for knife Windows winr
93
93
  clean_test_case
94
94
 
95
95
  winrm_bootstrapper = Chef::Knife::BootstrapWindowsWinrm.new([ "127.0.0.1" ])
96
- winrm_bootstrapper.stub(:wait_for_remote_response)
96
+ allow(winrm_bootstrapper).to receive(:wait_for_remote_response)
97
97
  winrm_bootstrapper.config[:template_file] = @template_file_path
98
98
 
99
99
  # Execute the commands locally that would normally be executed via WinRM
100
- winrm_bootstrapper.stub(:run_command) do |command|
100
+ allow(winrm_bootstrapper).to receive(:run_command) do |command|
101
101
  system(command)
102
102
  end
103
103
 
104
104
  winrm_bootstrapper.run
105
105
 
106
106
  # Download should succeed
107
- download_succeeded?.should == true
107
+ expect(download_succeeded?).to be true
108
108
  end
109
109
  end
110
110
 
data/spec/spec_helper.rb CHANGED
@@ -55,8 +55,6 @@ end
55
55
 
56
56
 
57
57
  RSpec.configure do |config|
58
- config.treat_symbols_as_metadata_keys_with_true_values = true
59
-
60
58
  config.filter_run_excluding :windows_only => true unless windows?
61
59
  config.filter_run_excluding :windows_2012_only => true unless windows2012?
62
60
  end
@@ -56,9 +56,9 @@ describe Chef::Knife::BootstrapWindowsWinrm do
56
56
  @knife.merge_configs
57
57
  @knife.config[:template_file] = TEMPLATE_FILE
58
58
  @stdout = StringIO.new
59
- @knife.ui.stub(:stdout).and_return(@stdout)
59
+ allow(@knife.ui).to receive(:stdout).and_return(@stdout)
60
60
  @stderr = StringIO.new
61
- @knife.ui.stub(:stderr).and_return(@stderr)
61
+ allow(@knife.ui).to receive(:stderr).and_return(@stderr)
62
62
  end
63
63
 
64
64
  describe "specifying no_proxy with various entries" do
@@ -77,14 +77,14 @@ describe Chef::Knife::BootstrapWindowsWinrm do
77
77
  let(:setting) { "api.opscode.com" }
78
78
 
79
79
  it "renders the client.rb with a single FQDN no_proxy entry" do
80
- rendered_template.should match(%r{.*no_proxy\s*\"api.opscode.com\".*})
80
+ expect(rendered_template).to match(%r{.*no_proxy\s*\"api.opscode.com\".*})
81
81
  end
82
82
  end
83
83
  context "via --bootstrap-no-proxy multiple" do
84
84
  let(:setting) { "api.opscode.com,172.16.10.*" }
85
85
 
86
86
  it "renders the client.rb with comma-separated FQDN and wildcard IP address no_proxy entries" do
87
- rendered_template.should match(%r{.*no_proxy\s*"api.opscode.com,172.16.10.\*".*})
87
+ expect(rendered_template).to match(%r{.*no_proxy\s*"api.opscode.com,172.16.10.\*".*})
88
88
  end
89
89
  end
90
90
  end
@@ -26,59 +26,80 @@ describe Chef::Knife::BootstrapWindowsWinrm do
26
26
 
27
27
  before do
28
28
  # Kernel.stub(:sleep).and_return 10
29
- bootstrap.stub(:sleep).and_return 10
29
+ allow(bootstrap).to receive(:sleep).and_return(10)
30
30
  end
31
31
 
32
32
  after do
33
33
  # Kernel.unstub(:sleep)
34
- bootstrap.stub(:sleep).and_return 10
34
+ allow(bootstrap).to receive(:sleep).and_return(10)
35
35
  end
36
36
 
37
- let (:bootstrap) { Chef::Knife::BootstrapWindowsWinrm.new }
37
+ let (:bootstrap) { Chef::Knife::BootstrapWindowsWinrm.new(['winrm', '-d', 'windows-chef-client-msi', '-x', 'Administrator', 'localhost']) }
38
+
38
39
  let(:initial_fail_count) { 4 }
39
40
  it 'should retry if a 401 is received from WinRM' do
40
41
  call_result_sequence = Array.new(initial_fail_count) {lambda {raise WinRM::WinRMHTTPTransportError, '401'}}
41
42
  call_result_sequence.push(0)
42
- bootstrap.stub(:run_command).and_return(*call_result_sequence)
43
+ allow(bootstrap).to receive(:run_command).and_return(*call_result_sequence)
43
44
 
44
- bootstrap.should_receive(:run_command).exactly(call_result_sequence.length).times
45
+ expect(bootstrap).to receive(:run_command).exactly(call_result_sequence.length).times
45
46
  bootstrap.send(:wait_for_remote_response, 2)
46
47
  end
47
48
 
48
49
  it 'should retry if something other than a 401 is received from WinRM' do
49
50
  call_result_sequence = Array.new(initial_fail_count) {lambda {raise WinRM::WinRMHTTPTransportError, '500'}}
50
51
  call_result_sequence.push(0)
51
- bootstrap.stub(:run_command).and_return(*call_result_sequence)
52
+ allow(bootstrap).to receive(:run_command).and_return(*call_result_sequence)
52
53
 
53
- bootstrap.should_receive(:run_command).exactly(call_result_sequence.length).times
54
+ expect(bootstrap).to receive(:run_command).exactly(call_result_sequence.length).times
54
55
  bootstrap.send(:wait_for_remote_response, 2)
55
56
  end
56
57
 
57
- it 'should have a wait timeout of 25 minutes by default' do
58
- bootstrap.stub(:run_command).and_raise WinRM::WinRMHTTPTransportError
59
- bootstrap.stub(:create_bootstrap_bat_command).and_raise SystemExit
60
- bootstrap.should_receive(:wait_for_remote_response).with(25)
61
- bootstrap.stub(:validate_name_args!).and_return(nil)
58
+ it 'should have a wait timeout of 2 minutes by default' do
59
+ allow(bootstrap).to receive(:run_command).and_raise(WinRM::WinRMHTTPTransportError)
60
+ allow(bootstrap).to receive(:create_bootstrap_bat_command).and_raise(SystemExit)
61
+ expect(bootstrap).to receive(:wait_for_remote_response).with(2)
62
+ allow(bootstrap).to receive(:validate_name_args!).and_return(nil)
62
63
  bootstrap.config[:auth_timeout] = bootstrap.options[:auth_timeout][:default]
63
- expect { bootstrap.bootstrap }.to raise_error SystemExit
64
+ expect { bootstrap.bootstrap }.to raise_error(SystemExit)
64
65
  end
65
66
 
66
67
  it 'should keep retrying at 10s intervals if the timeout in minutes has not elapsed' do
67
68
  call_result_sequence = Array.new(initial_fail_count) {lambda {raise WinRM::WinRMHTTPTransportError, '500'}}
68
69
  call_result_sequence.push(0)
69
- bootstrap.stub(:run_command).and_return(*call_result_sequence)
70
+ allow(bootstrap).to receive(:run_command).and_return(*call_result_sequence)
70
71
 
71
- bootstrap.should_receive(:run_command).exactly(call_result_sequence.length).times
72
+ expect(bootstrap).to receive(:run_command).exactly(call_result_sequence.length).times
72
73
  bootstrap.send(:wait_for_remote_response, 2)
73
74
  end
74
75
 
75
- it 'should stop retrying if more than 25 minutes has elapsed' do
76
- times = [ Time.new(2014, 4, 1, 22, 25), Time.new(2014, 4, 1, 22, 51), Time.new(2014, 4, 1, 22, 52) ]
77
- Time.stub(:now).and_return(*times)
76
+ it "should exit bootstrap with non-zero status if the bootstrap fails" do
77
+ command_status = 1
78
+
79
+ #Stub out calls to create the session and just get the exit codes back
80
+ winrm_mock = Chef::Knife::Winrm.new
81
+ allow(Chef::Knife::Winrm).to receive(:new).and_return(winrm_mock)
82
+ allow(winrm_mock).to receive(:configure_session)
83
+ allow(winrm_mock).to receive(:winrm_command)
84
+ session_mock = EventMachine::WinRM::Session.new
85
+ allow(EventMachine::WinRM::Session).to receive(:new).and_return(session_mock)
86
+ allow(session_mock).to receive(:exit_codes).and_return({"thishost" => command_status})
87
+
88
+ #Skip over templating stuff and checking with the remote end
89
+ allow(bootstrap).to receive(:create_bootstrap_bat_command)
90
+ allow(bootstrap).to receive(:wait_for_remote_response)
91
+
92
+ expect { bootstrap.run_with_pretty_exceptions }.to raise_error(SystemExit) { |e| expect(e.status).to eq(command_status) }
93
+ end
94
+
95
+
96
+ it 'should stop retrying if more than 2 minutes has elapsed' do
97
+ times = [ Time.new(2014, 4, 1, 22, 25), Time.new(2014, 4, 1, 22, 51), Time.new(2014, 4, 1, 22, 28) ]
98
+ allow(Time).to receive(:now).and_return(*times)
78
99
  run_command_result = lambda {raise WinRM::WinRMHTTPTransportError, '401'}
79
- bootstrap.stub(:validate_name_args!).and_return(nil)
80
- bootstrap.stub(:run_command).and_return(run_command_result)
81
- bootstrap.should_receive(:run_command).exactly(1).times
100
+ allow(bootstrap).to receive(:validate_name_args!).and_return(nil)
101
+ allow(bootstrap).to receive(:run_command).and_return(run_command_result)
102
+ expect(bootstrap).to receive(:run_command).exactly(1).times
82
103
  bootstrap.config[:auth_timeout] = bootstrap.options[:auth_timeout][:default]
83
104
  expect { bootstrap.bootstrap }.to raise_error RuntimeError
84
105
  end
@@ -51,15 +51,15 @@ describe Chef::Knife::Winrm do
51
51
  context "when there are some hosts found but they do not have an attribute to connect with" do
52
52
  before do
53
53
  @knife.config[:manual] = false
54
- @query.stub(:search).and_return([[@node_foo, @node_bar]])
54
+ allow(@query).to receive(:search).and_return([[@node_foo, @node_bar]])
55
55
  @node_foo.automatic_attrs[:fqdn] = nil
56
56
  @node_bar.automatic_attrs[:fqdn] = nil
57
- Chef::Search::Query.stub(:new).and_return(@query)
57
+ allow(Chef::Search::Query).to receive(:new).and_return(@query)
58
58
  end
59
-
59
+
60
60
  it "should raise a specific error (KNIFE-222)" do
61
- @knife.ui.should_receive(:fatal).with(/does not have the required attribute/)
62
- @knife.should_receive(:exit).with(10)
61
+ expect(@knife.ui).to receive(:fatal).with(/does not have the required attribute/)
62
+ expect(@knife).to receive(:exit).with(10)
63
63
  @knife.configure_session
64
64
  end
65
65
  end
@@ -67,13 +67,13 @@ describe Chef::Knife::Winrm do
67
67
  context "when there are nested attributes" do
68
68
  before do
69
69
  @knife.config[:manual] = false
70
- @query.stub(:search).and_return([[@node_foo, @node_bar]])
71
- Chef::Search::Query.stub(:new).and_return(@query)
70
+ allow(@query).to receive(:search).and_return([[@node_foo, @node_bar]])
71
+ allow(Chef::Search::Query).to receive(:new).and_return(@query)
72
72
  end
73
-
73
+
74
74
  it "should use nested attributes (KNIFE-276)" do
75
75
  @knife.config[:attribute] = "ec2.public_hostname"
76
- @knife.stub(:session_from_list)
76
+ allow(@knife).to receive(:session_from_list)
77
77
  @knife.configure_session
78
78
 
79
79
  end
@@ -92,61 +92,128 @@ describe Chef::Knife::Winrm do
92
92
  end
93
93
 
94
94
  it "should return with 0 if the command succeeds" do
95
- @winrm.stub(:winrm_command).and_return(0)
95
+ allow(@winrm).to receive(:winrm_command).and_return(0)
96
96
  exit_code = @winrm.run
97
- exit_code.should == 0
97
+ expect(exit_code).to be_zero
98
98
  end
99
99
 
100
- it "should exit the process with 0 if the command fails and returns config is not set" do
101
- @winrm.stub(:winrm_command).and_return(1)
102
- exit_code = @winrm.run
103
- exit_code.should == 0
100
+ it "should exit the process with exact exit status if the command fails and returns config is set to 0" do
101
+ command_status = 510
102
+ @winrm.config[:returns] = "0"
103
+ Chef::Config[:knife][:returns] = [0]
104
+ allow(@winrm).to receive(:winrm_command).and_return(command_status)
105
+ session_mock = EventMachine::WinRM::Session.new
106
+ allow(EventMachine::WinRM::Session).to receive(:new).and_return(session_mock)
107
+ allow(session_mock).to receive(:exit_codes).and_return({"thishost" => command_status})
108
+ begin
109
+ @winrm.run
110
+ expect(0).to eq(510)
111
+ rescue Exception => e
112
+ expect(e.status).to eq(command_status)
113
+ end
104
114
  end
105
115
 
106
116
  it "should exit the process with non-zero status if the command fails and returns config is set to 0" do
107
117
  command_status = 1
108
- @winrm.config[:returns] = [0,53]
118
+ @winrm.config[:returns] = "0,53"
109
119
  Chef::Config[:knife][:returns] = [0,53]
110
- @winrm.stub(:winrm_command).and_return(command_status)
111
- EventMachine::WinRM::Session.any_instance.stub(:exit_codes).and_return({"thishost" => command_status})
112
- expect { @winrm.run_with_pretty_exceptions }.to raise_error(SystemExit) { |e| e.status.should == command_status }
120
+ allow(@winrm).to receive(:winrm_command).and_return(command_status)
121
+ session_mock = EventMachine::WinRM::Session.new
122
+ allow(EventMachine::WinRM::Session).to receive(:new).and_return(session_mock)
123
+ allow(session_mock).to receive(:exit_codes).and_return({"thishost" => command_status})
124
+ expect { @winrm.run_with_pretty_exceptions }.to raise_error(SystemExit) { |e| expect(e.status).to eq(command_status) }
113
125
  end
114
126
 
115
127
  it "should exit the process with a zero status if the command returns an expected non-zero status" do
116
128
  command_status = 53
117
129
  Chef::Config[:knife][:returns] = [0,53]
118
- @winrm.stub(:winrm_command).and_return(command_status)
119
- EventMachine::WinRM::Session.any_instance.stub(:exit_codes).and_return({"thishost" => command_status})
130
+ allow(@winrm).to receive(:winrm_command).and_return(command_status)
131
+ session_mock = EventMachine::WinRM::Session.new
132
+ allow(EventMachine::WinRM::Session).to receive(:new).and_return(session_mock)
133
+ allow(session_mock).to receive(:exit_codes).and_return({"thishost" => command_status})
120
134
  exit_code = @winrm.run
121
- exit_code.should == 0
135
+ expect(exit_code).to be_zero
122
136
  end
123
137
 
124
138
  it "should exit the process with a zero status if the command returns an expected non-zero status" do
125
139
  command_status = 53
126
140
  Chef::Config[:knife][:returns] = [0,53]
127
- @winrm.stub(:winrm_command).and_return(command_status)
128
- EventMachine::WinRM::Session.any_instance.stub(:exit_codes).and_return({"thishost" => command_status})
141
+ allow(@winrm).to receive(:winrm_command).and_return(command_status)
142
+ session_mock = EventMachine::WinRM::Session.new
143
+ allow(EventMachine::WinRM::Session).to receive(:new).and_return(session_mock)
144
+ allow(session_mock).to receive(:exit_codes).and_return({"thishost" => command_status})
129
145
  exit_code = @winrm.run
130
- exit_code.should == 0
146
+ expect(exit_code).to be_zero
131
147
  end
132
148
 
133
149
  it "should exit the process with 100 if command execution raises an exception other than 401" do
134
- @winrm.stub(:winrm_command).and_raise(WinRM::WinRMHTTPTransportError, '500')
135
- expect { @winrm.run_with_pretty_exceptions }.to raise_error(SystemExit) { |e| e.status.should == 100 }
150
+ allow(@winrm).to receive(:winrm_command).and_raise(WinRM::WinRMHTTPTransportError, '500')
151
+ expect { @winrm.run_with_pretty_exceptions }.to raise_error(SystemExit) { |e| expect(e.status).to eq(100) }
136
152
  end
137
153
 
138
154
  it "should exit the process with 100 if command execution raises a 401" do
139
- @winrm.stub(:winrm_command).and_raise(WinRM::WinRMHTTPTransportError, '401')
140
- expect { @winrm.run_with_pretty_exceptions }.to raise_error(SystemExit) { |e| e.status.should == 100 }
155
+ allow(@winrm).to receive(:winrm_command).and_raise(WinRM::WinRMHTTPTransportError, '401')
156
+ expect { @winrm.run_with_pretty_exceptions }.to raise_error(SystemExit) { |e| expect(e.status).to eq(100) }
141
157
  end
142
158
 
143
159
  it "should exit the process with 0 if command execution raises a 401 and suppress_auth_failure is set to true" do
144
160
  @winrm.config[:suppress_auth_failure] = true
145
- @winrm.stub(:winrm_command).and_raise(WinRM::WinRMHTTPTransportError, '401')
161
+ allow(@winrm).to receive(:winrm_command).and_raise(WinRM::WinRMHTTPTransportError, '401')
146
162
  exit_code = @winrm.run_with_pretty_exceptions
147
- exit_code.should == 401
163
+ expect(exit_code).to eq(401)
148
164
  end
165
+
166
+ context "validate sspinegotiate transport option" do
167
+ before do
168
+ Chef::Config[:knife] = {:winrm_transport => :plaintext}
169
+ allow(@winrm).to receive(:winrm_command).and_return(0)
170
+ end
171
+
172
+ it "should have winrm opts transport set to sspinegotiate for windows" do
173
+ @winrm.config[:winrm_user] = "domain\\testuser"
174
+ allow(Chef::Platform).to receive(:windows?).and_return(true)
175
+ allow(@winrm).to receive(:require).with('winrm-s').and_return(true)
176
+ expect(@winrm.session).to receive(:use).with("localhost", {:user=>"domain\\testuser", :password=>"testpassword", :port=>nil, :operation_timeout=>1800, :basic_auth_only=>false, :transport=>:sspinegotiate, :disable_sspi=>false})
177
+ exit_code = @winrm.run
178
+ end
179
+
180
+ it "should use the winrm monkey patch for windows" do
181
+ @winrm.config[:winrm_user] = "domain\\testuser"
182
+ allow(Chef::Platform).to receive(:windows?).and_return(true)
183
+ expect(@winrm).to receive(:require).with('winrm-s')
184
+
185
+ exit_code = @winrm.run
186
+ end
187
+
188
+ context "when domain name not given" do
189
+ it "should skip winrm monkey patch for windows" do
190
+ @winrm.config[:winrm_user] = "testuser"
191
+ allow(Chef::Platform).to receive(:windows?).and_return(true)
192
+ expect(@winrm).to_not receive(:require).with('winrm-s')
193
+
194
+ exit_code = @winrm.run
195
+ end
196
+ end
197
+
198
+ context "when local domain name given" do
199
+ it "should use the winrm monkey patch for windows" do
200
+ @winrm.config[:winrm_user] = ".\\testuser"
201
+ allow(Chef::Platform).to receive(:windows?).and_return(true)
202
+ expect(@winrm).to receive(:require).with('winrm-s')
203
+
204
+ exit_code = @winrm.run
205
+ end
206
+ end
207
+
208
+ it "should not have winrm opts transport set to sspinegotiate for unix" do
209
+ allow(Chef::Platform).to receive(:windows?).and_return(false)
210
+
211
+ expect(@winrm.session).to receive(:use).with("localhost", {:user=>"testuser", :password=>"testpassword", :port=>nil, :operation_timeout=>1800, :basic_auth_only=>true, :transport=>:plaintext, :disable_sspi=>true})
212
+ exit_code = @winrm.run
213
+ end
214
+ end
215
+
149
216
  end
150
217
  end
151
218
  end
152
- end
219
+ end
metadata CHANGED
@@ -1,44 +1,64 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-windows
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seth Chisamore
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-12 00:00:00.000000000 Z
11
+ date: 2014-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: em-winrm
14
+ name: winrm-s
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: '0.5'
20
- - - ! '>='
19
+ version: '0.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '0.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: em-winrm
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
21
32
  - !ruby/object:Gem::Version
22
- version: 0.5.4
33
+ version: '0.6'
23
34
  type: :runtime
24
35
  prerelease: false
25
36
  version_requirements: !ruby/object:Gem::Requirement
26
37
  requirements:
27
38
  - - ~>
28
39
  - !ruby/object:Gem::Version
29
- version: '0.5'
40
+ version: '0.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
30
45
  - - ! '>='
31
46
  - !ruby/object:Gem::Version
32
- version: 0.5.4
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
33
55
  description: Plugin that adds functionality to Chef's Knife CLI for configuring/interacting
34
56
  with nodes running Microsoft Windows
35
57
  email:
36
58
  - schisamo@opscode.com
37
59
  executables: []
38
60
  extensions: []
39
- extra_rdoc_files:
40
- - README.rdoc
41
- - LICENSE
61
+ extra_rdoc_files: []
42
62
  files:
43
63
  - .gitignore
44
64
  - .rspec
@@ -47,7 +67,7 @@ files:
47
67
  - DOC_CHANGES.md
48
68
  - Gemfile
49
69
  - LICENSE
50
- - README.rdoc
70
+ - README.md
51
71
  - RELEASE_NOTES.md
52
72
  - Rakefile
53
73
  - features/knife_help.feature
@@ -68,7 +88,8 @@ files:
68
88
  - spec/unit/knife/bootstrap_windows_winrm_spec.rb
69
89
  - spec/unit/knife/winrm_spec.rb
70
90
  homepage: https://github.com/opscode/knife-windows
71
- licenses: []
91
+ licenses:
92
+ - Apache-2.0
72
93
  metadata: {}
73
94
  post_install_message:
74
95
  rdoc_options: []
@@ -99,4 +120,4 @@ test_files:
99
120
  - spec/unit/knife/bootstrap_template_spec.rb
100
121
  - spec/unit/knife/bootstrap_windows_winrm_spec.rb
101
122
  - spec/unit/knife/winrm_spec.rb
102
- has_rdoc: true
123
+ has_rdoc:
data/README.rdoc DELETED
@@ -1,134 +0,0 @@
1
- = Knife Windows Plugin
2
-
3
- = DESCRIPTION:
4
-
5
- This plugin adds additional functionality to the Chef Knife CLI tool for configuring/interacting with nodes running Microsoft Windows. The subcommands should function on any system running Ruby 1.9.1+ but nodes being configured via these subcommands require Windows Remote Management (WinRM) 1.0+. WinRM allows you to call native objects in Windows. This includes, but is not limited to, running batch scripts, powershell scripts and fetching WMI variables. For more information on WinRM, please visit {Microsoft's WinRM site}[http://msdn.microsoft.com/en-us/library/aa384426(v=VS.85).aspx]. You will want to familiarize yourself with (certain key aspects) of WinRM because you will be {writing scripts/running commands} with this tool to get you from (specific point A) to (specific point B).
6
-
7
- WinRM is built into Windows 7 and Windows Server 2008+. It can also be easily installed in older version of Windows, including:
8
-
9
- * Windows XP
10
- * Windows Server 2003
11
- * Windows Vista
12
-
13
- More information can be found on {Microsoft Support article 968930}[http://support.microsoft.com/?kbid=968930].
14
-
15
- This subcommands in this plugin have been tested and verified to work on Windows Server 2008 R2.
16
-
17
- = SUBCOMMANDS:
18
-
19
- This plugin provides the following Knife subcommands. Specific command options can be found by invoking the subcommand with a --+help+ flag
20
-
21
- == knife winrm
22
-
23
- The +winrm+ subcommand allows you to invoke commands in parallel on a subset of the nodes in your infrastructure. The +winrm+ subcommand uses the same syntax as the {search subcommand}[http://wiki.opscode.com/display/chef/Search]; you could could find the uptime of all your web servers using the command:
24
-
25
- % knife winrm "role:web" "net stats srv" -x Administrator -P 'super_secret_password'
26
-
27
- Or force a chef run:
28
-
29
- % knife winrm 'ec2-50-xx-xx-124.compute-1.amazonaws.com' 'chef-client -c c:/chef/client.rb' -m -x Administrator -P 'super_secret_password'
30
- ec2-50-xx-xx-124.compute-1.amazonaws.com [Fri, 04 Mar 2011 22:00:49 +0000] INFO: Starting Chef Run (Version 0.9.12)
31
- ec2-50-xx-xx-124.compute-1.amazonaws.com [Fri, 04 Mar 2011 22:00:50 +0000] WARN: Node ip-0A502FFB has an empty run list.
32
- ec2-50-xx-xx-124.compute-1.amazonaws.com [Fri, 04 Mar 2011 22:00:53 +0000] INFO: Chef Run complete in 4.383966 seconds
33
- ec2-50-xx-xx-124.compute-1.amazonaws.com [Fri, 04 Mar 2011 22:00:53 +0000] INFO: cleaning the checksum cache
34
- ec2-50-xx-xx-124.compute-1.amazonaws.com [Fri, 04 Mar 2011 22:00:53 +0000] INFO: Running report handlers
35
- ec2-50-xx-xx-124.compute-1.amazonaws.com [Fri, 04 Mar 2011 22:00:53 +0000] INFO: Report handlers complete
36
-
37
- This subcommand operates in a very similar manner as {knife ssh}[http://wiki.opscode.com/display/chef/Knife#Knife-SSHSubcommand]...just leveraging the WinRM protocol for communication. It also include's +knife+ +ssh+'s "{interactive session mode}[http://wiki.opscode.com/display/chef/Knife#Knife-InteractiveMode]"
38
-
39
- == knife bootstrap windows winrm
40
-
41
- Performs a Chef Bootstrap (via the WinRM protocol) on the target node. The goal of the bootstrap is to get Chef installed on the target system so it can run Chef Client with a Chef Server. The main assumption is a baseline OS installation exists. It is primarily intended for Chef Client systems that talk to a Chef server.
42
-
43
- This subcommand operates in a very similar manner as {knife bootstrap}[http://wiki.opscode.com/display/chef/Knife+Bootstrap]...just leveraging the WinRM protocol for communication. An initial run_list for the node can also be passed to the subcommand. Example usage:
44
-
45
- knife bootstrap windows winrm ec2-50-xx-xx-124.compute-1.amazonaws.com -r 'role[webserver],role[production]' -x Administrator -P 'super_secret_password'
46
-
47
- == knife bootstrap windows ssh
48
-
49
- Performs a Chef Bootstrap (via the SSH protocol) on the target node. The goal of the bootstrap is to get Chef installed on the target system so it can run Chef Client with a Chef Server. The main assumption is a baseline OS installation exists. It is primarily intended for Chef Client systems that talk to a Chef server.
50
-
51
- This subcommand assumes the SSH session will use Windows native cmd.exe command shell vs a bash shell through an emulated cygwin layer. Most popular Windows based SSHd daemons like {freeSSHd}[http://www.freesshd.com/] and {WinSSHD}[http://www.bitvise.com/winsshd] behave this way.
52
-
53
- An initial run_list for the node can also be passed to the subcommand. Example usage:
54
-
55
- knife bootstrap windows ssh ec2-50-xx-xx-124.compute-1.amazonaws.com -r 'role[webserver],role[production]' -x Administrator -i ~/.ssh/id_rsa
56
-
57
- = BOOTSTRAP TEMPLATES:
58
-
59
- This gem provides the following bootstrap templates:
60
-
61
- == windows-chef-client-msi
62
-
63
- This bootstrap template does the following:
64
-
65
- * Installs the latest version of Chef (and all dependencies) using the `chef-client` msi.
66
- * Writes the validation.pem per the local knife configuration.
67
- * Writes a default config file for Chef (C:\chef\client.rb) using values from the +knife.rb+.
68
- * Creates a JSON attributes file containing the specified run list and run Chef.
69
-
70
- This is the default bootstrap template used by both the +windows+ +bootstrap+ subcommands.
71
-
72
- = REQUIREMENTS/SETUP:
73
-
74
- == Ruby
75
-
76
- Ruby 1.9.1+ is needed.
77
-
78
- == Chef Version
79
-
80
- Knife plugins require >= Chef 0.10. More details about Knife plugins can be {found on the Chef wiki}[http://wiki.opscode.com/display/chef/Knife+Plugins].
81
-
82
- == Nodes
83
-
84
- *NOTE*: Before any WinRM related knife subcommands will function correctly a node's WinRM installation must be configured correctly. The below settings should be added to your base server image (AMI) or passed in using some sort of user-data mechanism provided by your cloud provider.
85
-
86
- A server running WinRM must also be configured properly to allow outside connections and the entire network path from the knife workstation to the server. The easiest way to accomplish this is to use {WinRM's quick configuration option}[http://msdn.microsoft.com/en-us/library/aa384372(v=vs.85).aspx#quick_default_configuration]:
87
-
88
- C:\Users\Administrator> winrm quickconfig -q
89
-
90
- The Chef and Ohai gem installations (that occur during bootstrap) take more memory than the default 150MB WinRM allocates per shell. Bump it up to 300MB with the following setting:
91
-
92
- C:\Users\Administrator> winrm set winrm/config/winrs @{MaxMemoryPerShellMB="300"}
93
-
94
- Bootstrap commands can take longer than the WinRM default 60 seconds to complete, bump to 30 minutes:
95
-
96
- C:\Users\Administrator> winrm set winrm/config @{MaxTimeoutms="1800000"}
97
-
98
- WinRM supports both the HTTP and HTTPS transports and the following authentication schemes: Kerberos, Digest, Certificate and Basic. The details of these authentication transports are outside of the scope of this README but details can be found on the {WinRM configuration guide}[http://msdn.microsoft.com/en-us/library/aa384372(v=vs.85).aspx]. Currently, this plugin support Kerberos and Basic authentication schemes.
99
-
100
- For development and testing purposes, unencrypted traffic with Basic authentication can make things easier:
101
-
102
- C:\Users\Administrator> winrm set winrm/config/service @{AllowUnencrypted="true"}
103
- C:\Users\Administrator> winrm set winrm/config/service/auth @{Basic="true"}
104
-
105
- === Troubleshooting
106
-
107
- #### When I run the winrm command I get: "Error: Invalid use of command line. Type "winrm -?" for help."
108
- - You're running the winrm command from powershell and you need to put the key/value pair in single quotes. For example:
109
- ```
110
- winrm set winrm/config/winrs '@{MaxMemoryPerShellMB="512"}'
111
- ```
112
-
113
- = CONTRIBUTING:
114
-
115
- Please file bugs against the KNIFE_WINDOWS project at http://tickets.opscode.com/browse/knife
116
-
117
- More information on the contribution process for Opscode projects can be found at: http://wiki.opscode.com/display/chef/How+to+Contribute
118
- = LICENSE:
119
-
120
- Author:: Seth Chisamore (<schisamo@opscode.com>)
121
- Copyright:: Copyright (c) 2011 Opscode, Inc.
122
- License:: Apache License, Version 2.0
123
-
124
- Licensed under the Apache License, Version 2.0 (the "License");
125
- you may not use this file except in compliance with the License.
126
- You may obtain a copy of the License at
127
-
128
- http://www.apache.org/licenses/LICENSE-2.0
129
-
130
- Unless required by applicable law or agreed to in writing, software
131
- distributed under the License is distributed on an "AS IS" BASIS,
132
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
133
- See the License for the specific language governing permissions and
134
- limitations under the License.