Windows – test-kitchen with Windows guest converging fails with WinRMAuthorizationError

cheftest-kitchenwindows

I'm trying to get test-kitchen working with a guest Windows VM. I've followed a lot of Matt Wrock's excellent blog posts. I've set up a working Windows Vagrant box, used the right test-kitchen and kitchen-vagrant branches and have managed to get kitchen create to work.

At this point I'm stuck on getting kitchen converge to work. I'll do a converge and run into:

$ kitchen converge
-----> Starting Kitchen (v1.3.2.dev)
-----> Converging <default-windows-7>...
       Preparing files for transfer
       Preparing dna.json
       Resolving cookbook dependencies with Berkshelf 3.1.3...
       Removing non-cookbook files before transfer
       Preparing validation.pem
       Preparing client.rb
>>>>>> ------Exception-------
>>>>>> Class: Kitchen::ActionFailed
>>>>>> Message: Failed to complete #converge action: [[Kitchen::Transport::Winrm] WinRM::WinRMAuthorizationError using shell: [powershell] and command: [ $ProgressPreference='SilentlyContinue';   if (-Not (Test-Path "/tmp/kitchen")) {
    mkdir "/tmp/kitchen" | Out-Null
  }
if ( Test-Path '/tmp/kitchen/data' ) { rm -r '/tmp/kitchen/data' };if ( Test-Path '/tmp/kitchen/data_bags' ) { rm -r '/tmp/kitchen/data_bags' };if ( Test-Path '/tmp/kitchen/environments' ) { rm -r '/tmp/kitchen/environments' };if ( Test-Path '/tmp/kitchen/roles' ) { rm -r '/tmp/kitchen/roles' };if ( Test-Path '/tmp/kitchen/clients' ) { rm -r '/tmp/kitchen/clients' };
  if (-Not (Test-Path "/tmp/kitchen")) {
    mkdir "/tmp/kitchen" | Out-Null
  }
if ( Test-Path '/tmp/kitchen/data' ) { rm -r '/tmp/kitchen/data' };if ( Test-Path '/tmp/kitchen/data_bags' ) { rm -r '/tmp/kitchen/data_bags' };if ( Test-Path '/tmp/kitchen/environments' ) { rm -r '/tmp/kitchen/environments' };if ( Test-Path '/tmp/kitchen/roles' ) { rm -r '/tmp/kitchen/roles' };if ( Test-Path '/tmp/kitchen/clients' ) { rm -r '/tmp/kitchen/clients' };
  if (-Not (Test-Path "/tmp/kitchen")) {
    mkdir "/tmp/kitchen" | Out-Null
  }
if ( Test-Path '/tmp/kitchen/data' ) { rm -r '/tmp/kitchen/data' };if ( Test-Path '/tmp/kitchen/data_bags' ) { rm -r '/tmp/kitchen/data_bags' };if ( Test-Path '/tmp/kitchen/environments' ) { rm -r '/tmp/kitchen/environments' };if ( Test-Path '/tmp/kitchen/roles' ) { rm -r '/tmp/kitchen/roles' };if ( Test-Path '/tmp/kitchen/clients' ) { rm -r '/tmp/kitchen/clients' };
  if (-Not (Test-Path "/tmp/kitchen")) {
    mkdir "/tmp/kitchen" | Out-Null
  }
if ( Test-Path '/tmp/kitchen/data' ) { rm -r '/tmp/kitchen/data' };if ( Test-Path '/tmp/kitchen/data_bags' ) { rm -r '/tmp/kitchen/data_bags' };if ( Test-Path '/tmp/kitchen/environments' ) { rm -r '/tmp/kitchen/environments' };if ( Test-Path '/tmp/kitchen/roles' ) { rm -r '/tmp/kitchen/roles' };if ( Test-Path '/tmp/kitchen/clients' ) { rm -r '/tmp/kitchen/clients' };
  if (-Not (Test-Path "/tmp/kitchen")) {
    mkdir "/tmp/kitchen" | Out-Null
  }
if ( Test-Path '/tmp/kitchen/data' ) { rm -r '/tmp/kitchen/data' };if ( Test-Path '/tmp/kitchen/data_bags' ) { rm -r '/tmp/kitchen/data_bags' };if ( Test-Path '/tmp/kitchen/environments' ) { rm -r '/tmp/kitchen/environments' };if ( Test-Path '/tmp/kitchen/roles' ) { rm -r '/tmp/kitchen/roles' };if ( Test-Path '/tmp/kitchen/clients' ) { rm -r '/tmp/kitchen/clients' };
  if (-Not (Test-Path "/tmp/kitchen")) {
    mkdir "/tmp/kitchen" | Out-Null
  }
if ( Test-Path '/tmp/kitchen/data' ) { rm -r '/tmp/kitchen/data' };if ( Test-Path '/tmp/kitchen/data_bags' ) { rm -r '/tmp/kitchen/data_bags' };if ( Test-Path '/tmp/kitchen/environments' ) { rm -r '/tmp/kitchen/environments' };if ( Test-Path '/tmp/kitchen/roles' ) { rm -r '/tmp/kitchen/roles' };if ( Test-Path '/tmp/kitchen/clients' ) { rm -r '/tmp/kitchen/clients' };]]
>>>>>> ----------------------
>>>>>> Please see .kitchen/logs/kitchen.log for more details
>>>>>> Also try running `kitchen diagnose --all` for configuration

At this point I'm at a loss, I'm able to run vagrant up and have the shell provisioner create a file, so the powershell permissions seem to be set correctly. I have more details with all the config files in a gist.

Best Answer

The branches for windows support has been recently merged into the latest version. My Gemfile (below) pointing to test master branch of both test-kitchen and kitchen-vagrant works for me. Hopefully it'll work for you as well.

PS: Finally signed in after years of using it and this is my first reply :-)

source 'https://rubygems.org'

group :development do
  gem "test-kitchen", :git => 'https://github.com/test-kitchen/test-kitchen.git', :branch => 'master'
  gem 'kitchen-vagrant', git: 'https://github.com/test-kitchen/kitchen-vagrant.git', :branch => 'master'
  gem "berkshelf"
  gem "vagrant-wrapper", ">= 2.0"
end