This is a good read if you haven't seen it already - http://docs.ansible.com/test_strategies.html
On Mon, Dec 15, 2014 at 4:33 AM, Bryan Berry <[email protected]> wrote: > > Dear Ansiblists, > > I need to integrate application-level tests with ansible runs. These test > are quite specific to that applications we are deploying and go quite > beyond the existing test support in ansible. The purpose of these tests is > not to test the ansible code but the entire deployment stack. Running these > tests as part as part of the ansible playbook makes sense as the ansible > run knows the location of all created resources. I am happy to go off and > create this on my own, but I would really like to collaborate if there are > others working on similar problems. I want to write the tests using plain > python unittest so it will be familiar to my developers. > > here is an example where i want to test a Consul cluster of 5 nodes. I > want to verify that the Consul API functions as expected. > > here is a code example of what I am looking to test > > # tests/test_consul.py > import unittest > import os.environ > import requests > import consul > import time > > > class TestConsul(unittest.TestCase): > > def setUp(self): > self.members = os.environ['CONSUL_CLUSTER'].split(',') > > def test_nodes_return_same_membership_list(self): > results = [] > for member in self.members: > member_list = requests.get('http://member:4444/v1/cluster/members' > % member) > member_list.sort() > results.append(member_list) > self.assertTrue(all([True for result in results if result == > results[0])) > > def test_kv_put(self): > c = > consul.Consul(self.members[0]) > > c.kv.put('foo', 'bar') > # wait for > replication > > time.sleep(5) > results = [] > for member in self.members: > c = > consul.Consul(member) > > results.append(c.kv.get('foo')) > self.assertTrue(all([True for result in results if result == 'bar'])) > > > > as you can see, I plan on passing the list of nodes as an environment > variable, but I would love to hear alternate approaches. > > I currently plan to trigger the running of these tests by an environment > variable. > > $ RUN_TESTS=TRUE ansible-playbook my-plays.yml > > - name: run tests > when: "{{ lookoup('ENV', 'RUN_TESTS')|bool}}" > roles: > - execute-tests # executes tests in tests/test_*.py using unittest > module, yet to be written > > It's really key that my developers be able to write tests using plain > python code rather than Ansible's YAML. This decouples the tests from > ansible. AThis could we helpful later if we every choose to run the exact > same tests later separately from ansible, for example executing them as > part of regular monitoring. > > Thoughts? > > Regards, > > Bryan W. Berry > > > > -- > 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]. > To post to this group, send email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/ansible-project/02e8c1c1-cb08-416c-9bf5-907607b529f5%40googlegroups.com > <https://groups.google.com/d/msgid/ansible-project/02e8c1c1-cb08-416c-9bf5-907607b529f5%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- 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]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CA%2BnsWgyNwsvqJOhoikq3hiDjJn%2BRsNG1VD7M%3DabwHX4-EH1MRA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
