Chef (3) Test Kitchen

1. Preparation:

Install Vagrant and VirtualBox at first. Check the version of Vagrant and VirtualBox.

$ vagrant --version
$ VBoxManage --version

2. Test Kitchen Init:

$ mkdir kitchen
$ cd kitchen
$ kitchen init --create-gemfile

You may get some error messages.

You must run `bundle install' to fetch any new gems.

Test Kitchen needs you to run bundle install to download and install the kitchen- vagrant driver and some supporting gems.

$ gem install budler
$ bundle install

We can use tree command to list the structure of the directory.

$ tree -a
.
├── chefignore
├── Gemfile
├── Gemfile.lock
├── .kitchen.yml
└── test
    └── integration
        └── default
  • .kitchen.yml: used to configure virtual environments for Test Kitchen.
  • Gemfile: a list of gems to be downloaded.
  • Gemfile.lock: records all the versions of the gems Bundler downloaded for the current project, plus the versions of all dependencies.
  • test/: directory structure that contains tests.

3. Start Test Kitchen:

Modify the .kitchen.yml as bellow. The OS is set to ubuntu-16.04.

---
driver:
  name: vagrant

provisioner:
  name: chef_solo

platforms:
  - name: ubuntu-16.04

suites:
  - name: default
    run_list:
    attributes:

Start the vagrant and wait (This might takes 5 to 15 minutes to download the images).

$ kitchen create default-ubuntu

Check the status of the kitchen and the virtual machine.

$ kitchen list # list kitchens
# Instance             Driver   Provisioner  Verifier  Transport  Last Action  Last Error
# default-ubuntu-1604  Vagrant  ChefSolo     Busser    Ssh        Created      <None>

$ VBoxManage list runningvms
# "default-ubuntu-1604_...... 

The VBoxManage command displays the information of the VM in the console. If you open the UI of VirtualBox, you can see the VM is up and running.

The Kitchen create logic is shows as the diagram.

The create logic of Kitchen is similar to Docker. First, Kitchen checks the local Basebox. If the Basebox is not found, Kitchen starts to download the Basebox from Vagrant Cloud. After the Basebox has been imported, Kitchen configures and boots the virtual machine.



4. Login Kitchen:

Now we can access the Kitchen instance with kitchen login command.

$ kitchen login <Kitchen name>
$ kitchen login default-ubuntu

Exit and release the resources used by Kitchen.

$ exit
$ kitchen list # the instance has not been terminated.

$ kitchen login default-ubuntu
$ kitchen list # the instance has been terminated now.

We can check the status of the Kitchen instances using kitchen list command after destroying the instance. If you check the status of the terminated instance, the Last Action of that instance shows Not Created.


Reference

[1] Mischa Taylor and Seth Vargo , Learning Chef , O'Reilly Media (2015)

留言

熱門文章