[Engineering] Fwd: [Ops] Testing puppet with rspec

Adam Baso abaso at wikimedia.org
Thu Mar 2 22:56:24 UTC 2017


In case you're not on the operations at lists list, this is pretty cool stuff.
Forwarding after checking with hashar if that was okay.

---------- Forwarded message ----------
From: Antoine Musso <hashar at free.fr>
Date: Thu, Mar 2, 2017 at 10:00 AM
Subject: [Ops] Testing puppet with rspec
To: Operations Engineers <ops at lists.wikimedia.org>


Hello,

Did you know Puppet manifests can be tested locally before using the
puppet compiler or trying them in labs or a production canary?

After several sprint sessions we finally have some helpers to easily run
such tests locally and hopefully soon on Jenkins whenever a patch is sent.

The magic is made possible thanks to the [rspec-puppet] project.  It
provides all the glue for ruby test harness rspec to be able to compile
a puppet catalog and run assertion against it.

A test looks like:

  describe 'module::class' do

    it { should compile }

  end

If you get an issue in module::class, another class it includes or one
the resource it generates (eg: an erb template). That will fail.  I have
used locally with great success and it is a huge time saver (no more
have to send to Gerrit + run puppet compiler on each iteration).


Some of our puppet modules already have some tests and rake has tasks
all of them to make it easy to run them. In short one does:

 sudo apt-get install bundler
 bundle exec rake spec

There are still some that are failling but I guess they will be fixed.
My hope is to soon have them run in Jenkins and thus make sure a patch
match the specifications.


I wrote a guide on wikitech which covers it in greater details:
https://wikitech.wikimedia.org/wiki/Puppet_coding/testing


I will be more than happy to present it more in depth on demand and/or
pair as needed :-}



[rspec-puppet] https://github.com/rodjek/rspec-puppet
The task that started it all https://phabricator.wikimedia.org/T78342

--
Antoine "hashar" Musso

_______________________________________________
Ops mailing list
Ops at lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/ops
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.wikimedia.org/pipermail/engineering/attachments/20170302/c582c8ba/attachment.html>


More information about the Engineering mailing list