Commit 80997f7e authored by Jérome Perrin's avatar Jérome Perrin

grid: output text for promise error when using SR python

Because we were reading subprocess output as bytes, the output in case
of promise errors was something like b'ERROR ...'

There was another problem writing string to an binary file in error path.
parent 36ecc00e
......@@ -64,5 +64,9 @@ os.dup2(2, 1)
try:
promise_checker.run()
except Exception as e:
os.write(out, str(e))
if sys.version_info < (3,):
error_str = unicode(str(e), 'utf-8', 'repr')
else:
error_str = str(e)
os.write(out, error_str.encode('utf-8', 'repr'))
sys.exit(2 if isinstance(e, PromiseError) else 1)
......@@ -730,6 +730,7 @@ stderr_logfile_backups=1
command,
preexec_fn=lambda: dropPrivileges(uid, gid, logger=self.logger),
cwd=instance_path,
universal_newlines=True,
stdout=subprocess.PIPE)
promises = plugins + len(listifdir(legacy_promise_dir))
# Add a timeout margin to let the process kill the promises and cleanup
......
......@@ -4173,6 +4173,26 @@ class TestSlapgridPluginPromiseWithInstancePython(TestSlapgridPromiseWithMaster)
super(TestSlapgridPluginPromiseWithInstancePython, self).tearDown()
self.assertEqual(self.expect_plugin, called)
def test_failed_promise_output(self):
computer = ComputerForTest(self.software_root, self.instance_root, 1, 1)
instance, = computer.instance_list
instance.requested_state = 'started'
instance.setPluginPromise(
"failing_promise_plugin.py",
promise_content="""if 1:
return self.logger.error("héhé fake promise plugin error")
""",
)
with httmock.HTTMock(computer.request_handler), \
patch.object(self.grid.logger, 'info',) as dummyLogger:
self.launchSlapgrid()
self.assertEqual(
dummyLogger.mock_calls[-1][1][0] % dummyLogger.mock_calls[-1][1][1:],
" 0[(not ready)]: Promise 'failing_promise_plugin.py' failed with output: héhé fake promise plugin error")
class TestSVCBackend(unittest.TestCase):
"""Tests for supervisor backend.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment