If the model is declaring desired state you test the outcome, not the implementation
Can I ping X, is this route able, is this web service up -- not does this file look like this. Think at the higher level and write tests that matter that are not just basic asserts. -- Michael On Dec 11, 2013, at 1:00 PM, John Dewey <[email protected]> wrote: Hi Aaron - I too would find it useful to have the ability to “unit test” my tasks. However, I have opted to create a testing playbook [1] which handles integration testing. It is not perfect, but allows for TDD/BDD, and integrate into CI gating. [1] https://github.com/blueboxgroup/ursula/tree/master/playbooks/tests/tasks On Wednesday, December 11, 2013 at 9:54 AM, Aaron Hunter wrote: I see your point but I'm not sure I agree. "Unit testing" may not be the best term for it but it's not too far off. Consider this case instead: installing and configuring a DHCP server. I have my senior admin write down exactly what the DHCP deployment should look like. This is how success will be measured. Testing this will include checking file permissions (which is also security issue), processes are running and with the right settings, logging , and a whole set of functionality based on the config file of the DHCP server. Another admin (let's say a junior admin) writes the Ansible code to accomplish this. When the code passes the test, it is done. Certainly this crosses into what is traditionally called functional testing. Testing IT infrastructure is somewhat different from testing a new software development. I would still test what is in the Ansible script for the DHCP server because the junior admin may have gotten it wrong and plus its still code and you always test code. Plus I would have the Ansible scripts initially written in a development environment with one suite of tests. These tests will be very obtrusive and are not the same I would use to test a successful deployment. To be sure, the most important part is testing that the DHCP server works as expected (i.e., testing the config file) which is not an Ansible issue. Still I would test everything. The issue for me is what to use to write the tests? Cucumber? JBehave? Plain Python? I know plenty of tools designed to test custom apps/code, I don't think the IT testing tools have caught up yet. Maybe this isn't even an Ansible issue. I was just speculating on how it might include automated TDD-like test process in the framework. --- Aaron DevOps Blog: http://www.sharknet.us On Wednesday, December 11, 2013 11:55:40 AM UTC-5, Michael DeHaan wrote: Yes, this is super easy to already do today, basically just call your tests at the end as the last step of your playbook. Executing arbitrary python code is possible, but you can use ansible modules like get_url and fail and so on. If you want to push a python script, the 'script' module is awesome for that. Many of users have tests integrated with their continuous deployment process so it will fail the rolling update block before moving on the to next, thus not taking more machines out of rotation. However, if you feel you have to test the file module, seriously, you're wasting time -- if the file module doesn't work for you, how good is the product? It would be much better to test instead for something functional, like whether your web service is operational, rather than duplicating all the basics of Ansible in, as you say, arbitrary python code just to make sure Ansible works. There's a difference between unit and integration testing, and also in testing a live deployment. Unit tests are things you run on development code. On Wed, Dec 11, 2013 at 11:39 AM, Aaron Hunter <[email protected]<javascript:> > wrote: I come from an Agile software development background in which test driven development (TDD) is the norm. As I write Ansible scripts, I'd like some way of testing them. In principle, I want to test every command in a playbook. For example, if one of my command changes the user permissions on a file, I want a test that independently confirms that it has in fact done so. I don't see a "test" module but I may have missed it. Is that something that Ansible may offer some day? I'm thinking of the Ansible equivalent to unit testing. I believe it would require the ability to execute arbitrary Python code in the test. The Java tests I have written could certainly be very complex. I'm also curious what others do for testing using Ansible. What frameworks, etc. Thanks, Aaron DevOps Blog: http://www.sharknet.us -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected] <javascript:>. For more options, visit https://groups.google.com/groups/opt_out. -- Michael DeHaan <[email protected] <javascript:>> CTO, AnsibleWorks, Inc. http://www.ansibleworks.com/ -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out. -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out. -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
