summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMatt Clay <matt@mystile.com>2016-07-01 14:52:45 -0700
committerMatt Clay <matt@mystile.com>2016-07-01 15:24:41 -0700
commit75fa80f73c44b50edf5a84617c64d09ad04ff570 (patch)
tree50b998d1cf22c05f155cd4f0bb218aa95dbd29b0 /test
parenta598f26006f5ae5c3d1813be81611161aad0af5c (diff)
downloadansible-75fa80f73c44b50edf5a84617c64d09ad04ff570.tar.gz
Parse async response in async action. (#16534)
* Parse async response in async action. * Add async test for non-JSON data before module output. * Fix existing async unit test. Resolves #16156 (cherry picked from commit 292785ff2bf557cafbe2bd18e95f2bd26cce0f0b)
Diffstat (limited to 'test')
-rw-r--r--test/integration/Makefile9
-rw-r--r--test/integration/test_async.yml10
-rw-r--r--test/units/executor/test_task_executor.py6
3 files changed, 22 insertions, 3 deletions
diff --git a/test/integration/Makefile b/test/integration/Makefile
index a812ace890..62343c1082 100644
--- a/test/integration/Makefile
+++ b/test/integration/Makefile
@@ -23,7 +23,7 @@ VAULT_PASSWORD_FILE = vault-password
CONSUL_RUNNING := $(shell python consul_running.py)
EUID := $(shell id -u -r)
-all: setup test_test_infra parsing test_var_precedence unicode test_templating_settings environment test_connection non_destructive destructive includes blocks pull check_mode test_hash test_handlers test_group_by test_vault test_tags test_lookup_paths no_log test_gathering_facts
+all: setup test_test_infra parsing test_var_precedence unicode test_templating_settings environment test_connection non_destructive destructive includes blocks pull check_mode test_hash test_handlers test_group_by test_vault test_tags test_lookup_paths no_log test_gathering_facts test_async
test_test_infra:
# ensure fail/assert work locally and can stop execution with non-zero exit code
@@ -284,3 +284,10 @@ test_lookup_paths: setup
no_log: setup
# This test expects 7 loggable vars and 0 non loggable ones, if either mismatches it fails, run the ansible-playbook command to debug
[ "$$(ansible-playbook no_log_local.yml -i $(INVENTORY) -e outputdir=$(TEST_DIR) -vvvvv | awk --source 'BEGIN { logme = 0; nolog = 0; } /LOG_ME/ { logme += 1;} /DO_NOT_LOG/ { nolog += 1;} END { printf "%d/%d", logme, nolog; }')" = "6/0" ]
+
+test_async:
+ # Verify that extra data before module JSON output during async call is ignored.
+ LC_ALL=bogus ansible-playbook test_async.yml -i $(INVENTORY) -e outputdir=$(TEST_DIR) -v $(TEST_FLAGS)
+ # Verify that the warning exists by examining debug output.
+ ANSIBLE_DEBUG=1 LC_ALL=bogus ansible-playbook test_async.yml -i $(INVENTORY) -e outputdir=$(TEST_DIR) -v $(TEST_FLAGS) \
+ | grep -q 'bash: warning: setlocale: LC_ALL: cannot change locale (bogus)'
diff --git a/test/integration/test_async.yml b/test/integration/test_async.yml
new file mode 100644
index 0000000000..ec370d7c7f
--- /dev/null
+++ b/test/integration/test_async.yml
@@ -0,0 +1,10 @@
+- hosts: testhost3
+ gather_facts: false
+ tasks:
+ # make sure non-JSON data before module output is ignored
+ - name: async ping with invalid locale via ssh
+ ping:
+ async: 3
+ poll: 1
+ register: result
+ - debug: var=result
diff --git a/test/units/executor/test_task_executor.py b/test/units/executor/test_task_executor.py
index 87704e2188..101b8967d2 100644
--- a/test/units/executor/test_task_executor.py
+++ b/test/units/executor/test_task_executor.py
@@ -26,6 +26,7 @@ from ansible.errors import AnsibleError, AnsibleParserError
from ansible.executor.task_executor import TaskExecutor
from ansible.playbook.play_context import PlayContext
from ansible.plugins import action_loader, lookup_loader
+from ansible.parsing.yaml.objects import AnsibleUnicode
from units.mock.loader import DictDataLoader
@@ -355,6 +356,7 @@ class TestTaskExecutor(unittest.TestCase):
# here: on Python 2 comparing MagicMock() > 0 returns True, and the
# other reason is that if I specify 0 here, the test fails. ;)
mock_task.async = 1
+ mock_task.poll = 0
mock_play_context = MagicMock()
mock_play_context.post_validate.return_value = None
@@ -388,11 +390,11 @@ class TestTaskExecutor(unittest.TestCase):
mock_action.run.return_value = dict(ansible_facts=dict())
res = te._execute()
- mock_task.changed_when = "1 == 1"
+ mock_task.changed_when = MagicMock(return_value=AnsibleUnicode("1 == 1"))
res = te._execute()
mock_task.changed_when = None
- mock_task.failed_when = "1 == 1"
+ mock_task.failed_when = MagicMock(return_value=AnsibleUnicode("1 == 1"))
res = te._execute()
mock_task.failed_when = None