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

Configuration Management Testing with Chef

Configuration Management Testing with Chef

Testing of configuration management tools: unit tests and systems tests. How do you verify that your configuration management tools are running correctly? How can you verify that the system as a whole is functioning as intended?

Atomic Object

October 13, 2014
Tweet

More Decks by Atomic Object

Other Decks in Technology

Transcript

  1. Test-driven Infrastructure (TDI) • In software development: •  Test-driven Development (TDD)

    • Applying this to infrastructure • Principles: •  Document •  Test •  Script •  Version •  Continuous
  2. Configuration Management Testing • Frameworks allow testing: •  Logic of scripts.

    •  Convergence of configuration changes •  Desired outcome. • Virtual machines provide means to rapidly test convergence and final system behavior.
  3. Just enough Chef • Chef-Solo: client only version of chef • Chef-Server:

    client-server version of chef • Node: single client system being operated on • Resources: representation of system resources • Recipes: specify actions on resources • Cookbooks: modular collections of recipes • Chef Run: execution of chef against node
  4. Testing with Chef • Tools •  Chefspec •  https://github.com/sethvargo/chefspec •  https://docs.getchef.com/chefspec.html

    •  Test Kitchen •  https://github.com/test-kitchen/test-kitchen •  http://kitchen.ci/docs/getting-started/ •  Serverspec •  https://github.com/serverspec/serverspec •  http://serverspec.org/
  5. Testing Goals • Generally: •  Cookbooks tested individually. • And then: • 

    Servers tested • Chef Solo and Chef Server considerations…
  6. ChefSpec • Testing your recipes. • Rspec style expressions: •  describe ‘host_configuration::default’

    •  expect(chef_run).to create_template(‘/etc/hosts’) •  expect(chef_run.template(’/etc/hosts')).to notify('service[apache2]').to(:restart).delayed
  7. Test Kitchen • Testing convergence. • Plug-ins to provide virtualization drivers and

    testing tools. driver: name: vagrant run_list: - recipe[apt] - recipe[build-essential]
  8. Serverspec • Testing behavior / outcome. • Rspec style expressions: describe port

    443 do it { should be_listening } end describe service 'mysql' do it { should be_running } it { should be_enabled } end
  9. Example • Continuous Running on Travis-CI • https://travis-ci.org/kuleszaj/chef_testing_example • Currently only runs ChefSpec

    and some linting/ style tools (Foodcritic and Rubocop) • Could run Test-Kitchen too: •  https://travis-ci.org/opscode-cookbooks/apt •  Just takes more work to get going…
  10. Some final resources… •  Nice, modern overview of TDI Principles:

    •  (From IBM, of all things.) •  http://www.ibm.com/developerworks/library/a-devops5/ •  Foodcritic •  Lint check for your cookbooks. •  http://acrmp.github.io/foodcritic/ •  Rubocop •  Static analysis of your ruby code. •  (Good for writing consistent code, and avoiding obvious problems.) •  http://batsov.com/rubocop/