Skip to content

Instantly share code, notes, and snippets.

@plathrop
Forked from jedi4ever/gist:2726756
Created May 18, 2012 18:39
Show Gist options
  • Save plathrop/2726954 to your computer and use it in GitHub Desktop.
Save plathrop/2726954 to your computer and use it in GitHub Desktop.
Strategy: Logic to determine if a commit (or series) has impact on a Puppet Role (class)

Problem:

Given a puppet tree (with manifest and modules) dir
When rspec-puppet tests and puppet lint tests pass Instead of re-running test on all possible roles I want to calculate what roles (classes) were impacted in between revision of the puppet tree

Roles would translate to classes in puppet tree with a special prefix f.i. role_

Usage

Within a CI system - a new build gets params current and previous hash of commits. If you would run this this tool , you can know on what machines you need to run tests on. This would be determine the next stage in your current build plan (Bamboo speak)

Option(1): use standby CI server

Do an actual noop run on CI standby servers and see if things changed using detailed-exit-codes. This would require us to do a run on CI servers for all possible roles we define in our tree. And this will take time and will generate a lot of 'unneeded' puppet applies. (debatable) We want to be clever and detect only the roles that have been impacted by a change.

Option(2):calculate the impact of the change

  1. Get a list of files changed in your puppet tree F.i. mercurial get a list of files that changed in between revisions. (-S for subrepos)

    hg status --rev cc01cf47d579:3951a60e401e -m -a -r -d -S

    M moduleA/glbl A moduleB/...

Or git (not sure on submodules) - See http://stackoverflow.com/questions/1552340/git-show-all-changed-files-between-two-commits

  1. using the filename prefixes we can see what puppet modules have been impacted in between git commits

moduleA, module B are impacted

See - http://www.devco.net/archives/2012/04/28/trigger-puppet-runs.php

  1. Specify the current state of a node and build a catalog facts can be given (ala rspec puppet style) or using actual catalog files

See - https://github.com/ripienaar/puppet-catalog-diff See - https://github.com/rodjek/rspec-puppet/blob/master/lib/rspec-puppet/support.rb

  1. for both commit-ids checkout the puppet tree either using plain commands or fancy using grit or mercurial-ruby

  2. for both commit-ids calculate a list of resources/classes based on given facts Calculate the dependency tree for a role(class) and see if the roles depend on the module changed.

  3. filter the resources based on a role prefix

Et voilà

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment