[yocto] [[PATCH][error-report-web] 6/8] Post/{models, parser}.py: Add support for receive/store error_type.

Aníbal Limón anibal.limon at linux.intel.com
Mon Jun 13 16:32:14 PDT 2016


For compatibility reasons if error_type isn't specified in the JSON
payload use BuildErrorType.RECIPE by default.

[YOCTO #7584]

Signed-off-by: Aníbal Limón <anibal.limon at linux.intel.com>
---
 Post/models.py | 10 ++++++++++
 Post/parser.py | 11 +++++++++--
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/Post/models.py b/Post/models.py
index f8d9916..bec2abd 100644
--- a/Post/models.py
+++ b/Post/models.py
@@ -17,6 +17,16 @@ class BuildErrorType(object):
     BITBAKE_SELFTEST = "Bitbake selftest"
     OE_SELFTEST = "OE selftest"
 
+    @staticmethod
+    def is_supported(error_type):
+        if error_type == BuildErrorType.RECIPE or \
+                error_type == BuildErrorType.BITBAKE_CORE or \
+                error_type == BuildErrorType.BITBAKE_SELFTEST or \
+                error_type == BuildErrorType.OE_SELFTEST:
+            return True
+
+        return False
+
 # Create your models here.
 class Build(models.Model):
     DATE = models.DateTimeField('Submit date', blank=True, null=True)
diff --git a/Post/parser.py b/Post/parser.py
index 599afde..295870f 100644
--- a/Post/parser.py
+++ b/Post/parser.py
@@ -8,7 +8,7 @@
 # Licensed under the MIT license, see COPYING.MIT for details
 
 import json, re
-from Post.models import Build, BuildFailure
+from Post.models import Build, BuildFailure, BuildErrorType
 from django.conf import settings
 from django.utils import timezone
 from django.core.urlresolvers import reverse
@@ -40,6 +40,7 @@ class Parser:
         if self.contains_tags(jsondata) == True:
             return  { 'error' : 'Invalid characters in json' }
 
+        error_desc = ""
         b = Build.objects.create()
         try:
             b.MACHINE = str(jsondata['machine'])
@@ -53,6 +54,12 @@ class Parser:
             b.EMAIL = str(jsondata['email'])
             b.LINK_BACK = jsondata.get("link_back", None)
 
+            error_type = jsondata.get("error_type", None) or BuildErrorType.RECIPE
+            if not BuildErrorType.is_supported(error_type):
+                error_desc = "Unsupported error_type %s" % error_type
+                raise ""
+            b.ERROR_TYPE = error_type
+
             # Extract the branch and commit
             g = re.match(r'(.*): (.*)', jsondata['branch_commit'])
 
@@ -68,7 +75,7 @@ class Parser:
             b.save()
             failures = jsondata['failures']
         except:
-            return { 'error' : "Problem reading json payload" }
+            return { 'error' : "Problem reading json payload, %s" % error_desc }
 
         for fail in failures:
             if len(fail) > int(settings.MAX_UPLOAD_SIZE):
-- 
2.1.4




More information about the yocto mailing list