[Patchew-devel] [PATCH] patchew-tester: truncate logs if they are too large

Paolo Bonzini pbonzini at redhat.com
Thu Jan 24 07:28:04 UTC 2019


If the logs are too large for the server, the tester loops forever on the same test.
Instead, trap 413 errors (request entity too large) and truncate the log to a smaller
amount of data.

Signed-off-by: Paolo Bonzini <pbonzini at redhat.com>
---
 patchew-cli | 35 ++++++++++++++++++++++++++---------
 1 file changed, 26 insertions(+), 9 deletions(-)

diff --git a/patchew-cli b/patchew-cli
index 430dbe3..b2d0bbb 100755
--- a/patchew-cli
+++ b/patchew-cli
@@ -577,15 +577,32 @@ class TesterCommand(SubCommand):
                     log = "N/A. Internal error while reading log file\n"
                 print("  Result:", "Passed" if passed else "Failed")
                 logging.debug(log)
-                self.api_do("testing-report", project=r["project"],
-                                              identity=r["identity"],
-                                              test=r["test"]["name"],
-                                              tester=name,
-                                              head=r["head"],
-                                              base=r["base"],
-                                              passed=passed,
-                                              log=log,
-                                              is_timeout=is_timeout)
+                max_size = 100000000
+                prefixed = False
+                orig_log_size = len(log)
+                while max_size > 100000:
+                    try:
+                        self.api_do("testing-report", project=r["project"],
+                                                      identity=r["identity"],
+                                                      test=r["test"]["name"],
+                                                      tester=name,
+                                                      head=r["head"],
+                                                      base=r["base"],
+                                                      passed=passed,
+                                                      log=log,
+                                                      is_timeout=is_timeout)
+                    except error.HTTPError as e:
+                        if e.code != 413:
+                            raise e
+                        if not prefixed:
+                            prefixed = True
+                            log = 'WARNING: Log truncated!\n\n' + log
+                        log = log[:max_size]
+                        max_size = max_size / 10
+                    else:
+                        break
+                if prefixed:
+                    print("Log truncated from %d to %d bytes" % {orig_log_size, len(log)})
                 logf.close()
             finally:
                 if not no_clean_up:
-- 
2.20.1




More information about the Patchew-devel mailing list