Skip to contentSkip to conversation

oeqa.utils.commands: limit runCmd exception output

PATCH New Markus Lehtonen 1 participant 2 messages Mar 24, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 oeqa.utils.commands: limit runCmd exception output

Make it possible to limit the length of output lines shown in runCmd exceptions. E.g when running bitbake we easily get thousands of lines of log output, where only the last few (tens) are interesting or relevant when an error occurs.

---
 meta/lib/oeqa/utils/commands.py | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
meta/lib/oeqa/utils/commands.py +10 -3
index 82c5908..6901f1a 100644
@@ -97,7 +97,8 @@ class Result(object):
     pass
 
 
-def runCmd(command, ignore_status=False, timeout=None, assert_error=True, native_sysroot=None, **options):
+def runCmd(command, ignore_status=False, timeout=None, assert_error=True,
+          native_sysroot=None, limit_exc_output=0, **options):
     result = Result()
 
     if native_sysroot:
@@ -117,10 +118,16 @@ def runCmd(command, ignore_status=False, timeout=None, assert_error=True, native
     result.pid = cmd.process.pid
 
     if result.status and not ignore_status:
+        exc_output = result.output
+        if limit_exc_output > 0:
+            split = result.output.splitlines()
+            if len(split) > limit_exc_output:
+                exc_output = "\n... (last %d lines of output)\n" % limit_exc_output + \
+                             '\n'.join(split[-limit_exc_output:])
         if assert_error:
-            raise AssertionError("Command '%s' returned non-zero exit status %d:\n%s" % (command, result.status, result.output))
+            raise AssertionError("Command '%s' returned non-zero exit status %d:\n%s" % (command, result.status, exc_output))
         else:
-            raise CommandError(result.status, command, result.output)
+            raise CommandError(result.status, command, exc_output)
 
     return result
 
Signature · 1 line
2.10.2
#1 lore raw

PATCH 2/2 oeqa.buildperf: limit the length of error output

Limit the length of error logs to 40 lines. We don't need to show/archive thousands of lines of bitbake logs if an error occurs.

---
 meta/lib/oeqa/buildperf/base.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
meta/lib/oeqa/buildperf/base.py +1 -1
index dd473a0..e9a53dc 100644
@@ -35,7 +35,7 @@ log = logging.getLogger('build-perf')
 
 # Our own version of runCmd which does not raise AssertErrors which would cause
 # errors to interpreted as failures
-runCmd2 = partial(runCmd, assert_error=False)
+runCmd2 = partial(runCmd, assert_error=False, limit_exc_output=40)
 
 
 class KernelDropCaches(object):
Signature · 1 line
2.10.2