unit testing framework for salt

507 views
Skip to first unread message

Zippy Zeppoli

unread,
Mar 8, 2013, 6:37:55 PM3/8/13
to salt-...@googlegroups.com
Hi List,
Is there a unit test framework for salt?
Something that will allow you to track code coverage, etc?

Sean Channel

unread,
Mar 8, 2013, 6:51:30 PM3/8/13
to salt-...@googlegroups.com, Zippy Zeppoli
In the Salt source there is a top level 'tests' subdirectory. You can
run './runtests.py --help' from there to see testing options.

https://github.com/saltstack/salt/tree/develop/tests

HTH,
_S

Zippy Zeppoli

unread,
Mar 10, 2013, 2:39:48 PM3/10/13
to Sean Channel, salt-...@googlegroups.com
What about for your own state's / modules?

Zippy Zeppoli

unread,
Mar 11, 2013, 12:55:26 PM3/11/13
to Sean Channel, salt-...@googlegroups.com
It helps. Thanks!

On Sun, Mar 10, 2013 at 11:57 AM, Sean Channel <penta...@gmail.com> wrote:
> A great question! There is some documentation on that here:
>
> http://docs.saltstack.org/en/latest/topics/tests/index.html
>
> feedback welcome. HTH,
>
> _S.

Jose

unread,
Dec 2, 2015, 1:04:24 AM12/2/15
to Salt-users, penta...@gmail.com, zippyz...@gmail.com
Hi Zippy,

I know this is an old thread but it seems like there is no resolution with regards to testing your own modules.  Were you able to test your own modules?  The unit testing document in salt stack  (https://docs.saltstack.com/en/latest/topics/development/tests/unit.html) I believe is for testing salt modules integrated with the main source tree.


Cheers,
Jose

Dani C

unread,
Dec 19, 2015, 4:48:26 PM12/19/15
to Salt-users, penta...@gmail.com, zippyz...@gmail.com
I'm looking for a method ot test my own modules/ states ...shame nothing has been progressed for such a long time....

Mike Place

unread,
Dec 19, 2015, 6:24:27 PM12/19/15
to salt-...@googlegroups.com, penta...@gmail.com, zippyz...@gmail.com
Really, the only thing preventing one from doing this is a lack of
documentation. Upon checking out the salt source code, a custom module
could easily be placed into
salt/tests/integration/files/file/base/_modules and then unit tests
could be written and placed in salt/tests/integration/modules.

For example, to write and run unit tests for a module named
my_custom_module, place the module in

salt/tests/integration/files/file/base/_modules/my_custom_module.py

And place your unit test in:

salt/tests/integration/modules/my_custom_module_test.py (Note the
_test in the filename, which is required.)

Then you could run unit tests using Salt's own test suite as follows:

python salt/tests/runtests.py -n unit.modules.my_custom_module_test

The same scheme could be used to create and write integration tests
for custom modules.

Let me know if you have questions.

-mp
> --
> You received this message because you are subscribed to the Google Groups
> "Salt-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to salt-users+...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Dani C

unread,
Dec 20, 2015, 2:43:03 AM12/20/15
to Salt-users, penta...@gmail.com, zippyz...@gmail.com
Hi Mike,

Thank you for reply/ info, very useful!

Indeed is all about docs, is all about how high/ low the entry barrier is... w/o the simple example like your or few phrases the barrier is high and this is what is killing this beautiful project i love called Salt

Cheers,
Dani

Ulli Keuthe

unread,
Dec 20, 2015, 9:25:04 AM12/20/15
to Salt-users, penta...@gmail.com, zippyz...@gmail.com
Dani,

Not sure if this will help you.
I copy & paste coded a python script that takes salts json output and transforms it into a junit.xml file.

Usage is: salt --out=json myminion state.sls super.complex.state | junitxml.py -c "super.complex.state" -o super_complex_state.xml

This can then be called jenkins and jenkins will generate a nice html report based on the xml file.
This is certainly super ugly but it does exactly what I need.

A shame I haven't had the time to wrap this into a custom junit outputter.

Sorry, Ulli

Mike Place

unread,
Dec 20, 2015, 10:14:11 AM12/20/15
to salt-...@googlegroups.com, Sean Channel, zippyz...@gmail.com
Documentation is certainly helpful! I'll try to get this formatted and
added to the official docs this afternoon. Thanks for the reminder.

-mp

pepe

unread,
Dec 20, 2015, 11:16:17 PM12/20/15
to Salt-users, penta...@gmail.com, zippyz...@gmail.com
Hi Mike,

Just a suggestion:  Would also be helpful to have a simple diagram describing how the tests are run, especially the integration tests which involves running a minion & master.  I've tried both the unit & integration tests and also run my modules with it successfully within my mac.  However, when I tried it in my in a small vagrant provisioned vm, resource issues such as 'can't allocate memory' or 'address already in use' came out. 

The unit/integration tests were very useful!

Cheers,
Jose

Mike Place

unread,
Dec 20, 2015, 11:29:54 PM12/20/15
to salt-...@googlegroups.com, Sean Channel, zippyz...@gmail.com
The test suite does use a fair amount of memory, but we've been
working over the past week in the develop branch to try and reduce
that footprint.

There is another issue where the test suite doesn't exist cleanly
which can produce the 'address already in use' error. You might need
to kill any instances of the test suite by hand from your process list
and that should clean it up.

I'll see about getting some of this documentation written tomorrow
since I won't have time tonight. Thanks for the good suggestions!

-mp

pepe

unread,
Dec 21, 2015, 12:01:02 AM12/21/15
to Salt-users, penta...@gmail.com, zippyz...@gmail.com
Hi Mike,

It's good to know the causes of the errors I've mentioned, thanks!

Cheers,
Jose Cueto
Reply all
Reply to author
Forward
0 new messages