<div dir="ltr">In case you're not on the operations@lists list, this is pretty cool stuff. Forwarding after checking with hashar if that was okay.<div><br><div class="gmail_quote">---------- Forwarded message ----------<br>From: <b class="gmail_sendername">Antoine Musso</b> <span dir="ltr"><<a href="mailto:hashar@free.fr">hashar@free.fr</a>></span><br>Date: Thu, Mar 2, 2017 at 10:00 AM<br>Subject: [Ops] Testing puppet with rspec<br>To: Operations Engineers <<a href="mailto:ops@lists.wikimedia.org">ops@lists.wikimedia.org</a>><br><br><br>Hello,<br>
<br>
Did you know Puppet manifests can be tested locally before using the<br>
puppet compiler or trying them in labs or a production canary?<br>
<br>
After several sprint sessions we finally have some helpers to easily run<br>
such tests locally and hopefully soon on Jenkins whenever a patch is sent.<br>
<br>
The magic is made possible thanks to the [rspec-puppet] project.  It<br>
provides all the glue for ruby test harness rspec to be able to compile<br>
a puppet catalog and run assertion against it.<br>
<br>
A test looks like:<br>
<br>
  describe 'module::class' do<br>
<br>
    it { should compile }<br>
<br>
  end<br>
<br>
If you get an issue in module::class, another class it includes or one<br>
the resource it generates (eg: an erb template). That will fail.  I have<br>
used locally with great success and it is a huge time saver (no more<br>
have to send to Gerrit + run puppet compiler on each iteration).<br>
<br>
<br>
Some of our puppet modules already have some tests and rake has tasks<br>
all of them to make it easy to run them. In short one does:<br>
<br>
 sudo apt-get install bundler<br>
 bundle exec rake spec<br>
<br>
There are still some that are failling but I guess they will be fixed.<br>
My hope is to soon have them run in Jenkins and thus make sure a patch<br>
match the specifications.<br>
<br>
<br>
I wrote a guide on wikitech which covers it in greater details:<br>
<a href="https://wikitech.wikimedia.org/wiki/Puppet_coding/testing" rel="noreferrer" target="_blank">https://wikitech.wikimedia.<wbr>org/wiki/Puppet_coding/testing</a><br>
<br>
<br>
I will be more than happy to present it more in depth on demand and/or<br>
pair as needed :-}<br>
<br>
<br>
<br>
[rspec-puppet] <a href="https://github.com/rodjek/rspec-puppet" rel="noreferrer" target="_blank">https://github.com/rodjek/<wbr>rspec-puppet</a><br>
The task that started it all <a href="https://phabricator.wikimedia.org/T78342" rel="noreferrer" target="_blank">https://phabricator.wikimedia.<wbr>org/T78342</a><br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
Antoine "hashar" Musso<br>
<br>
______________________________<wbr>_________________<br>
Ops mailing list<br>
<a href="mailto:Ops@lists.wikimedia.org">Ops@lists.wikimedia.org</a><br>
<a href="https://lists.wikimedia.org/mailman/listinfo/ops" rel="noreferrer" target="_blank">https://lists.wikimedia.org/<wbr>mailman/listinfo/ops</a><br>
</font></span></div><br></div></div>