87
(without introducing more risk) The Future of Testing Puppet Code Puppet Gareth Rushgrove Who, What, Why, How

PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

  • Upload
    puppet

  • View
    121

  • Download
    0

Embed Size (px)

Citation preview

Page 1: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

(without introducing more risk)

The Future of Testing Puppet Code

PuppetGareth Rushgrove

Who, What, Why, How

Page 2: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

(without introducing more risk)

@garethr

Page 3: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

(without introducing more risk)

Gareth Rushgrove

Page 4: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

(without introducing more risk)This TalkWhat we’ll cover

Page 5: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

- Why test Puppet anyway- Existing Puppet testing tools- Different users and usecases- Future challenges

Gareth Rushgrove

Page 6: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

Mainly a talk about problems,rather than solutions

Gareth Rushgrove

Page 7: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

Not a talk about how to testPuppet code. Lot of existing content on that subject

Gareth Rushgrove

Page 8: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

(without introducing more risk)

Gareth Rushgrove

PuppetConf 2014

Page 9: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

(without introducing more risk)

Gareth Rushgrove

Survey of 300 Puppet users

Page 10: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

(without introducing more risk)

Gareth Rushgrove

Page 11: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

(without introducing more risk)Why Test Puppet

And a little history

Page 12: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

Gareth Rushgrove

Page 13: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

- You have lots of Puppet code- You’re targeting a wide range of OS’s- The Puppet language has more features

Gareth Rushgrove

Page 14: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

(without introducing more risk)

Gareth Rushgrove

Lots of codeBut how much is lots

Page 15: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

Note that this just represents public code on GitHub. Lots of private Puppet code out there too

Gareth Rushgrove

Page 16: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

(without introducing more risk)

Gareth Rushgrove

How many .pp files on GitHub?

SELECT COUNT(*) FROM [puppet.puppet_files]

-- 489725

Page 17: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

(without introducing more risk)

Gareth Rushgrove

How many lines of Puppet code?

SELECT COUNT(line) total_lines FROM ( SELECT SPLIT(content, '\n') AS line FROM [puppet.puppet_content] )

-- 6697099

Page 18: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

(without introducing more risk)

Gareth Rushgrove

How big are .pp files?

SELECT QUANTILES(total_lines, 10) AS q FROM ( SELECT COUNT(line) total_lines FROM ( SELECT SPLIT(content, '\n') AS line, id FROM [puppet.puppet_content] ) GROUP BY id )

Page 19: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

50% of Puppet files are 20 lines or less. 90% of Puppet files are 100 lines or less

Gareth Rushgrove

Page 20: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

The largest Puppet file public on GitHub has 25,238 lines

Gareth Rushgrove

Page 21: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

(without introducing more risk)

Gareth Rushgrove

Mixed environmentsSo many platforms

Page 22: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

Gareth Rushgrove

Page 23: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

A third of respondents run more than one OS on there development machine

Gareth Rushgrove

Page 24: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

Gareth Rushgrove

Page 25: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

60% of respondents run more than one OS in production

Gareth Rushgrove

Page 26: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

(without introducing more risk)

Gareth Rushgrove

The Puppet language

Types, lambdas, iterators, functions

Page 27: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

Gareth Rushgrove

Page 28: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

(without introducing more risk)Existing Tools

Providing some context

Page 29: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

Gareth Rushgrove

Page 30: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

(without introducing more risk)Core tools

Common starting points

Gareth Rushgrove

Page 31: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

(without introducing more risk)

Gareth Rushgrove

puppet-lint

Page 32: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

(without introducing more risk)

Gareth Rushgrove

Style conformance

$ puppet-lint /etc/puppet/modules foo/manifests/bar.pp - ERROR: trailing whitespace found on line 1 apache/manifests/server.pp - WARNING: variable not enclosed in {} on line 56 ...

Page 33: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

(without introducing more risk)

Gareth Rushgrove

rspec-puppet

Page 34: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

(without introducing more risk)

Gareth Rushgrove

Unit tests for Puppet

it { is_expected.to compile } it { is_expected.to contain_class('db') } it do is_expected.to contain_package('mysql-server') .with_ensure('present') end it { is_expected.to have_exec_resource_count(0) }

Page 35: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

(without introducing more risk)

Gareth Rushgrove

puppet-syntax

Page 36: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

(without introducing more risk)

Gareth Rushgrove

Popular Puppet gemsSELECT package, COUNT(*) count FROM ( SELECT REGEXP_EXTRACT(line, r'gem [\'|"](.*)[\'|"]') package, id FROM ( SELECT SPLIT(content, '\n') line, id FROM [puppet.gemfile_contents] WHERE content CONTAINS 'gem' ) GROUP BY package, id ) GROUP BY 1 ORDER BY count DESC LIMIT 30;

Page 37: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

(without introducing more risk)

Gareth Rushgrove

Popular gem results

puppetlabs_spec_helper 1157 puppet 1142 rake 1135 puppet-lint 768 beaker-rspec 610 rspec-puppet 576 metadata-json-lint 566 beaker 440 puppet-blacksmith 425 serverspec 359

Page 38: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

(without introducing more risk)

Gareth Rushgrove

puppetlabs_spec_helper

Page 39: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

(without introducing more risk)

Gareth Rushgrove

Advanced toolsNext steps

Page 40: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

(without introducing more risk)

Gareth Rushgrove

beaker-rspec

Page 41: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

(without introducing more risk)

Gareth Rushgrove

Serverspec

Page 42: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

(without introducing more risk)

Gareth Rushgrove

rubocop

Page 43: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

(without introducing more risk)

Gareth Rushgrove

Other toolsAlternative approaches

Page 44: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

(without introducing more risk)

Gareth Rushgrove

puppet-catalog-test

Page 45: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

(without introducing more risk)

Gareth Rushgrove

Test catalogue compilation

$ puppet-catalog-test -m modules -M site.pp [INFO] Using puppet 3.0.2 [PASSED] foo (compile time: 0.168182 seconds) [PASSED] default (compile time: 0.003451 seconds)

---------------------------------------- Compiled 2 catalogs in 0.1717 seconds (avg: 0.0858 seconds)

Page 46: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

(without introducing more risk)

Gareth Rushgrove

Test Kitchen

Page 47: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

(without introducing more risk)Different Users

And different usecases

Page 48: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

Gareth Rushgrove

Page 49: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

Half of respondents regularly writetests for Puppet code

Gareth Rushgrove

Page 50: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

A quarter of respondents never write tests for Puppet code

Gareth Rushgrove

Page 51: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

The problem with a tool-centricworld view

Gareth Rushgrove

Page 52: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

Understanding user needs meansstarting with users

Gareth Rushgrove

Page 53: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

Gareth Rushgrove

- The Vox Pupuli folks- Lots of Puppet employees- You in-house Puppet expert- Custom functions

The module authors

Page 54: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

The regular Puppet users

Gareth Rushgrove

- Roles and profiles- Using Puppet weekly or more- PuppetDB, Puppet Server- Custom facts

Page 55: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

The occasional Puppet user

Gareth Rushgrove

- Using Puppet as needed- Basic Puppet code- Hieradata

Page 56: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

Today different types of Puppet users have a very different experience

Gareth Rushgrove

Page 57: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

Gareth Rushgrove

Page 58: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

For those with no Ruby experience the average was 2 out of 5

Gareth Rushgrove

Page 59: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

For those with a little Ruby experience the average was still only 2.5 out of 5

Gareth Rushgrove

Page 60: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

Of the people who love the testing experience 33% are self-described power users of both Puppet and Ruby

Gareth Rushgrove

Page 61: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

Gareth Rushgrove

Page 62: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

But more than 50% of respondents have little or no Ruby experience

Gareth Rushgrove

Page 63: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

(without introducing more risk)Challenges

What we need for the future

Page 64: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

(without introducing more risk)

Gareth Rushgrove

Improved getting started experience

Helping a new generation of users

Page 65: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

- Getting started testing documentation- Single entry point for users- Opinionated workflow

Gareth Rushgrove

Page 66: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

(without introducing more risk)

Gareth Rushgrove

Adopting acceptance testing

Still too hard

Page 67: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

27 of the 67 Serverspec users are not using either Beaker or Test Kitchen.

Gareth Rushgrove

Page 68: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

Only 5 of the Beaker (without rspec) users are not also using beaker-rspec

Gareth Rushgrove

Page 69: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

3 of the Test Kitchen users are also using some flavour of Beaker

Gareth Rushgrove

Page 70: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

So only 26% to 35% of respondents are using an acceptance testing tool with there Puppet code

Gareth Rushgrove

Page 71: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

(without introducing more risk)

Gareth Rushgrove

Experience mattersConsistence interfaces

Page 72: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

(without introducing more risk)

Gareth Rushgrove

Inconsistencies

$ puppet-lint vs rake lint vs rake validate $ rake syntax vs puppet parser validate $ rspec vs rake spec $ BEAKER_destroy=no rake beaker vs beaker

Page 73: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

We have a language style guide. What about other Puppet user interfaces?

Gareth Rushgrove

Page 74: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

(without introducing more risk)

Gareth Rushgrove

Ruby heritageRuby as a development environment

Page 75: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

60% of respondents described themselves as Puppet power users

Gareth Rushgrove

Page 76: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

Only 12% of respondents described themselves as Ruby power users. A third of those work for Puppet!

Gareth Rushgrove

Page 77: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

- More help with using Ruby for testing?- Support for testing in other languages?- Native Puppet support for testing?- Containerised testing abstraction?

Gareth Rushgrove

Page 78: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

(without introducing more risk)

Gareth Rushgrove

jordan/spec

Page 79: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

(without introducing more risk)

Gareth Rushgrove

Test Puppet with Puppet

file { '/tmp/test': ensure => present, content => 'The file content', }

assertion { 'that the file has the correct contents': subject => File['/tmp/test'], attribute => 'content', expectation => 'The file content', }

Page 80: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

(without introducing more risk)Conclusions

Where to go from here

Page 81: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

Thanks to the community we have a collection of powerful testing tools in the Puppet ecosystem

Gareth Rushgrove

Page 82: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

But we don’t have consistent user interfaces or the opinionated workflows useful for beginners

Gareth Rushgrove

Page 83: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

Testing shouldn’t just be apower user feature

Gareth Rushgrove

Page 84: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

As a community we should talkabout design more often

Gareth Rushgrove

Page 85: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

(without introducing more risk)

Gareth Rushgrove

https://goo.gl/forms/nchOp5hYdLLgmJ8z1

Page 86: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

Gareth Rushgrove

Page 87: PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet

(without introducing more risk)Questions?And thanks for listening