removing blank excepts

This commit is contained in:
David Goetz 2011-01-26 14:31:33 -08:00
parent 50f3c9379b
commit 86cb12036b
25 changed files with 77 additions and 74 deletions

10
bin/st
View File

@ -38,13 +38,13 @@ from urlparse import urlparse, urlunparse
try:
from eventlet import sleep
except:
except Exception:
from time import sleep
try:
from swift.common.bufferedhttp \
import BufferedHTTPConnection as HTTPConnection
except:
except Exception:
from httplib import HTTPConnection
@ -91,7 +91,7 @@ except ImportError:
else:
res.append(val)
return eval(''.join(res), {}, consts)
except:
except Exception:
raise AttributeError()
@ -1615,7 +1615,7 @@ def st_upload(options, args, print_queue, error_queue):
conn.put_container(args[0])
if options.segment_size is not None:
conn.put_container(args[0] + '_segments')
except:
except Exception:
pass
try:
for arg in args[1:]:
@ -1722,7 +1722,7 @@ Example:
error_thread.abort = True
while error_thread.isAlive():
error_thread.join(0.01)
except:
except Exception:
for thread in threading_enumerate():
thread.abort = True
raise

View File

@ -89,7 +89,7 @@ if __name__ == '__main__':
c = ConfigParser()
try:
conf_path = sys.argv[1]
except:
except Exception:
print "Usage: %s CONF_FILE" % sys.argv[0].split('/')[-1]
sys.exit(1)
if not c.read(conf_path):

View File

@ -29,7 +29,7 @@ if __name__ == '__main__':
sys.exit(1)
try:
ring = Ring('/etc/swift/object.ring.gz')
except:
except Exception:
ring = None
datafile = sys.argv[1]
fp = open(datafile, 'rb')

View File

@ -38,7 +38,7 @@ def put_container(connpool, container, report):
retries_done += conn.attempts - 1
if report:
report(True)
except:
except Exception:
if report:
report(False)
raise
@ -53,7 +53,7 @@ def put_object(connpool, container, obj, report):
retries_done += conn.attempts - 1
if report:
report(True)
except:
except Exception:
if report:
report(False)
raise

View File

@ -305,7 +305,7 @@ class AccountController(object):
res = getattr(self, req.method)(req)
else:
res = HTTPMethodNotAllowed()
except:
except Exception:
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

@ -96,7 +96,7 @@ class AuthController(object):
msg = _('No super_admin_key set in conf file! Exiting.')
try:
self.logger.critical(msg)
except:
except Exception:
pass
raise ValueError(msg)
self.swift_dir = conf.get('swift_dir', '/etc/swift')
@ -237,7 +237,7 @@ YOU HAVE A FEW OPTIONS:
except Exception, err:
try:
conn.close()
except:
except Exception:
pass
self.conn = get_db_connection(self.db_file)
raise err
@ -637,7 +637,7 @@ YOU HAVE A FEW OPTIONS:
else:
return HTTPBadRequest(request=env)(env, start_response)
response = handler(req)
except:
except Exception:
self.logger.exception(
_('ERROR Unhandled exception in ReST request'))
return HTTPServiceUnavailable(request=req)(env, start_response)

View File

@ -97,7 +97,7 @@ class Bench(object):
self.logger.info(_("CannotSendRequest. Skipping..."))
try:
hc.close()
except:
except Exception:
pass
self.failures += 1
hc = self.conn_pool.create()

View File

@ -87,7 +87,7 @@ except ImportError:
else:
res.append(val)
return eval(''.join(res), {}, consts)
except:
except Exception:
raise AttributeError()

View File

@ -269,7 +269,7 @@ class DatabaseBroker(object):
yield conn
conn.rollback()
self.conn = conn
except:
except Exception:
conn.close()
raise
@ -288,13 +288,13 @@ class DatabaseBroker(object):
conn.execute('BEGIN IMMEDIATE')
try:
yield True
except:
except Exception:
pass
try:
conn.execute('ROLLBACK')
conn.isolation_level = orig_isolation_level
self.conn = conn
except: # pragma: no cover
except Exception:
logging.exception(
_('Broker error trying to rollback locked connection'))
conn.close()
@ -749,7 +749,7 @@ class ContainerBroker(DatabaseBroker):
timestamp, 'size': size, 'content_type':
content_type, 'etag': etag,
'deleted': deleted})
except:
except Exception:
self.logger.exception(
_('Invalid pending entry %(file)s: %(entry)s'),
{'file': self.pending_file, 'entry': entry})
@ -1216,7 +1216,7 @@ class AccountBroker(DatabaseBroker):
'object_count': object_count,
'bytes_used': bytes_used,
'deleted': deleted})
except:
except Exception:
self.logger.exception(
_('Invalid pending entry %(file)s: %(entry)s'),
{'file': self.pending_file, 'entry': entry})

View File

@ -21,7 +21,7 @@ import math
import time
import shutil
from eventlet import GreenPool, sleep, Timeout
from eventlet import GreenPool, sleep, Timeout, TimeoutError
from eventlet.green import subprocess
import simplejson
from webob import Response
@ -79,7 +79,7 @@ class ReplConnection(BufferedHTTPConnection):
response = self.getresponse()
response.data = response.read()
return response
except:
except Exception:
self.logger.exception(
_('ERROR reading HTTP response from %s'), self.node)
return None
@ -359,7 +359,7 @@ class Replicator(Daemon):
except DriveNotMounted:
repl_nodes.append(more_nodes.next())
self.logger.error(_('ERROR Remote drive not mounted %s'), node)
except:
except (Exception, TimeoutError):
self.logger.exception(_('ERROR syncing %(file)s with node'
' %(node)s'), {'file': object_file, 'node': node})
self.stats['success' if success else 'failure'] += 1
@ -432,7 +432,7 @@ class Replicator(Daemon):
while True:
try:
self.run_once()
except:
except (Exception, TimeoutError):
self.logger.exception(_('ERROR trying to replicate'))
sleep(self.run_pause)

View File

@ -25,6 +25,7 @@ from urlparse import urlparse
from uuid import uuid4
from eventlet.timeout import Timeout
from eventlet import TimeoutError
from webob import Response, Request
from webob.exc import HTTPAccepted, HTTPBadRequest, HTTPConflict, \
HTTPCreated, HTTPForbidden, HTTPNoContent, HTTPNotFound, \
@ -283,7 +284,7 @@ class Swauth(object):
response = self.handle_request(req)(env, start_response)
self.posthooklogger(env, req)
return response
except:
except (Exception, TimeoutError):
print "EXCEPTION IN handle: %s: %s" % (format_exc(), env)
start_response('500 Server Error',
[('Content-Type', 'text/plain')])
@ -589,7 +590,7 @@ class Swauth(object):
if resp.status // 100 != 2:
raise Exception('Could not create account on the Swift '
'cluster: %s %s %s' % (path, resp.status, resp.reason))
except:
except (Exception, TimeoutError):
self.logger.error(_('ERROR: Exception while trying to communicate '
'with %(scheme)s://%(host)s:%(port)s/%(path)s'),
{'scheme': self.dsc_parsed2.scheme,

View File

@ -24,6 +24,7 @@ from datetime import datetime
import simplejson
from eventlet.timeout import Timeout
from eventlet import TimeoutError
from webob import Request, Response
from webob.exc import HTTPAccepted, HTTPBadRequest, HTTPConflict, \
HTTPCreated, HTTPInternalServerError, HTTPNoContent, \
@ -118,7 +119,7 @@ class ContainerController(object):
'device': account_device,
'status': account_response.status,
'reason': account_response.reason})
except:
except (Exception, TimeoutError):
self.logger.exception(_('ERROR account update failed with '
'%(ip)s:%(port)s/%(device)s (will retry later)'),
{'ip': account_ip, 'port': account_port,
@ -393,7 +394,7 @@ class ContainerController(object):
res = getattr(self, req.method)(req)
else:
res = HTTPMethodNotAllowed()
except:
except Exception:
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, shuffle
from eventlet import spawn, patcher, Timeout
from eventlet import spawn, patcher, Timeout, TimeoutError
from swift.container.server import DATADIR
from swift.common.bufferedhttp import http_connect
@ -221,7 +221,7 @@ class ContainerUpdater(Daemon):
'X-Object-Count': count,
'X-Bytes-Used': bytes,
'X-Account-Override-Deleted': 'yes'})
except:
except (Exception, TimeoutError):
self.logger.exception(_('ERROR account update failed with '
'%(ip)s:%(port)s/%(device)s (will retry later): '), node)
return 500
@ -230,7 +230,7 @@ class ContainerUpdater(Daemon):
resp = conn.getresponse()
resp.read()
return resp.status
except:
except (Exception, TimeoutError):
if self.logger.getEffectiveLevel() <= logging.DEBUG:
self.logger.exception(
_('Exception with %(ip)s:%(port)s/%(device)s'), node)

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, tpool
from eventlet import sleep, Timeout, TimeoutError, tpool
from swift.common.utils import mkdirs, normalize_timestamp, \
storage_directory, hash_path, renamer, fallocate, \
@ -308,7 +308,7 @@ class ObjectController(object):
'response from %(ip)s:%(port)s/%(dev)s'),
{'status': response.status, 'ip': ip, 'port': port,
'dev': contdevice})
except:
except (Exception, TimeoutError):
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})
@ -582,7 +582,7 @@ class ObjectController(object):
res = getattr(self, req.method)(req)
else:
res = HTTPMethodNotAllowed()
except:
except Exception:
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
from eventlet import patcher, Timeout, TimeoutError
from swift.common.bufferedhttp import http_connect
from swift.common.exceptions import ConnectionTimeout
@ -202,7 +202,7 @@ class ObjectUpdater(Daemon):
resp = conn.getresponse()
resp.read()
return resp.status
except:
except (Exception, TimeoutError):
self.logger.exception(_('ERROR with remote server '
'%(ip)s:%(port)s/%(device)s'), node)
return 500

View File

@ -30,7 +30,7 @@ import uuid
import functools
from hashlib import md5
from eventlet import sleep
from eventlet import sleep, TimeoutError
from eventlet.timeout import Timeout
from webob.exc import HTTPBadRequest, HTTPMethodNotAllowed, \
HTTPNotFound, HTTPPreconditionFailed, \
@ -383,7 +383,7 @@ class Controller(object):
attempts_left -= 1
if attempts_left <= 0:
break
except:
except (Exception, TimeoutError):
self.exception_occurred(node, _('Account'),
_('Trying to get account info for %s') % path)
if self.app.memcache and result_code in (200, 404):
@ -461,7 +461,7 @@ class Controller(object):
attempts_left -= 1
if attempts_left <= 0:
break
except:
except (Exception, TimeoutError):
self.exception_occurred(node, _('Container'),
_('Trying to get container info for %s') % path)
if self.app.memcache and result_code in (200, 404):
@ -592,7 +592,7 @@ class Controller(object):
query_string=req.query_string)
with Timeout(self.app.node_timeout):
source = conn.getresponse()
except:
except (Exception, TimeoutError):
self.exception_occurred(node, server_type,
_('Trying to %(method)s %(path)s') %
{'method': req.method, 'path': req.path})
@ -624,7 +624,7 @@ class Controller(object):
except GeneratorExit:
res.client_disconnect = True
self.app.logger.info(_('Client disconnected on read'))
except:
except (Exception, TimeoutError):
self.exception_occurred(node, _('Object'),
_('Trying to read during GET of %s') % req.path)
raise
@ -691,7 +691,7 @@ class ObjectController(Controller):
_('ERROR %(status)d %(body)s From Object Server') %
{'status': response.status, 'body': body[:1024]})
return response.status, response.reason, body
except:
except (Exception, TimeoutError):
self.exception_occurred(node, _('Object'),
_('Trying to %(method)s %(path)s') %
{'method': req.method, 'path': req.path})
@ -998,7 +998,7 @@ class ObjectController(Controller):
conn.node = node
with Timeout(self.app.node_timeout):
resp = conn.getexpect()
except:
except (Exception, TimeoutError):
self.exception_occurred(node, _('Object'),
_('Expect: 100-continue on %s') % req.path)
if conn and resp:
@ -1038,7 +1038,7 @@ class ObjectController(Controller):
conn.send('%x\r\n%s\r\n' % (len_chunk, chunk))
else:
conn.send(chunk)
except:
except (Exception, TimeoutError):
self.exception_occurred(conn.node, _('Object'),
_('Trying to write to %s') % req.path)
conns.remove(conn)
@ -1055,7 +1055,7 @@ class ObjectController(Controller):
self.app.logger.info(
_('ERROR Client read timeout (%ss)'), err.seconds)
return HTTPRequestTimeout(request=req)
except:
except Exception:
req.client_disconnect = True
self.app.logger.exception(
_('ERROR Exception causing client disconnect'))
@ -1083,7 +1083,7 @@ class ObjectController(Controller):
'body': bodies[-1][:1024], 'path': req.path})
elif 200 <= response.status < 300:
etags.add(response.getheader('etag').strip('"'))
except:
except (Exception, TimeoutError):
self.exception_occurred(conn.node, _('Object'),
_('Trying to get final status of PUT to %s') % req.path)
if len(etags) > 1:
@ -1294,7 +1294,7 @@ class ContainerController(Controller):
if source.status == 507:
self.error_limit(node)
accounts.insert(0, account)
except:
except (Exception, TimeoutError):
accounts.insert(0, account)
self.exception_occurred(node, _('Container'),
_('Trying to PUT to %s') % req.path)
@ -1350,7 +1350,7 @@ class ContainerController(Controller):
bodies.append(body)
elif source.status == 507:
self.error_limit(node)
except:
except (Exception, TimeoutError):
self.exception_occurred(node, _('Container'),
_('Trying to POST %s') % req.path)
if len(statuses) >= len(containers):
@ -1406,7 +1406,7 @@ class ContainerController(Controller):
if source.status == 507:
self.error_limit(node)
accounts.insert(0, account)
except:
except (Exception, TimeoutError):
accounts.insert(0, account)
self.exception_occurred(node, _('Container'),
_('Trying to DELETE %s') % req.path)
@ -1491,7 +1491,7 @@ class AccountController(Controller):
else:
if source.status == 507:
self.error_limit(node)
except:
except (Exception, TimeoutError):
self.exception_occurred(node, _('Account'),
_('Trying to PUT to %s') % req.path)
if len(statuses) >= len(accounts):
@ -1539,7 +1539,7 @@ class AccountController(Controller):
bodies.append(body)
elif source.status == 507:
self.error_limit(node)
except:
except (Exception, TimeoutError):
self.exception_occurred(node, _('Account'),
_('Trying to POST %s') % req.path)
if len(statuses) >= len(accounts):
@ -1584,7 +1584,7 @@ class AccountController(Controller):
bodies.append(body)
elif source.status == 507:
self.error_limit(node)
except:
except (Exception, TimeoutError):
self.exception_occurred(node, _('Account'),
_('Trying to DELETE %s') % req.path)
if len(statuses) >= len(accounts):
@ -1685,7 +1685,7 @@ class BaseApplication(object):
response = self.handle_request(req)(env, start_response)
self.posthooklogger(env, req)
return response
except:
except Exception:
print "EXCEPTION IN __call__: %s: %s" % \
(traceback.format_exc(), env)
start_response('500 Server Error',

View File

@ -273,7 +273,7 @@ class LogProcessorDaemon(Daemon):
already_processed_files = cPickle.loads(buf)
else:
already_processed_files = set()
except:
except Exception:
already_processed_files = set()
self.logger.debug(_('found %d processed files') % \
len(already_processed_files))

View File

@ -49,7 +49,7 @@ def kill_pids(pids):
for pid in pids.values():
try:
kill(pid, SIGTERM)
except:
except Exception:
pass

View File

@ -95,7 +95,7 @@ class TestObjectHandoff(unittest.TestCase):
try:
direct_client.direct_get_object(onode, opart, self.account,
container, obj)
except:
except Exception:
exc = True
if not exc:
raise Exception('Previously downed object server had test object')
@ -119,7 +119,7 @@ class TestObjectHandoff(unittest.TestCase):
try:
direct_client.direct_get_object(another_onode, opart, self.account,
container, obj)
except:
except Exception:
exc = True
if not exc:
raise Exception('Handoff object server still had test object')
@ -134,7 +134,7 @@ class TestObjectHandoff(unittest.TestCase):
try:
direct_client.direct_get_object(another_onode, opart, self.account,
container, obj)
except:
except Exception:
exc = True
if not exc:
raise Exception('Handoff server claimed it had the object when '
@ -171,7 +171,7 @@ class TestObjectHandoff(unittest.TestCase):
exc = False
try:
client.head_object(self.url, self.token, container, obj)
except:
except Exception:
exc = True
if not exc:
raise Exception('Regular object HEAD was still successful')
@ -209,7 +209,7 @@ class TestObjectHandoff(unittest.TestCase):
try:
direct_client.direct_get_object(another_onode, opart, self.account,
container, obj)
except:
except Exception:
exc = True
if not exc:
raise Exception('Handoff object server still had the object')

View File

@ -51,7 +51,7 @@ class FakeMemcache(object):
def delete(self, key):
try:
del self.store[key]
except:
except Exception:
pass
return True

View File

@ -51,7 +51,7 @@ class FakeMemcache(object):
def delete(self, key):
try:
del self.store[key]
except:
except Exception:
pass
return True

View File

@ -49,7 +49,7 @@ class FakeMemcache(object):
def delete(self, key):
try:
del self.store[key]
except:
except Exception:
pass
return True

View File

@ -165,14 +165,14 @@ class TestDatabaseBroker(unittest.TestCase):
try:
with broker.get() as conn:
conn.execute('SELECT 1')
except:
except Exception:
got_exc = True
broker = DatabaseBroker(os.path.join(self.testdir, '1.db'))
got_exc = False
try:
with broker.get() as conn:
conn.execute('SELECT 1')
except:
except Exception:
got_exc = True
self.assert_(got_exc)
def stub(*args, **kwargs):
@ -186,7 +186,7 @@ class TestDatabaseBroker(unittest.TestCase):
conn.execute('INSERT INTO test (one) VALUES ("1")')
raise Exception('test')
conn.commit()
except:
except Exception:
pass
broker = DatabaseBroker(os.path.join(self.testdir, '1.db'))
with broker.get() as conn:
@ -230,7 +230,7 @@ class TestDatabaseBroker(unittest.TestCase):
try:
with broker.lock():
raise Exception('test')
except:
except Exception:
pass
with broker.lock():
pass
@ -548,7 +548,7 @@ class TestContainerBroker(unittest.TestCase):
with broker.get() as conn:
self.assertEquals(first_conn, conn)
raise Exception('OMG')
except:
except Exception:
pass
self.assert_(broker.conn == None)
@ -1363,7 +1363,7 @@ class TestAccountBroker(unittest.TestCase):
try:
with broker.get() as conn:
pass
except:
except Exception:
got_exc = True
self.assert_(got_exc)
broker.initialize(normalize_timestamp('1'))
@ -1384,7 +1384,7 @@ class TestAccountBroker(unittest.TestCase):
with broker.get() as conn:
self.assertEquals(first_conn, conn)
raise Exception('OMG')
except:
except Exception:
pass
self.assert_(broker.conn == None)

View File

@ -107,7 +107,7 @@ class TestUtils(unittest.TestCase):
testroot = os.path.join(os.path.dirname(__file__), 'mkdirs')
try:
os.unlink(testroot)
except:
except Exception:
pass
rmtree(testroot, ignore_errors=1)
self.assert_(not os.path.exists(testroot))
@ -211,14 +211,14 @@ class TestUtils(unittest.TestCase):
try:
for line in lfo:
pass
except:
except Exception:
got_exc = True
self.assert_(got_exc)
got_exc = False
try:
for line in lfo.xreadlines():
pass
except:
except Exception:
got_exc = True
self.assert_(got_exc)
self.assertRaises(IOError, lfo.read)

View File

@ -47,7 +47,7 @@ from swift.common import ring
from swift.common.constraints import MAX_META_NAME_LENGTH, \
MAX_META_VALUE_LENGTH, MAX_META_COUNT, MAX_META_OVERALL_SIZE, MAX_FILE_SIZE
from swift.common.utils import mkdirs, normalize_timestamp, NullLogger
from swift.common.wsgi import monkey_patch_mimetools
# mocks
logging.getLogger().addHandler(logging.StreamHandler(sys.stdout))
@ -426,6 +426,7 @@ class TestObjectController(unittest.TestCase):
self.app = proxy_server.Application(None, FakeMemcache(),
account_ring=FakeRing(), container_ring=FakeRing(),
object_ring=FakeRing())
monkey_patch_mimetools()
def assert_status_map(self, method, statuses, expected, raise_exc=False):
with save_globals():