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

The Future of Testing Puppet Code

The Future of Testing Puppet Code

A talk from #PuppetConf 2016 covering the state of affairs with testing Puppet code. Mainly a talk about what we, as a community, can do to improve the tools and adoption of those tools. Lots of survey data and bigquery research.

Gareth Rushgrove

October 21, 2016
Tweet

More Decks by Gareth Rushgrove

Other Decks in Technology

Transcript

  1. (without introducing more risk) The Future of Testing Puppet Code

    Puppet Gareth Rushgrove Who, What, Why, How
  2. - Why test Puppet anyway - Existing Puppet testing tools

    - Different users and usecases - Future challenges Gareth Rushgrove
  3. Not a talk about how to test Puppet code. Lot

    of existing content on that subject Gareth Rushgrove
  4. - You have lots of Puppet code - You’re targeting

    a wide range of OS’s - The Puppet language has more features Gareth Rushgrove
  5. Note that this just represents public code on GitHub. Lots

    of private Puppet code out there too Gareth Rushgrove
  6. (without introducing more risk) Gareth Rushgrove How many .pp files

    on GitHub? SELECT COUNT(*) FROM [puppet.puppet_files] -- 489725
  7. (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
  8. (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 )
  9. 50% of Puppet files are 20 lines or less. 90%

    of Puppet files are 100 lines or less Gareth Rushgrove
  10. A third of respondents run more than one OS on

    there development machine Gareth Rushgrove
  11. (without introducing more risk) Gareth Rushgrove Style conformance $ puppet-lint

    /etc/puppet/modules foo/manifests/bar.pp - ERROR: trailing whitespace found on li apache/manifests/server.pp - WARNING: variable not enclosed i ...
  12. (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) }
  13. (without introducing more risk) Gareth Rushgrove Popular Puppet gems SELECT

    package, COUNT(*) count FROM ( SELECT REGEXP_EXTRACT(line, r'gem [\'|"](.*)[\'|"]') packag 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;
  14. (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
  15. (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)
  16. Gareth Rushgrove - The Vox Pupuli folks - Lots of

    Puppet employees - You in-house Puppet expert - Custom functions The module authors
  17. The regular Puppet users Gareth Rushgrove - Roles and profiles

    - Using Puppet weekly or more - PuppetDB, Puppet Server - Custom facts
  18. The occasional Puppet user Gareth Rushgrove - Using Puppet as

    needed - Basic Puppet code - Hieradata
  19. For those with a little Ruby experience the average was

    still only 2.5 out of 5 Gareth Rushgrove
  20. Of the people who love the testing experience 33% are

    self-described power users of both Puppet and Ruby Gareth Rushgrove
  21. But more than 50% of respondents have little or no

    Ruby experience Gareth Rushgrove
  22. - Getting started testing documentation - Single entry point for

    users - Opinionated workflow Gareth Rushgrove
  23. 27 of the 67 Serverspec users are not using either

    Beaker or Test Kitchen. Gareth Rushgrove
  24. Only 5 of the Beaker (without rspec) users are not

    also using beaker-rspec Gareth Rushgrove
  25. 3 of the Test Kitchen users are also using some

    flavour of Beaker Gareth Rushgrove
  26. So only 26% to 35% of respondents are using an

    acceptance testing tool with there Puppet code Gareth Rushgrove
  27. (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
  28. Only 12% of respondents described themselves as Ruby power users.

    A third of those work for Puppet! Gareth Rushgrove
  29. - More help with using Ruby for testing? - Support

    for testing in other languages? - Native Puppet support for testing? - Containerised testing abstraction? Gareth Rushgrove
  30. (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', }
  31. Thanks to the community we have a collection of powerful

    testing tools in the Puppet ecosystem Gareth Rushgrove
  32. But we don’t have consistent user interfaces or the opinionated

    workflows useful for beginners Gareth Rushgrove