From 0db24a5c9780751dab0b380f0221ea86085e6968 Mon Sep 17 00:00:00 2001 From: Ryan Petrello Date: Wed, 4 Apr 2018 08:28:05 -0400 Subject: [PATCH] more gracefully account for undefined stdout see: https://github.com/ansible/tower/issues/1215 related: https://github.com/ansible/tower/pull/1192#issuecomment-377982131 --- awx/main/tasks.py | 1 + awx/main/tests/unit/test_tasks.py | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/awx/main/tasks.py b/awx/main/tasks.py index ff72647352..e3bb397f33 100644 --- a/awx/main/tasks.py +++ b/awx/main/tasks.py @@ -885,6 +885,7 @@ class BaseTask(LogErrorsTask): output_replacements = [] extra_update_fields = {} event_ct = 0 + stdout_handle = None try: kwargs['isolated'] = isolated_host is not None self.pre_run_hook(instance, **kwargs) diff --git a/awx/main/tests/unit/test_tasks.py b/awx/main/tests/unit/test_tasks.py index 6def112522..90023d9076 100644 --- a/awx/main/tests/unit/test_tasks.py +++ b/awx/main/tests/unit/test_tasks.py @@ -13,6 +13,7 @@ import fcntl import mock import pytest import yaml + from django.conf import settings @@ -295,6 +296,15 @@ class TestJobExecution: class TestGenericRun(TestJobExecution): + def test_generic_failure(self): + self.task.build_private_data_files = mock.Mock(side_effect=IOError()) + with pytest.raises(Exception): + self.task.run(self.pk) + update_model_call = self.task.update_model.call_args[1] + assert 'IOError' in update_model_call['result_traceback'] + assert update_model_call['status'] == 'error' + assert update_model_call['emitted_events'] == 0 + def test_cancel_flag(self): self.instance.cancel_flag = True with pytest.raises(Exception):