Slide 1

Slide 1 text

Configuration Management Testing with Chef DevOps West Michigan

Slide 2

Slide 2 text

Test-driven Infrastructure (TDI) • In software development: •  Test-driven Development (TDD) • Applying this to infrastructure • Principles: •  Document •  Test •  Script •  Version •  Continuous

Slide 3

Slide 3 text

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.

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

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/

Slide 6

Slide 6 text

Testing Goals • Generally: •  Cookbooks tested individually. • And then: •  Servers tested • Chef Solo and Chef Server considerations…

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

Test Kitchen • Testing convergence. • Plug-ins to provide virtualization drivers and testing tools. driver: name: vagrant run_list: - recipe[apt] - recipe[build-essential]

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

Example • Document We want an Ubuntu 14.04 LTS server running Apache2 with mod_rewrite.

Slide 11

Slide 11 text

Example • Version With Git on GitHub! • https://github.com/kuleszaj/chef_testing_example

Slide 12

Slide 12 text

Example • Test ChefSpec, Test-Kitchen, and Serverspec • ChefSpec •  spec/unit/recipes/default_spec.rb •  Serverspec •  test/integration/default/serverspec/default_spec.rb

Slide 13

Slide 13 text

Example • Script Written as a Chef cookbook! • Recipes: •  default.rb • Templates: •  default_example.rb.erb

Slide 14

Slide 14 text

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…

Slide 15

Slide 15 text

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/