{"id":32099,"date":"2022-12-01T04:21:23","date_gmt":"2022-12-01T04:21:23","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=32099"},"modified":"2022-12-23T05:44:50","modified_gmt":"2022-12-23T05:44:50","slug":"chef-tutorials-test-kitchen-workflow-and-examples","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/chef-tutorials-test-kitchen-workflow-and-examples\/","title":{"rendered":"Chef Tutorials: Test Kitchen Workflow and Examples"},"content":{"rendered":"\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"520\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/12\/test-kitchen-workflow-1-1024x520.jpg\" alt=\"\" class=\"wp-image-32100\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/12\/test-kitchen-workflow-1-1024x520.jpg 1024w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/12\/test-kitchen-workflow-1-300x152.jpg 300w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/12\/test-kitchen-workflow-1-768x390.jpg 768w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/12\/test-kitchen-workflow-1.jpg 1468w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"516\" height=\"452\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/12\/test-kitchen-workflow-2.jpg\" alt=\"\" class=\"wp-image-32101\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/12\/test-kitchen-workflow-2.jpg 516w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/12\/test-kitchen-workflow-2-300x263.jpg 300w\" sizes=\"auto, (max-width: 516px) 100vw, 516px\" \/><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-comment\"># kitchen init --create-gemfile<\/span>\r\n\r\nRun the kitchen init --create-gemfile command in your newly created kitchen directory. The kitchen init command generates all the config files needed to add Test Kitchen support to a project. We need to <span class=\"hljs-keyword\">use<\/span> <span class=\"hljs-title\">the<\/span> --<span class=\"hljs-title\">create<\/span>-<span class=\"hljs-title\">gemfile<\/span> <span class=\"hljs-title\">option<\/span>, <span class=\"hljs-title\">because<\/span> <span class=\"hljs-title\">if<\/span> <span class=\"hljs-title\">we<\/span> <span class=\"hljs-title\">don<\/span>\u2019<span class=\"hljs-title\">t<\/span>, <span class=\"hljs-title\">Test<\/span> <span class=\"hljs-title\">Kitchen<\/span> <span class=\"hljs-title\">will<\/span> <span class=\"hljs-title\">immediately<\/span> <span class=\"hljs-title\">try<\/span> <span class=\"hljs-title\">to<\/span> <span class=\"hljs-title\">run<\/span> <span class=\"hljs-title\">gem<\/span> <span class=\"hljs-title\">install<\/span> <span class=\"hljs-title\">as<\/span> <span class=\"hljs-title\">a<\/span> <span class=\"hljs-title\">user<\/span> <span class=\"hljs-title\">instead<\/span> <span class=\"hljs-title\">of<\/span> <span class=\"hljs-title\">as<\/span> <span class=\"hljs-title\">an<\/span> <span class=\"hljs-title\">admin<\/span>. <span class=\"hljs-title\">This<\/span> <span class=\"hljs-title\">fails<\/span> <span class=\"hljs-title\">on<\/span> <span class=\"hljs-title\">some<\/span> <span class=\"hljs-title\">platforms<\/span> <span class=\"hljs-title\">because<\/span> <span class=\"hljs-title\">the<\/span> <span class=\"hljs-title\">Chef<\/span> <span class=\"hljs-title\">Development<\/span> <span class=\"hljs-title\">Kit<\/span> <span class=\"hljs-title\">installation<\/span> <span class=\"hljs-title\">doesn<\/span>\u2019<span class=\"hljs-title\">t<\/span> <span class=\"hljs-title\">always<\/span> <span class=\"hljs-title\">make<\/span> <span class=\"hljs-title\">its<\/span> <span class=\"hljs-title\">gem<\/span> <span class=\"hljs-title\">directory<\/span> <span class=\"hljs-title\">user<\/span>-<span class=\"hljs-title\">writeable<\/span>:\r\n\r\n\r\n$ <span class=\"hljs-title\">kitchen<\/span> <span class=\"hljs-title\">init<\/span> --<span class=\"hljs-title\">create<\/span>-<span class=\"hljs-title\">gemfile<\/span>\r\n <span class=\"hljs-title\">create<\/span> .<span class=\"hljs-title\">kitchen<\/span>.<span class=\"hljs-title\">yml<\/span>\r\n <span class=\"hljs-title\">create<\/span> <span class=\"hljs-title\">test<\/span>\/<span class=\"hljs-title\">integration<\/span>\/<span class=\"hljs-title\">default<\/span>\r\n <span class=\"hljs-title\">create<\/span> <span class=\"hljs-title\">Gemfile<\/span>\r\n <span class=\"hljs-title\">append<\/span> <span class=\"hljs-title\">Gemfile<\/span>\r\n <span class=\"hljs-title\">append<\/span> <span class=\"hljs-title\">Gemfile<\/span>\r\n<span class=\"hljs-title\">You<\/span> <span class=\"hljs-title\">must<\/span> <span class=\"hljs-title\">run<\/span> `<span class=\"hljs-title\">bundle<\/span> <span class=\"hljs-title\">install<\/span>' <span class=\"hljs-title\">to<\/span> <span class=\"hljs-title\">fetch<\/span> <span class=\"hljs-title\">any<\/span> <span class=\"hljs-title\">new<\/span> <span class=\"hljs-title\">gems<\/span>.\r\n\r\n# <span class=\"hljs-title\">bundle<\/span> <span class=\"hljs-title\">install<\/span>\r\n<span class=\"hljs-title\">The<\/span> <span class=\"hljs-title\">bundle<\/span> <span class=\"hljs-title\">install<\/span> <span class=\"hljs-title\">command<\/span> <span class=\"hljs-title\">referenced<\/span> <span class=\"hljs-title\">in<\/span> <span class=\"hljs-title\">the<\/span> <span class=\"hljs-title\">preceding<\/span> <span class=\"hljs-title\">command<\/span> <span class=\"hljs-title\">line<\/span> <span class=\"hljs-title\">output<\/span> <span class=\"hljs-title\">refers<\/span> <span class=\"hljs-title\">to<\/span> <span class=\"hljs-title\">the<\/span> <span class=\"hljs-title\">Bundler<\/span> <span class=\"hljs-title\">tool<\/span>. <span class=\"hljs-title\">Bundler<\/span> <span class=\"hljs-title\">is<\/span> <span class=\"hljs-title\">a<\/span> <span class=\"hljs-title\">tool<\/span> <span class=\"hljs-title\">that<\/span> <span class=\"hljs-title\">downloads<\/span> <span class=\"hljs-title\">and<\/span> <span class=\"hljs-title\">manages<\/span> <span class=\"hljs-title\">Ruby<\/span> <span class=\"hljs-title\">gems<\/span>. <span class=\"hljs-title\">Test<\/span> <span class=\"hljs-title\">Kitchen<\/span> <span class=\"hljs-title\">needs<\/span> <span class=\"hljs-title\">you<\/span> <span class=\"hljs-title\">to<\/span> <span class=\"hljs-title\">run<\/span> <span class=\"hljs-title\">bundle<\/span> <span class=\"hljs-title\">install<\/span> <span class=\"hljs-title\">to<\/span> <span class=\"hljs-title\">download<\/span> <span class=\"hljs-title\">and<\/span> <span class=\"hljs-title\">install<\/span> <span class=\"hljs-title\">the<\/span> <span class=\"hljs-title\">kitchen<\/span>\u0002<span class=\"hljs-title\">vagrant<\/span> <span class=\"hljs-title\">driver<\/span> <span class=\"hljs-title\">and<\/span> <span class=\"hljs-title\">some<\/span> <span class=\"hljs-title\">supporting<\/span> <span class=\"hljs-title\">gems<\/span>.\r\n\r\n$ <span class=\"hljs-title\">bundle<\/span> <span class=\"hljs-title\">install<\/span>\r\n<span class=\"hljs-title\">Fetching<\/span> <span class=\"hljs-title\">gem<\/span> <span class=\"hljs-title\">metadata<\/span> <span class=\"hljs-title\">from<\/span> <span class=\"hljs-title\">https<\/span>:\/\/<span class=\"hljs-title\">rubygems<\/span>.<span class=\"hljs-title\">org<\/span>\/..........\r\n<span class=\"hljs-title\">Resolving<\/span> <span class=\"hljs-title\">dependencies<\/span>...\r\n<span class=\"hljs-title\">Using<\/span> <span class=\"hljs-title\">mixlib<\/span>-<span class=\"hljs-title\">shellout<\/span> (1.4.0)\r\n<span class=\"hljs-title\">Using<\/span> <span class=\"hljs-title\">net<\/span>-<span class=\"hljs-title\">ssh<\/span> (2.9.1)\r\n<span class=\"hljs-title\">Using<\/span> <span class=\"hljs-title\">net<\/span>-<span class=\"hljs-title\">scp<\/span> (1.2.1)\r\n<span class=\"hljs-title\">Using<\/span> <span class=\"hljs-title\">safe_yaml<\/span> (1.0.3)\r\n<span class=\"hljs-title\">Using<\/span> <span class=\"hljs-title\">thor<\/span> (0.19.1)\r\n<span class=\"hljs-title\">Using<\/span> <span class=\"hljs-title\">test<\/span>-<span class=\"hljs-title\">kitchen<\/span> (1.2.1)\r\n<span class=\"hljs-title\">Using<\/span> <span class=\"hljs-title\">kitchen<\/span>-<span class=\"hljs-title\">vagrant<\/span> (0.15.0)\r\n<span class=\"hljs-title\">Using<\/span> <span class=\"hljs-title\">bundler<\/span> (1.5.2)\r\n<span class=\"hljs-title\">Your<\/span> <span class=\"hljs-title\">bundle<\/span> <span class=\"hljs-title\">is<\/span> <span class=\"hljs-title\">complete<\/span>!\r\n<span class=\"hljs-title\">Use<\/span> `<span class=\"hljs-title\">bundle<\/span> <span class=\"hljs-title\">show<\/span> &#91;<span class=\"hljs-title\">gemname<\/span>]` <span class=\"hljs-title\">to<\/span> <span class=\"hljs-title\">see<\/span> <span class=\"hljs-title\">where<\/span> <span class=\"hljs-title\">a<\/span> <span class=\"hljs-title\">bundled<\/span> <span class=\"hljs-title\">gem<\/span> <span class=\"hljs-title\">is<\/span> <span class=\"hljs-title\">installed<\/span>.<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"509\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/12\/image-4-1024x509.png\" alt=\"\" class=\"wp-image-32112\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/12\/image-4-1024x509.png 1024w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/12\/image-4-300x149.png 300w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/12\/image-4-768x382.png 768w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/12\/image-4.png 1131w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">kitchen.yml<\/h3>\n\n\n\n<p>Used to configure virtual environments for Test Kitchen<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Gemfile<\/h3>\n\n\n\n<p>Bundler uses this file to configure the gem repository and the list of gems to down\u2010load. Bundler will automatically determine a gem\u2019s dependencies by its references to other gems, so you need only list the top level gems you require.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Gemfile.lock<\/h3>\n\n\n\n<p>Records all the versions of the gems Bundler downloaded for the current project, plus the versions of all dependencies. This file can be used by another Chef devel\u2010oper to reproduce your current gem environment using bundle install.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">.kitchen\/<\/h3>\n\n\n\n<p>Hidden directory that Test Kitchen uses to store persistent data it needs to function properly.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">.kitchen\/logs\/kitchen.log<\/h3>\n\n\n\n<p>Text file that contains the output from the last run of Test Kitchen.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">test\/<\/h3>\n\n\n\n<p>Directory structure that contains tests (initially just a skeleton structure with the subdirectory tree test\/integration\/default\/).<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Running the Commands in Sequence<\/h2>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-comment\"># Kitchen List<\/span>\r\n$ kitchen <span class=\"hljs-keyword\">list<\/span> \r\n\r\n<span class=\"hljs-comment\"># Kitchen Create<\/span>\r\n$ kitchen create\r\n\r\n<span class=\"hljs-comment\"># Kitchen Converge<\/span>\r\n$ kitchen converge\r\n\r\n<span class=\"hljs-comment\"># Testing Setup - Kitchen login is used to test if the testing VM is provisioned correctly.<\/span>\r\n$ kitchen login \r\n\r\n<span class=\"hljs-comment\"># Finally Exit<\/span>\r\n$ <span class=\"hljs-keyword\">exit<\/span>\r\n\r\n<span class=\"hljs-comment\"># Destroying Setup<\/span>\r\n$ Kitchen destroy <\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<script src=\"https:\/\/gist.github.com\/devops-school\/caf80bcc51f50409a89adcee712154a0.js\"><\/script>\n","protected":false},"excerpt":{"rendered":"<p>kitchen.yml Used to configure virtual environments for Test Kitchen Gemfile Bundler uses this file to configure the gem repository and the list of gems to down\u2010load. Bundler&#8230; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[2],"tags":[],"class_list":["post-32099","post","type-post","status-publish","format-standard","hentry","category-uncategorised"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/32099","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=32099"}],"version-history":[{"count":2,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/32099\/revisions"}],"predecessor-version":[{"id":32114,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/32099\/revisions\/32114"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=32099"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=32099"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=32099"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}