summaryrefslogtreecommitdiff
path: root/test/TestPlayBook.py
diff options
context:
space:
mode:
authorMichael DeHaan <michael.dehaan@gmail.com>2013-04-16 20:06:06 -0400
committerMichael DeHaan <michael.dehaan@gmail.com>2013-04-16 20:06:06 -0400
commit7c6341718e05e3fca6ce125c96d2d159be0446f3 (patch)
tree85047c076ec43cb0bf72106e6dd01565a74445ba /test/TestPlayBook.py
parent863cb50530304749721c418af33f1b27db867df0 (diff)
parent6826aa7360ed76d84a9c60eb8f2fb1d46e6ac964 (diff)
downloadansible-7c6341718e05e3fca6ce125c96d2d159be0446f3.tar.gz
Merge branch 'combine_vars' of git://github.com/laggyluke/ansible into exp
Conflicts: lib/ansible/inventory/vars_plugins/group_vars.py lib/ansible/runner/__init__.py lib/ansible/utils/__init__.py test/TestPlayBook.py
Diffstat (limited to 'test/TestPlayBook.py')
-rw-r--r--test/TestPlayBook.py70
1 files changed, 70 insertions, 0 deletions
diff --git a/test/TestPlayBook.py b/test/TestPlayBook.py
index 0f61134992..af233ff103 100644
--- a/test/TestPlayBook.py
+++ b/test/TestPlayBook.py
@@ -10,6 +10,7 @@ import ansible.utils as utils
import ansible.callbacks as ans_callbacks
import os
import shutil
+import ansible.constants as C
EVENTS = []
@@ -93,6 +94,8 @@ class TestPlaybook(unittest.TestCase):
os.unlink('/tmp/ansible_test_data_copy.out')
if os.path.exists('/tmp/ansible_test_data_template.out'):
os.unlink('/tmp/ansible_test_data_template.out')
+ if os.path.exists('/tmp/ansible_test_messages.out'):
+ os.unlink('/tmp/ansible_test_messages.out')
def _prepare_stage_dir(self):
stage_path = os.path.join(self.test_dir, 'test_data')
@@ -285,3 +288,70 @@ class TestPlaybook(unittest.TestCase):
print utils.jsonify(expected, format=True)
assert utils.jsonify(expected, format=True) == utils.jsonify(actual,format=True)
+
+ def test_playbook_hash_replace(self):
+ # save default hash behavior so we can restore it in the end of the test
+ saved_hash_behavior = C.DEFAULT_HASH_BEHAVIOUR
+ C.DEFAULT_HASH_BEHAVIOUR = "replace"
+
+ test_callbacks = TestCallbacks()
+ playbook = ansible.playbook.PlayBook(
+ playbook=os.path.join(self.test_dir, 'test_hash_behavior', 'playbook.yml'),
+ host_list='test/ansible_hosts',
+ stats=ans_callbacks.AggregateStats(),
+ callbacks=test_callbacks,
+ runner_callbacks=test_callbacks
+ )
+ playbook.run()
+
+ with open('/tmp/ansible_test_messages.out') as f:
+ actual = [l.strip() for l in f.readlines()]
+
+ print "**ACTUAL**"
+ print actual
+
+ expected = [
+ "goodbye: Goodbye World!"
+ ]
+
+ print "**EXPECTED**"
+ print expected
+
+ assert actual == expected
+
+ # restore default hash behavior
+ C.DEFAULT_HASH_BEHAVIOUR = saved_hash_behavior
+
+ def test_playbook_hash_merge(self):
+ # save default hash behavior so we can restore it in the end of the test
+ saved_hash_behavior = C.DEFAULT_HASH_BEHAVIOUR
+ C.DEFAULT_HASH_BEHAVIOUR = "merge"
+
+ test_callbacks = TestCallbacks()
+ playbook = ansible.playbook.PlayBook(
+ playbook=os.path.join(self.test_dir, 'test_hash_behavior', 'playbook.yml'),
+ host_list='test/ansible_hosts',
+ stats=ans_callbacks.AggregateStats(),
+ callbacks=test_callbacks,
+ runner_callbacks=test_callbacks
+ )
+ playbook.run()
+
+ with open('/tmp/ansible_test_messages.out') as f:
+ actual = [l.strip() for l in f.readlines()]
+
+ print "**ACTUAL**"
+ print actual
+
+ expected = [
+ "hello: Hello World!",
+ "goodbye: Goodbye World!"
+ ]
+
+ print "**EXPECTED**"
+ print expected
+
+ assert actual == expected
+
+ # restore default hash behavior
+ C.DEFAULT_HASH_BEHAVIOUR = saved_hash_behavior