How do i use chef test kitchen to test my cookbooks?



  • Chef test kitchen tests cookbooks before uploading them to the chef server. This is a very simplistic test to just show how test kitchen works.

    Refer to this link for meanings of the different sections: https://docs.chef.io/config_yml_kitchen.html

    driver_name - What will create your virtual machine?
    provisioner_name - How will chef simulate chef-client?
    verifier_name - Which application to use to test?
    transport_name - How do i execute remote commands on my test?instance, windows - winrm, linux - ssh.
    platform-version - What platform will I use to test? ubuntu-12.04 or centos-6.4, etc
    platforms - What common chef server parameters will be used?
    suites - What do i want to test in the cookbook?

    In your ~/chef-repo/cookbooks/your_cookbook/, create a file called .kitchen.yml

    ---
    driver:
      name: vagrant
    
    provisioner:
      name: chef_zero
    
    platforms:
      - name: ubuntu-16.04
    
    suites:
      - name: default
        run_list:
          - recipe[local_cookbook::default]
    
    attributes:
    

    Produces a lot of screen output as it creates the VM and tests it.

    $ kitchen test
    

    The kitchen test goes through various stages of during the test. Not Created, Created, Converged, Verified, and back to Not Created.

    $ kitchen list
    Instance             Driver   Provisioner  Verifier  Transport  Last Action    Last Error
    default-ubuntu-1604  Vagrant  ChefZero     Busser    Ssh        <Not Created>  <None>
    
    $ kitchen list
    Instance             Driver   Provisioner  Verifier  Transport  Last Action  Last Error
    default-ubuntu-1604  Vagrant  ChefZero     Busser    Ssh        Created      <None>
    
    $ kitchen list
    Instance             Driver   Provisioner  Verifier  Transport  Last Action  Last Error
    default-ubuntu-1604  Vagrant  ChefZero     Busser    Ssh        Converged      <None>
    
    $ kitchen list
    Instance             Driver   Provisioner  Verifier  Transport  Last Action  Last Error
    default-ubuntu-1604  Vagrant  ChefZero     Busser    Ssh        Verified      <None>
    
    $ kitchen list
    Instance             Driver   Provisioner  Verifier  Transport  Last Action    Last Error
    default-ubuntu-1604  Vagrant  ChefZero     Busser    Ssh        <Not Created>  <None>
    

Log in to reply
 

© Lightnetics 2024