• Artifacts are executable programs created by compilers. • Compiled artifacts cannot be edited directly. Source code must be changed and re-compiled to produce a new build artifact. Thursday, February 6, 14
• Write tests to verify that code works as intended • Run tests at different stages of the code lifecycle to ensure correctness Thursday, February 6, 14
developing software, most time isn’t actually spent coding • 10-second changes to source code can take minutes to vet • Compiling code • Deploying code • Writing & Running tests Thursday, February 6, 14
• Things that are fun: • Designing programs! • Writing source code! • Things that are boring: • Compiling code • Deploying artifacts • Running tests Thursday, February 6, 14
just like the source code for other programs. • Changes are tracked and versioned with source control software such as git • Code is inert until it has been deployed • Code can be used to re-create the desired system configuration from scratch Source' Code' Compiler' Ar/fact' Test' Thursday, February 6, 14
Chef code is not compiled until it is executed by the Chef-Client • There is no lengthy compilation step between committing Chef Cookbooks and deploying them Source' Code' Compiler' Ar/fact' Test' X Thursday, February 6, 14
the artifacts for other programs. • Cookbooks are deployed • Cookbooks are released with versions • Cookbooks are immutable once deployed • Cookbooks are packaged for distribution • Cookbooks can depend on one another Source' Code' Compiler' Ar/fact' Test' X Thursday, February 6, 14
can be either source code OR artifacts. Close Encounters of the Third Kind, copyright 1977, Columbia Pictures “This means something! This is important!” Thursday, February 6, 14
to overlook: Treating cookbooks only as source code or only as artifacts will lead to long-term problems when using Chef cookbooks to manage infrastructure. • Because Chef cookbooks are source code and artifacts, depending on the context, they have all the properties of each. Source' Code' Ar+fact' Thursday, February 6, 14
Stored in a source repository • Inert while in development Source' Code' Ar+fact' A good Chef workflow treats cookbooks appropriately depending on context • Cookbooks are artifacts! • Versioned • Deployed to a Chef Server • Executable by Chef-client once deployed Thursday, February 6, 14
automatically keep my Chef Code Repository and my Chef Server Artifact Repository in sync?” • Answer: The same way that one would automatically keep a code repo and an artifact repo in sync with any other software released to production. Deploy with care! Source' Code' Ar+fact' A brief aside about deploying cookbook artifacts: Thursday, February 6, 14
recipes/default.rb • Version & dependencies: metadata.rb • git commit • git tag Cookbooks as Source Code Source Code Compiler Artifact Test X Thursday, February 6, 14
upload • Immutable once deployed, can only be replaced • Version & dependencies: metadata.rb • chef-client Source Code Compiler Artifact Test Thursday, February 6, 14
cookbook: 1) A place to store the cookbook artifact. 2) A Chef-client with access to the cookbook. Source' Code' Compiler' Ar/fact' Test' X Thursday, February 6, 14
cookbook: 1) A place to store the cookbook artifact. 2) A Chef-client with access to the cookbook. 3) A target server running the same OS as production. Source' Code' Compiler' Ar/fact' Test' X Thursday, February 6, 14
target+ Worksta(on:+ Edit+target+run+ list+ ssh+target+ Target:+Run+ chef>client+ Traditional Cookbook Development: First Chef Run Thursday, February 6, 14
“paperwork” •vi recipes/something.rb •knife cookbook upload •sudo pkill -USR1 chef- client • #%$#%$ something broke, let me do that all again • Not enough time doing fun stuff! • Writing recipes Less Fun! More Boring! X Thursday, February 6, 14
“paperwork” •vi recipes/something.rb •knife cookbook upload •sudo pkill -USR1 chef- client • #%$#%$ something broke, let me do that all again • Not enough time doing fun stuff! • Writing recipes Less Fun! More Boring! X TH IS SUCKS! Thursday, February 6, 14
Less time waiting around for cookbook deploys and Chef runs • More frequent testing • Better code • Business needs met more quickly More Fun! Less Boring! X Thursday, February 6, 14
acceptance tests • Running on a real virtualized “node” • Lots of memory (4GB+, 8GB recommended) • Fast disk (SSD) • Good processor (Intel i5+) • Modern OS X Thursday, February 6, 14
up our home page. • Yes, • it’s super-simple • it’s not a “real-life” example • it will allow us to see lots of testing tools 36 Thursday, February 6, 14
offences detected Created rubocop-todo.yml. Run rubocop with --config rubocop-todo.yml, or add inherit_from: rubocop-todo.yml in a .rubocop.yml file. Thursday, February 6, 14
• Checks code correctness • Catches common mistakes before they cause problems • Extensible & Configurable • Create new rulesets • Ignore existing rulesets • Integrates nicely into CI pipelines Thursday, February 6, 14
in corrected code! • Make Foodcritic a part of your build pipeline with commit hooks or other methods • The Foodcritic web page has extensive documentation & examples showing how to build Foodcritic rules into Jenkins or Travis-CI Thursday, February 6, 14
the correct command? • Signal Processing • Did Chef interpret my command correctly? What and When To Test Flickr user: Rain Rabbit Thursday, February 6, 14
the correct command? • Signal Processing • Did Chef interpret my command correctly? • Acceptance Test: Signal Output What and When To Test Flickr user: Rain Rabbit Thursday, February 6, 14
the correct command? • Signal Processing • Did Chef interpret my command correctly? • Acceptance Test: Signal Output • Did my expressed intent, executed by Chef, achieve the desired result? What and When To Test Flickr user: Rain Rabbit Thursday, February 6, 14
a Chef run in memory • Overrides all providers to take no action • Make assertions about the in-memory Chef run • Mock Ohai data (automatic attributes) with Fauxhai Thursday, February 6, 14
test file. • recipes/default.rb • specs/default_test.rb • In addition, a helper file lets us define our own functions for testing. • specs/spec_helper.rb Thursday, February 6, 14