Propagate exceptions during submit
authorJonathan Griffin <jgriffin@mozilla.com>
Thu, 12 May 2011 12:07:39 -0700
changeset 25 40fd052d2432292e6cad97bce509f4c99e27c6f2
parent 24 02743764c800434af13452654bf5511c95e93031
child 26 222935a2a23a04d927ea6272b018f1924cb8638d
push id26
push userjgriffin@mozilla.com
push dateThu, 12 May 2011 19:07:53 +0000
Propagate exceptions during submit
mozautoeslib/autolog.py
--- a/mozautoeslib/autolog.py
+++ b/mozautoeslib/autolog.py
@@ -1,19 +1,21 @@
 import calendar
 import datetime
 import json
 import re
 import socket
 import urllib2
+import weakref
 
 from mozautoeslib import ESLib
 
 
 class AutologProduct(object):
+  """Class which represents a product, e.g., Firefox"""
 
   def __init__(self, tree=None, revision=None, branch=None,
                buildtype=None, buildid=None, version=None,
                buildurl=None, productname=None):
     self.tree = tree
     self.revision = revision
     self.branch = branch
     self.buildtype = buildtype
@@ -31,16 +33,17 @@ class AutologProduct(object):
       'buildtype': self.buildtype,
       'buildid': self.buildid,
       'version': self.version,
       'buildurl': self.buildurl,
     })
 
 
 class AutologTestFailure(object):
+  """Class which represents a test failure in autolog"""
 
   def __init__(self, test=None, logurl=None, testgroup_id=None,
                testsuite_id=None, id=None,
                duration=None, **kwargs):
     self.test = test
     self.logurl = logurl
     self.testgroup_id = testgroup_id
     self.testsuite_id = testsuite_id
@@ -67,16 +70,17 @@ class AutologTestFailure(object):
       testfailure.update({ 'duration': self.duration })
 
     if self.id:
       testfailure.update({ 'testfailure_id': self.id })
 
     return testfailure
 
 class AutologTestSuite(object):
+  """Class which represents a test suite in autolog"""
 
   def __init__(self, cmdline=None, testsuite=None, passed=0,
                failed=0, todo=0, elapsedtime=None, testgroup_id=None,
                id=None):
     self.testgroup_id = testgroup_id
     self.testfailures = []
     self.id = id
     self.cmdline = cmdline
@@ -101,22 +105,25 @@ class AutologTestSuite(object):
 
     if self.id:
       testsuite.update({ 'testsuite_id': self.id })
 
     return testsuite
 
 
 class AutologTestGroup(object):
+  """Class which represents a test group in autolog"""
 
   def __init__(self, harness=None, testgroup=None, server=None, machine=None,
                starttime=None, logurl=None, platform=None,
                os=None, testrun=None, pending=False, index='autolog',
                doc_types=None, builder=None, id=None, errors=None,
                restserver=None):
+    self._logs = []
+
     # make sure server names are str, not unicode
     self.server = str(server) if server else 'elasticsearch1.metrics.sjc1.mozilla.com:9200'
     self.restserver = str(restserver) if restserver else 'http://brasstacks.mozilla.com/autologserver/'
 
     self.testsuites = []
     self.total_test_failures = 0
     self.id = id
     self.harness = harness
@@ -341,22 +348,19 @@ class AutologTestGroup(object):
       data['testsuites'].append(testsuite._to_json())
       data['testsuites'][-1]['testfailures'] = []
 
       for testfailure in testsuite.testfailures:
         data['testsuites'][-1]['testfailures'].append(testfailure._to_json())
 
     # make the HTTP POST
     host = "%s/addtestgroup" % self.restserver
-    try:
-      req = urllib2.Request(host, json.dumps(data), {'content-type': 'application/json'})
-      response_stream = urllib2.urlopen(req)
-      response = json.loads(response_stream.read())
-    except:
-      return
+    req = urllib2.Request(host, json.dumps(data), {'content-type': 'application/json'})
+    response_stream = urllib2.urlopen(req)
+    response = json.loads(response_stream.read())
 
     # Retrieve the testrun, testgroup_id, and testsuite_id's from the
     # HTTP response JSON, and update the related objects with them.
     if response.get('testgroup_id'):
       self.id = response.get('testgroup_id')
       self.testrun = response.get('testrun')
       idx = 0
       for testsuite in self.testsuites:
@@ -453,8 +457,15 @@ class AutologTestGroup(object):
         id=id,
         duration=duration,
         **kwargs
       ))
 
     self.dirty = True
     testsuite.dirty = True
 
+  def _add_log(self, proxy, logfile):
+    self._logs.append((proxy, logfile))
+
+  def add_log(self, logfile):
+    """Adds the specified logfile to this testgroup"""
+
+    self._add_log(weakref.proxy(self), logfile)