mirror of
https://github.com/ansible/awx.git
synced 2026-03-03 17:51:06 -03:30
pending vs. missing stdout message
This commit is contained in:
@@ -610,11 +610,15 @@ class UnifiedJob(PolymorphicModel, PasswordFieldsModel, CommonModelNameNotUnique
|
|||||||
"""Return a file-like object containing the standard out of the
|
"""Return a file-like object containing the standard out of the
|
||||||
job's result.
|
job's result.
|
||||||
"""
|
"""
|
||||||
|
msg = {
|
||||||
|
'pending': 'stdout capture pending',
|
||||||
|
'missing': 'stdout capture is missing',
|
||||||
|
}
|
||||||
if self.result_stdout_text:
|
if self.result_stdout_text:
|
||||||
return StringIO(self.result_stdout_text)
|
return StringIO(self.result_stdout_text)
|
||||||
else:
|
else:
|
||||||
if not os.path.exists(self.result_stdout_file):
|
if not os.path.exists(self.result_stdout_file):
|
||||||
return StringIO("stdout capture is missing")
|
return StringIO(msg['missing' if self.finished else 'pending'])
|
||||||
|
|
||||||
# There is a potential timing issue here, because another
|
# There is a potential timing issue here, because another
|
||||||
# process may be deleting the stdout file after it is written
|
# process may be deleting the stdout file after it is written
|
||||||
@@ -631,7 +635,7 @@ class UnifiedJob(PolymorphicModel, PasswordFieldsModel, CommonModelNameNotUnique
|
|||||||
self.result_stdout_text = type(self).objects.get(id=self.id).result_stdout_text
|
self.result_stdout_text = type(self).objects.get(id=self.id).result_stdout_text
|
||||||
return self.result_stdout_raw_handle(attempt=attempt + 1)
|
return self.result_stdout_raw_handle(attempt=attempt + 1)
|
||||||
else:
|
else:
|
||||||
return StringIO("stdout capture is missing")
|
return StringIO(msg['missing' if self.finished else 'pending'])
|
||||||
|
|
||||||
def _escape_ascii(self, content):
|
def _escape_ascii(self, content):
|
||||||
ansi_escape = re.compile(r'\x1b[^m]*m')
|
ansi_escape = re.compile(r'\x1b[^m]*m')
|
||||||
|
|||||||
@@ -17,3 +17,4 @@ from awx.main.tests.redact import * # noqa
|
|||||||
from awx.main.tests.views import * # noqa
|
from awx.main.tests.views import * # noqa
|
||||||
from awx.main.tests.commands import * # noqa
|
from awx.main.tests.commands import * # noqa
|
||||||
from awx.main.tests.fact import * # noqa
|
from awx.main.tests.fact import * # noqa
|
||||||
|
from awx.main.tests.unified_jobs import * # noqa
|
||||||
|
|||||||
53
awx/main/tests/unified_jobs.py
Normal file
53
awx/main/tests/unified_jobs.py
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
# Copyright (c) 2015 Ansible, Inc.
|
||||||
|
# All Rights Reserved
|
||||||
|
|
||||||
|
# Python
|
||||||
|
import mock
|
||||||
|
from StringIO import StringIO
|
||||||
|
from django.utils.timezone import now
|
||||||
|
|
||||||
|
# Django
|
||||||
|
from django.test import SimpleTestCase
|
||||||
|
|
||||||
|
# AWX
|
||||||
|
from awx.main.models import * # noqa
|
||||||
|
|
||||||
|
__all__ = ['UnifiedJobsUnitTest',]
|
||||||
|
|
||||||
|
class UnifiedJobsUnitTest(SimpleTestCase):
|
||||||
|
|
||||||
|
# stdout file present
|
||||||
|
@mock.patch('os.path.exists', return_value=True)
|
||||||
|
@mock.patch('codecs.open', return_value='my_file_handler')
|
||||||
|
def test_result_stdout_raw_handle_file__found(self, exists, open):
|
||||||
|
unified_job = UnifiedJob()
|
||||||
|
unified_job.result_stdout_file = 'dummy'
|
||||||
|
|
||||||
|
result = unified_job.result_stdout_raw_handle()
|
||||||
|
|
||||||
|
self.assertEqual(result, 'my_file_handler')
|
||||||
|
|
||||||
|
# stdout file missing, job finished
|
||||||
|
@mock.patch('os.path.exists', return_value=False)
|
||||||
|
def test_result_stdout_raw_handle__missing(self, exists):
|
||||||
|
unified_job = UnifiedJob()
|
||||||
|
unified_job.result_stdout_file = 'dummy'
|
||||||
|
unified_job.finished = now()
|
||||||
|
|
||||||
|
result = unified_job.result_stdout_raw_handle()
|
||||||
|
|
||||||
|
self.assertIsInstance(result, StringIO)
|
||||||
|
self.assertEqual(result.read(), 'stdout capture is missing')
|
||||||
|
|
||||||
|
# stdout file missing, job not finished
|
||||||
|
@mock.patch('os.path.exists', return_value=False)
|
||||||
|
def test_result_stdout_raw_handle__pending(self, exists):
|
||||||
|
unified_job = UnifiedJob()
|
||||||
|
unified_job.result_stdout_file = 'dummy'
|
||||||
|
unified_job.finished = None
|
||||||
|
|
||||||
|
result = unified_job.result_stdout_raw_handle()
|
||||||
|
|
||||||
|
self.assertIsInstance(result, StringIO)
|
||||||
|
self.assertEqual(result.read(), 'stdout capture pending')
|
||||||
|
|
||||||
Reference in New Issue
Block a user