Fix for https://github.com/salimfadhley/jenkinsapi/issues/53
authorSanteri Paavolainen <santeri.paavolainen@codento.com>
Tue, 23 Oct 2012 08:19:26 +0000 (11:19 +0300)
committerSanteri Paavolainen <santeri.paavolainen@codento.com>
Tue, 23 Oct 2012 08:43:54 +0000 (11:43 +0300)
Changed retry_function to return 404s directly, as in that
case we have reached the server, so it is not a network or internal
server error, redirect, proxy failure or anything like that.

Artifact.valid will consider the fingerprint valid if the
fingerprint is not available at server (but it can still exist, so
it cannot be claimed as invalid with certainty).

jenkinsapi/fingerprint.py
jenkinsapi/jenkinsbase.py
jenkinsapi/utils/retry.py

index 54abfab..6fef282 100644 (file)
@@ -30,11 +30,24 @@ class Fingerprint(JenkinsBase):
 
     def valid(self):
         """
-        Return True / False if valid
+        Return True / False if valid. If returns True, self.unknown is
+        set to either True or False, and can be checked if we have
+        positive validity (fingerprint known at server) or negative
+        validity (fingerprint not known at server, but not really an
+        error).
         """
         try:
             self.poll()
-        except urllib2.HTTPError:
+            self.unknown = False
+        except urllib2.HTTPError, e:
+            # We can't really say anything about the validity of
+            # fingerprints not found -- but the artifact can still
+            # exist, so it is not possible to definitely say they are
+            # valid or not.
+            if e.code == 404:
+                self.unknown = True
+                return True
+
             return False
         return True
 
@@ -42,6 +55,9 @@ class Fingerprint(JenkinsBase):
         if not self.valid():
             log.info("Unknown to jenkins.")
             return False
+        if self.unknown:
+            # not request error, but unknown to jenkins
+            return True
         if not self._data["original"] is None:
             if self._data["original"]["name"] == job:
                 if self._data["original"]["number"] == build:
index 7198a98..ca5c182 100644 (file)
@@ -68,6 +68,8 @@ class JenkinsBase(object):
             stream = fn_urlopen(url)
             result = eval(stream.read())
         except urllib2.HTTPError, e:
+            if e.code == 404:
+                raise
             log.warn("Error reading %s" % url)
             log.exception(e)
             raise
index 334d5c8..a9f1478 100644 (file)
@@ -1,5 +1,6 @@
 import logging
 import time
+import urllib2
 
 log = logging.getLogger( __name__ )
 
@@ -25,6 +26,11 @@ def retry_function( tries, fn, *args, **kwargs ):
             if attempt > 0:
                 log.info( "Result obtained after attempt %i" % attemptno )
             return result
+        except urllib2.HTTPError, e:
+            if e.code == 404:
+                raise
+
+            log.exception(e)
         except Exception, e:
             if type(e) in IGNORE_EXCEPTIONS:
                 # Immediatly raise in some cases.