Updated TimeoutError and except Exception refs...

Updated eventlet.TimeoutError (deprecated) references to
Timeout and, more importantly, updated many except Exception
clauses to except (Exception, Timeout).

Change-Id: Ib089265551bd20b94c00ea84f11140ccd795d301
This commit is contained in:
gholt 2011-11-07 16:24:08 +00:00
parent 52ec042976
commit dd839048f1
24 changed files with 81 additions and 78 deletions

View File

@ -22,6 +22,8 @@ from swift.common.db import AccountBroker
from swift.common.utils import get_logger, audit_location_generator
from swift.common.daemon import Daemon
from eventlet import Timeout
class AccountAuditor(Daemon):
"""Audit accounts."""
@ -98,7 +100,7 @@ class AccountAuditor(Daemon):
info = broker.get_info()
self.account_passes += 1
self.logger.debug(_('Audit passed for %s') % broker.db_file)
except Exception:
except (Exception, Timeout):
self.account_failures += 1
self.logger.exception(_('ERROR Could not get account info %s'),
(broker.db_file))

View File

@ -19,7 +19,7 @@ from logging import DEBUG
from math import sqrt
from time import time
from eventlet import GreenPool, sleep
from eventlet import GreenPool, sleep, Timeout
from swift.account.server import DATADIR
from swift.common.db import AccountBroker
@ -233,12 +233,12 @@ class AccountReaper(Daemon):
self.container_pool.spawn(self.reap_container, account,
partition, nodes, container)
self.container_pool.waitall()
except Exception:
except (Exception, Timeout):
self.logger.exception(
_('Exception with containers for account %s'), account)
marker = containers[-1][0]
log = 'Completed pass on account %s' % account
except Exception:
except (Exception, Timeout):
self.logger.exception(
_('Exception with account %s'), account)
log = _('Incomplete pass on account %s') % account
@ -329,7 +329,7 @@ class AccountReaper(Daemon):
pool.spawn(self.reap_object, account, container, part,
nodes, obj['name'])
pool.waitall()
except Exception:
except (Exception, Timeout):
self.logger.exception(_('Exception with objects for container '
'%(container)s for account %(account)s'),
{'container': container, 'account': account})

View File

@ -21,6 +21,7 @@ import traceback
from urllib import unquote
from xml.sax import saxutils
from eventlet import Timeout
from webob import Request, Response
from webob.exc import HTTPAccepted, HTTPBadRequest, \
HTTPCreated, HTTPForbidden, HTTPInternalServerError, \
@ -312,7 +313,7 @@ class AccountController(object):
res = getattr(self, req.method)(req)
else:
res = HTTPMethodNotAllowed()
except Exception:
except (Exception, Timeout):
self.logger.exception(_('ERROR __call__ error with %(method)s'
' %(path)s '), {'method': req.method, 'path': req.path})
res = HTTPInternalServerError(body=traceback.format_exc())

View File

@ -29,7 +29,7 @@ import errno
from random import randint
from tempfile import mkstemp
from eventlet import sleep
from eventlet import sleep, Timeout
import simplejson as json
import sqlite3
@ -317,7 +317,7 @@ class DatabaseBroker(object):
except:
pass
self.possibly_quarantine(*sys.exc_info())
except Exception:
except (Exception, Timeout):
conn.close()
raise
@ -336,13 +336,13 @@ class DatabaseBroker(object):
conn.execute('BEGIN IMMEDIATE')
try:
yield True
except Exception:
except (Exception, Timeout):
pass
try:
conn.execute('ROLLBACK')
conn.isolation_level = orig_isolation_level
self.conn = conn
except Exception:
except (Exception, Timeout):
logging.exception(
_('Broker error trying to rollback locked connection'))
conn.close()

View File

@ -23,7 +23,7 @@ import shutil
import uuid
import errno
from eventlet import GreenPool, sleep, Timeout, TimeoutError
from eventlet import GreenPool, sleep, Timeout
from eventlet.green import subprocess
import simplejson
from webob import Response
@ -90,7 +90,7 @@ class ReplConnection(BufferedHTTPConnection):
response = self.getresponse()
response.data = response.read()
return response
except Exception:
except (Exception, Timeout):
self.logger.exception(
_('ERROR reading HTTP response from %s'), self.node)
return None
@ -331,7 +331,7 @@ class Replicator(Daemon):
broker.reclaim(time.time() - self.reclaim_age,
time.time() - (self.reclaim_age * 2))
info = broker.get_replication_info()
except Exception, e:
except (Exception, Timeout), e:
if 'no such table' in str(e):
self.logger.error(_('Quarantining DB %s'), object_file)
quarantine_db(broker.db_file, broker.db_type)
@ -370,7 +370,7 @@ class Replicator(Daemon):
except DriveNotMounted:
repl_nodes.append(more_nodes.next())
self.logger.error(_('ERROR Remote drive not mounted %s'), node)
except (Exception, TimeoutError):
except (Exception, Timeout):
self.logger.exception(_('ERROR syncing %(file)s with node'
' %(node)s'), {'file': object_file, 'node': node})
self.stats['success' if success else 'failure'] += 1
@ -443,7 +443,7 @@ class Replicator(Daemon):
while True:
try:
self.run_once()
except (Exception, TimeoutError):
except (Exception, Timeout):
self.logger.exception(_('ERROR trying to replicate'))
sleep(self.run_pause)
@ -487,7 +487,7 @@ class ReplicatorRpc(object):
timemark = time.time()
try:
info = broker.get_replication_info()
except Exception, e:
except (Exception, Timeout), e:
if 'no such table' in str(e):
self.logger.error(_("Quarantining DB %s") % broker.db_file)
quarantine_db(broker.db_file, broker.db_type)

View File

@ -13,17 +13,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from eventlet import TimeoutError
from eventlet import Timeout
class MessageTimeout(TimeoutError):
class MessageTimeout(Timeout):
def __init__(self, seconds=None, msg=None):
TimeoutError.__init__(self, seconds=seconds)
Timeout.__init__(self, seconds=seconds)
self.msg = msg
def __str__(self):
return '%s: %s' % (TimeoutError.__str__(self), self.msg)
return '%s: %s' % (Timeout.__str__(self), self.msg)
class AuditException(Exception):
@ -42,15 +42,15 @@ class AuthException(Exception):
pass
class ChunkReadTimeout(TimeoutError):
class ChunkReadTimeout(Timeout):
pass
class ChunkWriteTimeout(TimeoutError):
class ChunkWriteTimeout(Timeout):
pass
class ConnectionTimeout(TimeoutError):
class ConnectionTimeout(Timeout):
pass

View File

@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from eventlet import Timeout
from webob import Request
from webob.exc import HTTPServerError
import uuid
@ -44,7 +45,7 @@ class CatchErrorMiddleware(object):
response_headers.append(trans_header)
return start_response(status, response_headers, exc_info)
return self.app(env, my_start_response)
except Exception, err:
except (Exception, Timeout), err:
self.logger.exception(_('Error: %s'), err)
resp = HTTPServerError(request=Request(env),
body='An error occurred',

View File

@ -21,7 +21,7 @@ from hashlib import sha1
import hmac
import base64
from eventlet import TimeoutError
from eventlet import Timeout
from webob import Response, Request
from webob.exc import HTTPBadRequest, HTTPForbidden, HTTPNotFound, \
HTTPUnauthorized
@ -300,7 +300,7 @@ class TempAuth(object):
response = self.handle_request(req)(env, start_response)
self.posthooklogger(env, req)
return response
except (Exception, TimeoutError):
except (Exception, Timeout):
print "EXCEPTION IN handle: %s: %s" % (format_exc(), env)
start_response('500 Server Error',
[('Content-Type', 'text/plain')])

View File

@ -17,6 +17,8 @@ import os
import time
from random import random
from eventlet import Timeout
from swift.container import server as container_server
from swift.common.db import ContainerBroker
from swift.common.utils import get_logger, audit_location_generator
@ -101,7 +103,7 @@ class ContainerAuditor(Daemon):
info = broker.get_info()
self.container_passes += 1
self.logger.debug(_('Audit passed for %s'), broker.db_file)
except Exception:
except (Exception, Timeout):
self.container_failures += 1
self.logger.exception(_('ERROR Could not get container info %s'),
(broker.db_file))

View File

@ -23,8 +23,7 @@ from xml.sax import saxutils
from datetime import datetime
import simplejson
from eventlet.timeout import Timeout
from eventlet import TimeoutError
from eventlet import Timeout
from webob import Request, Response
from webob.exc import HTTPAccepted, HTTPBadRequest, HTTPConflict, \
HTTPCreated, HTTPInternalServerError, HTTPNoContent, \
@ -125,7 +124,7 @@ class ContainerController(object):
'device': account_device,
'status': account_response.status,
'reason': account_response.reason})
except (Exception, TimeoutError):
except (Exception, Timeout):
self.logger.exception(_('ERROR account update failed with '
'%(ip)s:%(port)s/%(device)s (will retry later)'),
{'ip': account_ip, 'port': account_port,
@ -430,7 +429,7 @@ class ContainerController(object):
res = getattr(self, req.method)(req)
else:
res = HTTPMethodNotAllowed()
except Exception:
except (Exception, Timeout):
self.logger.exception(_('ERROR __call__ error with %(method)s'
' %(path)s '), {'method': req.method, 'path': req.path})
res = HTTPInternalServerError(body=traceback.format_exc())

View File

@ -18,7 +18,7 @@ from time import ctime, time
from random import random, shuffle
from struct import unpack_from
from eventlet import sleep
from eventlet import sleep, Timeout
from swift.container import server as container_server
from swift.common.client import ClientException, delete_object, put_object, \
@ -322,7 +322,7 @@ class ContainerSync(Daemon):
sync_point1 = row['ROWID']
broker.set_x_container_sync_points(sync_point1, None)
self.container_syncs += 1
except Exception, err:
except (Exception, Timeout), err:
self.container_failures += 1
self.logger.exception(_('ERROR Syncing %s'), (broker.db_file))
@ -415,7 +415,7 @@ class ContainerSync(Daemon):
{'db_file': broker.db_file, 'row': row})
self.container_failures += 1
return False
except Exception, err:
except (Exception, Timeout), err:
self.logger.exception(
_('ERROR Syncing %(db_file)s %(row)s'),
{'db_file': broker.db_file, 'row': row})

View File

@ -21,7 +21,7 @@ import time
from random import random, shuffle
from tempfile import mkstemp
from eventlet import spawn, patcher, Timeout, TimeoutError
from eventlet import spawn, patcher, Timeout
from swift.container.server import DATADIR
from swift.common.bufferedhttp import http_connect
@ -262,7 +262,7 @@ class ContainerUpdater(Daemon):
'X-Object-Count': count,
'X-Bytes-Used': bytes,
'X-Account-Override-Deleted': 'yes'})
except (Exception, TimeoutError):
except (Exception, Timeout):
self.logger.exception(_('ERROR account update failed with '
'%(ip)s:%(port)s/%(device)s (will retry later): '), node)
return 500
@ -271,7 +271,7 @@ class ContainerUpdater(Daemon):
resp = conn.getresponse()
resp.read()
return resp.status
except (Exception, TimeoutError):
except (Exception, Timeout):
if self.logger.getEffectiveLevel() <= logging.DEBUG:
self.logger.exception(
_('Exception with %(ip)s:%(port)s/%(device)s'), node)

View File

@ -19,6 +19,9 @@ import uuid
import errno
from hashlib import md5
from random import random
from eventlet import Timeout
from swift.obj import server as object_server
from swift.obj.replicator import invalidate_hash
from swift.common.utils import get_logger, renamer, audit_location_generator, \
@ -128,7 +131,7 @@ class AuditorWorker(object):
return
try:
name = object_server.read_metadata(path)['name']
except Exception, exc:
except (Exception, Timeout), exc:
raise AuditException('Error when reading metadata: %s' % exc)
_junk, account, container, obj = name.split('/', 3)
df = object_server.DiskFile(self.devices, device, partition,
@ -169,7 +172,7 @@ class AuditorWorker(object):
object_server.quarantine_renamer(
os.path.join(self.devices, device), path)
return
except Exception:
except (Exception, Timeout):
self.errors += 1
self.logger.exception(_('ERROR Trying to audit %s'), path)
return

View File

@ -18,7 +18,7 @@ from sys import exc_info
from time import time
from urllib import quote
from eventlet import sleep, TimeoutError
from eventlet import sleep, Timeout
from paste.deploy import loadapp
from webob import Request
@ -99,20 +99,20 @@ class ObjectExpirer(Daemon):
self.delete_actual_object(actual_obj, timestamp)
self.delete_object(container, obj)
self.report_objects += 1
except (Exception, TimeoutError), err:
except (Exception, Timeout), err:
self.logger.exception(
_('Exception while deleting object %s %s %s') %
(container, obj, str(err)))
self.report()
try:
self.delete_container(container)
except (Exception, TimeoutError), err:
except (Exception, Timeout), err:
self.logger.exception(
_('Exception while deleting container %s %s') %
(container, str(err)))
self.logger.debug(_('Run end'))
self.report(final=True)
except (Exception, TimeoutError):
except (Exception, Timeout):
self.logger.exception(_('Unhandled exception'))
def run_forever(self, *args, **kwargs):
@ -129,7 +129,7 @@ class ObjectExpirer(Daemon):
begin = time()
try:
self.run_once()
except (Exception, TimeoutError):
except (Exception, Timeout):
self.logger.exception(_('Unhandled exception'))
elapsed = time() - begin
if elapsed < self.interval:
@ -146,7 +146,7 @@ class ObjectExpirer(Daemon):
if resp.status_int in acceptable_statuses or \
resp.status_int // 100 in acceptable_statuses:
return resp
except (Exception, TimeoutError):
except (Exception, Timeout):
exc_type, exc_value, exc_traceback = exc_info()
sleep(2 ** (attempt + 1))
if resp:

View File

@ -588,7 +588,7 @@ class ObjectReplicator(Daemon):
try:
dump_recon_cache('object_replication_time', total, \
self.recon_object)
except Exception:
except (Exception, Timeout):
self.logger.exception(_('Exception dumping recon cache'))
def run_forever(self, *args, **kwargs):
@ -606,7 +606,7 @@ class ObjectReplicator(Daemon):
try:
dump_recon_cache('object_replication_time', total, \
self.recon_object)
except Exception:
except (Exception, Timeout):
self.logger.exception(_('Exception dumping recon cache'))
self.logger.debug(_('Replication sleeping for %s seconds.'),
self.run_pause)

View File

@ -33,7 +33,7 @@ from webob.exc import HTTPAccepted, HTTPBadRequest, HTTPCreated, \
HTTPNotModified, HTTPPreconditionFailed, \
HTTPRequestTimeout, HTTPUnprocessableEntity, HTTPMethodNotAllowed
from xattr import getxattr, setxattr
from eventlet import sleep, Timeout, TimeoutError, tpool
from eventlet import sleep, Timeout, tpool
from swift.common.utils import mkdirs, normalize_timestamp, \
storage_directory, hash_path, renamer, fallocate, \
@ -222,7 +222,7 @@ class DiskFile(object):
try:
if verify_file:
self._handle_close_quarantine()
except Exception, e:
except (Exception, Timeout), e:
import traceback
self.logger.error(_('ERROR DiskFile %(data_file)s in '
'%(data_dir)s close failure: %(exc)s : %(stack)'),
@ -412,7 +412,7 @@ class ObjectController(object):
'response from %(ip)s:%(port)s/%(dev)s'),
{'status': response.status, 'ip': ip, 'port': port,
'dev': contdevice})
except (Exception, TimeoutError):
except (Exception, Timeout):
self.logger.exception(_('ERROR container update failed with '
'%(ip)s:%(port)s/%(dev)s (saving for async update later)'),
{'ip': ip, 'port': port, 'dev': contdevice})
@ -810,7 +810,7 @@ class ObjectController(object):
res = getattr(self, req.method)(req)
else:
res = HTTPMethodNotAllowed()
except Exception:
except (Exception, Timeout):
self.logger.exception(_('ERROR __call__ error with %(method)s'
' %(path)s '), {'method': req.method, 'path': req.path})
res = HTTPInternalServerError(body=traceback.format_exc())

View File

@ -20,7 +20,7 @@ import sys
import time
from random import random
from eventlet import patcher, Timeout, TimeoutError
from eventlet import patcher, Timeout
from swift.common.bufferedhttp import http_connect
from swift.common.exceptions import ConnectionTimeout
@ -214,7 +214,7 @@ class ObjectUpdater(Daemon):
resp = conn.getresponse()
resp.read()
return resp.status
except (Exception, TimeoutError):
except (Exception, Timeout):
self.logger.exception(_('ERROR with remote server '
'%(ip)s:%(port)s/%(device)s'), node)
return 500

View File

@ -31,7 +31,7 @@ import functools
from hashlib import md5
from random import shuffle
from eventlet import sleep, GreenPile, Queue, TimeoutError
from eventlet import sleep, GreenPile, Queue, Timeout
from eventlet.timeout import Timeout
from webob.exc import HTTPAccepted, HTTPBadRequest, HTTPMethodNotAllowed, \
HTTPNotFound, HTTPPreconditionFailed, \
@ -174,7 +174,7 @@ class SegmentedIterable(object):
self.segment_iter = resp.app_iter
except StopIteration:
raise
except Exception, err:
except (Exception, Timeout), err:
if not getattr(err, 'swift_logged', False):
self.controller.app.logger.exception(_('ERROR: While '
'processing manifest /%(acc)s/%(cont)s/%(obj)s'),
@ -207,7 +207,7 @@ class SegmentedIterable(object):
yield chunk
except StopIteration:
raise
except Exception, err:
except (Exception, Timeout), err:
if not getattr(err, 'swift_logged', False):
self.controller.app.logger.exception(_('ERROR: While '
'processing manifest /%(acc)s/%(cont)s/%(obj)s'),
@ -254,7 +254,7 @@ class SegmentedIterable(object):
yield chunk
except StopIteration:
raise
except Exception, err:
except (Exception, Timeout), err:
if not getattr(err, 'swift_logged', False):
self.controller.app.logger.exception(_('ERROR: While '
'processing manifest /%(acc)s/%(cont)s/%(obj)s'),
@ -385,7 +385,7 @@ class Controller(object):
attempts_left -= 1
if attempts_left <= 0:
break
except (Exception, TimeoutError):
except (Exception, Timeout):
self.exception_occurred(node, _('Account'),
_('Trying to get account info for %s') % path)
if result_code == 404 and autocreate:
@ -475,7 +475,7 @@ class Controller(object):
attempts_left -= 1
if attempts_left <= 0:
break
except (Exception, TimeoutError):
except (Exception, Timeout):
self.exception_occurred(node, _('Container'),
_('Trying to get container info for %s') % path)
if self.app.memcache and result_code in (200, 404):
@ -626,7 +626,7 @@ class Controller(object):
query_string=req.query_string)
with Timeout(self.app.node_timeout):
possible_source = conn.getresponse()
except (Exception, TimeoutError):
except (Exception, Timeout):
self.exception_occurred(node, server_type,
_('Trying to %(method)s %(path)s') %
{'method': req.method, 'path': req.path})
@ -685,7 +685,7 @@ class Controller(object):
except GeneratorExit:
res.client_disconnect = True
self.app.logger.warn(_('Client disconnected on read'))
except (Exception, TimeoutError):
except (Exception, Timeout):
self.exception_occurred(node, _('Object'),
_('Trying to read during GET of %s') % req.path)
raise
@ -1173,7 +1173,7 @@ class ObjectController(Controller):
self.app.logger.warn(
_('ERROR Client read timeout (%ss)'), err.seconds)
return HTTPRequestTimeout(request=req)
except Exception:
except (Exception, Timeout):
req.client_disconnect = True
self.app.logger.exception(
_('ERROR Exception causing client disconnect'))
@ -1201,7 +1201,7 @@ class ObjectController(Controller):
'body': bodies[-1][:1024], 'path': req.path})
elif 200 <= response.status < 300:
etags.add(response.getheader('etag').strip('"'))
except (Exception, TimeoutError):
except (Exception, Timeout):
self.exception_occurred(conn.node, _('Object'),
_('Trying to get final status of PUT to %s') % req.path)
if len(etags) > 1:
@ -1663,7 +1663,7 @@ class BaseApplication(object):
response = self.handle_request(req)(env, start_response)
self.posthooklogger(env, req)
return response
except Exception:
except (Exception, Timeout):
print "EXCEPTION IN __call__: %s: %s" % \
(traceback.format_exc(), env)
start_response('500 Server Error',
@ -1733,7 +1733,7 @@ class BaseApplication(object):
if not getattr(handler, 'delay_denial', None):
return resp
return handler(req)
except Exception:
except (Exception, Timeout):
self.logger.exception(_('ERROR Unhandled exception in request'))
return HTTPServerError(request=req)

View File

@ -15,8 +15,7 @@
import unittest
from eventlet import spawn, TimeoutError, listen
from eventlet.timeout import Timeout
from eventlet import spawn, Timeout, listen
from swift.common import bufferedhttp

View File

@ -33,7 +33,7 @@ from tempfile import TemporaryFile, NamedTemporaryFile
from eventlet import sleep
from swift.common.exceptions import TimeoutError, MessageTimeout, \
from swift.common.exceptions import Timeout, MessageTimeout, \
ConnectionTimeout
from swift.common import utils
@ -338,7 +338,7 @@ class TestUtils(unittest.TestCase):
def log_exception(exc):
try:
raise exc
except (Exception, TimeoutError):
except (Exception, Timeout):
logger.exception('blah')
try:
# establish base case

View File

@ -21,8 +21,7 @@ from StringIO import StringIO
from time import time
from tempfile import mkdtemp
from eventlet import spawn, TimeoutError, listen
from eventlet.timeout import Timeout
from eventlet import spawn, Timeout, listen
import simplejson
from webob import Request

View File

@ -21,8 +21,7 @@ from gzip import GzipFile
from shutil import rmtree
from tempfile import mkdtemp
from eventlet import spawn, TimeoutError, listen
from eventlet.timeout import Timeout
from eventlet import spawn, Timeout, listen
from swift.common import utils
from swift.container import updater as container_updater

View File

@ -22,8 +22,7 @@ from shutil import rmtree
from time import time
from distutils.dir_util import mkpath
from eventlet import spawn, TimeoutError, listen
from eventlet.timeout import Timeout
from eventlet import spawn, Timeout, listen
from swift.obj import updater as object_updater, server as object_server
from swift.obj.server import ASYNCDIR

View File

@ -33,8 +33,7 @@ from hashlib import md5
from tempfile import mkdtemp
import eventlet
from eventlet import sleep, spawn, TimeoutError, util, wsgi, listen
from eventlet.timeout import Timeout
from eventlet import sleep, spawn, Timeout, util, wsgi, listen
import simplejson
from webob import Request, Response
from webob.exc import HTTPNotFound, HTTPUnauthorized
@ -166,7 +165,7 @@ def fake_http_connect(*code_iter, **kwargs):
if kwargs.get('raise_exc'):
raise Exception('test')
if kwargs.get('raise_timeout_exc'):
raise TimeoutError()
raise Timeout()
return self
def getexpect(self):