Questions about Test Kitchen

1,185 views
Skip to first unread message

Testing with Chef

unread,
Apr 23, 2014, 5:45:50 PM4/23/14
to testing-...@googlegroups.com

From: Denis Uraganov

I have few small questions about test kitchen

- How can I create synced_folder in test kitchen as "config.vm.synced_folder 'shared/', '/vagrant/'"  in vagrant?

- How can I use vagrant plugins in test kitchen (For example, hostmanager https://github.com/smdahlen/vagrant-hostmanager)?

- At this moment test kitchen does not support Ubuntu 14.04 as sandbox environments. Could you point me to the way how to create/integrate custom sandbox platform?

I'm looking forward to your response

Best Regards
Denis Uraganov

Mischa Taylor

unread,
Apr 23, 2014, 5:55:56 PM4/23/14
to testing-...@googlegroups.com

Re 1: How can I create synced_folder in test kitchen as "config.vm.synced_folder 'shared/', '/vagrant/'"  in vagrant?

Test Kitchen supports a synced_folders block as a pass-through to vagrant with the same parameters as config.vm.synced_folder.  The first parameter is a path to a directory on the host machine (can be relative).  The second parameter is an absolute path specifying a mount point within the guest.  You can also add all the modifiers Vagrant supports for specifying NFS, RSync & SMB shares as an optional third parameter.  The parameters need to be passed as an array in the .kitchen.yml.  If you want to specify more than one share, just use the YAML list construct. 

For example:

driver:

  synced_folders: 
    - ["data/%{instance_name}", "/opt/instance_data"],
    - ["/host_path", "/vm_path", "create: true, type: :nfs"]


One thing that isn't documented very well about using relative paths in the .kitchen.yml is that it is relative to where the actual Vagrantfile lives, not where the .kitchen.yml file resides, which is what you might expect.  Behind the scenes, Test Kitchen is creating Vagrantfiles in .kitchen/kitchen-vagrant/{instance_name}.  So if you want to specify a relative path to say, shared/, relative to where the .kitchen.yml lives in the cookbook root, you need to specify the relative path like so: ../../shared

Here's a more complete example of a full .kitchen.yml using this example:

---

driver:
  name: vagrant

provisioner:
  name: chef_solo

platforms:
  - name: ubuntu1404
    driver:
      box: ubuntu1404
      box_url: https://dl.dropboxusercontent.com/s/hxvl5cbnsbh11u4/ubuntu1404-provisionerless.box?dl=1&token_hash=AAGgieIVpfXetzEZcLFZFSqgVZV3__R5fU_-SDBp5krLMA
      synced_folders:
        - ["../../../shared", "/vagrant"]

suites:
  - name: default
    run_list:
    attributes:


Assuming that the cookbook structure resembles the following:

.

├── .bundle
│   └── config
├── .kitchen
│   ├── default-ubuntu1404.yml
│   ├── kitchen-vagrant
│   └── logs
├── .kitchen.yml
├── Gemfile
├── Gemfile.lock
├── shared
│   └── hi.txt
├── test
│   └── integration
└── vendor
    └── bundle


Mischa Taylor

unread,
Apr 23, 2014, 5:58:00 PM4/23/14
to testing-...@googlegroups.com

Re 2: How can I use vagrant plugins in test kitchen (For example, hostmanager https://github.com/smdahlen/vagrant-hostmanager)?

Test Kitchen uses Vagrant behind the scenes, so as long as you have the proper vagrant plugins installed, they will still work when Test Kitchen drives the VM lifecycle, executing whatever hooks a plugin monitors for vagrant processes.  The trick is to make sure that the Vagrantfile gets written out properly to .kitchen/kitchen-vagrant/{instance_name}/Vagrantfile if the plugin relies on special extensions to the Vagrantfile format.

You can override the Vagrantfile that is generated by using the vagrantfile_erb directive in the .kitchen.yml  It's documented here: https://github.com/test-kitchen/kitchen-vagrant#-vagrantfile_erb 

And if needed, you can add a special pre_create_command to run things before "vagrant up" to prep things if that's needed: https://github.com/test-kitchen/kitchen-vagrant#-pre_create_command

That being said a many vagrant plugins duplicate functionality that is either already in Test Kitchen or Chef.  For example you can set the hostname with the vm_hostname setting in the .kitchen.yml.  Internally at Chef Software, we're fond of using the hostfile LWRP to manage /etc/hostshttp://community.opscode.com/cookbooks/hostsfile (a.k.a. using Chef to manage our Vagrant boxes for anything above the OS level).  And now with chef-metal, it makes things even easier to create clusters of machines managed by Chef. There's also an evolving Test Kitchen driver being written to integrate chef-metal into Test Kitchen: https://github.com/doubt72/kitchen-metal  but it is not yet usable - waiting on a few changes to Test Kitchen to get merged in first.

Just something to consider, that since Test Kitchen was built from the ground up to integrate well with Chef, you can use Chef more in the instance/machine creating process, where you used to need to rely more on vagrant-plugins.

Mischa Taylor

unread,
Apr 23, 2014, 9:39:21 PM4/23/14
to testing-...@googlegroups.com
Re 3 - At this moment test kitchen does not support Ubuntu 14.04 as sandbox environments. Could you point me to the way how to create/integrate custom sandbox platform?

Just use the box & box_url directives in your .kitchen.yml.  The box directive is required when you use box_url - it is the name that is used to register the vagrant box (it does not currently reuse the name field like you would expect, but I usually make them match).  I recommend at least using local copies of the boxes so that you don't have to wait for the downloads over the internet, if not anything else.  Here's an example:

---

driver:
  name: vagrant

provisioner:
  name: chef_solo

platforms:
  - name: ubuntu1404
    driver:
      box: ubuntu1404
      box_url: https://dl.dropboxusercontent.com/s/hxvl5cbnsbh11u4/ubuntu1404-provisionerless.box?dl=1&token_hash=AAGgieIVpfXetzEZcLFZFSqgVZV3__R5fU_-SDBp5krLMA

suites:
  - name: default
    run_list:
    attributes:



VMware works just as well, if you've purchased the VMware plugin from Hashicorp.  Just set the provider: field to either vmware_fusion or vmware_workstation accordingly


---

driver:

  name: vagrant


provisioner:

  name: chef_solo


platforms:

  - name: ubuntu1404

    driver:

      provider: vmware_fusion

      box: ubuntu1404

      box_url: https://dl.dropboxusercontent.com/s/4nsx9l7q4of22oa/ubuntu1404-provisionerless.box?dl=1&token_hash=AAGJZiONV3YbgfSKVmg-xw_b3EwzD1WC2Ti8EgIPkckEpw

      customize:

        memory: 1024


suites:

  - name: default




BTW Julian just added Ubuntu 14.04 to Bento, so the alias should work in Test Kitchen now:

---

driver:

  name: vagrant


provisioner:

  name: chef_solo


platforms:

  - name: ubuntu-14.04


suites:

  - name: default



maj...@gmail.com

unread,
May 6, 2014, 12:01:35 PM5/6/14
to testing-...@googlegroups.com
Does this work with Docker? I tried the same syntax, but the directory doesn't seem to get populated.

Mischa Taylor

unread,
May 8, 2014, 2:26:22 AM5/8/14
to testing-...@googlegroups.com, maj...@gmail.com
I'm not sure what "directory" you're talking about, but the operation is a little different in the Docker context.  You'll want to use a Docker repository with your image instead of directly using a .box file via a URL.  There are official public repositories for Ubuntu in the Docker Index: https://index.docker.io/_/ubuntu/  Here's an example .kitchen.yml that will spin up Ubuntu 14.04 in docker:


---

driver:

  name: docker

  binary: docker.io


provisioner:

  name: chef_solo


platforms:

  - name: ubuntu-14.04

    driver:

      image: ubuntu:14.04

      platform: ubuntu


suites:

  - name: default

    run_list:

    attributes:



This .kitchen.yml is written for the new training VM which is itself Ubuntu 14.04, where the docker application name is now docker.io.  If you're using the old Ubuntu 12.04 training image, the following .kitchen.yml omitting the binary: value should work.  Thankfully the old training image uses the same 3.13 kernel that Ubuntu 14.04 requires:


---

driver:

  name: docker


provisioner:

  name: chef_solo


platforms:

  - name: ubuntu-14.04

    driver:

      image: ubuntu:14.04

      platform: ubuntu


suites:

  - name: default

    run_list:

    attributes:

tiagui...@gmail.com

unread,
Jun 2, 2014, 2:30:32 PM6/2/14
to testing-...@googlegroups.com
Hello, sorry for intromition,
How is set the vagrantfile_erb in test kitchen?
I've googled and I dont find examples.
I did in my .kitchen.yml file something like:

---
driver:
name: vagrant
vagrantfile_erb: /home/admin/Vagrantfile.erb
customize:
ssh_private: ~/.ssh/id_rsa
....

But kitchen doesnt uses my custom Vagrantfile yet :(

Thanks for the help.

ula...@gmail.com

unread,
Aug 20, 2015, 2:29:16 AM8/20/15
to Testing with Chef, maj...@gmail.com, Ulaganathan Namasivayam
Hi,
I am getting trouble with this setup.i have a ubuntu14.04 Vagrant-VM running on my windows8 machine... i have packaged it as a vagrant BOX. now in the Vagrant-VM i am running test kitchen/vagrant/virtualbox combination.. There by using test kitchen am trying to spin up a new VM using the existing BOX in the BOX_URL defined in kithen.yml. I also passed network paramters in kithchen.yml.. Now kitchen create command causing action failed error by throwing waiting for ssh service 127.0.0.1 on port 2222..

Question :

1) Why testkitchen is not using my ip address defined in kitchen.yml and going with 127.0.0.1 and port 2222 which are part of the existing BOX. how to pass new network parameter for sandbox created by test kitchen??

Reply all
Reply to author
Forward
0 new messages