Merge "Use Python 3.x compatible except: construct"
This commit is contained in:
commit
87bec5dc70
@ -472,7 +472,7 @@ class StorageManagerCommands(object):
|
|||||||
db.sm_flavor_create(context.get_admin_context(),
|
db.sm_flavor_create(context.get_admin_context(),
|
||||||
dict(label=label,
|
dict(label=label,
|
||||||
description=desc))
|
description=desc))
|
||||||
except exception.DBError, e:
|
except exception.DBError as e:
|
||||||
_db_error(e)
|
_db_error(e)
|
||||||
|
|
||||||
@args('label', help='label of flavor to be deleted')
|
@args('label', help='label of flavor to be deleted')
|
||||||
@ -480,7 +480,7 @@ class StorageManagerCommands(object):
|
|||||||
try:
|
try:
|
||||||
db.sm_flavor_delete(context.get_admin_context(), label)
|
db.sm_flavor_delete(context.get_admin_context(), label)
|
||||||
|
|
||||||
except exception.DBError, e:
|
except exception.DBError as e:
|
||||||
_db_error(e)
|
_db_error(e)
|
||||||
|
|
||||||
def _splitfun(self, item):
|
def _splitfun(self, item):
|
||||||
@ -541,7 +541,7 @@ class StorageManagerCommands(object):
|
|||||||
sr_uuid = params['sr_uuid']
|
sr_uuid = params['sr_uuid']
|
||||||
try:
|
try:
|
||||||
backend = db.sm_backend_conf_get_by_sr(ctxt, sr_uuid)
|
backend = db.sm_backend_conf_get_by_sr(ctxt, sr_uuid)
|
||||||
except exception.DBError, e:
|
except exception.DBError as e:
|
||||||
_db_error(e)
|
_db_error(e)
|
||||||
|
|
||||||
if backend:
|
if backend:
|
||||||
@ -556,7 +556,7 @@ class StorageManagerCommands(object):
|
|||||||
flavor_id=flavors['id'],
|
flavor_id=flavors['id'],
|
||||||
sr_type=sr_type,
|
sr_type=sr_type,
|
||||||
config_params=config_params))
|
config_params=config_params))
|
||||||
except exception.DBError, e:
|
except exception.DBError as e:
|
||||||
_db_error(e)
|
_db_error(e)
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -572,7 +572,7 @@ class StorageManagerCommands(object):
|
|||||||
sr_uuid=sr_uuid,
|
sr_uuid=sr_uuid,
|
||||||
sr_type=sr_type,
|
sr_type=sr_type,
|
||||||
config_params=config_params))
|
config_params=config_params))
|
||||||
except exception.DBError, e:
|
except exception.DBError as e:
|
||||||
_db_error(e)
|
_db_error(e)
|
||||||
|
|
||||||
@args('backend_conf_id')
|
@args('backend_conf_id')
|
||||||
@ -581,7 +581,7 @@ class StorageManagerCommands(object):
|
|||||||
db.sm_backend_conf_delete(context.get_admin_context(),
|
db.sm_backend_conf_delete(context.get_admin_context(),
|
||||||
backend_conf_id)
|
backend_conf_id)
|
||||||
|
|
||||||
except exception.DBError, e:
|
except exception.DBError as e:
|
||||||
_db_error(e)
|
_db_error(e)
|
||||||
|
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ if __name__ == '__main__':
|
|||||||
try:
|
try:
|
||||||
cinder.volume.utils.notify_usage_exists(admin_context,
|
cinder.volume.utils.notify_usage_exists(admin_context,
|
||||||
volume_ref)
|
volume_ref)
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
print traceback.format_exc(e)
|
print traceback.format_exc(e)
|
||||||
|
|
||||||
snapshots = db.snapshot_get_active_by_window(admin_context,
|
snapshots = db.snapshot_get_active_by_window(admin_context,
|
||||||
@ -95,7 +95,7 @@ if __name__ == '__main__':
|
|||||||
snapshot_ref,
|
snapshot_ref,
|
||||||
'exists',
|
'exists',
|
||||||
extra_info)
|
extra_info)
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
print traceback.fromat_exc(e)
|
print traceback.fromat_exc(e)
|
||||||
|
|
||||||
print _("Volume usage audit completed")
|
print _("Volume usage audit completed")
|
||||||
|
@ -82,7 +82,7 @@ class AdminController(wsgi.Controller):
|
|||||||
'update': update})
|
'update': update})
|
||||||
try:
|
try:
|
||||||
self._update(context, id, update)
|
self._update(context, id, update)
|
||||||
except exception.NotFound, e:
|
except exception.NotFound as e:
|
||||||
raise exc.HTTPNotFound(e)
|
raise exc.HTTPNotFound(e)
|
||||||
return webob.Response(status_int=202)
|
return webob.Response(status_int=202)
|
||||||
|
|
||||||
|
@ -164,7 +164,7 @@ class VolumeActionsController(wsgi.Controller):
|
|||||||
force = params.get('force', False)
|
force = params.get('force', False)
|
||||||
try:
|
try:
|
||||||
volume = self.volume_api.get(context, id)
|
volume = self.volume_api.get(context, id)
|
||||||
except exception.VolumeNotFound, error:
|
except exception.VolumeNotFound as error:
|
||||||
raise webob.exc.HTTPNotFound(explanation=unicode(error))
|
raise webob.exc.HTTPNotFound(explanation=unicode(error))
|
||||||
authorize(context, "upload_image")
|
authorize(context, "upload_image")
|
||||||
image_metadata = {"container_format": params.get("container_format",
|
image_metadata = {"container_format": params.get("container_format",
|
||||||
@ -176,9 +176,9 @@ class VolumeActionsController(wsgi.Controller):
|
|||||||
volume,
|
volume,
|
||||||
image_metadata,
|
image_metadata,
|
||||||
force)
|
force)
|
||||||
except exception.InvalidVolume, error:
|
except exception.InvalidVolume as error:
|
||||||
raise webob.exc.HTTPBadRequest(explanation=unicode(error))
|
raise webob.exc.HTTPBadRequest(explanation=unicode(error))
|
||||||
except ValueError, error:
|
except ValueError as error:
|
||||||
raise webob.exc.HTTPBadRequest(explanation=unicode(error))
|
raise webob.exc.HTTPBadRequest(explanation=unicode(error))
|
||||||
except rpc_common.RemoteError as error:
|
except rpc_common.RemoteError as error:
|
||||||
msg = "%(err_type)s: %(err_msg)s" % {'err_type': error.exc_type,
|
msg = "%(err_type)s: %(err_msg)s" % {'err_type': error.exc_type,
|
||||||
|
@ -894,7 +894,7 @@ class Resource(wsgi.Application):
|
|||||||
try:
|
try:
|
||||||
msg_dict = dict(url=request.url, status=response.status_int)
|
msg_dict = dict(url=request.url, status=response.status_int)
|
||||||
msg = _("%(url)s returned with HTTP %(status)d") % msg_dict
|
msg = _("%(url)s returned with HTTP %(status)d") % msg_dict
|
||||||
except AttributeError, e:
|
except AttributeError as e:
|
||||||
msg_dict = dict(url=request.url, e=e)
|
msg_dict = dict(url=request.url, e=e)
|
||||||
msg = _("%(url)s returned a fault: %(e)s") % msg_dict
|
msg = _("%(url)s returned a fault: %(e)s") % msg_dict
|
||||||
|
|
||||||
|
@ -1479,7 +1479,7 @@ def volume_type_create(context, values):
|
|||||||
volume_type_ref = models.VolumeTypes()
|
volume_type_ref = models.VolumeTypes()
|
||||||
volume_type_ref.update(values)
|
volume_type_ref.update(values)
|
||||||
volume_type_ref.save()
|
volume_type_ref.save()
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
raise db_exc.DBError(e)
|
raise db_exc.DBError(e)
|
||||||
return volume_type_ref
|
return volume_type_ref
|
||||||
|
|
||||||
@ -1629,7 +1629,7 @@ def volume_type_extra_specs_update_or_create(context, volume_type_id,
|
|||||||
try:
|
try:
|
||||||
spec_ref = volume_type_extra_specs_get_item(
|
spec_ref = volume_type_extra_specs_get_item(
|
||||||
context, volume_type_id, key, session)
|
context, volume_type_id, key, session)
|
||||||
except exception.VolumeTypeExtraSpecsNotFound, e:
|
except exception.VolumeTypeExtraSpecsNotFound as e:
|
||||||
spec_ref = models.VolumeTypeExtraSpecs()
|
spec_ref = models.VolumeTypeExtraSpecs()
|
||||||
spec_ref.update({"key": key, "value": value,
|
spec_ref.update({"key": key, "value": value,
|
||||||
"volume_type_id": volume_type_id,
|
"volume_type_id": volume_type_id,
|
||||||
|
@ -66,7 +66,7 @@ class SchedulerOptions(object):
|
|||||||
"""Get the last modified datetime. Broken out for testing."""
|
"""Get the last modified datetime. Broken out for testing."""
|
||||||
try:
|
try:
|
||||||
return os.path.getmtime(filename)
|
return os.path.getmtime(filename)
|
||||||
except os.error, e:
|
except os.error as e:
|
||||||
LOG.exception(_("Could not stat scheduler options file "
|
LOG.exception(_("Could not stat scheduler options file "
|
||||||
"%(filename)s: '%(e)s'"), locals())
|
"%(filename)s: '%(e)s'"), locals())
|
||||||
raise
|
raise
|
||||||
@ -75,7 +75,7 @@ class SchedulerOptions(object):
|
|||||||
"""Decode the JSON file. Broken out for testing."""
|
"""Decode the JSON file. Broken out for testing."""
|
||||||
try:
|
try:
|
||||||
return json.load(handle)
|
return json.load(handle)
|
||||||
except ValueError, e:
|
except ValueError as e:
|
||||||
LOG.exception(_("Could not decode scheduler options: "
|
LOG.exception(_("Could not decode scheduler options: "
|
||||||
"'%(e)s'") % locals())
|
"'%(e)s'") % locals())
|
||||||
return {}
|
return {}
|
||||||
|
@ -370,7 +370,7 @@ class ParseLimitsTest(BaseLimitTestSuite):
|
|||||||
'(PUT, /foo*, /foo.*, 10, hour);'
|
'(PUT, /foo*, /foo.*, 10, hour);'
|
||||||
'(POST, /bar*, /bar.*, 5, second);'
|
'(POST, /bar*, /bar.*, 5, second);'
|
||||||
'(Say, /derp*, /derp.*, 1, day)')
|
'(Say, /derp*, /derp.*, 1, day)')
|
||||||
except ValueError, e:
|
except ValueError as e:
|
||||||
assert False, str(e)
|
assert False, str(e)
|
||||||
|
|
||||||
# Make sure the number of returned limits are correct
|
# Make sure the number of returned limits are correct
|
||||||
|
@ -370,7 +370,7 @@ class ParseLimitsTest(BaseLimitTestSuite):
|
|||||||
'(PUT, /foo*, /foo.*, 10, hour);'
|
'(PUT, /foo*, /foo.*, 10, hour);'
|
||||||
'(POST, /bar*, /bar.*, 5, second);'
|
'(POST, /bar*, /bar.*, 5, second);'
|
||||||
'(Say, /derp*, /derp.*, 1, day)')
|
'(Say, /derp*, /derp.*, 1, day)')
|
||||||
except ValueError, e:
|
except ValueError as e:
|
||||||
assert False, str(e)
|
assert False, str(e)
|
||||||
|
|
||||||
# Make sure the number of returned limits are correct
|
# Make sure the number of returned limits are correct
|
||||||
|
@ -133,7 +133,7 @@ class TestMigrations(test.TestCase):
|
|||||||
for key, value in defaults.items():
|
for key, value in defaults.items():
|
||||||
self.test_databases[key] = value
|
self.test_databases[key] = value
|
||||||
self.snake_walk = cp.getboolean('walk_style', 'snake_walk')
|
self.snake_walk = cp.getboolean('walk_style', 'snake_walk')
|
||||||
except ConfigParser.ParsingError, e:
|
except ConfigParser.ParsingError as e:
|
||||||
self.fail("Failed to read test_migrations.conf config "
|
self.fail("Failed to read test_migrations.conf config "
|
||||||
"file. Got error: %s" % e)
|
"file. Got error: %s" % e)
|
||||||
else:
|
else:
|
||||||
|
@ -220,7 +220,7 @@ def trycmd(*args, **kwargs):
|
|||||||
try:
|
try:
|
||||||
out, err = execute(*args, **kwargs)
|
out, err = execute(*args, **kwargs)
|
||||||
failed = False
|
failed = False
|
||||||
except exception.ProcessExecutionError, exn:
|
except exception.ProcessExecutionError as exn:
|
||||||
out, err = '', str(exn)
|
out, err = '', str(exn)
|
||||||
LOG.debug(err)
|
LOG.debug(err)
|
||||||
failed = True
|
failed = True
|
||||||
@ -620,7 +620,7 @@ class LoopingCall(object):
|
|||||||
if not self._running:
|
if not self._running:
|
||||||
break
|
break
|
||||||
greenthread.sleep(interval)
|
greenthread.sleep(interval)
|
||||||
except LoopingCallDone, e:
|
except LoopingCallDone as e:
|
||||||
self.stop()
|
self.stop()
|
||||||
done.send(e.retvalue)
|
done.send(e.retvalue)
|
||||||
except Exception:
|
except Exception:
|
||||||
@ -1062,7 +1062,7 @@ def tempdir(**kwargs):
|
|||||||
finally:
|
finally:
|
||||||
try:
|
try:
|
||||||
shutil.rmtree(tmpdir)
|
shutil.rmtree(tmpdir)
|
||||||
except OSError, e:
|
except OSError as e:
|
||||||
LOG.debug(_('Could not remove tmpdir: %s'), str(e))
|
LOG.debug(_('Could not remove tmpdir: %s'), str(e))
|
||||||
|
|
||||||
|
|
||||||
|
@ -328,7 +328,7 @@ class CoraidDriver(driver.VolumeDriver):
|
|||||||
% snapshot['id'])
|
% snapshot['id'])
|
||||||
try:
|
try:
|
||||||
self.esm.create_snapshot(volume_name, snapshot_name)
|
self.esm.create_snapshot(volume_name, snapshot_name)
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
msg = _('Failed to Create Snapshot %(snapname)s')
|
msg = _('Failed to Create Snapshot %(snapname)s')
|
||||||
LOG.debug(msg % dict(snapname=snapshot_name))
|
LOG.debug(msg % dict(snapname=snapshot_name))
|
||||||
raise
|
raise
|
||||||
|
@ -169,7 +169,7 @@ class GlusterfsDriver(nfs.RemoteFsDriver):
|
|||||||
try:
|
try:
|
||||||
self._ensure_share_mounted(share)
|
self._ensure_share_mounted(share)
|
||||||
self._mounted_shares.append(share)
|
self._mounted_shares.append(share)
|
||||||
except Exception, exc:
|
except Exception as exc:
|
||||||
LOG.warning(_('Exception during mounting %s') % (exc,))
|
LOG.warning(_('Exception during mounting %s') % (exc,))
|
||||||
|
|
||||||
LOG.debug('Available shares %s' % str(self._mounted_shares))
|
LOG.debug('Available shares %s' % str(self._mounted_shares))
|
||||||
|
@ -310,7 +310,7 @@ class NfsDriver(RemoteFsDriver):
|
|||||||
try:
|
try:
|
||||||
self._ensure_share_mounted(share)
|
self._ensure_share_mounted(share)
|
||||||
self._mounted_shares.append(share)
|
self._mounted_shares.append(share)
|
||||||
except Exception, exc:
|
except Exception as exc:
|
||||||
LOG.warning(_('Exception during mounting %s') % (exc,))
|
LOG.warning(_('Exception during mounting %s') % (exc,))
|
||||||
|
|
||||||
LOG.debug('Available shares %s' % str(self._mounted_shares))
|
LOG.debug('Available shares %s' % str(self._mounted_shares))
|
||||||
|
@ -145,7 +145,7 @@ class SolidFire(SanISCSIDriver):
|
|||||||
data = response.read()
|
data = response.read()
|
||||||
try:
|
try:
|
||||||
data = json.loads(data)
|
data = json.loads(data)
|
||||||
except (TypeError, ValueError), exc:
|
except (TypeError, ValueError) as exc:
|
||||||
connection.close()
|
connection.close()
|
||||||
msg = _("Call to json.loads() raised "
|
msg = _("Call to json.loads() raised "
|
||||||
"an exception: %s") % exc
|
"an exception: %s") % exc
|
||||||
|
@ -645,7 +645,7 @@ class VolumeManager(manager.SchedulerDependentManager):
|
|||||||
image_meta)
|
image_meta)
|
||||||
LOG.debug(_("Uploaded volume %(volume_id)s to "
|
LOG.debug(_("Uploaded volume %(volume_id)s to "
|
||||||
"image (%(image_id)s) successfully") % locals())
|
"image (%(image_id)s) successfully") % locals())
|
||||||
except Exception, error:
|
except Exception as error:
|
||||||
with excutils.save_and_reraise_exception():
|
with excutils.save_and_reraise_exception():
|
||||||
payload['message'] = unicode(error)
|
payload['message'] = unicode(error)
|
||||||
finally:
|
finally:
|
||||||
|
@ -125,7 +125,7 @@ def get_default_volume_type():
|
|||||||
ctxt = context.get_admin_context()
|
ctxt = context.get_admin_context()
|
||||||
try:
|
try:
|
||||||
vol_type = get_volume_type_by_name(ctxt, name)
|
vol_type = get_volume_type_by_name(ctxt, name)
|
||||||
except exception.VolumeTypeNotFoundByName, e:
|
except exception.VolumeTypeNotFoundByName as e:
|
||||||
# Couldn't find volume type with the name in default_volume_type
|
# Couldn't find volume type with the name in default_volume_type
|
||||||
# flag, record this issue and move on
|
# flag, record this issue and move on
|
||||||
#TODO(zhiteng) consider add notification to warn admin
|
#TODO(zhiteng) consider add notification to warn admin
|
||||||
|
@ -155,7 +155,7 @@ class Server(object):
|
|||||||
if use_ssl:
|
if use_ssl:
|
||||||
sock = wrap_ssl(sock)
|
sock = wrap_ssl(sock)
|
||||||
|
|
||||||
except socket.error, err:
|
except socket.error as err:
|
||||||
if err.args[0] != errno.EADDRINUSE:
|
if err.args[0] != errno.EADDRINUSE:
|
||||||
raise
|
raise
|
||||||
eventlet.sleep(0.1)
|
eventlet.sleep(0.1)
|
||||||
|
@ -79,7 +79,7 @@ def _print_module(mod_str):
|
|||||||
mod_str = mod_str[:mod_str.rfind(".")]
|
mod_str = mod_str[:mod_str.rfind(".")]
|
||||||
try:
|
try:
|
||||||
mod_obj = importutils.import_module(mod_str)
|
mod_obj = importutils.import_module(mod_str)
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
sys.stderr.write("Failed to collect options from module %s: %s\n" % (
|
sys.stderr.write("Failed to collect options from module %s: %s\n" % (
|
||||||
mod_str, str(e)))
|
mod_str, str(e)))
|
||||||
return
|
return
|
||||||
@ -153,7 +153,7 @@ def _print_opt(opt):
|
|||||||
opt_type = None
|
opt_type = None
|
||||||
try:
|
try:
|
||||||
opt_type = OPTION_REGEX.search(str(type(opt))).group(0)
|
opt_type = OPTION_REGEX.search(str(type(opt))).group(0)
|
||||||
except (ValueError, AttributeError), err:
|
except (ValueError, AttributeError) as err:
|
||||||
sys.stderr.write("%s\n" % str(err))
|
sys.stderr.write("%s\n" % str(err))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
opt_help += ' (' + OPT_TYPES[opt_type] + ')'
|
opt_help += ' (' + OPT_TYPES[opt_type] + ')'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user