mirror of
https://github.com/ansible/awx.git
synced 2024-11-02 18:21:12 +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:
parent
9b49e80dc5
commit
b59d9b766f
@ -166,7 +166,7 @@ class BaseTask(Task):
|
|||||||
passwords when requested.
|
passwords when requested.
|
||||||
'''
|
'''
|
||||||
status, stdout = 'error', ''
|
status, stdout = 'error', ''
|
||||||
logfile = cStringIO.StringIO()
|
logfile = task_stdout_handle#cStringIO.StringIO()
|
||||||
logfile_pos = logfile.tell()
|
logfile_pos = logfile.tell()
|
||||||
child = pexpect.spawn(args[0], args[1:], cwd=cwd, env=env)
|
child = pexpect.spawn(args[0], args[1:], cwd=cwd, env=env)
|
||||||
child.logfile_read = logfile
|
child.logfile_read = logfile
|
||||||
@ -187,11 +187,11 @@ class BaseTask(Task):
|
|||||||
if result_id in expect_passwords:
|
if result_id in expect_passwords:
|
||||||
child.sendline(expect_passwords[result_id])
|
child.sendline(expect_passwords[result_id])
|
||||||
if logfile_pos != logfile.tell():
|
if logfile_pos != logfile.tell():
|
||||||
old_logfile_pos = logfile_pos
|
#old_logfile_pos = logfile_pos
|
||||||
logfile_pos = logfile.tell()
|
logfile_pos = logfile.tell()
|
||||||
#updates['result_stdout'] = logfile.getvalue()
|
#updates['result_stdout'] = logfile.getvalue()
|
||||||
task_stdout_handle.write(logfile.getvalue()[old_logfile_pos:logfile_pos])
|
#task_stdout_handle.write(logfile.getvalue()[old_logfile_pos:logfile_pos])
|
||||||
task_stdout_handle.flush()
|
#task_stdout_handle.flush()
|
||||||
last_stdout_update = time.time()
|
last_stdout_update = time.time()
|
||||||
instance = self.get_model(instance.pk)
|
instance = self.get_model(instance.pk)
|
||||||
# Commit transaction needed when running unit tests. FIXME: Is it
|
# Commit transaction needed when running unit tests. FIXME: Is it
|
||||||
@ -210,7 +210,7 @@ class BaseTask(Task):
|
|||||||
status = 'successful'
|
status = 'successful'
|
||||||
else:
|
else:
|
||||||
status = 'failed'
|
status = 'failed'
|
||||||
stdout = logfile.getvalue()
|
#stdout = logfile.getvalue()
|
||||||
return status, stdout
|
return status, stdout
|
||||||
|
|
||||||
def pre_run_check(self, instance, **kwargs):
|
def pre_run_check(self, instance, **kwargs):
|
||||||
@ -271,6 +271,8 @@ class BaseTask(Task):
|
|||||||
cwd = self.build_cwd(instance, **kwargs)
|
cwd = self.build_cwd(instance, **kwargs)
|
||||||
env = self.build_env(instance, **kwargs)
|
env = self.build_env(instance, **kwargs)
|
||||||
safe_env = self.build_safe_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_filename = os.path.join(settings.JOBOUTPUT_ROOT, str(uuid.uuid1()) + ".out")
|
||||||
stdout_handle = open(stdout_filename, 'w')
|
stdout_handle = open(stdout_filename, 'w')
|
||||||
instance = self.update_model(pk, job_args=json.dumps(safe_args),
|
instance = self.update_model(pk, job_args=json.dumps(safe_args),
|
||||||
|
@ -47,8 +47,10 @@ class BaseTestMixin(object):
|
|||||||
# commands that run from tests.
|
# commands that run from tests.
|
||||||
for opt in ('ENGINE', 'NAME', 'USER', 'PASSWORD', 'HOST', 'PORT'):
|
for opt in ('ENGINE', 'NAME', 'USER', 'PASSWORD', 'HOST', 'PORT'):
|
||||||
os.environ['AWX_TEST_DATABASE_%s' % opt] = settings.DATABASES['default'][opt]
|
os.environ['AWX_TEST_DATABASE_%s' % opt] = settings.DATABASES['default'][opt]
|
||||||
if not os.path.exists(settings.JOBOUTPUT_ROOT):
|
# Make temp job status directory for unit tests.
|
||||||
os.makedirs(settings.JOBOUTPUT_ROOT)
|
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):
|
def tearDown(self):
|
||||||
super(BaseTestMixin, self).tearDown()
|
super(BaseTestMixin, self).tearDown()
|
||||||
|
@ -83,8 +83,9 @@ MEDIA_URL = '/media/'
|
|||||||
# This directory should not be web-accessible.
|
# This directory should not be web-accessible.
|
||||||
PROJECTS_ROOT = os.path.join(BASE_DIR, 'projects')
|
PROJECTS_ROOT = os.path.join(BASE_DIR, 'projects')
|
||||||
|
|
||||||
# Absolute filesystem path to the directory to host job stdout
|
# Absolute filesystem path to the directory for job status stdout (default for
|
||||||
# This directory should not be web-accessible.
|
# 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')
|
JOBOUTPUT_ROOT = os.path.join(BASE_DIR, 'job_output')
|
||||||
|
|
||||||
SITE_ID = 1
|
SITE_ID = 1
|
||||||
|
Loading…
Reference in New Issue
Block a user