Update your Style in Test Kitchen

It is surprising how many resources on the Internet are carrying on outdated or deprecated information - the Chef ecosystem is no exception to this. While outdated style in Ruby files has been detected via cookstyle for a while, Test Kitchen files still have no sanity checks yet.

Let’s see what changed in this short post.

Note: As of version 2.5.2, while kitchen doctor does exist only the chef_base.rb file has an actual implementation for the related doctor method. Some of the items below might become common knowledge when this situation changes.

Naming of your Kitchen Files

If you still use files like .kitchen.yml in your projects, you should mark this for refactoring. Test Kitchen made the non-hidden alternative name kitchen.yml and kitchen.local.yml the default some time ago.

Outdated since version 1.21.0 (February 2018)

Legacy Driver Format

This one is present in many well-known examples for Test Kitchen and almost always somewhere in a project. Considering its age, it is surprising that is has survived: Sections like driver_config: or driver_plugin: were renamed to plain driver:. These keys are commonly found under your platforms or suites.

Old Style:

platforms:
  - name: ubuntu18
    driver_config:
      template: ubuntu18-vm

New Style:

platforms:
  - name: ubuntu18
    driver:
      template: ubuntu18-vm

Outdated since version 1.0.0.rc.1 (November 2013)

Legacy Chef Paths

When Test Kitchen was still a tool geared towards Chef, many settings were deeply integrated. As more and more provisioners were added, compatibility was preserved. Still, they are marked as deprecated under suites:

  • data_path
  • data_bags_path
  • encrypted_data_bag_secret_key_path
  • environment_path
  • nodes_path
  • roles_path

As those parameters are Chef-specific, you should put them in a provisioner: subsection instead like this:

Old Style:

suites:
  - name: default
    data_bags_path: test/integration

New Style:

suites:
  - name: default
    provisioner:
      data_bags_path: test/integration

Outdated since version 1.0.0.rc.1 (November 2013)

Pass Chef Data to Provisioner

While not being deprecated yet (probably due to wide-spread use), this fits into the same category as “Legacy Chef Paths”. The same reasoning is applied to:

  • run_list
  • named_run_list
  • attributes

Old Style:

suites:
  - name: default
    run_list:
      - recipe[empty]
    attributes:
      java:
        install_flavor: "oracle"

New Style:

suites:
  - name: default
    provisioner:
      run_list:
        - recipe[empty]
      attributes:
        java:
          install_flavor: "oracle"

Recommended since version 1.0.0.rc.1 (November 2013)

Similar Posts You Might Enjoy

tecRacer is Chef Partner of the Year Financial Services

ChefConf Online started this year with a big announcement for us. We have received the Chef Hartman award as “Partner of the year Financial Services”! This special award goes to companies that drove successful customer outcomes, developed special solution expertise and leveraged Chef’s GTM to drive growth. It makes us proud to be part of the whole Chef world. Thank you Chef, thank you Barry for this award! - by Patrick Schaumburg

Testing Physical Machines with kitchen-static (Part 2)

Testing on Physical Machines - Part 2 After introducing how to work with physical machines and Test Kitchen last time, we will look at a feature to allow central orchestration of available machines. - by Thomas Heinen

Testing Physical Machines with kitchen-static

Testing on Physical Machines with kitchen-static This article shows how to work with Test Kitchen on physical machines using the kitchen-static Driver. If you need to deliver a product (bundle of server and software) instead of just configuration, some tasks cannot be run on virtual machines alone but need testing on actual hardware. - by Thomas Heinen