utils: capture and log phantomjs stderr (#32773)

This commit is contained in:
Frédéric Péters 2019-05-03 13:18:51 +02:00
parent df41dfa6a1
commit b5f323ff07
2 changed files with 5 additions and 4 deletions

View File

@ -37,7 +37,8 @@ def run(send_end, data, script):
os.path.join(settings.BASE_DIR, 'mandayejs', script)],
close_fds=True,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
stdout, stderr = phantom.communicate(json.dumps(data))
@ -49,7 +50,7 @@ def run(send_end, data, script):
result = json.loads(stdout)
except (ValueError,):
result = {"result": "json_error"}
logger.error("invalid json: %s" % stdout)
logger.error("invalid json: %s (stderr: %s)", stdout, stderr)
if result.get('stderr'):
logger.warning(result['stderr'])

View File

@ -100,7 +100,7 @@ def test_command_migrate_users(mocked_idps, command):
@mock.patch('mandayejs.mandaye.utils.subprocess.Popen')
@mock.patch('mandayejs.applications.Test.SITE_LOCATORS', MOCKED_SITE_LOCATORS)
def test_phantom_invalid_json(mocked_popen, caplog, user_john):
expected_output = ('This is not a valid JSON', None)
expected_output = ('This is not a valid JSON', 'msg on stderr')
mocked_popen.return_value = MockedPopen(expected_output=expected_output)
UserCredentials.objects.create(user=user_john,
@ -119,7 +119,7 @@ def test_phantom_invalid_json(mocked_popen, caplog, user_john):
for record in caplog.records:
if record.levelname == 'ERROR':
assert record.message == 'invalid json: This is not a valid JSON'
assert record.message == 'invalid json: This is not a valid JSON (stderr: msg on stderr)'
@mock.patch('mandayejs.mandaye.utils.subprocess.Popen')