All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Aníbal Limón" <anibal.limon@linux.intel.com>
To: yocto@yoctoproject.org
Cc: joshua.g.lock@intel.com
Subject: [[yocto-autobuilder][PATCHv2] 03/15] lib/buildsteps: BitbakeShellCommand add support for create error reports
Date: Tue, 21 Jun 2016 18:07:40 -0500	[thread overview]
Message-ID: <1466550472-1365-4-git-send-email-anibal.limon@linux.intel.com> (raw)
In-Reply-To: <1466550472-1365-1-git-send-email-anibal.limon@linux.intel.com>

When bitbake command fails and isn't a recipe task failure then create
an error report and store into yocto-controller folder for be able to
transfer to the worker in order to send to the Error report web.

Signed-off-by: Aníbal Limón <anibal.limon@linux.intel.com>
---
 .../site-packages/autobuilder/lib/buildsteps.py    | 63 +++++++++++++++++++++-
 1 file changed, 62 insertions(+), 1 deletion(-)

diff --git a/lib/python2.7/site-packages/autobuilder/lib/buildsteps.py b/lib/python2.7/site-packages/autobuilder/lib/buildsteps.py
index 9822b3c..7354c83 100644
--- a/lib/python2.7/site-packages/autobuilder/lib/buildsteps.py
+++ b/lib/python2.7/site-packages/autobuilder/lib/buildsteps.py
@@ -13,9 +13,15 @@ __email__ = "anibal.limon@linux.intel.com"
 import os
 import re
 
+import time
+import json
+import codecs
+
 from buildbot.steps.shell import ShellCommand
 from buildbot.process.buildstep import LogLineObserver
 
+from autobuilder.config import YOCTO_ABBASE
+
 DEFAULT_SHELL = 'bash'
 
 class ShellCommandCleanEnv(ShellCommand):
@@ -86,6 +92,12 @@ class BitbakeLogLineObserver(LogLineObserver):
     def errLineReceived(self, line):
         self._handleError(line)
 
+def get_error_report_bitbake_dir(buildername, buildnumber):
+    errordir_base = os.path.join(YOCTO_ABBASE, 'yocto-controller', buildername,
+            'error-report')
+    errordir = os.path.join(errordir_base, str(buildnumber))
+    return errordir
+
 class BitbakeShellCommand(ShellCommand):
     def __init__(self, factory, argdict=None, **kwargs):
         super(BitbakeShellCommand, self).__init__(**kwargs)
@@ -93,6 +105,55 @@ class BitbakeShellCommand(ShellCommand):
         self.stdio_observer = BitbakeLogLineObserver()
         self.addLogObserver('stdio', self.stdio_observer)
 
+    def _get_variables(self, log):
+        vrs = {}
+
+        rexp = re.compile("^(.*)=.*\"(.*)\"$")
+        for line in log:
+            m = rexp.match(line)
+            if m:
+                vrs[m.group(1).rstrip()] = m.group(2)
+
+        return vrs
+
+    def _createBitbakeErrorReport(self, log):
+        vrs = self._get_variables(log)
+
+        report = {}
+        report['machine'] = vrs['MACHINE']
+        report['build_sys'] = vrs['BUILD_SYS']
+        report['nativelsb'] = vrs['NATIVELSBSTRING']
+        report['distro'] = vrs['DISTRO']
+        report['target_sys'] = vrs['TARGET_SYS']
+
+        report['component'] = 'bitbake'
+        report['branch_commit'] = self.getProperty('branch') + ': ' + \
+                self.getProperty('got_revision')
+
+        failure = {}
+        failure['package'] = "bitbake-%s" % vrs['BB_VERSION']
+        failure['task'] = self.command
+        failure['log'] = "\n".join(log)
+
+        report['failures'] = [failure]
+
+        return report
+
+    def _saveBitbakeErrorReport(self, report):
+        buildername = self.getProperty('buildername')
+        buildnumber = self.getProperty('buildnumber')
+
+        errordir = get_error_report_bitbake_dir(buildername, buildnumber)
+        if not os.path.exists(errordir):
+            os.makedirs(errordir)
+
+        filename = os.path.join(errordir, "error_report_bitbake_%d.txt" % \
+                int(time.time()))
+        with codecs.open(filename, 'w', 'utf-8') as f:
+            json.dump(report, f, indent=4, sort_keys=True)
+
     def commandComplete(self, cmd):
         if cmd.didFail():
-            pass
+            if self.errors['bitbake']:
+                report = self._createBitbakeErrorReport(self.errors['log'])
+                self._saveBitbakeErrorReport(report)
-- 
2.1.4



  parent reply	other threads:[~2016-06-21 23:08 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-21 23:07 [[yocto-autobuilder][PATCHv2] 00/15] Add support for generate bitbake/oe-selftest error reports Aníbal Limón
2016-06-21 23:07 ` [[yocto-autobuilder][PATCHv2] 01/15] lib/buildsteps.py: Add BitbakeShellCommand class Aníbal Limón
2016-06-21 23:07 ` [[yocto-autobuilder][PATCHv2] 02/15] lib/buildsteps.py: Add BitbakeLogLineObserver for BitbakeShellCommands Aníbal Limón
2016-06-21 23:07 ` Aníbal Limón [this message]
2016-06-21 23:07 ` [[yocto-autobuilder][PATCHv2] 04/15] lib/ABTools: Add functions for get errordir path in controller and worker Aníbal Limón
2016-06-21 23:07 ` [[yocto-autobuilder][PATCHv2] 05/15] buildbot: Add support for DirectoryDownload transfer step Aníbal Limón
2016-06-21 23:07 ` [[yocto-autobuilder][PATCHv2] 06/15] autobuilder/buildsteps: Add DownloadBitbakeErrorReports step Aníbal Limón
2016-06-21 23:07 ` [[yocto-autobuilder][PATCHv2] 07/15] buiidsets: Add DownloadBitbakeErrorReport step Aníbal Limón
2016-06-21 23:07 ` [[yocto-autobuilder][PATCHv2] 08/15] lib/buildsteps.py: BitbakeShellCommand add support for error_type Aníbal Limón
2016-06-21 23:07 ` [[yocto-autobuilder][PATCHv2] 09/15] autobuilder/lib/buildsteps.py: BitbakeShellCommand update error report types Aníbal Limón
2016-06-21 23:07 ` [[yocto-autobuilder][PATCHv2] 10/15] autobuilder/lib/{ABtools, builsteps}.py: Create save_error_report func Aníbal Limón
2016-06-21 23:07 ` [[yocto-autobuilder][PATCHv2] 11/15] autobuilder/lib/ABTools.py: Add get_lsb_distro function Aníbal Limón
2016-06-21 23:07 ` [[yocto-autobuilder][PATCHv2] 12/15] buildsteps/RunOeSelftest.py: Add support for create/save error reports Aníbal Limón
2016-06-21 23:07 ` [[yocto-autobuilder][PATCHv2] 13/15] nightly-oe-selftest.conf: Add steps for Download and Send error report Aníbal Limón
2016-06-21 23:07 ` [[yocto-autobuilder][PATCHv2] 14/15] autobuilder/buildsteps: Rename DownloadBitbakeErrorReports to DownloadErrorReports Aníbal Limón
2016-06-21 23:07 ` [[yocto-autobuilder][PATCHv2] 15/15] buildset-config: Update references from " Aníbal Limón
2016-06-22  7:44 ` [[yocto-autobuilder][PATCHv2] 00/15] Add support for generate bitbake/oe-selftest error reports Beth 'pidge' Flanagan
2016-06-22 20:17   ` Aníbal Limón
2016-06-23 15:27     ` Aníbal Limón
2016-06-23 15:35       ` Beth 'pidge' Flanagan
2016-06-27 12:28 ` Beth 'pidge' Flanagan
2016-06-28 14:55   ` Aníbal Limón

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1466550472-1365-4-git-send-email-anibal.limon@linux.intel.com \
    --to=anibal.limon@linux.intel.com \
    --cc=joshua.g.lock@intel.com \
    --cc=yocto@yoctoproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.