Contenu connexe Similaire à How and why you should test (8) How and why you should test2. testing!
www.nedap.com
Sunday, April 7, 13
3. testing!
before production
not in production
www.nedap.com
Sunday, April 7, 13
4. whoami
• Daniele Sluijters
• @daenney: irc, twitter, github, ...
• mail: daniele.sluijters@nedap.com
• XMPP / Jabber: ☝
www.nedap.com
Sunday, April 7, 13
6. consequences
exec
{
‘first-‐run-‐reboot’:
command
=>
‘touch
/tmp/first-‐run
&&
reboot’,
creates
=>
‘/tmp/first-‐run’,
}
www.nedap.com
Sunday, April 7, 13
7. avoid latest
class
mysql
{
package
{
‘mysql-‐server’:
ensure
=>
latest,
notify
=>
Service[‘mysql’],
}
}
www.nedap.com
Sunday, April 7, 13
8. structure
www.nedap.com
Sunday, April 7, 13
9. params
class
acme::params
{
case
$::osfamily
{
‘Debian’:
{
$founder
=
‘Marvin’
}
default:
{
fail(“No
can’t
do.”)
}
}
}
www.nedap.com
Sunday, April 7, 13
10. params
class
acme::package
{
package
{
‘marvin’:
ensure
=>
$::acme::version,
}
...
}
www.nedap.com
Sunday, April 7, 13
11. configurable
class
acme(
$version
=
‘1.6’,
$enable
=
true,
)
inherits
acme::params
{
...
}
www.nedap.com
Sunday, April 7, 13
12. users are crazy
class
acme(
$version
=
‘1.6’,
$enable
=
true,
){
validate_string($version)
validate_bool($enable)
}
www.nedap.com
Sunday, April 7, 13
13. data sources
• Don’t couple modules to data
• Pass in data through params
• Use a profile to configure the module
www.nedap.com
Sunday, April 7, 13
14. profile
class
profile::acme
{
class
{
‘acme’:
version
=>
hiera(‘version’)
...
}
}
www.nedap.com
Sunday, April 7, 13
15. misc
• Write docs
• Include a README + license
www.nedap.com
Sunday, April 7, 13
19. setup
• Setup:
• use puppetlabs_spec_helper
• https://puppetlabs.com/blog/the-
next-generation-of-puppet-module-
testing/
• Read the tutorial:
• http://rspec-puppet.com/tutorial/
www.nedap.com
Sunday, April 7, 13
20. setup
source
:rubygems
gem
'puppet'
,
'~>
3.1'
gem
'facter'
,
'~>
1.6.18'
gem
'puppet-‐lint'
,
'~>
0.3.2'
gem
'puppetlabs_spec_helper'
,
'~>
0.4.1'
www.nedap.com
Sunday, April 7, 13
21. data
• let
:params
do
{}
end
• let
:facts
do
{}
end
• let
:pre_condition
do
{}
end
www.nedap.com
Sunday, April 7, 13
22. matchers
• should ⬌
should_not
• include_type
• with_attr(‘value’)
• ‘value2’})
with({:attr1
=>
‘value1’,
:attr2
=>
• with_content(regex)
www.nedap.com
Sunday, April 7, 13
23. example
describe
'acme'
do
it
'should
declare
itself'
do
should
contain_class('acme')
end
end
www.nedap.com
Sunday, April 7, 13
24. example
context
‘on
Debian’
do
let
:facts
do
{
:osfamily
=>
‘Debian’
}
end
let
:params
do
{
:ver
=>
‘1.2’
}
end
it
‘should
install
mysql’
do
should
contain_package(‘mysql’).with_ensure(params[:ver]})
end
it
‘should
not
install
redis’
do
should_not
contain_package(‘redis’).with_ensure(‘present’)
end
end
www.nedap.com
Sunday, April 7, 13
25. success
module
git:master
›❯
rake
spec
.............
Finished
in
2.43
seconds
13
examples,
0
failures
www.nedap.com
Sunday, April 7, 13
27. automate
• Generate module structure
• init, install, config, services, params
• Generate tests
• Generate README
• CI
www.nedap.com
Sunday, April 7, 13
28. behaviour
www.nedap.com
Sunday, April 7, 13
29. options
• Deploy to a testing environment
• Monitor your testing environment
• Test with rspec-...?
www.nedap.com
Sunday, April 7, 13
30. environment
• Jenkins + vagrant
• Can’t run on slaves
• Can’t run concurrent builds
www.nedap.com
Sunday, April 7, 13
31. monitoring
• Any tool you want to:
• nagios / icinga
• zabbix / zenoss / sensu
• ...
www.nedap.com
Sunday, April 7, 13
33. q?
www.nedap.com
Sunday, April 7, 13