Se ha denunciado esta presentación.
Utilizamos tu perfil de LinkedIn y tus datos de actividad para personalizar los anuncios y mostrarte publicidad más relevante. Puedes cambiar tus preferencias de publicidad en cualquier momento.

cfgmgmt2015 - Testing with Beaker

1.920 visualizaciones

Publicado el

Acceptance testing your Puppet code with the Beaker testing framework.

Publicado en: Tecnología
  • Sé el primero en comentar

cfgmgmt2015 - Testing with Beaker

  1. 1. Testing with Beaker
  2. 2. Who am I? • Senior Infrastructure Engineer at OpenTable • 4 year Puppeteer • Frequent contributor to the Beaker project @liamjbennett
  3. 3. Who am I?
  4. 4. Who am I?
  5. 5. What this talk is about? What is beaker? What does acceptance testing your puppet code look like? Demos and future things.
  6. 6. 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
  7. 7. 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
  8. 8. The building blocks of Beaker • Rspec • ServerSpec • Hypervisors (and the nodeset file)
  9. 9. Rspec describe 'modulename::classname' do context 'create users' do it 'should work with no errors' do … … … end end end
  10. 10. ServerSpec
  11. 11. 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
  12. 12. Hypervisors
  13. 13. 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
  14. 14. 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
  15. 15. 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
  16. 16. 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
  17. 17. Writing the first test -- DEMO -- https://github.com/opentable/puppet-homes/
  18. 18. The DSL Sugar on <role> pp = <<-EOS node fubar.local { package { “openssl”: ensure => installed } } EOS on master, “echo ‘#{pp}’ >> /etc/puppet/manifest/site.pp”
  19. 19. The DSL Sugar install_puppet hosts.each do |host| install_puppet(:version => ‘3.7.1’) end
  20. 20. 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
  21. 21. The DSL Sugar run_agent_on run = run_agent_on(agent, :catch_failures => true) expect(run.exit_code).to be_zero
  22. 22. The DSL Sugar • scp_from + scp_to • sign_certificate_for • fact_on • facter • cfacter • hiera • puppet command wrappers
  23. 23. Testing modules in the wild https://github.com/opentable/puppet-homes https://github.com/puppetlabs/puppet/ https://github.com/opentable/puppet-windowsfeature https://github.com/solarkennedy/puppet-consul/
  24. 24. 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
  25. 25. 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
  26. 26. Other things you can do with Beaker BEAKER_destroy=no Provisioning ??? Testing real servers ??? Baking into base images BEAKER_provision=no
  27. 27. The Future More Hypervisors - Azure - Digital Ocean More OS support - FreeBSD WinRM for Windows Plugin Support
  28. 28. liamjbennet t @liamjbennett liamjbennett@gmail.com liamjbennett.me opentable @OpenTableTechUK tech.opentable.co.uk

×