4400 Remove redundant transport error handling logic
authorjohansen <johansen@sun.com>
Mon, 03 Nov 2008 14:12:03 -0800
changeset 670 2785b97791ed
parent 669 1c075c478f7c
child 671 8c6d0d1315cc
4400 Remove redundant transport error handling logic
src/modules/client/filelist.py
src/modules/client/retrieve.py
src/modules/misc.py
--- a/src/modules/client/filelist.py	Mon Nov 03 14:06:05 2008 -0800
+++ b/src/modules/client/filelist.py	Mon Nov 03 14:12:03 2008 -0800
@@ -47,6 +47,7 @@
 from pkg.misc import TransportException
 from pkg.misc import TransportFailures
 from pkg.misc import TransferTimedOutException
+from pkg.misc import TransferIOException
 from pkg.misc import TransferContentException
 from pkg.misc import InvalidContentException
 from pkg.misc import TruncatedTransferException
@@ -382,15 +383,10 @@
                                 sockerr = e.args[0]
                                 if isinstance(sockerr.args, tuple) and \
                                     sockerr.args[0] in retryable_socket_errors:
-                                        raise TransferContentException(
+                                        raise TransferIOException(
                                             url_prefix,
                                             "Retryable socket error: %s" %
                                             e.reason)
-                                else:
-                                        raise FileListRetrievalError(
-                                            "Could not retrieve filelist from"
-                                            " '%s'\nURLError, reason: %s" %
-                                            (url_prefix, e.reason))
 
                         raise FileListRetrievalError("Could not retrieve"
                             " filelist from '%s'\nURLError reason: %d" % 
@@ -429,14 +425,14 @@
                                 self.image.cleanup_downloads()
                                 if isinstance(e.args, tuple) and \
                                     e.args[0] in retryable_socket_errors:
-                                        raise TransferContentException(
+                                        raise TransferIOException(
                                             url_prefix,
                                             "Retryable socket error: %s" % e)
-                                else:
-                                        raise FileListRetrievalError(
-                                            "Could not retrieve filelist from"
-                                            " '%s'\nsocket error, reason: %s" %
-                                            (url_prefix, e))
+
+                                raise FileListRetrievalError(
+                                    "Could not retrieve filelist from"
+                                    " '%s'\nsocket error, reason: %s" %
+                                    (url_prefix, e))
                         except (ValueError, httplib.IncompleteRead):
                                 self.image.cleanup_downloads()
                                 raise TransferContentException(url_prefix,
--- a/src/modules/client/retrieve.py	Mon Nov 03 14:06:05 2008 -0800
+++ b/src/modules/client/retrieve.py	Mon Nov 03 14:12:03 2008 -0800
@@ -32,6 +32,7 @@
 import pkg.updatelog as updatelog
 from pkg.misc import versioned_urlopen
 from pkg.misc import TransferTimedOutException
+from pkg.misc import TransferIOException
 from pkg.misc import TruncatedTransferException
 from pkg.misc import TransferContentException
 from pkg.misc import retryable_http_errors
@@ -101,13 +102,8 @@
                         sockerr = e.args[0]
                         if isinstance(sockerr.args, tuple) and \
                             sockerr.args[0] in retryable_socket_errors:
-                                raise TransferContentException(prefix,
+                                raise TransferIOException(prefix,
                                     "Retryable socket error: %s" % e.reason)
-                        else:
-                                raise CatalogRetrievalError(
-                                    "Could not retrieve catalog from"
-                                    " '%s'\nURLError, reason: %s" %
-                                    (prefix, e.reason))
 
                 raise CatalogRetrievalError("Could not retrieve catalog from"
                     " '%s'\nURLError, reason: %s" % (prefix, e.reason))
@@ -134,12 +130,11 @@
         except socket.error, e:
                 if isinstance(e.args, tuple) \
                      and e.args[0] in retryable_socket_errors:
-                        raise TransferContentException(prefix,
+                        raise TransferIOException(prefix,
                             "Retryable socket error: %s" % e)
-                else:
-                        raise CatalogRetrievalError("Could not retrieve catalog"
-                            " from '%s'\nsocket error, reason: %s" %
-                            (prefix, e))
+
+                raise CatalogRetrievalError("Could not retrieve catalog"
+                    " from '%s'\nsocket error, reason: %s" % (prefix, e))
         except EnvironmentError, e:
                 raise CatalogRetrievalError("Could not retrieve catalog "
                     "from '%s'\nException: str:%s repr:%r" % (prefix,
@@ -329,13 +324,8 @@
                         sockerr = e.args[0]
                         if isinstance(sockerr.args, tuple) and \
                             sockerr.args[0] in retryable_socket_errors:
-                                raise TransferContentException(url_prefix,
+                                raise TransferIOException(url_prefix,
                                     "Retryable socket error: %s" % e.reason)
-                        else:
-                                raise ManifestRetrievalError(
-                                    "Could not retrieve manifest from"
-                                    " '%s'\nURLError, reason: %s" %
-                                    (url_prefix, e.reason))
 
                 raise ManifestRetrievalError("Could not retrieve manifest"
                     " '%s' from '%s'\nURLError, reason: %s" %
@@ -360,12 +350,12 @@
         except socket.error, e:
                 if isinstance(e.args, tuple) \
                      and e.args[0] in retryable_socket_errors:
-                        raise TransferContentException(url_prefix,
+                        raise TransferIOException(url_prefix,
                             "Retryable socket error: %s" % e)
-                else:
-                        raise ManifestRetrievalError("Could not retrieve"
-                            " manifest from '%s'\nsocket error, reason: %s" %
-                            (url_prefix, e))
+
+                raise ManifestRetrievalError("Could not retrieve"
+                    " manifest from '%s'\nsocket error, reason: %s" %
+                    (url_prefix, e))
         except (ValueError, httplib.IncompleteRead):
                 raise TransferContentException(url_prefix,
                     "Incomplete Read from remote host")
--- a/src/modules/misc.py	Mon Nov 03 14:06:05 2008 -0800
+++ b/src/modules/misc.py	Mon Nov 03 14:12:03 2008 -0800
@@ -459,6 +459,29 @@
                         s += "\n"
                 return s
 
+class TransferIOException(TransportException):
+        """Raised for retryable IO errors on underlying transport.
+        Protocol errors are TransferContentExceptions, timeouts
+        are TransferTimedOutExceptions."""
+        def __init__(self, url, reason=None):
+                TransportException.__init__(self)
+                self.url = url
+                self.reason = reason
+
+        def __str__(self):
+                s = "IO Error while communicating with '%s'" % self.url
+                if self.reason:
+                        s += ": %s" % self.reason
+                s += "."
+                return s
+
+        def __cmp__(self, other):
+                if not isinstance(other, TransferIOException):
+                        return -1        
+                r = cmp(self.url, other.url)
+                if r != 0:
+                        return r
+                return cmp(self.reason, other.reason)
 
 class TransferTimedOutException(TransportException):
         """Raised when the transfer times out, or is terminated with a