際際滷

際際滷Share a Scribd company logo
Chef Tooling & TDD
Sai/ Ops Tools
Existing Chef Workflow
1. Engineer writes a chef cookbook
2. May perhaps write Minitest suite
3. May spin up vagrant with chef solo
4. Engineer does a `Rake release`
a. Json lint
b. FoodCritic warnings
c. Push to hooks
d. Berks upload cookbook
Chef Tooling
 Pre-convergence - Linting, Style and Rules
 Unit-tests
 Convergence - Integration Tests
 Post Convergence
Cookstyle/Rubocop
 Cookstyle - Invoked with Rubocop. Does autocorrection with rules from
cookstyle.yml
 Rubocop - Static Code analyzes code for Ruby errors and style guidelines
> rubocop recipes/counter.rb
Chef tooling and  TDD
Foodcritic
 Flags problems that may cause chef cookbooks to fail
 Chef cookbook style guidelines
>foodcritic -B bjn_counter
Foodcritic
Unit Tests
ChefSpec
 Rspec style unit testing for cookbooks
 Help regression testing when making changes
 Simulate convergence of resources on node
But do we really need this, if we use tools in convergence?
 Does not test chef runs
 May not catch all failures in spite of perfect run
Integration Testing
# Test Kitchen
What is it?
 Test Harness
 Allows to execute code on one or more platforms in isolation
 Cloud Providers, dockers, vagrant and VMs
 Supports testing frameworks - Inspec, minitest, Serverspec and BATS
 Uses kitchen-vagrant driver for managing vms (just like vagrant-berkshelf)
Why use Test Kitchen?
 Multiple platforms support with single config
 Chef-zero does not require additional flags for environment, roles, data bags
etc. Not required to add chef-solo conditionals in recipes.
 Full in-memory, fast start so chef runs for zero would be faster.
 Minitest is no longer actively supported and is being deprecated in favour of
inspec :(
Test kitchen commands
 vagrant status  kitchen list
 vagrant up  kitchen converge
 vagrant provision
 vagrant ssh  kitchen login
 minitest-handler  kitchen verify (supports inspec, serverspec)
 kitchen test (all in one)
Post-Convergence
Inspec
 Rspec like tests to ensure state of node
 Built in resource types for Chef
 Add tests for business assumptions and outcomes
New Chef Tooling
 Cookstyle/Rubocop
 FoodCritic
 ChefSpec
 Test Kitchen
 Inspec
 Automate into CI
1. Replace hooks with Jenkins jobs that download cookbooks, upload to
Chef server
Other Tools
 Cookbook skeleton generator - Bourdain/Chef/Kitchen-cabinet
 Bump and release cookbooks - Bourdain
 Berkshelf over Policyfiles
 Chef Push jobs - Ansible/Rundeck style jobs triggered independently of chef
runs
Sources
 https://docs.chef.io
 Alex Manly - Chef workflow
https://www.youtube.com/watch?v=jauXuwIfgbs&t=49s
 Inspec - https://www.inspec.io/tutorials/
 Chef solo to Zero - https://blog.chef.io/2014/06/24/from-solo-to-zero-
migrating-to-chef-client-local-mode/
 kitchen.ci

More Related Content

Chef tooling and TDD

  • 1. Chef Tooling & TDD Sai/ Ops Tools
  • 2. Existing Chef Workflow 1. Engineer writes a chef cookbook 2. May perhaps write Minitest suite 3. May spin up vagrant with chef solo 4. Engineer does a `Rake release` a. Json lint b. FoodCritic warnings c. Push to hooks d. Berks upload cookbook
  • 3. Chef Tooling Pre-convergence - Linting, Style and Rules Unit-tests Convergence - Integration Tests Post Convergence
  • 4. Cookstyle/Rubocop Cookstyle - Invoked with Rubocop. Does autocorrection with rules from cookstyle.yml Rubocop - Static Code analyzes code for Ruby errors and style guidelines > rubocop recipes/counter.rb
  • 6. Foodcritic Flags problems that may cause chef cookbooks to fail Chef cookbook style guidelines
  • 8. Unit Tests ChefSpec Rspec style unit testing for cookbooks Help regression testing when making changes Simulate convergence of resources on node But do we really need this, if we use tools in convergence? Does not test chef runs May not catch all failures in spite of perfect run
  • 9. Integration Testing # Test Kitchen What is it? Test Harness Allows to execute code on one or more platforms in isolation Cloud Providers, dockers, vagrant and VMs Supports testing frameworks - Inspec, minitest, Serverspec and BATS Uses kitchen-vagrant driver for managing vms (just like vagrant-berkshelf)
  • 10. Why use Test Kitchen? Multiple platforms support with single config Chef-zero does not require additional flags for environment, roles, data bags etc. Not required to add chef-solo conditionals in recipes. Full in-memory, fast start so chef runs for zero would be faster. Minitest is no longer actively supported and is being deprecated in favour of inspec :(
  • 11. Test kitchen commands vagrant status kitchen list vagrant up kitchen converge vagrant provision vagrant ssh kitchen login minitest-handler kitchen verify (supports inspec, serverspec) kitchen test (all in one)
  • 12. Post-Convergence Inspec Rspec like tests to ensure state of node Built in resource types for Chef Add tests for business assumptions and outcomes
  • 13. New Chef Tooling Cookstyle/Rubocop FoodCritic ChefSpec Test Kitchen Inspec Automate into CI 1. Replace hooks with Jenkins jobs that download cookbooks, upload to Chef server
  • 14. Other Tools Cookbook skeleton generator - Bourdain/Chef/Kitchen-cabinet Bump and release cookbooks - Bourdain Berkshelf over Policyfiles Chef Push jobs - Ansible/Rundeck style jobs triggered independently of chef runs
  • 15. Sources https://docs.chef.io Alex Manly - Chef workflow https://www.youtube.com/watch?v=jauXuwIfgbs&t=49s Inspec - https://www.inspec.io/tutorials/ Chef solo to Zero - https://blog.chef.io/2014/06/24/from-solo-to-zero- migrating-to-chef-client-local-mode/ kitchen.ci