0
votes

I'm playing around to try and get minitests working in test kitchen with vagrant.

My own tests succeed but the chef-client cookbook includes a test to start the chef-client which fails the test run. The reason why the chef-client start fails is because it cannot authenticate with my chef server, as the box does not have my client validation key.

# Running tests:       

chef-client::service#test_0001_starts the chef-client service = 0.03 s = F       
ntp::default#test_0001_starts the NTP daemon = 0.15 s = .       
ntp::default#test_0003_creates the ntp.conf = 0.01 s = .       
ntp::default#test_0002_creates the leapfile = 0.00 s = .       
recipe::my_cookbook::default::greeting file#test_0001_creates the greeting file = 0.00 s = .       
recipe::my_cookbook::default::greeting file#test_0002_continas what's stored in the 'greeting' node attribute = 0.00 s = .       


Finished tests in 0.199086s, 30.1377 tests/s, 55.2525 assertions/s.       

  1) Failure:       
chef-client::service#test_0001_starts the chef-client service [/var/chef/minitest/chef-client/service_test.rb:25]:       
Expected: true       
  Actual: false       


6 tests, 11 assertions, 1 failures, 0 errors, 0 skips       
[2013-11-24T13:07:45+00:00] INFO: Report handlers complete       
[2013-11-24T13:07:45+00:00] ERROR: Running exception handlers       
[2013-11-24T13:07:45+00:00] ERROR: Exception handlers complete       
[2013-11-24T13:07:45+00:00] FATAL: Stacktrace dumped to /tmp/kitchen-chef-solo/cache/chef-stacktrace.out       
Chef Client failed. 38 resources updated       
[2013-11-24T13:07:45+00:00] ERROR: MiniTest failed with 1 failure(s) and 0 error(s).       
Failure:       
chef-client::service#test_0001_starts the chef-client service [/var/chef/minitest/chef-client/service_test.rb:25]:       
Expected: true       
  Actual: false       

[2013-11-24T13:07:45+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)       
>>>>>> Converge failed on instance <default-ubuntu-1204>.
>>>>>> Please see .kitchen/logs/default-ubuntu-1204.log for more details
>>>>>> ------Exception-------
>>>>>> Class: Kitchen::ActionFailed
>>>>>> Message: SSH exited (1) for command: [sudo -E chef-solo --config /tmp/kitchen-chef-solo/solo.rb --json-attributes /tmp/kitchen-chef-solo/dna.json  --log_level info]
>>>>>> ----------------------

Here is the output of a manual chef-client run on the vagrant box spun up by test kitchen:

vagrant@default-ubuntu-1204:~$ sudo chef-client
[2013-11-24T18:29:21+00:00] WARN: *****************************************
[2013-11-24T18:29:21+00:00] WARN: Did not find config file: /etc/chef/client.rb, using command line options.
[2013-11-24T18:29:21+00:00] WARN: *****************************************
Starting Chef Client, version 11.8.0
Creating a new client identity for default-ubuntu-1204.vagrantup.com using the validator key.
[2013-11-24T18:29:21+00:00] WARN: Failed to read the private key /etc/chef/validation.pem: #<Errno::ENOENT: No such file or directory - /etc/chef/validation.pem>

================================================================================
Chef encountered an error attempting to create the client "default-ubuntu-1204.vagrantup.com"
================================================================================


Private Key Not Found:
----------------------
Your private key could not be loaded. If the key file exists, ensure that it is
readable by chef-client.



Relevant Config Settings:
-------------------------
validation_key "/etc/chef/validation.pem"



[2013-11-24T18:29:21+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
Chef Client failed. 0 resources updated
[2013-11-24T18:29:21+00:00] ERROR: I cannot read /etc/chef/validation.pem, which you told me to use to sign requests!
[2013-11-24T18:29:21+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)

I've tried to find a way to get my client key onto the vagrant box created by test kitchen, and I assumed this would be through the .kitchen.yml, as this is the file that is used to create the VagrantFile. I configured my other vagrants to find my client authentication key with the VagrantFile so I assumed this method should work.

Test Kitchen sort of seems to support vagrant provision, however it's not very clear to me how this is supposed to be done just by setting use_vagrant_provision: true https://github.com/test-kitchen/kitchen-vagrant#-use_vagrant_provision

I feel like I'm missing something obvious here that has not occurred to me yet...?

2
dont forget to accept the right answer!!Robert

2 Answers

0
votes

The "correct" solution would be to allow you to say "don't run these tests, just the recipe" in kitchen, but I am not aware of such functionality. Might be worth a look into whether or not you can do this.

Why do you need to use the chef-client cookbook? I'm fairly sure kitchen uses vagrant-omnibus to install the client anyway? I've never needed it, but then I only use solo with kitchen stuff.

If you really need to hack around this then perhaps you could use the virtual box synced folders capability / http / ftp and some test helper recipes to get the key onto the machine.

0
votes

Try putting your private key in a file in your cookbook's files folder and then load it onto your vm as a cookbook_file resource in your recipe.

cookbook_file "/home/user/.chef/user.pem" do
  source user.pem
  action :create_if_missing
end