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

Paolo Bonzini posted 1 patch 4 weeks ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/patchew next tags/patchew/20190124072804.9622-3-pbonzini@redhat.com
patchew-cli | 35 ++++++++++++++++++++++++++---------
1 file changed, 26 insertions(+), 9 deletions(-)

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

Posted by Paolo Bonzini 4 weeks ago
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@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

_______________________________________________
Patchew-devel mailing list
Patchew-devel@redhat.com
https://www.redhat.com/mailman/listinfo/patchew-devel