Upgrade to Pro — share decks privately, control downloads, hide ads and more …

The Bay Area Chef User Group - Test Kitchen 1.0 with Fletcher Nichol

The Bay Area Chef User Group - Test Kitchen 1.0 with Fletcher Nichol

We just found the perfect way to get you in the right mood for ChefConf :). Come join us Tuesday April 23rd in Mountain View for a great evening with an awesome presentation about everyone's favorite subject, Chef testing by Fletcher Nichol one of the most awesome community chefs.

Test Kitchen is a tool that helps you test a Chef cookbook or other software in an isolated target environment. The current version started life as a project called Jamie CI and was incorporated under the Test Kitchen banner in January. In this talk Fletcher will cover the project's goals, core concepts, the anatomy of a test run, how to use it in your own project, and how to extend it for maximum flexibility. Test Kitchen is designed to be as minimal as possible and focused on real world use cases so if something is missing, he wants to know about it! There will be plenty of time for all your test kitchen related questions.

9891e8299426fb9b6e361b84b3155a2d?s=128

Fletcher Nichol

April 28, 2013
Tweet

Transcript

  1. Test Kitchen 1.0 Fletcher Nichol The Bay Area Chef User

    Group April 23, 2013
  2. > whoami

  3. Fletcher Nichol

  4. https://bluebox.net

  5. fnichol

  6. fnichol@nichol.ca

  7. @fnichol

  8. github.com/fnichol

  9. None
  10. Jamie CI “The Accidental Project”

  11. Let’s talk about

  12. RVM (!)

  13. None
  14. None
  15. RVM Cookbook Complex

  16. RVM Cookbook Multiple installation setups

  17. RVM Cookbook Lengthy converges (+40 minutes/platform)

  18. RVM Cookbook Many resources/ providers (LWRPs)

  19. Friday Night Hacks™

  20. Friday Night Hacks™ December 1, 2012

  21. Friday Night Hacks™ RVM pull request testing

  22. Friday Night Hacks™ Frustration…

  23. Friday Night Hacks™ …

  24. “I know, I’ll use Vagrant!”

  25. Friday Night Hacks™ ✔ Insane Vagrantfile

  26. Friday Night Hacks™ ✔ Extract to Ruby Hash

  27. Friday Night Hacks™ ✔ Extract to YAML

  28. “Houston, we have a library!”

  29. Jamie CI Validation in December 2012

  30. Jamie CI ☛ Test Kitchen Combine forces with Opscode in

    January 2013
  31. Jamie codebase + Test Kitchen name

  32. YAY!

  33. Test Kitchen “Your short-order food taster”

  34. Let’s talk about

  35. Possums!

  36. Or

  37. Testing Levels Testing, all the way down

  38. Testing Levels Level 1: Infrastructure

  39. Level 1: Infrastructure Business value.

  40. Level 1: Infrastructure Multi-node

  41. Level 1: Infrastructure Multi-cookbook

  42. Level 1: Infrastructure Outside-in point of view

  43. Testing Levels Level 2: Cookbook Integration

  44. Level 2: Cookbook Integration A cookbook as SOFTWARE

  45. Level 2: Cookbook Integration “Infrastructure as code”? Yep.

  46. Level 2: Cookbook Integration Run that stuff, for reals

  47. Testing Levels Level 3: Cookbook Unit

  48. Level 3: Cookbook Unit My fav <3

  49. Level 3: Cookbook Unit Tightest feedback loop

  50. Level 3: Cookbook Unit Catches simple logic errors

  51. Level 3: Cookbook Unit Good for regression tests

  52. Level 3: Cookbook Unit Think about “flow of data”

  53. Level 3: Cookbook Unit For cookbooks? Hard(ish)

  54. Test Kitchen is Level 2

  55. Goals In other words, why bother re-writing?

  56. Goals

  57. Goals Declarative

  58. Goals Static

  59. Goals Multiple Chef runs

  60. Goals Simple workflow, stressing speed

  61. Goals Dead simple CI integration

  62. Goals Testing freedom, framework agnostic

  63. Goals Isolated log files

  64. Goals Concurrent test execution

  65. Goals Virtualization freedom

  66. Goals Decoupled (plugin architecture)

  67. Goals Explicit vs. implicit

  68. Concepts Learn the Test Kitchen lingo

  69. Concepts

  70. Concepts Platform

  71. Platform Operating system or target system

  72. Platform OS version

  73. Platform OS architecture

  74. Platform Networking, virtualized, Chef version, etc.

  75. Platform It has a NAME

  76. Concepts Suite

  77. Suite The Chef configuration

  78. Suite A run list

  79. Suite Node attributes

  80. Suite It has a NAME

  81. Concepts Instance

  82. Instance Suite + Platform = Instance

  83. Instance Name is auto- generated

  84. Instance “The thing you run to test”

  85. Concepts Instance Actions

  86. Instance Actions “Lifecycle activities”

  87. Instance Actions 1. Create

  88. Instance Actions 2. Converge

  89. Instance Actions 3. Setup

  90. Instance Actions 4. Verify

  91. Instance Actions 5. Destroy

  92. Instance Actions (11). Test

  93. Concepts Driver

  94. Driver Implementation of instance actions

  95. Driver Ships as a RubyGem

  96. Driver One driver per instance

  97. Driver Defines its own configuration

  98. Driver Implementations kitchen-bluebox kitchen-ec2 kitchen-lxc kitchen-openstack kitchen-rackspace kitchen-vagrant

  99. Driver `kitchen driver discover`

  100. Concepts Busser

  101. Busser Your Mars Rover on a converged node

  102. Busser Only dependency is the Ruby Chef uses

  103. Busser Prepares node for test suites

  104. Busser Installs test runner plugins

  105. Busser Test runner plugins are RubyGems!

  106. Busser Test Runners busser-bash busser-bats busser-minitest busser-shunit2

  107. Busser “Your tests, your way”

  108. Anatomy …of a Test Kitchen run…

  109. Anatomy

  110. Anatomy 1. Create

  111. 1. Create “Bring that thing into existence”

  112. 1. Create Wait until node is ready

  113. Anatomy 2. Converge

  114. 2. Converge Install Chef (if needed)

  115. 2. Converge Upload Chef artifacts (cookbooks, roles, data bags, JSON,

    etc.)
  116. 2. Converge Run chef-solo

  117. Anatomy 3. Setup

  118. 3. Setup Install Busser, run `busser setup`

  119. 3. Setup Boom.

  120. Anatomy 4. Verify

  121. 4. Verify Install any needed Busser runner plugins for the

    instance’s suite
  122. 4. Verify Upload test files for the instance’s suite

  123. Anatomy 5. Destroy

  124. 5. Destroy Delete, de-provision, kill, terminate, bring down, nuke, recyle,

    shutdown, make-go-away
  125. Anatomy (11). Test

  126. (11). Test “Your Easy Button for workflow”

  127. (11). Test Invokes: [delete], [create], [converge], [setup], [verify], [delete]

  128. (11). Test Slightly different behavior depending on context

  129. .kitchen.yml Describe to me your problems…

  130. Let’s talk about

  131. YAML (!)

  132. None
  133. None
  134. Why YAML?

  135. Why YAML? Why not?

  136. Why YAML? Declarative

  137. Why YAML? Static

  138. Why YAML? Easy to author

  139. Why YAML? Meant for humans

  140. Why YAML? Easy to combine and merge Important!

  141. platforms: - name: ubuntu-12.04 driver_config: box: opscode-ubuntu-12.04 box_url: https://...box run_list:

    - recipe[apt] - name: centos-6.3 driver_config: box: opscode-centos-6.3 box_url: https://...box run_list: - recipe[yum::epel] .kitchen.yml: platform
  142. platforms: - name: ubuntu-12.04 driver_config: box: opscode-ubuntu-12.04 box_url: https://...box run_list:

    - recipe[apt] - name: centos-6.3 driver_config: box: opscode-centos-6.3 box_url: https://...box run_list: - recipe[yum::epel] .kitchen.yml: platform
  143. platforms: - name: ubuntu-12.04 driver_config: box: opscode-ubuntu-12.04 box_url: https://...box run_list:

    - recipe[apt] - name: centos-6.3 driver_config: box: opscode-centos-6.3 box_url: https://...box run_list: - recipe[yum::epel] .kitchen.yml: platform
  144. platforms: - name: ubuntu-12.04 driver_config: box: opscode-ubuntu-12.04 box_url: https://...box run_list:

    - recipe[apt] - name: centos-6.3 driver_config: box: opscode-centos-6.3 box_url: https://...box run_list: - recipe[yum::epel] .kitchen.yml: platform
  145. suites: - name: rubies run_list: - recipe[java] - recipe[rvm::system] attributes:

    rvm: default_ruby: system rubies: - 1.9.3 - version: 1.9.3-p327 patch: railsexpress - version: 1.8.7 rubygems_version: 1.6.0 .kitchen.yml: suite
  146. suites: - name: rubies run_list: - recipe[java] - recipe[rvm::system] attributes:

    rvm: default_ruby: system rubies: - 1.9.3 - version: 1.9.3-p327 patch: railsexpress - version: 1.8.7 rubygems_version: 1.6.0 .kitchen.yml: suite
  147. suites: - name: rubies run_list: - recipe[java] - recipe[rvm::system] attributes:

    rvm: default_ruby: system rubies: - 1.9.3 - version: 1.9.3-p327 patch: railsexpress - version: 1.8.7 rubygems_version: 1.6.0 .kitchen.yml: suite
  148. suites: - name: rubies run_list: - recipe[java] - recipe[rvm::system] attributes:

    rvm: default_ruby: system rubies: - 1.9.3 - version: 1.9.3-p327 patch: railsexpress - version: 1.8.7 rubygems_version: 1.6.0 .kitchen.yml: suite
  149. --- driver_plugin: ec2 driver_config: region: us-east-1 flavor_id: m1.small platforms: -

    name: smartos driver_plugin: vagrant driver_config: box: smartos - name: freebsd driver_config: image_id: ami-5339bb3a .kitchen.yml: driver_config
  150. --- driver_plugin: ec2 driver_config: region: us-east-1 flavor_id: m1.small platforms: -

    name: smartos driver_plugin: vagrant driver_config: box: smartos - name: freebsd driver_config: image_id: ami-5339bb3a .kitchen.yml: driver_config
  151. --- driver_plugin: ec2 driver_config: region: us-east-1 flavor_id: m1.small platforms: -

    name: smartos driver_plugin: vagrant driver_config: box: smartos - name: freebsd driver_config: image_id: ami-5339bb3a .kitchen.yml: driver_config
  152. --- driver_plugin: ec2 driver_config: region: us-east-1 flavor_id: m1.small platforms: -

    name: smartos driver_plugin: vagrant driver_config: box: smartos - name: freebsd driver_config: image_id: ami-5339bb3a .kitchen.yml: driver_config
  153. .kitchen.yml: Bonus Round Configuration Injection

  154. .kitchen.local.yml

  155. .kitchen.local.yml Not tracked in version control

  156. .kitchen.local.yml Data merges over .kitchen.yml data

  157. .kitchen.local.yml Ship a “stock” .kitchen.yml

  158. .kitchen.local.yml Swap out the default driver for your environment

  159. .kitchen.local.yml e.g., .kitchen.yml (vagrant) .kitchen.local.yml (bluebox)

  160. ERB Processing

  161. ERB Processing YAML files passed through ERB before loading

  162. ERB Processing For great good, or evil

  163. ERB Processing Load secrets from ENV hash

  164. --- driver_plugin: ec2 driver_config: aws_access_key_id: <%= ENV['ACCESS_KEY_ID'] %> aws_secret_access_key: <%=

    ENV['SECRET_ACCESS_KEY'] %> aws_ssh_key_id: <%= ENV['SSH_KEY_ID'] %> ssh_key: <%= File.expand_path('~/.ssh/id_rsa-aws') %> region: us-east-1 flavor_id: m1.small ERB FTW
  165. Stop! Demo time!

  166. [paste demo here]

  167. So remember...

  168. “gem install test-kitchen --pre”

  169. “kitchen init”

  170. “kitchen test”

  171. Thank You!

  172. Image Credits http://www.flickr.com/photos/seattlemunicipalarchives/8425176934/ http://www.flickr.com/photos/shebalso/8548418258/ http://www.flickr.com/photos/anthonycramp/4428561177/ http://www.flickr.com/photos/mattwyn/2448866914/ http://www.flickr.com/photos/nazgul_darkrider/181539663/ http://www.flickr.com/photos/gogovisual/3481300208/ http://www.flickr.com/photos/thelifeofbryan/145706581/ http://www.flickr.com/photos/thekellyscope/4633292987/

  173. Questions? Fletcher Nichol fnichol@nichol.ca @fnichol github.com/fnichol

  174. Questions? Fletcher Nichol fnichol@nichol.ca @fnichol github.com/fnichol