Correct reraising of exception

When an exception was caught and rethrown,
it should call 'raise' without any arguments
because it shows the place where an exception
occured initially instead of place where the exception re-raised.

Change-Id: I5fb6dea5da7fb6e1e2b339a713c7d37f8c99e407
This commit is contained in:
qinchunhua 2016-07-07 07:42:01 -04:00 committed by Steve Martinelli
parent 272d193401
commit 6f36385cb8
12 changed files with 29 additions and 29 deletions

4
openstackclient/common/availability_zone.py Normal file → Executable file
View File

@ -122,11 +122,11 @@ class ListAvailabilityZone(command.Lister):
compute_client = self.app.client_manager.compute compute_client = self.app.client_manager.compute
try: try:
data = compute_client.availability_zones.list() data = compute_client.availability_zones.list()
except nova_exceptions.Forbidden as e: # policy doesn't allow except nova_exceptions.Forbidden: # policy doesn't allow
try: try:
data = compute_client.availability_zones.list(detailed=False) data = compute_client.availability_zones.list(detailed=False)
except Exception: except Exception:
raise e raise
# Argh, the availability zones are not iterable... # Argh, the availability zones are not iterable...
result = [] result = []

2
openstackclient/common/quota.py Normal file → Executable file
View File

@ -231,7 +231,7 @@ class ShowQuota(command.ShowOne):
if type(e).__name__ == 'EndpointNotFound': if type(e).__name__ == 'EndpointNotFound':
return {} return {}
else: else:
raise e raise
return quota._info return quota._info
def get_network_quota(self, parsed_args): def get_network_quota(self, parsed_args):

8
openstackclient/identity/v2_0/project.py Normal file → Executable file
View File

@ -86,7 +86,7 @@ class CreateProject(command.ShowOne):
enabled=enabled, enabled=enabled,
**kwargs **kwargs
) )
except ks_exc.Conflict as e: except ks_exc.Conflict:
if parsed_args.or_show: if parsed_args.or_show:
project = utils.find_resource( project = utils.find_resource(
identity_client.tenants, identity_client.tenants,
@ -94,7 +94,7 @@ class CreateProject(command.ShowOne):
) )
LOG.info(_('Returning existing project %s'), project.name) LOG.info(_('Returning existing project %s'), project.name)
else: else:
raise e raise
# TODO(stevemar): Remove the line below when we support multitenancy # TODO(stevemar): Remove the line below when we support multitenancy
project._info.pop('parent_id', None) project._info.pop('parent_id', None)
@ -242,7 +242,7 @@ class ShowProject(command.ShowOne):
parsed_args.project, parsed_args.project,
) )
info.update(project._info) info.update(project._info)
except ks_exc.Forbidden as e: except ks_exc.Forbidden:
auth_ref = self.app.client_manager.auth_ref auth_ref = self.app.client_manager.auth_ref
if ( if (
parsed_args.project == auth_ref.project_id or parsed_args.project == auth_ref.project_id or
@ -256,7 +256,7 @@ class ShowProject(command.ShowOne):
'enabled': True, 'enabled': True,
} }
else: else:
raise e raise
# TODO(stevemar): Remove the line below when we support multitenancy # TODO(stevemar): Remove the line below when we support multitenancy
info.pop('parent_id', None) info.pop('parent_id', None)

4
openstackclient/identity/v2_0/role.py Normal file → Executable file
View File

@ -93,7 +93,7 @@ class CreateRole(command.ShowOne):
identity_client = self.app.client_manager.identity identity_client = self.app.client_manager.identity
try: try:
role = identity_client.roles.create(parsed_args.role_name) role = identity_client.roles.create(parsed_args.role_name)
except ks_exc.Conflict as e: except ks_exc.Conflict:
if parsed_args.or_show: if parsed_args.or_show:
role = utils.find_resource( role = utils.find_resource(
identity_client.roles, identity_client.roles,
@ -101,7 +101,7 @@ class CreateRole(command.ShowOne):
) )
LOG.info(_('Returning existing role %s'), role.name) LOG.info(_('Returning existing role %s'), role.name)
else: else:
raise e raise
info = {} info = {}
info.update(role._info) info.update(role._info)

8
openstackclient/identity/v2_0/user.py Normal file → Executable file
View File

@ -102,7 +102,7 @@ class CreateUser(command.ShowOne):
tenant_id=project_id, tenant_id=project_id,
enabled=enabled, enabled=enabled,
) )
except ks_exc.Conflict as e: except ks_exc.Conflict:
if parsed_args.or_show: if parsed_args.or_show:
user = utils.find_resource( user = utils.find_resource(
identity_client.users, identity_client.users,
@ -110,7 +110,7 @@ class CreateUser(command.ShowOne):
) )
LOG.info(_('Returning existing user %s'), user.name) LOG.info(_('Returning existing user %s'), user.name)
else: else:
raise e raise
# NOTE(dtroyer): The users.create() method wants 'tenant_id' but # NOTE(dtroyer): The users.create() method wants 'tenant_id' but
# the returned resource has 'tenantId'. Sigh. # the returned resource has 'tenantId'. Sigh.
@ -349,7 +349,7 @@ class ShowUser(command.ShowOne):
parsed_args.user, parsed_args.user,
) )
info.update(user._info) info.update(user._info)
except ks_exc.Forbidden as e: except ks_exc.Forbidden:
auth_ref = self.app.client_manager.auth_ref auth_ref = self.app.client_manager.auth_ref
if ( if (
parsed_args.user == auth_ref.user_id or parsed_args.user == auth_ref.user_id or
@ -364,7 +364,7 @@ class ShowUser(command.ShowOne):
'enabled': True, 'enabled': True,
} }
else: else:
raise e raise
if 'tenantId' in info: if 'tenantId' in info:
info.update( info.update(

4
openstackclient/identity/v3/domain.py Normal file → Executable file
View File

@ -76,13 +76,13 @@ class CreateDomain(command.ShowOne):
description=parsed_args.description, description=parsed_args.description,
enabled=enabled, enabled=enabled,
) )
except ks_exc.Conflict as e: except ks_exc.Conflict:
if parsed_args.or_show: if parsed_args.or_show:
domain = utils.find_resource(identity_client.domains, domain = utils.find_resource(identity_client.domains,
parsed_args.name) parsed_args.name)
LOG.info(_('Returning existing domain %s'), domain.name) LOG.info(_('Returning existing domain %s'), domain.name)
else: else:
raise e raise
domain._info.pop('links') domain._info.pop('links')
return zip(*sorted(six.iteritems(domain._info))) return zip(*sorted(six.iteritems(domain._info)))

4
openstackclient/identity/v3/group.py Normal file → Executable file
View File

@ -160,14 +160,14 @@ class CreateGroup(command.ShowOne):
name=parsed_args.name, name=parsed_args.name,
domain=domain, domain=domain,
description=parsed_args.description) description=parsed_args.description)
except ks_exc.Conflict as e: except ks_exc.Conflict:
if parsed_args.or_show: if parsed_args.or_show:
group = utils.find_resource(identity_client.groups, group = utils.find_resource(identity_client.groups,
parsed_args.name, parsed_args.name,
domain_id=domain) domain_id=domain)
LOG.info(_('Returning existing group %s'), group.name) LOG.info(_('Returning existing group %s'), group.name)
else: else:
raise e raise
group._info.pop('links') group._info.pop('links')
return zip(*sorted(six.iteritems(group._info))) return zip(*sorted(six.iteritems(group._info)))

4
openstackclient/identity/v3/project.py Normal file → Executable file
View File

@ -111,14 +111,14 @@ class CreateProject(command.ShowOne):
enabled=enabled, enabled=enabled,
**kwargs **kwargs
) )
except ks_exc.Conflict as e: except ks_exc.Conflict:
if parsed_args.or_show: if parsed_args.or_show:
project = utils.find_resource(identity_client.projects, project = utils.find_resource(identity_client.projects,
parsed_args.name, parsed_args.name,
domain_id=domain) domain_id=domain)
LOG.info(_('Returning existing project %s'), project.name) LOG.info(_('Returning existing project %s'), project.name)
else: else:
raise e raise
project._info.pop('links') project._info.pop('links')
return zip(*sorted(six.iteritems(project._info))) return zip(*sorted(six.iteritems(project._info)))

4
openstackclient/identity/v3/role.py Normal file → Executable file
View File

@ -165,13 +165,13 @@ class CreateRole(command.ShowOne):
try: try:
role = identity_client.roles.create(name=parsed_args.name) role = identity_client.roles.create(name=parsed_args.name)
except ks_exc.Conflict as e: except ks_exc.Conflict:
if parsed_args.or_show: if parsed_args.or_show:
role = utils.find_resource(identity_client.roles, role = utils.find_resource(identity_client.roles,
parsed_args.name) parsed_args.name)
LOG.info(_('Returning existing role %s'), role.name) LOG.info(_('Returning existing role %s'), role.name)
else: else:
raise e raise
role._info.pop('links') role._info.pop('links')
return zip(*sorted(six.iteritems(role._info))) return zip(*sorted(six.iteritems(role._info)))

4
openstackclient/identity/v3/user.py Normal file → Executable file
View File

@ -121,14 +121,14 @@ class CreateUser(command.ShowOne):
description=parsed_args.description, description=parsed_args.description,
enabled=enabled enabled=enabled
) )
except ks_exc.Conflict as e: except ks_exc.Conflict:
if parsed_args.or_show: if parsed_args.or_show:
user = utils.find_resource(identity_client.users, user = utils.find_resource(identity_client.users,
parsed_args.name, parsed_args.name,
domain_id=domain_id) domain_id=domain_id)
LOG.info(_('Returning existing user %s'), user.name) LOG.info(_('Returning existing user %s'), user.name)
else: else:
raise e raise
user._info.pop('links') user._info.pop('links')
return zip(*sorted(six.iteritems(user._info))) return zip(*sorted(six.iteritems(user._info)))

8
openstackclient/image/v2/image.py Normal file → Executable file
View File

@ -339,7 +339,7 @@ class CreateImage(command.ShowOne):
with fp: with fp:
try: try:
image_client.images.upload(image.id, fp) image_client.images.upload(image.id, fp)
except Exception as e: except Exception:
# If the upload fails for some reason attempt to remove the # If the upload fails for some reason attempt to remove the
# dangling queued image made by the create() call above but # dangling queued image made by the create() call above but
# only if the user did not specify an id which indicates # only if the user did not specify an id which indicates
@ -349,7 +349,7 @@ class CreateImage(command.ShowOne):
image_client.images.delete(image.id) image_client.images.delete(image.id)
except Exception: except Exception:
pass # we don't care about this one pass # we don't care about this one
raise e # now, throw the upload exception again raise # now, throw the upload exception again
# update the image after the data has been uploaded # update the image after the data has been uploaded
image = image_client.images.get(image.id) image = image_client.images.get(image.id)
@ -834,11 +834,11 @@ class SetImage(command.Command):
try: try:
image = image_client.images.update(image.id, **kwargs) image = image_client.images.update(image.id, **kwargs)
except Exception as e: except Exception:
if activation_status is not None: if activation_status is not None:
LOG.info(_("Image %(id)s was %(status)s."), LOG.info(_("Image %(id)s was %(status)s."),
{'id': image.id, 'status': activation_status}) {'id': image.id, 'status': activation_status})
raise e raise
class ShowImage(command.ShowOne): class ShowImage(command.ShowOne):

4
openstackclient/shell.py Normal file → Executable file
View File

@ -331,10 +331,10 @@ class OpenStackShell(app.App):
'auth_type': auth_type, 'auth_type': auth_type,
}, },
) )
except (IOError, OSError) as e: except (IOError, OSError):
self.log.critical("Could not read clouds.yaml configuration file") self.log.critical("Could not read clouds.yaml configuration file")
self.print_help_if_requested() self.print_help_if_requested()
raise e raise
# TODO(thowe): Change cliff so the default value for debug # TODO(thowe): Change cliff so the default value for debug
# can be set to None. # can be set to None.