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

cfgmgmt2015 - Testing with Beaker

Liam Bennett
February 03, 2015
26

cfgmgmt2015 - Testing with Beaker

Acceptance testing your Puppet code with the Beaker testing framework.

Liam Bennett

February 03, 2015
Tweet

Transcript

  1. Who am I? • Senior Infrastructure Engineer at OpenTable •

    4 year Puppeteer • Frequent contributor to the Beaker project @liamjbennett
  2. What this talk is about? What is beaker? What does

    acceptance testing your puppet code look like? Demos and future things.
  3. What is beaker? • Testing framework built on top of

    a testing framework • DSL for acceptance testing puppet code against a ‘real’ environment • Spin up a box • Apply your puppet code • Test your expectations • Uses rspec and serverspec under the hood to spin up nodes in vagrant/aws/vsphere/docker
  4. Why should you care? • Modules that support multiple distros

    • Modules that support multiple versions of distros • Not every “base” image is the same • You care about idempotency • You don’t trust modules written by others • You’re baking your images
  5. ServerSpec describe file('/etc/passwd') do it { should be_file } end

    describe service('ntpd') do it { should be_enabled } end describe docker_container(‘mysql’) do it { should be_running } end describe windows_feature('Web-Webserver') do it { should be_installed.by("powershell") } end
  6. NodeSet HOSTS: ubuntu-server-12042-x64: roles: - master platform: ubuntu-12.04-amd64 box: ubuntu-server-12042-x64-vbox4210-nocm

    box_url: http://puppet-vagrant-boxes.puppetlabs.com/ubuntu-server-12042- x64-vbox4210-nocm.box hypervisor: vagrant CONFIG: type: foss HOSTS: centos-65-x64: roles: - master platform: el-6-x86_64 box: puppetlabs/centos-6.5-64-puppet hypervisor : vagrant CONFIG: type: foss
  7. NodeSet HOSTS: ubuntu-server-12042-x64: roles: - master platform: ubuntu-12.04-amd64 box: ubuntu-server-12042-x64-vbox4210-nocm

    box_url: http://puppet-vagrant-boxes.puppetlabs.com/ubuntu-server-12042- x64-vbox4210-nocm.box hypervisor: vagrant CONFIG: type: foss HOSTS: centos-65-x64: roles: - master platform: el-6-x86_64 box: puppetlabs/centos-6.5-64-puppet hypervisor : vagrant CONFIG: type: foss
  8. NodeSet HOSTS: ubuntu-server-12042-x64: roles: - master platform: ubuntu-12.04-amd64 box: ubuntu-server-12042-x64-vbox4210-nocm

    box_url: http://puppet-vagrant-boxes.puppetlabs.com/ubuntu-server-12042- x64-vbox4210-nocm.box hypervisor: vagrant CONFIG: type: foss HOSTS: centos-65-x64: roles: - master platform: el-6-x86_64 box: puppetlabs/centos-6.5-64-puppet hypervisor : vagrant CONFIG: type: foss
  9. NodeSet HOSTS: ubuntu-server-12042-x64-master: roles: - master platform: ubuntu-12.04-amd64 box: puppetlabs/ubuntu-12.04-64-nocm

    hypervisor: vagrant ubuntu-server-12042-x64-agent: roles: - agent - default platform: ubuntu-12.04-amd64 box: puppetlabs/ubuntu-12.04-64-nocm hypervisor: vagrant CONFIG: log_level: verbose type: git
  10. The DSL Sugar on <role> pp = <<-EOS node fubar.local

    { package { “openssl”: ensure => installed } } EOS on master, “echo ‘#{pp}’ >> /etc/puppet/manifest/site.pp”
  11. The DSL Sugar apply_manifest_on # Run it twice and test

    for idempotency apply_manifest(pp, :catch_failures => true) run = apply_manifest(pp, :catch_failures => true) expect(run.exit_code).to be_zero
  12. The DSL Sugar • scp_from + scp_to • sign_certificate_for •

    fact_on • facter • cfacter • hiera • puppet command wrappers
  13. Testing Roles and Profiles • Multi-node nodeset (master+agent) • Setting

    up the master • puppet.conf • environment • signing • installing forge modules • copying private modules http://tech.opentable.co.uk/blog/2014/09/01/testing-puppet-with- beaker-pt-dot-3-testing-roles/ https://gist.github.com/liamjbennett/ad6e2a2689aa8c4e2460
  14. Integration into CI • Different NodeSet file • Junit report

    • How do you manage yours?? Compile rake syntax Style rake lint Unit Test rake spec Acceptance Test rake acceptance Release rake module:release
  15. Other things you can do with Beaker BEAKER_destroy=no Provisioning ???

    Testing real servers ??? Baking into base images BEAKER_provision=no
  16. The Future More Hypervisors - Azure - Digital Ocean More

    OS support - FreeBSD WinRM for Windows Plugin Support