Workarounded osc bug by retrying to call it 3 times.
authorEd Bartosh <eduard.bartosh@intel.com>
Thu, 23 Aug 2012 14:29:42 +0000 (17:29 +0300)
committerEd Bartosh <eduard.bartosh@intel.com>
Tue, 28 Aug 2012 11:28:15 +0000 (14:28 +0300)
Sometimes core.http_GET returns empty responce, which leeds to
core.ET.ParseError: no element found: line 1, column 0. Trying to send
request again solves the problem in most of the cases.

Fixes #252

Change-Id: I9b418393110464abf2f698136fe36e4c3dddfba3

gitbuildsys/oscapi.py

index 785d81593715dde88659e19c301ff71db6c2b51d..4eb4fbe9cf7226bb9f4bcd2dc0170e7a8def0f6f 100644 (file)
@@ -68,11 +68,21 @@ class OSC(object):
     @staticmethod
     def core_http(method, url, data=None, filep=None):
         """Wrapper above core.<http_METHOD> to catch exceptions."""
-        try:
-            return method(url, data=data, file=filep)
-        except (urllib2.URLError, M2Crypto.m2urllib2.URLError,
-                M2Crypto.SSL.SSLError, ssl.SSLError), err:
-            raise OSCError(str(err))
+
+        # Workarounded osc bug. http_GET sometimes returns empty responce
+        # Usually next try succeeds, so let's try 3 times
+        for count in (1, 2, 3):
+            try:
+                result = method(url, data=data, file=filep)
+            except (urllib2.URLError, M2Crypto.m2urllib2.URLError,
+                    M2Crypto.SSL.SSLError, ssl.SSLError), err:
+                if count == 3:
+                    raise OSCError(str(err))
+            if result:
+                return result
+
+        raise OSCError('Got empty responce from %s %s' % \
+                       (method.func_name.split('_')[-1], url))
 
     def copy_project(self, src, target, rewrite=False):
         """
@@ -189,8 +199,14 @@ class OSC(object):
         """
         if not fnames:
             url = core.makeurl(self.apiurl, ['source', prj, pkg])
+            try:
+                responce = self.core_http(core.http_GET, url).read()
+            except OSCError, err:
+                raise ObsError("can't get list of sources from"\
+                               " %s/%s: %s" % (prj, pkg, err))
+
             fnames = [entry.get('name') for entry in \
-                      core.ET.fromstring(core.http_GET(url).read())]
+                                            core.ET.fromstring(responce)]
         for fname in fnames:
             query = 'rev=upload'
             url = core.makeurl(self.apiurl,