Commit bdf2aa32 authored by Xavier Thompson's avatar Xavier Thompson

slap/standalone: Increase slapos error log size

The output of slapos commands has been observed to be truncated earlier
than desired in some cases due to long promise messages in output of
slapos node instance and long paths included in the logs.

See merge request nexedi/slapos.core!551
parent 9b3d044b
Pipeline #29030 failed with stage
in 0 seconds
...@@ -942,13 +942,15 @@ class StandaloneSlapOS(object): ...@@ -942,13 +942,15 @@ class StandaloneSlapOS(object):
if process_info['exitstatus'] == 0: if process_info['exitstatus'] == 0:
return return
if retry >= max_retry: if retry >= max_retry:
# get the last lines of output, at most `error_lines`. If # get the last lines of output, at most `error_lines`.
# these lines are long, the output may be truncated. getTail = supervisor.tailProcessStdoutLog
_, log_offset, _ = supervisor.tailProcessStdoutLog(command, 0, 0) output, size, overflow = getTail(command, 0, 2 << 15)
output, _, _ = supervisor.tailProcessStdoutLog( output_lines = output.splitlines()
command, log_offset - (2 << 13), 2 << 13) if overflow:
if error_lines == 0 or len(output_lines) < error_lines:
output_lines = getTail(command, 0, size)[0].splitlines()
raise SlapOSNodeCommandError({ raise SlapOSNodeCommandError({
'output': '\n'.join(output.splitlines()[-error_lines:]), 'output': '\n'.join(output_lines[-error_lines:]),
'exitstatus': process_info['exitstatus'], 'exitstatus': process_info['exitstatus'],
}) })
break break
......
...@@ -656,3 +656,35 @@ class TestSlapOSStandaloneInstance(SlapOSStandaloneTestCase): ...@@ -656,3 +656,35 @@ class TestSlapOSStandaloneInstance(SlapOSStandaloneTestCase):
self.assertEqual(set([True]), set([p.is_running() for p in process_list])) self.assertEqual(set([True]), set([p.is_running() for p in process_list]))
self.stopStandalone() self.stopStandalone()
self.assertEqual(set([False]), set([p.is_running() for p in process_list])) self.assertEqual(set([False]), set([p.is_running() for p in process_list]))
class TestSlapOSStandaloneLongSoftwareError(SlapOSStandaloneTestCase):
def test(self):
with tempfile.NamedTemporaryFile(suffix="-%s.cfg" % self.id()) as f:
very_long_string = "a" * (2 << 16)
software_url = f.name
f.write(
textwrap.dedent(
'''
[buildout]
parts = fail
newest = false
[fail]
recipe = plone.recipe.command==1.1
stop-on-error = true
command = echo %r && false
''' % very_long_string).encode())
f.flush()
self.standalone.supply(software_url)
# Not using assertRaises context manager for python2 compatibility
try:
self.standalone.waitForSoftware()
except SlapOSNodeSoftwareError as e:
self.assertIn(very_long_string, str(e))
except Exception as e:
self.fail("waitForSoftware raised unexpected exception %r" % e)
else:
self.fail("waitForSoftware should have raised")
\ No newline at end of file
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