1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-02 09:51:09 +03:00

AC-620 Updates to tests to create temp job output root, update tasks to write to stdout file directly instead of storing any stdout in memory.

This commit is contained in:
Chris Church 2013-11-21 17:41:51 -05:00
parent 9b49e80dc5
commit b59d9b766f
3 changed files with 14 additions and 9 deletions

View File

@ -166,7 +166,7 @@ class BaseTask(Task):
passwords when requested.
'''
status, stdout = 'error', ''
logfile = cStringIO.StringIO()
logfile = task_stdout_handle#cStringIO.StringIO()
logfile_pos = logfile.tell()
child = pexpect.spawn(args[0], args[1:], cwd=cwd, env=env)
child.logfile_read = logfile
@ -187,11 +187,11 @@ class BaseTask(Task):
if result_id in expect_passwords:
child.sendline(expect_passwords[result_id])
if logfile_pos != logfile.tell():
old_logfile_pos = logfile_pos
#old_logfile_pos = logfile_pos
logfile_pos = logfile.tell()
#updates['result_stdout'] = logfile.getvalue()
task_stdout_handle.write(logfile.getvalue()[old_logfile_pos:logfile_pos])
task_stdout_handle.flush()
#task_stdout_handle.write(logfile.getvalue()[old_logfile_pos:logfile_pos])
#task_stdout_handle.flush()
last_stdout_update = time.time()
instance = self.get_model(instance.pk)
# Commit transaction needed when running unit tests. FIXME: Is it
@ -210,7 +210,7 @@ class BaseTask(Task):
status = 'successful'
else:
status = 'failed'
stdout = logfile.getvalue()
#stdout = logfile.getvalue()
return status, stdout
def pre_run_check(self, instance, **kwargs):
@ -271,6 +271,8 @@ class BaseTask(Task):
cwd = self.build_cwd(instance, **kwargs)
env = self.build_env(instance, **kwargs)
safe_env = self.build_safe_env(instance, **kwargs)
if not os.path.exists(settings.JOBOUTPUT_ROOT):
os.makedirs(settings.JOBOUTPUT_ROOT)
stdout_filename = os.path.join(settings.JOBOUTPUT_ROOT, str(uuid.uuid1()) + ".out")
stdout_handle = open(stdout_filename, 'w')
instance = self.update_model(pk, job_args=json.dumps(safe_args),

View File

@ -47,8 +47,10 @@ class BaseTestMixin(object):
# commands that run from tests.
for opt in ('ENGINE', 'NAME', 'USER', 'PASSWORD', 'HOST', 'PORT'):
os.environ['AWX_TEST_DATABASE_%s' % opt] = settings.DATABASES['default'][opt]
if not os.path.exists(settings.JOBOUTPUT_ROOT):
os.makedirs(settings.JOBOUTPUT_ROOT)
# Make temp job status directory for unit tests.
job_status_dir = tempfile.mkdtemp()
self._temp_project_dirs.append(job_status_dir)
settings.JOBOUTPUT_ROOT = os.path.abspath(job_status_dir)
def tearDown(self):
super(BaseTestMixin, self).tearDown()

View File

@ -83,8 +83,9 @@ MEDIA_URL = '/media/'
# This directory should not be web-accessible.
PROJECTS_ROOT = os.path.join(BASE_DIR, 'projects')
# Absolute filesystem path to the directory to host job stdout
# This directory should not be web-accessible.
# Absolute filesystem path to the directory for job status stdout (default for
# development and tests, default for production defined in production.py). This
# directory should not be web-accessible
JOBOUTPUT_ROOT = os.path.join(BASE_DIR, 'job_output')
SITE_ID = 1