Commit 3a62e218 authored by Jérome Perrin's avatar Jérome Perrin

standalone: strip ansi codes in logs

This fixes a bug when the program output contain some ansi code, like
the \e[0;31m ansi code to display text in color on the terminal. These
characters are not allowed in XML so if they end up in the XML-RPC
messages this cause the underlying expat library to complain that the
stream is not well-formed (invalid token).

Fortunately, supervisor supports this and has a `strip_ansi` option that
we can set in the config to prevent these problems.
parent 006a4925
...@@ -147,6 +147,7 @@ class SupervisorConfigWriter(ConfigWriter): ...@@ -147,6 +147,7 @@ class SupervisorConfigWriter(ConfigWriter):
logfile = {standalone_slapos._supervisor_log} logfile = {standalone_slapos._supervisor_log}
pidfile = {standalone_slapos._supervisor_pid} pidfile = {standalone_slapos._supervisor_pid}
childlogdir = {standalone_slapos._log_directory} childlogdir = {standalone_slapos._log_directory}
strip_ansi = true
[rpcinterface:supervisor] [rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
......
...@@ -424,6 +424,28 @@ class TestSlapOSStandaloneSoftware(SlapOSStandaloneTestCase): ...@@ -424,6 +424,28 @@ class TestSlapOSStandaloneSoftware(SlapOSStandaloneTestCase):
str(e.exception)) str(e.exception))
self.assertNotIn(r"\n", str(e.exception)) self.assertNotIn(r"\n", str(e.exception))
def test_install_software_failure_log_with_ansi_codes(self):
with tempfile.NamedTemporaryFile(suffix="-%s.cfg" % self.id()) as f:
f.write(
textwrap.dedent(
r'''
[buildout]
parts = error
newest = false
[error]
recipe = plone.recipe.command==1.1
command = bash -c "echo -e '\033[0;31mRed\033[0m \033[0;32mGreen\033[0m \033[0;34mBlue\033[0m' ; exit 123"
stop-on-error = true
''').encode())
f.flush()
self.standalone.supply(f.name)
with self.assertRaises(SlapOSNodeSoftwareError) as e:
self.standalone.waitForSoftware()
self.assertEqual(1, e.exception.args[0]['exitstatus'])
self.assertIn("Red Green Blue", e.exception.args[0]['output'])
class TestSlapOSStandaloneInstance(SlapOSStandaloneTestCase): class TestSlapOSStandaloneInstance(SlapOSStandaloneTestCase):
_auto_stop_standalone = False # we stop explicitly _auto_stop_standalone = False # we stop explicitly
......
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