Good resources for writing rspec tests for puppet code changes?

64 views
Skip to first unread message

HPUX_PUPPET

unread,
Feb 19, 2014, 12:56:51 AM2/19/14
to puppet...@googlegroups.com
I am trying to get puppet to support HPUX better than it does now so it can manage user accounts properly.  I have already contributed changes to the HPUX module to change passwords, but writing the rspec at the time was more hack and guess than any real methodology.  I did read the Learning Rspec guide. It helped a small bit.  My problem is that I tried to write updates to handle password expiration and found what should have worked did not.

Not coding daily the rspec drains out of my head faster that I can get it back in.

I see lots of examples out on the net, but even trying to hack around on that code to try to get it work is still not doing providing valid test cases.

Can someone point me to something that will make logical sense to me as well as how to actually get useful debug info when testing puppet rspec files against my changes?  I have tried dozens of ways from the net, but I am just not getting any trace type output to let me know what it found when it did a test, what was passed to the code block or even much to help me track down why it is not working. 

I can get the Ruby code to do what I want, but cannot submit it without associated rspec tests.  I would prefer to learn to do it correctly for when I want to tweak more HPUX specific work and then possibly some AIX as well.  I really want to get puppet in place to handle all of the non-Linux boxes, but right now it is not doing it in all cases.

It is not that rspec is that complex, it is the integration into puppet and having to dig back through tons of code to try to find where everything is getting fed into the hpux user modules to be able to test. If I coded regularly I am sure this would be a lot easier :)  I am still trying to self-teach Ruby and now add in Rspec.  

  Thanks!
Message has been deleted

HPUX_PUPPET

unread,
Feb 19, 2014, 1:03:56 AM2/19/14
to puppet...@googlegroups.com

Just a bit more explanation...

When I was looking for references I was only finding puppet-lint and rspec-puppet for testing manifests, but not finding anything for writing the spec files to test module functionality or modifications to existing modules such as the HPUX user management.  


Johan De Wit

unread,
Feb 19, 2014, 6:44:00 AM2/19/14
to puppet...@googlegroups.com
> --
> You received this message because you are subscribed to the Google
> Groups "Puppet Users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to puppet-users...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/puppet-users/cf5de8e3-d6c9-490c-a497-d9fbd27a3e88%40googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
There is not that much documentation available.

I did a talk on cfgmgmtcamp.eu about TDD and puppet. Yoiu can find a
little blog at the BPUG website : puppet-be.github.io. (there are some
references in the slides)

I look mostly at the puppet code for examples for writing rspec files.
Some interesting links I also have to look at :

http://www.morethanseven.net/2014/01/25/code-coverage-for-puppet-modules/
http://hajee.github.io/2014/01/18/testing-your-system-installation-with-rspec

https://github.com/ghoneycutt/puppet-module-nfs/blob/v1.6.2/spec/classes/init_spec.rb#L58-186

I will delve again into this topic shortly, and share my experiences in
my sequel of the talk on puppetcamp Paris/Berlin.

Also looking for people interested in testing using rspec and there
experience/problems

Sorry i couldn't give you the info you need, but hope you will find
some answers in the links.

Grts

johan






--
Johan De Wit

Open Source Consultant

Red Hat Certified Engineer (805008667232363)
Puppet Certified Professional 2013 (PCP0000006)
_________________________________________________________

Open-Future Phone +32 (0)2/255 70 70
Zavelstraat 72 Fax +32 (0)2/255 70 71
3071 KORTENBERG Mobile +32 (0)474/42 40 73
BELGIUM http://www.open-future.be
_________________________________________________________


Next Events:
Zabbix Certified Training | http://www.open-future.be/zabbix-certified-training-10-till-12th-march
Zabbix for Large Environments Training | http://www.open-future.be/zabbix-large-environments-training-13-till-14th-march
Puppet Intruction Course | http://www.open-future.be/puppet-introduction-course-14th-april
Puppet Advanced Training | http://www.open-future.be/puppet-advanced-training-15-till-17th-april
Subscribe to our newsletter | http://eepurl.com/BUG8H

Martin Alfke

unread,
Feb 19, 2014, 9:44:47 AM2/19/14
to puppet...@googlegroups.com
Hi,

On 19 Feb 2014, at 07:44, Johan De Wit <jo...@open-future.be> wrote:

> On 02/19/2014 02:03 AM, HPUX_PUPPET wrote:
>>
>> Just a bit more explanation...
>>
>> When I was looking for references I was only finding puppet-lint and rspec-puppet for testing manifests, but not finding anything for writing the spec files to test module functionality or modifications to existing modules such as the HPUX user management.
>>
>>
> There is not that much documentation available.
>
> I did a talk on cfgmgmtcamp.eu about TDD and puppet. Yoiu can find a little blog at the BPUG website : puppet-be.github.io. (there are some references in the slides)
>
> I look mostly at the puppet code for examples for writing rspec files. Some interesting links I also have to look at :
>
> http://www.morethanseven.net/2014/01/25/code-coverage-for-puppet-modules/
> http://hajee.github.io/2014/01/18/testing-your-system-installation-with-rspec
>
> https://github.com/ghoneycutt/puppet-module-nfs/blob/v1.6.2/spec/classes/init_spec.rb#L58-186
>
Maybe you want to attend Extending Puppet using Ruby classes (https://puppetlabs.com/services/training/extending-puppet)

Besides this I also did a small module with spec examples (https://github.com/tuxmea/tuxmea-stdmodule)

hth,

Martin


Jim Perry

unread,
Feb 19, 2014, 2:04:04 PM2/19/14
to puppet...@googlegroups.com
Thanks for the links, I will take a look at them.

I would love to get some training on it, but the company won't spring for it. So it looks like I am hacking it out with everyone's help and Google.




--
You received this message because you are subscribed to a topic in the Google Groups "Puppet Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/puppet-users/187mS-NiiyE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/259F6EBC-480E-460B-9070-47682B78A344%40gmail.com.

HPUX_PUPPET

unread,
Feb 19, 2014, 2:22:20 PM2/19/14
to puppet...@googlegroups.com
Thanks Johan and Martin.  I looked at the links you sent, but this is what I have already found and it really did not provide any new insights.  

The main problem I am having is that what I put in rspec code should be working but just does not. I have even hard-coded in a true or false return, but the spec script just does not respond.  

If anyone happens to have a good rspec language / syntax reference that would be greatly helpful.  The "The RSpec Book" gives some good examples, but not a language reference.   

Also I cannot seem to get any of the debug code from the net to work with puppet and rspec together to get some useful output to find the error. Does anyone have a good link to that information?  

I am just a lowly sys admin given the task to hack Puppet to get it to work correctly on HPUX for user management. 

Johan De Wit

unread,
Feb 19, 2014, 2:28:55 PM2/19/14
to puppet...@googlegroups.com
Don't have any experience/access to hpux, but you can always show us
the code and the rspec files.
So we can have at least a look at it :)

And multiple eyes see more then two :)

HPUX_PUPPET

unread,
Feb 19, 2014, 5:36:59 PM2/19/14
to puppet...@googlegroups.com

On Wednesday, February 19, 2014 9:28:55 AM UTC-5, Johan De Wit wrote:
Don't have any experience/access to hpux,  but you can always show us
the code and the rspec files.
So we can have at least a look at it :)

And multiple eyes see more then two :)

 
Thanks.  I think I tracked the problem down to the source tree where I was working.  It seems I am missing some config flag or ENV variable to tell rspec to test relative the to directory where I am working and it was not getting the correct hpux_user.rb file, instead defaulting to the one installed on the box.  Now if I could just find out where to tell rspec to use a specific source tree, it would probably be much better :)

Martin Alfke

unread,
Feb 20, 2014, 8:58:58 AM2/20/14
to puppet...@googlegroups.com
Maybe you want to dig into bundle (see Gemfile from my example github code) and .fixtures.yaml file.

Bundle has the possibility to install gems in a non-system path (not requiring root or sudo permissions) and use the gems from there instead of system gems.

Reply all
Reply to author
Forward
0 new messages