cfgmgmt2015 - testing with beaker

Post on 16-Jul-2015

604 Views

Category:

Technology

3 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Testing with Beaker

Who am I?

• Senior Infrastructure Engineer at OpenTable• 4 year Puppeteer• Frequent contributor to the Beaker project

@liamjbennett

Who am I?

Who am I?

What this talk is about?

What is beaker?

What does acceptance testing your puppet code look like?

Demos and future things.

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

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

The building blocks of Beaker

• Rspec• ServerSpec• Hypervisors (and the nodeset file)

Rspec

describe 'modulename::classname' do

context 'create users' do

it 'should work with no errors' do

end

end

end

ServerSpec

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

Hypervisors

NodeSetHOSTS:

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

NodeSetHOSTS:

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

NodeSetHOSTS:

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

NodeSetHOSTS:

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

Writing the first test

-- DEMO --

https://github.com/opentable/puppet-homes/

The DSL Sugar

on <role>

pp = <<-EOS

node fubar.local {

package { “openssl”:

ensure => installed

}

}

EOS

on master, “echo ‘#{pp}’ >> /etc/puppet/manifest/site.pp”

The DSL Sugar

install_puppet

hosts.each do |host|

install_puppet(:version => ‘3.7.1’)

end

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

The DSL Sugar

run_agent_on

run = run_agent_on(agent, :catch_failures => true)

expect(run.exit_code).to be_zero

The DSL Sugar

• scp_from + scp_to• sign_certificate_for• fact_on• facter• cfacter• hiera

• puppet command wrappers

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/

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

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

Other things you can do with Beaker

BEAKER_destroy=no

Provisioning ???

Testing real servers ???

Baking into base images

BEAKER_provision=no

The Future

More Hypervisors - Azure- Digital Ocean

More OS support- FreeBSD

WinRM for Windows

Plugin Support

liamjbennett

@liamjbennett

liamjbennett@gmail.com

liamjbennett.me

opentable

@OpenTableTechUK

tech.opentable.co.uk

top related