Ask Your Question
0

where (server/agent) and how to run unit test in puppet

asked 2017-05-25 05:42:15 -0500

CKT gravatar image

I want to run unit test in puppet ,i have created spec and tests folder inside my module folder. I have tried the steps provided in (https://puppet.com/blog/next-generati...), but not able to make it. Please help on it

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2017-05-26 08:48:18 -0500

DarylW gravatar image

updated 2017-05-26 08:48:51 -0500

You don't run your tests on your puppet master, you usually run them either locally on your 'development' machine, or inside of a container or VM (with vagrant).

The article you link is a bit dated (it's from 2012), but it is still mostly correct. It talks about the parts that you need for your test, and how to run it, but it is generally expecting you to do that locally on your machine. It has a section describing how you would set up your tests to run on a continuous integration server, using RVM and bundler to use the appropriate version of ruby and the gems you need for your module.

This article is from 2015, but it is a much better description of rspec testing with puppet https://rnelson0.com/2015/11/24/moder... You can also find some information in puppets Beginner's Guide to Module writing

Generally, you would start locally on your development machine. The steps are generally this.. 1) Install an appropriate version of ruby (based on the version that your install of puppet is using, /opt/puppetlabs/bin/ruby --version should tell you what you need)

2) install bundler so that you can isolate the gem dependencies of your module for testing gem install bundler

3) Make sure you have the appropriate test files in place, you can bootstrap a new module using the https://github.com/garethr/puppet-mod...

4) in the module directory, run 'bundle install' to have bundler fetch all of the dependencies, and store them for this module

5) use bundler to run the tests, using 'bundle exec rake spec'

If you generate a new module with the skeleton, you should be able to step through that and have a single, successful passing test. You can then add additional tests as appropriate to your module.

If you run into any more issues, let us know on the forum and we can help!

edit flag offensive delete link more

Comments

I have tried the following steps and failed to execute tests. Below are the steps 1.Generated module using 'puppet module generate user-module'. Currently i am using Puppet 4.10.1 and my folder structures are below

CKT gravatar imageCKT ( 2017-06-08 01:18:13 -0500 )edit

facts\lib\facter\*.rb && *.yaml class_name\manifests\*.pp Mymodule\lib\puppet\functions\Mymodule\*.rb 2.Moved above folders to "user-module" 3.Tried the 1-4steps you have mentioned above.

CKT gravatar imageCKT ( 2017-06-08 01:18:45 -0500 )edit

I am using/calling ruby function inside my *.pp file error during compilation: Evaluation Error: Unknown function: 'my_module::rubyfunctioncall

CKT gravatar imageCKT ( 2017-06-08 01:18:58 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2017-05-25 05:42:15 -0500

Seen: 79 times

Last updated: May 26