mirror of
https://github.com/ansible/awx.git
synced 2024-11-01 08:21:15 +03:00
Fix UnicodeDecodeError from pexpect when ansible-playbook output contains unicode.
This commit is contained in:
parent
074b882714
commit
20d76bfc91
@ -2,6 +2,7 @@
|
|||||||
# All Rights Reserved.
|
# All Rights Reserved.
|
||||||
|
|
||||||
# Python
|
# Python
|
||||||
|
import codecs
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
@ -506,7 +507,7 @@ class UnifiedJob(PolymorphicModel, PasswordFieldsModel, CommonModelNameNotUnique
|
|||||||
if self.result_stdout_file != "":
|
if self.result_stdout_file != "":
|
||||||
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("stdout capture is missing")
|
||||||
return open(self.result_stdout_file, "r")
|
return codecs.open(self.result_stdout_file, "r", encoding='utf-8')
|
||||||
else:
|
else:
|
||||||
return StringIO(self.result_stdout_text)
|
return StringIO(self.result_stdout_text)
|
||||||
|
|
||||||
@ -520,7 +521,7 @@ class UnifiedJob(PolymorphicModel, PasswordFieldsModel, CommonModelNameNotUnique
|
|||||||
return ansi_escape.sub('', self.result_stdout_raw)
|
return ansi_escape.sub('', self.result_stdout_raw)
|
||||||
|
|
||||||
def result_stdout_raw_limited(self, start_line=0, end_line=None):
|
def result_stdout_raw_limited(self, start_line=0, end_line=None):
|
||||||
return_buffer = ""
|
return_buffer = u""
|
||||||
if end_line is not None:
|
if end_line is not None:
|
||||||
end_line = int(end_line)
|
end_line = int(end_line)
|
||||||
stdout_lines = self.result_stdout_raw_handle().readlines()
|
stdout_lines = self.result_stdout_raw_handle().readlines()
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
# All Rights Reserved.
|
# All Rights Reserved.
|
||||||
|
|
||||||
# Python
|
# Python
|
||||||
|
import codecs
|
||||||
import ConfigParser
|
import ConfigParser
|
||||||
import cStringIO
|
import cStringIO
|
||||||
from distutils.version import StrictVersion as Version
|
from distutils.version import StrictVersion as Version
|
||||||
@ -388,7 +389,7 @@ class BaseTask(Task):
|
|||||||
if not os.path.exists(settings.JOBOUTPUT_ROOT):
|
if not os.path.exists(settings.JOBOUTPUT_ROOT):
|
||||||
os.makedirs(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 = codecs.open(stdout_filename, 'w', encoding='utf-8')
|
||||||
instance = self.update_model(pk, job_args=json.dumps(safe_args),
|
instance = self.update_model(pk, job_args=json.dumps(safe_args),
|
||||||
job_cwd=cwd, job_env=safe_env, result_stdout_file=stdout_filename)
|
job_cwd=cwd, job_env=safe_env, result_stdout_file=stdout_filename)
|
||||||
status = self.run_pexpect(instance, args, cwd, env, kwargs['passwords'], stdout_handle)
|
status = self.run_pexpect(instance, args, cwd, env, kwargs['passwords'], stdout_handle)
|
||||||
|
@ -180,7 +180,7 @@ class BaseTestMixin(object):
|
|||||||
handle, playbook_path = tempfile.mkstemp(suffix='.yml',
|
handle, playbook_path = tempfile.mkstemp(suffix='.yml',
|
||||||
dir=project_dir)
|
dir=project_dir)
|
||||||
test_playbook_file = os.fdopen(handle, 'w')
|
test_playbook_file = os.fdopen(handle, 'w')
|
||||||
test_playbook_file.write(playbook_content)
|
test_playbook_file.write(playbook_content.encode('utf-8'))
|
||||||
test_playbook_file.close()
|
test_playbook_file.close()
|
||||||
# Role playbooks are specified as a dict of role name and the
|
# Role playbooks are specified as a dict of role name and the
|
||||||
# content of tasks/main.yml playbook.
|
# content of tasks/main.yml playbook.
|
||||||
|
@ -20,12 +20,12 @@ from awx.main.models import *
|
|||||||
from awx.main.tests.base import BaseLiveServerTest
|
from awx.main.tests.base import BaseLiveServerTest
|
||||||
from awx.main.tasks import RunJob
|
from awx.main.tasks import RunJob
|
||||||
|
|
||||||
TEST_PLAYBOOK = '''
|
TEST_PLAYBOOK = u'''
|
||||||
- name: test success
|
- name: test success
|
||||||
hosts: test-group
|
hosts: test-group
|
||||||
gather_facts: False
|
gather_facts: False
|
||||||
tasks:
|
tasks:
|
||||||
- name: should pass
|
- name: should pass \u2623
|
||||||
command: test 1 = 1
|
command: test 1 = 1
|
||||||
- name: should also pass
|
- name: should also pass
|
||||||
command: test 2 = 2
|
command: test 2 = 2
|
||||||
@ -329,13 +329,13 @@ class RunJobTest(BaseCeleryTest):
|
|||||||
|
|
||||||
def check_job_result(self, job, expected='successful', expect_stdout=True,
|
def check_job_result(self, job, expected='successful', expect_stdout=True,
|
||||||
expect_traceback=False):
|
expect_traceback=False):
|
||||||
msg = 'job status is %s, expected %s' % (job.status, expected)
|
msg = u'job status is %s, expected %s' % (job.status, expected)
|
||||||
msg = '%s\nargs:\n%s' % (msg, job.job_args)
|
msg = u'%s\nargs:\n%s' % (msg, job.job_args)
|
||||||
msg = '%s\nenv:\n%s' % (msg, job.job_env)
|
msg = u'%s\nenv:\n%s' % (msg, job.job_env)
|
||||||
if job.result_traceback:
|
if job.result_traceback:
|
||||||
msg = '%s\ngot traceback:\n%s' % (msg, job.result_traceback)
|
msg = u'%s\ngot traceback:\n%s' % (msg, job.result_traceback)
|
||||||
if job.result_stdout:
|
if job.result_stdout:
|
||||||
msg = '%s\ngot stdout:\n%s' % (msg, job.result_stdout)
|
msg = u'%s\ngot stdout:\n%s' % (msg, job.result_stdout)
|
||||||
if isinstance(expected, (list, tuple)):
|
if isinstance(expected, (list, tuple)):
|
||||||
self.assertTrue(job.status in expected)
|
self.assertTrue(job.status in expected)
|
||||||
else:
|
else:
|
||||||
@ -344,13 +344,13 @@ class RunJobTest(BaseCeleryTest):
|
|||||||
self.assertTrue(job.result_stdout)
|
self.assertTrue(job.result_stdout)
|
||||||
else:
|
else:
|
||||||
self.assertFalse(job.result_stdout,
|
self.assertFalse(job.result_stdout,
|
||||||
'expected no stdout, got:\n%s' %
|
u'expected no stdout, got:\n%s' %
|
||||||
job.result_stdout)
|
job.result_stdout)
|
||||||
if expect_traceback:
|
if expect_traceback:
|
||||||
self.assertTrue(job.result_traceback)
|
self.assertTrue(job.result_traceback)
|
||||||
else:
|
else:
|
||||||
self.assertFalse(job.result_traceback,
|
self.assertFalse(job.result_traceback,
|
||||||
'expected no traceback, got:\n%s' %
|
u'expected no traceback, got:\n%s' %
|
||||||
job.result_traceback)
|
job.result_traceback)
|
||||||
|
|
||||||
def check_job_events(self, job, runner_status='ok', plays=1, tasks=1,
|
def check_job_events(self, job, runner_status='ok', plays=1, tasks=1,
|
||||||
|
Loading…
Reference in New Issue
Block a user