Estimated time: 1 hour (with your own virtual machines)
This step introduces you to fundamentals of cookbook development and walks you through the process of creating, editing, and testing a simple cookbook. These are the same basic steps that you will expand on in developing your Chef Desktop cookbook.
Testing is central to good software development. Testing your Chef Desktop cookbook provides you the opportunity to detect and correct problems before putting changes into production. Testing saves time and money, but it adds value by helping your organization achieve and maintain operational velocity.
It is important to understand your operating license and service agreements. The best place to begin is find and understand your SLA:
In this step, you will prepare your workstation for developing, testing, and deploying the Chef Desktop cookbook.
Create your local repo
You will need a local repository on your workstation for storing your cookbooks and related chef work, and for sharing it with GitHub or another version control system.
From the command line in your root folder (c:\ or ~/), run:
chef generate repo my_repo
This is a practice cookbook to understand how to test.
Create your cookbook
chef generate cookbook my_repo/cookbooks/my_cookbook
Edit the metadata.rb file
Open your repo in Visual Studio Code. The one key file you will want to manage is the metadata.rb file. Please take a moment now to add your contact information and enter a starting version number for your cookbook.
name 'my_cookbook'
maintainer 'The Authors'
maintainer_email '[email protected]'
license 'All Rights Reserved'
description 'Installs/Configures my_cookbook'
version '0.1.0'
chef_version '>= 16.0'
Edit the default recipe
Open my_repo\cookbook\my_cookbook\recipes\default.rb in Visual Studio and add:
For Windows:
powershell_script 'get my path' do
code <<-CODE
[Environment]::GetEnvironmentVariable("Path")
CODE
end
For macOS:
bash 'get my path' do
user 'root'
code <<-EOH
echo $PATH
EOH
end
Note
If you want to use the Chef Desktop cookbook you received from Chef instead of creating a new one, then navigate and unzip that file into your cookbooks directory. Now you have two cookbooks. Update the metadata.rb file for the Chef Desktop cookbook to add your contact details.
Chef Desktop comes with a large number of options for configuring your Windows and Mac desktops. Look through the mac.rb and windows.rb files to explore what settings you want to turn on for your testing and evaluation. For those resources you do not want to explore yet, set their action to ‘:nothing’. See the Chef Desktop cookbook documentation for more information about settings.
Test Kitchen was installed with Chef Workstation. It provides Chef Infra with a testing harness for cookbooks that uses virtual machines(VMs). Consult your Apple and Microsoft licenses and service level agreements (SLA) to understand your options for acquiring or creating VMs for development.
Test Kitchen uses a driver plugin architecture to enable Test Kitchen to test instances on cloud providers such as Amazon EC2, Google Compute Engine, and Microsoft Azure. You can also test on multiple local hypervisors, such as VMware, Hyper-V, or VirtualBox. Test Kitchen Documentation and the Test Kitchen GitHub Repository.
Run the Virtual Devices
When working with desktop cookbook that you received from Chef, you downloaded the two virtual devices, also called testing images. Now issue the following command to get them started:
kitchen create
Apply the Cookbooks to the Images
Run the following command to apply, or ‘converge’, the cookbooks with the base OS image:
kitchen converge
Verify the settings
Confirm that the converged code is the code that you meant to apply. In VSCode, navigate to the test\integration\default directory and examine the generated integration tests. Carefully go through these tests and adjust them to match the setting to the changes in the default.rb file. Next, run:
kitchen verify
If any of the tests fail, check the output and compare your settings in the mac.rb or windows.rb files against the matching tests.
Cleanup
When you finish with your testing, you can run the following command to delete the running test images:
kitchen destroy
Once you are familiar with Test Kitchen, you can perform all of the steps at once, including cleanup, with:
kitchen test
© Chef Software, Inc.
Licensed under the Creative Commons Attribution 3.0 Unported License.
The Chef™ Mark and Chef Logo are either registered trademarks/service marks or trademarks/servicemarks of Chef, in the United States and other countries and are used with Chef Inc's permission.
We are not affiliated with, endorsed or sponsored by Chef Inc.
https://docs.chef.io/desktop/cookbook_repository/