Merge "Ensure log messages are not translated"

This commit is contained in:
Jenkins 2017-04-27 22:39:12 +00:00 committed by Gerrit Code Review
commit 30a00a0dc3
27 changed files with 232 additions and 198 deletions

View File

@ -66,13 +66,14 @@ class JSONMessage(object):
except ValueError as exc:
self.failed = True
msg = _("Message json file '%(path)s' is malformed."
" %(exception)s")
msg = msg % {'path': self._path, 'exception': str(exc)}
params = {'path': self._path, 'exception': exc}
if self.fail_silently:
LOG.warning(msg)
LOG.warning("Message json file '%(path)s' is malformed. "
"%(exception)s", params)
else:
raise exceptions.MessageFailure(msg)
raise exceptions.MessageFailure(
_("Message json file '%(path)s' is malformed. "
"%(exception)s") % params)
else:
level_name = attrs.get('level', 'info')
if level_name in self.MESSAGE_LEVELS:
@ -89,13 +90,14 @@ class JSONMessage(object):
except Exception as exc:
self.failed = True
msg = _("Error processing message json file '%(path)s': "
"%(exception)s")
msg = msg % {'path': self._path, 'exception': str(exc)}
params = {'path': self._path, 'exception': exc}
if self.fail_silently:
LOG.warning(msg)
LOG.warning("Error processing message json file '%(path)s': "
"%(exception)s", params)
else:
raise exceptions.MessageFailure(msg)
raise exceptions.MessageFailure(
_("Error processing message json file '%(path)s': "
"%(exception)s") % params)
def send_message(self, request):
if self.failed:

View File

@ -391,10 +391,9 @@ class Column(html.HTMLElement):
# Basic object lookups
data = getattr(datum, self.transform, None)
if not hasattr(datum, self.transform):
msg = _("The attribute %(attr)s doesn't exist on "
"%(obj)s.") % {'attr': self.transform, 'obj': datum}
msg = termcolors.colorize(msg, **PALETTE['ERROR'])
LOG.debug(msg)
msg = "The attribute %(attr)s doesn't exist on %(obj)s."
LOG.debug(termcolors.colorize(msg, **PALETTE['ERROR']),
{'attr': self.transform, 'obj': datum})
return data
def get_data(self, datum):

View File

@ -45,8 +45,8 @@ def get_microversion_for_feature(service, feature, wrapper_class,
try:
service_features = MICROVERSION_FEATURES[service]
except KeyError:
LOG.debug("'%s' could not be found in the MICROVERSION_FEATURES "
"dict" % service)
LOG.debug("'%s' could not be found in the MICROVERSION_FEATURES dict",
service)
return None
feature_versions = service_features[feature]
for version in reversed(feature_versions):

View File

@ -1123,9 +1123,9 @@ def servers_update_addresses(request, servers, all_tenants=False):
networks = list_resources_with_long_filters(
network_list, 'id', set([port.network_id for port in ports]),
request=request)
except Exception:
except Exception as e:
LOG.error('Unable to connect to Neutron: %s', e)
error_message = _('Unable to connect to Neutron.')
LOG.error(error_message)
messages.error(request, error_message)
return
@ -1160,9 +1160,10 @@ def _server_get_addresses(request, server, ports, floating_ips, network_names):
def _format_address(mac, ip, type):
try:
version = netaddr.IPAddress(ip).version
except Exception:
except Exception as e:
LOG.error('Unable to parse IP address %(ip)s: %(exc)s',
{'ip': ip, 'exc': e})
error_message = _('Unable to parse IP address %s.') % ip
LOG.error(error_message)
messages.error(request, error_message)
raise
return {u'OS-EXT-IPS-MAC:mac_addr': mac,
@ -1283,10 +1284,9 @@ def get_feature_permission(request, feature, operation=None):
network_config = getattr(settings, 'OPENSTACK_NEUTRON_NETWORK', {})
feature_info = FEATURE_MAP.get(feature)
if not feature_info:
# Translators: Only used inside Horizon code and invisible to users
raise ValueError(_("The requested feature '%(feature)s' is unknown. "
"Please make sure to specify a feature defined "
"in FEATURE_MAP."))
raise ValueError("The requested feature '%(feature)s' is unknown. "
"Please make sure to specify a feature defined "
"in FEATURE_MAP.")
# Check dashboard settings
feature_config = feature_info.get('config')
@ -1300,10 +1300,9 @@ def get_feature_permission(request, feature, operation=None):
if feature_policies:
policy_name = feature_policies.get(operation)
if not policy_name:
# Translators: Only used inside Horizon code and invisible to users
raise ValueError(_("The 'operation' parameter for "
"get_feature_permission '%(feature)s' "
"is invalid. It should be one of %(allowed)s")
raise ValueError("The 'operation' parameter for "
"get_feature_permission '%(feature)s' "
"is invalid. It should be one of %(allowed)s"
% {'feature': feature,
'allowed': ' '.join(feature_policies.keys())})
role = (('network', policy_name),)
@ -1316,9 +1315,8 @@ def get_feature_permission(request, feature, operation=None):
try:
return is_extension_supported(request, feature_extension)
except Exception:
msg = (_("Failed to check Neutron '%s' extension is not supported")
% feature_extension)
LOG.info(msg)
LOG.info("Failed to check Neutron '%s' extension is not supported",
feature_extension)
return False
# If all checks are passed, now a given feature is allowed.

View File

@ -349,8 +349,8 @@ class SecurityGroupManager(network_base.SecurityGroupManager):
self.client.servers.remove_security_group(instance_id, group)
num_groups_to_modify -= 1
except nova_exceptions.ClientException as err:
LOG.error(_("Failed to modify %(num_groups_to_modify)d instance "
"security groups: %(err)s"),
LOG.error("Failed to modify %(num_groups_to_modify)d instance "
"security groups: %(err)s",
{'num_groups_to_modify': num_groups_to_modify,
'err': err})
# reraise novaclient.exceptions.ClientException, but with

View File

@ -54,8 +54,8 @@ class DeleteDHCPAgent(tables.DeleteAction):
api.neutron.remove_network_from_dhcp_agent(request, obj_id,
network_id)
except Exception as e:
LOG.info('Failed to delete agent: %s', e)
msg = _('Failed to delete agent: %s') % e
LOG.info(msg)
redirect = reverse('horizon:admin:networks:detail',
args=[network_id])
exceptions.handle(request, msg, redirect=redirect)

View File

@ -262,7 +262,7 @@ class CreateNetwork(forms.SelfHandlingForm):
params['provider:segmentation_id'] = (
data['segmentation_id'])
network = api.neutron.network_create(request, **params)
LOG.debug(_('Network %s was successfully created.'), data['name'])
LOG.debug('Network %s was successfully created.', data['name'])
return network
except Exception:
redirect = reverse('horizon:admin:networks:index')
@ -327,11 +327,11 @@ class UpdateNetwork(forms.SelfHandlingForm):
self.initial['network_id'],
**params)
msg = _('Network %s was successfully updated.') % data['name']
LOG.debug(msg)
messages.success(request, msg)
return network
except Exception:
except Exception as e:
LOG.info('Failed to update network %(id)s: %(exc)s',
{'id': self.initial['network_id'], 'exc': e})
msg = _('Failed to update network %s') % data['name']
LOG.info(msg)
redirect = reverse(self.failure_url)
exceptions.handle(request, msg, redirect=redirect)

View File

@ -127,15 +127,15 @@ class CreatePort(project_forms.CreatePort):
port = api.neutron.port_create(request, **params)
msg = _('Port %s was successfully created.') % port['id']
LOG.debug(msg)
messages.success(request, msg)
return port
except Exception:
msg = _('Failed to create a port for network %s') \
% data['network_id']
LOG.info(msg)
except Exception as e:
net_id = data['network_id']
LOG.info('Failed to create a port for network %(id)s: %(exc)s',
{'id': net_id, 'exc': e})
msg = _('Failed to create a port for network %s') % net_id
redirect = reverse(self.failure_url,
args=(data['network_id'],))
args=(net_id,))
exceptions.handle(request, msg, redirect=redirect)
@ -187,12 +187,12 @@ class UpdatePort(project_forms.UpdatePort):
mac_address=data['mac_address'],
**extension_kwargs)
msg = _('Port %s was successfully updated.') % data['port_id']
LOG.debug(msg)
messages.success(request, msg)
return port
except Exception:
except Exception as e:
LOG.info('Failed to update port %(id)s: %(exc)s',
{'id': data['port_id'], 'exc': e})
msg = _('Failed to update port %s') % data['port_id']
LOG.info(msg)
redirect = reverse(self.failure_url,
args=[data['network_id']])
exceptions.handle(request, msg, redirect=redirect)

View File

@ -54,9 +54,10 @@ class DeleteSubnet(proj_tables.SubnetPolicyTargetMixin, tables.DeleteAction):
def delete(self, request, obj_id):
try:
api.neutron.subnet_delete(request, obj_id)
except Exception:
except Exception as e:
LOG.info('Failed to delete subnet %(id)s: %(exc)s',
{'id': obj_id, 'exc': e})
msg = _('Failed to delete subnet %s') % obj_id
LOG.info(msg)
network_id = self.table.kwargs['network_id']
redirect = reverse('horizon:admin:networks:detail',
args=[network_id])

View File

@ -64,10 +64,11 @@ class CreateSubnet(project_workflows.CreateSubnet):
# created for if admin user does not belong to the tenant.
network = api.neutron.network_get(request,
self.context['network_id'])
except Exception:
except Exception as e:
LOG.info('Failed to retrieve network %(id)s for a subnet: %(exc)s',
{'id': data['network_id'], 'exc': e})
msg = (_('Failed to retrieve network %s for a subnet') %
data['network_id'])
LOG.info(msg)
redirect = self.get_failure_url()
exceptions.handle(request, msg, redirect=redirect)
subnet = self._create_subnet(request, data,

View File

@ -53,9 +53,10 @@ class DeleteNetwork(policy.PolicyTargetMixin, tables.DeleteAction):
def delete(self, request, obj_id):
try:
api.neutron.network_delete(request, obj_id)
except Exception:
except Exception as e:
LOG.info('Failed to delete network %(id)s: %(exc)s',
{'id': obj_id, 'exc': e})
msg = _('Failed to delete network %s') % obj_id
LOG.info(msg)
redirect = reverse('horizon:admin:networks:index')
exceptions.handle(request, msg, redirect=redirect)

View File

@ -40,8 +40,8 @@ class AddProtocolForm(forms.SelfHandlingForm):
try:
mappings = api.keystone.mapping_list(request)
except Exception as e:
LOG.info('Failed to get mapping list %s', e)
msg = _('Failed to get mapping list %s') % e
LOG.info(msg)
messages.error(request, msg)
choices = [(m.id, m.id) for m in mappings]

View File

@ -12,7 +12,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import abc
import logging
from django.core.urlresolvers import reverse
@ -89,13 +88,13 @@ class UpdateRule(forms.SelfHandlingForm):
try:
rule = api.fwaas.rule_update(request, rule_id, **context)
msg = _('Rule %s was successfully updated.') % name_or_id
LOG.debug(msg)
messages.success(request, msg)
return rule
except Exception as e:
LOG.error('Failed to update rule %(id)s: %(reason)s',
{'id': rule_id, 'reason': e})
msg = (_('Failed to update rule %(name)s: %(reason)s') %
{'name': name_or_id, 'reason': e})
LOG.error(msg)
redirect = reverse(self.failure_url)
exceptions.handle(request, msg, redirect=redirect)
@ -115,13 +114,13 @@ class UpdatePolicy(forms.SelfHandlingForm):
try:
policy = api.fwaas.policy_update(request, policy_id, **context)
msg = _('Policy %s was successfully updated.') % name_or_id
LOG.debug(msg)
messages.success(request, msg)
return policy
except Exception as e:
msg = _('Failed to update policy %(name)s: %(reason)s') % {
'name': name_or_id, 'reason': e}
LOG.error(msg)
LOG.error('Failed to update policy %(id)s: %(reason)s',
{'id': policy_id, 'reason': e})
msg = (_('Failed to update policy %(name)s: %(reason)s') %
{'name': name_or_id, 'reason': e})
redirect = reverse(self.failure_url)
exceptions.handle(request, msg, redirect=redirect)
@ -167,13 +166,13 @@ class UpdateFirewall(forms.SelfHandlingForm):
firewall = api.fwaas.firewall_update(request, firewall_id,
**context)
msg = _('Firewall %s was successfully updated.') % name_or_id
LOG.debug(msg)
messages.success(request, msg)
return firewall
except Exception as e:
msg = _('Failed to update firewall %(name)s: %(reason)s') % {
'name': name_or_id, 'reason': e}
LOG.error(msg)
LOG.error('Failed to update firewall %(id)s: %(reason)s',
{'id': firewall_id, 'reason': e})
msg = (_('Failed to update firewall %(name)s: %(reason)s') %
{'name': name_or_id, 'reason': e})
redirect = reverse(self.failure_url)
exceptions.handle(request, msg, redirect=redirect)
@ -207,8 +206,8 @@ class InsertRuleToPolicy(forms.SelfHandlingForm):
current_choices = [(r.id, r.name_or_id) for r in current_rules]
except Exception as e:
LOG.error('Failed to retrieve available rules: %s', e)
msg = _('Failed to retrieve available rules: %s') % e
LOG.error(msg)
redirect = reverse(self.failure_url)
exceptions.handle(request, msg, redirect=redirect)
@ -230,13 +229,13 @@ class InsertRuleToPolicy(forms.SelfHandlingForm):
'%(policy)s.') % {
'rule': insert_rule.name or insert_rule.id,
'policy': policy_name_or_id}
LOG.debug(msg)
messages.success(request, msg)
return policy
except Exception as e:
msg = _('Failed to insert rule to policy %(name)s: %(reason)s') % {
'name': policy_id, 'reason': e}
LOG.error(msg)
LOG.error('Failed to insert rule to policy %(id)s: %(reason)s',
{'id': policy_id, 'reason': e})
msg = (_('Failed to insert rule to policy %(name)s: %(reason)s') %
{'name': policy_id, 'reason': e})
redirect = reverse(self.failure_url)
exceptions.handle(request, msg, redirect=redirect)
@ -260,9 +259,12 @@ class RemoveRuleFromPolicy(forms.SelfHandlingForm):
current_choices = [(r.id, r.name_or_id) for r in current_rules]
except Exception as e:
msg = _('Failed to retrieve current rules in policy %(name)s: '
'%(reason)s') % {'name': self.initial['name'], 'reason': e}
LOG.error(msg)
LOG.error('Failed to retrieve current rules in policy %(id)s: '
'%(reason)s',
{'id': self.initial['policy_id'], 'reason': e})
msg = (_('Failed to retrieve current rules in policy %(name)s: '
'%(reason)s') %
{'name': self.initial['name'], 'reason': e})
redirect = reverse(self.failure_url)
exceptions.handle(request, msg, redirect=redirect)
@ -280,58 +282,18 @@ class RemoveRuleFromPolicy(forms.SelfHandlingForm):
'%(policy)s.') % {
'rule': remove_rule.name or remove_rule.id,
'policy': policy_name_or_id}
LOG.debug(msg)
messages.success(request, msg)
return policy
except Exception as e:
msg = _('Failed to remove rule from policy %(name)s: '
'%(reason)s') % {'name': self.initial['name'],
'reason': e}
LOG.error(msg)
LOG.error('Failed to remove rule from policy %(id)s: %(reason)s',
{'id': policy_id, 'reason': e})
msg = (_('Failed to remove rule from policy %(name)s: %(reason)s')
% {'name': self.initial['name'], 'reason': e})
redirect = reverse(self.failure_url)
exceptions.handle(request, msg, redirect=redirect)
class RouterInsertionFormBase(forms.SelfHandlingForm):
def __init__(self, request, *args, **kwargs):
super(RouterInsertionFormBase, self).__init__(request, *args, **kwargs)
try:
router_choices = self.get_router_choices(request, kwargs)
self.fields['router_ids'].choices = router_choices
except Exception as e:
msg = self.init_failure_msg % {'name': self.initial['name'],
'reason': e}
LOG.error(msg)
redirect = reverse(self.failure_url)
exceptions.handle(request, msg, redirect=redirect)
@abc.abstractmethod
def get_router_choices(self, request, kwargs):
"""Return a list of selectable routers."""
@abc.abstractmethod
def get_new_router_ids(self, context):
"""Return a new list of router IDs associated with the firewall."""
def handle(self, request, context):
firewall_id = self.initial['firewall_id']
firewall_name_or_id = self.initial['name'] or firewall_id
try:
body = {'router_ids': self.get_new_router_ids(context)}
firewall = api.fwaas.firewall_update(request, firewall_id, **body)
msg = self.success_msg % {'firewall': firewall_name_or_id}
LOG.debug(msg)
messages.success(request, msg)
return firewall
except Exception as e:
msg = self.failure_msg % {'name': firewall_name_or_id, 'reason': e}
LOG.error(msg)
redirect = reverse(self.failure_url)
exceptions.handle(request, msg, redirect=redirect)
class AddRouterToFirewall(RouterInsertionFormBase):
class AddRouterToFirewall(forms.SelfHandlingForm):
router_ids = forms.MultipleChoiceField(
label=_("Add Routers"),
required=False,
@ -339,10 +301,17 @@ class AddRouterToFirewall(RouterInsertionFormBase):
help_text=_("Add selected router(s) to the firewall."))
failure_url = 'horizon:project:firewalls:index'
success_msg = _('Router(s) was/were successfully added to firewall '
'%(firewall)s.')
failure_msg = _('Failed to add router(s) to firewall %(name)s: %(reason)s')
init_failure_msg = _('Failed to retrieve available routers: %(reason)s')
def __init__(self, request, *args, **kwargs):
super(AddRouterToFirewall, self).__init__(request, *args, **kwargs)
try:
router_choices = self.get_router_choices(request, kwargs)
self.fields['router_ids'].choices = router_choices
except Exception as e:
LOG.error('Failed to retrieve available routers: %s', e)
msg = _('Failed to retrieve available routers: %s') % e
redirect = reverse(self.failure_url)
exceptions.handle(request, msg, redirect=redirect)
def get_router_choices(self, request, kwargs):
tenant_id = self.request.user.tenant_id
@ -355,8 +324,28 @@ class AddRouterToFirewall(RouterInsertionFormBase):
add_router_ids = context['router_ids']
return add_router_ids + existing_router_ids
def handle(self, request, context):
firewall_id = self.initial['firewall_id']
firewall_name_or_id = self.initial['name'] or firewall_id
try:
body = {'router_ids': self.get_new_router_ids(context)}
firewall = api.fwaas.firewall_update(request, firewall_id, **body)
msg = (_('Router(s) was/were successfully added to firewall '
'%(firewall)s.') %
{'firewall': firewall_name_or_id})
messages.success(request, msg)
return firewall
except Exception as e:
LOG.error('Failed to add router(s) to firewall %(id)s: %(reason)s',
{'id': firewall_id, 'reason': e})
msg = (_('Failed to add router(s) to firewall %(name)s: '
'%(reason)s') %
{'name': firewall_name_or_id, 'reason': e})
redirect = reverse(self.failure_url)
exceptions.handle(request, msg, redirect=redirect)
class RemoveRouterFromFirewall(RouterInsertionFormBase):
class RemoveRouterFromFirewall(forms.SelfHandlingForm):
router_ids = forms.MultipleChoiceField(
label=_("Associated Routers"),
required=False,
@ -364,12 +353,22 @@ class RemoveRouterFromFirewall(RouterInsertionFormBase):
help_text=_("Unselect the router(s) to be removed from firewall."))
failure_url = 'horizon:project:firewalls:index'
success_msg = _('Router(s) was successfully removed from firewall '
'%(firewall)s.')
failure_msg = _('Failed to remove router(s) from firewall %(name)s: '
'%(reason)s')
init_failure_msg = _('Failed to retrieve current routers in firewall '
'%(name)s: %(reason)s')
def __init__(self, request, *args, **kwargs):
super(RemoveRouterFromFirewall, self).__init__(request,
*args, **kwargs)
try:
router_choices = self.get_router_choices(request, kwargs)
self.fields['router_ids'].choices = router_choices
except Exception as e:
LOG.error('Failed to retrieve current routers in firewall %(id)s: '
'%(reason)s',
{'id': self.initial['firewall_id'], 'reason': e})
msg = (_('Failed to retrieve current routers in firewall '
'%(name)s: %(reason)s') %
{'name': self.initial['name'], 'reason': e})
redirect = reverse(self.failure_url)
exceptions.handle(request, msg, redirect=redirect)
def get_router_choices(self, request, kwargs):
tenant_id = self.request.user.tenant_id
@ -381,3 +380,23 @@ class RemoveRouterFromFirewall(RouterInsertionFormBase):
def get_new_router_ids(self, context):
# context[router_ids] is router IDs to be kept.
return context['router_ids']
def handle(self, request, context):
firewall_id = self.initial['firewall_id']
firewall_name_or_id = self.initial['name'] or firewall_id
try:
body = {'router_ids': self.get_new_router_ids(context)}
firewall = api.fwaas.firewall_update(request, firewall_id, **body)
msg = (_('Router(s) was successfully removed from firewall '
'%(firewall)s.') %
{'firewall': firewall_name_or_id})
messages.success(request, msg)
return firewall
except Exception as e:
LOG.error('Failed to remove router(s) from firewall %(id)s: '
'%(reason)s', {'id': firewall_id, 'reason': e})
msg = (_('Failed to remove router(s) from firewall %(name)s: '
'%(reason)s') %
{'name': firewall_name_or_id, 'reason': e})
redirect = reverse(self.failure_url)
exceptions.handle(request, msg, redirect=redirect)

View File

@ -418,7 +418,6 @@ class FirewallsTable(tables.DataTable):
'fwaasrouterinsertion'):
del self.columns['router_ids']
except Exception as e:
msg = _('Failed to verify extension support %(reason)s') % {
'reason': e}
LOG.error(msg)
LOG.error('Failed to verify extension support %s', e)
msg = _('Failed to verify extension support %s') % e
exceptions.handle(request, msg)

View File

@ -62,11 +62,11 @@ class UpdateNetwork(forms.SelfHandlingForm):
data['network_id'],
**params)
msg = _('Network %s was successfully updated.') % data['name']
LOG.debug(msg)
messages.success(request, msg)
return network
except Exception:
except Exception as e:
LOG.info('Failed to update network %(id)s: %(exc)s',
{'id': data['network_id'], 'exc': e})
msg = _('Failed to update network %s') % data['name']
LOG.info(msg)
redirect = reverse(self.failure_url)
exceptions.handle(request, msg, redirect=redirect)

View File

@ -159,13 +159,13 @@ class CreatePort(forms.SelfHandlingForm):
msg = _('Port %s was successfully created.') % port['name']
else:
msg = _('Port %s was successfully created.') % port['id']
LOG.debug(msg)
messages.success(request, msg)
return port
except Exception:
msg = _('Failed to create a port for network %s') \
% data['network_id']
LOG.info(msg)
except Exception as e:
LOG.info('Failed to create a port for network %(id)s: %(exc)s',
{'id': data['network_id'], 'exc': e})
msg = (_('Failed to create a port for network %s')
% data['network_id'])
redirect = reverse(self.failure_url,
args=(data['network_id'],))
exceptions.handle(request, msg, redirect=redirect)
@ -248,12 +248,12 @@ class UpdatePort(forms.SelfHandlingForm):
admin_state_up=data['admin_state'],
**extension_kwargs)
msg = _('Port %s was successfully updated.') % data['port_id']
LOG.debug(msg)
messages.success(request, msg)
return port
except Exception:
except Exception as e:
LOG.info('Failed to update port %(id)s: %(exc)s',
{'id': data['port_id'], 'exc': e})
msg = _('Failed to update port %s') % data['port_id']
LOG.info(msg)
redirect = reverse(self.failure_url,
args=[data['network_id']])
exceptions.handle(request, msg, redirect=redirect)

View File

@ -106,9 +106,10 @@ class DeletePort(policy.PolicyTargetMixin, tables.DeleteAction):
failure_url = "horizon:project:networks:detail"
try:
api.neutron.port_delete(request, port_id)
except Exception:
msg = _('Failed to delete port: %s') % port_id
LOG.info(msg)
except Exception as e:
LOG.info('Failed to delete port %(id)s: %(exc)s',
{'id': port_id, 'exc': e})
msg = _('Failed to delete port %s') % port_id
network_id = self.table.kwargs['network_id']
redirect = reverse(failure_url,
args=[network_id])

View File

@ -79,9 +79,10 @@ class DeleteSubnet(SubnetPolicyTargetMixin, CheckNetworkEditable,
def delete(self, request, obj_id):
try:
api.neutron.subnet_delete(request, obj_id)
except Exception:
except Exception as e:
LOG.info('Failed to delete subnet %(id)s: %(exc)s',
{'id': obj_id, 'exc': e})
msg = _('Failed to delete subnet %s') % obj_id
LOG.info(msg)
network_id = self.table.kwargs['network_id']
redirect = reverse('horizon:project:networks:detail',
args=[network_id])

View File

@ -75,9 +75,10 @@ class DeleteNetwork(policy.PolicyTargetMixin, CheckNetworkEditable,
LOG.debug('Deleted subnet %s', subnet_id)
api.neutron.network_delete(request, network_id)
LOG.debug('Deleted network %s successfully', network_id)
except Exception:
except Exception as e:
LOG.info('Failed to delete network %(id)s: %(exc)s',
{'id': network_id, 'exc': e})
msg = _('Failed to delete network %s')
LOG.info(msg, network_id)
redirect = reverse("horizon:project:networks:index")
exceptions.handle(request, msg % network_name, redirect=redirect)

View File

@ -469,9 +469,9 @@ class CreateNetwork(workflows.Workflow):
network.name_or_id)
return network
except Exception as e:
LOG.info('Failed to create network: %s', e)
msg = (_('Failed to create network "%(network)s": %(reason)s') %
{"network": data['net_name'], "reason": e})
LOG.info(msg)
redirect = self.get_failure_url()
exceptions.handle(request, msg, redirect=redirect)
return False
@ -560,15 +560,17 @@ class CreateNetwork(workflows.Workflow):
"""Delete the created network when subnet creation failed."""
try:
api.neutron.network_delete(request, network.id)
LOG.debug('Delete the created network %s '
'due to subnet creation failure.', network.id)
msg = _('Delete the created network "%s" '
'due to subnet creation failure.') % network.name
LOG.debug(msg)
redirect = self.get_failure_url()
messages.info(request, msg)
raise exceptions.Http302(redirect)
except Exception:
except Exception as e:
LOG.info('Failed to delete network %(id)s: %(exc)s',
{'id': network.id, 'exc': e})
msg = _('Failed to delete network "%s"') % network.name
LOG.info(msg)
redirect = self.get_failure_url()
exceptions.handle(request, msg, redirect=redirect)

View File

@ -43,18 +43,18 @@ class AddRouterRoute(forms.SelfHandlingForm):
router_id,
route)
msg = _('Static route added')
LOG.debug(msg)
messages.success(request, msg)
return True
except neutron_exc.BadRequest as e:
msg = (_('Invalid format for routes : %s') % e)
LOG.info(msg)
LOG.info('Invalid format for routes %(route)s: %(exc)s',
{'route': route, 'exc': e})
msg = _('Invalid format for routes: %s') % e
messages.error(request, msg)
redirect = reverse(self.failure_url, args=[router_id])
exceptions.handle(request, msg, redirect=redirect)
except Exception as e:
msg = (_('Failed to add route : %s') % e)
LOG.info(msg)
LOG.info('Failed to add route: %s', e)
msg = _('Failed to add route: %s') % e
messages.error(request, msg)
redirect = reverse(self.failure_url, args=[router_id])
exceptions.handle(request, msg, redirect=redirect)

View File

@ -36,9 +36,9 @@ class ExtraRoutesTab(tabs.TableTab):
def allowed(self, request):
try:
return api.is_extension_supported(request, 'extraroute')
except Exception:
LOG.info(_("Failed to check if Neutron extraroute extension is "
"supported"))
except Exception as e:
LOG.info("Failed to check if Neutron extraroute extension is "
"supported: %s", e)
return False
def get_extra_routes_data(self):

View File

@ -74,9 +74,9 @@ class CreateForm(forms.SelfHandlingForm):
search_opts = {'router:external': True}
try:
networks = api.neutron.network_list(request, **search_opts)
except Exception:
except Exception as e:
LOG.info('Failed to get network list: %s', e)
msg = _('Failed to get network list.')
LOG.info(msg)
messages.warning(request, msg)
networks = []
@ -103,11 +103,11 @@ class CreateForm(forms.SelfHandlingForm):
messages.success(request, message)
return router
except Exception as exc:
LOG.info('Failed to create router: %s', exc)
if exc.status_code == 409:
msg = _('Quota exceeded for resource router.')
else:
msg = _('Failed to create router "%s".') % data['name']
LOG.info(msg)
redirect = reverse(self.failure_url)
exceptions.handle(request, msg, redirect=redirect)
return False
@ -162,10 +162,10 @@ class UpdateForm(forms.SelfHandlingForm):
router = api.neutron.router_update(request, data['router_id'],
**params)
msg = _('Router %s was successfully updated.') % data['name']
LOG.debug(msg)
messages.success(request, msg)
return router
except Exception:
except Exception as exc:
LOG.info('Failed to update router %(id)s: %(exc)s',
{'id': data['router_id'], 'exc': exc})
msg = _('Failed to update router %s') % data['name']
LOG.info(msg)
exceptions.handle(request, msg, redirect=self.redirect_url)

View File

@ -59,8 +59,8 @@ class AddInterface(forms.SelfHandlingForm):
router_subnet_ids = [fixed_ip["subnet_id"] for port in ports
for fixed_ip in port.fixed_ips]
except Exception as e:
msg = _('Failed to get network list %s') % e
LOG.info(msg)
LOG.info('Failed to get network list: %s', e)
msg = _('Failed to get network list: %s') % e
messages.error(request, msg)
if router_id:
redirect = reverse(self.failure_url, args=[router_id])
@ -92,7 +92,6 @@ class AddInterface(forms.SelfHandlingForm):
msg = _('Interface added')
if port:
msg += ' ' + port.fixed_ips[0]['ip_address']
LOG.debug(msg)
messages.success(request, msg)
return True
@ -136,17 +135,18 @@ class AddInterface(forms.SelfHandlingForm):
return port
def _handle_error(self, request, router_id, reason):
msg = _('Failed to add_interface: %s') % reason
LOG.info(msg)
LOG.info('Failed to add_interface: %s', reason)
msg = _('Failed to add interface: %s') % reason
redirect = reverse(self.failure_url, args=[router_id])
exceptions.handle(request, msg, redirect=redirect)
def _delete_port(self, request, port):
try:
api.neutron.port_delete(request, port.id)
except Exception:
except Exception as e:
LOG.info('Failed to delete port %(id)s: %(exc)s',
{'id': port.id, 'exc': e})
msg = _('Failed to delete port %s') % port.id
LOG.info(msg)
exceptions.handle(request, msg)
@ -170,8 +170,8 @@ class SetGatewayForm(forms.SelfHandlingForm):
try:
networks = api.neutron.network_list(request, **search_opts)
except Exception as e:
msg = _('Failed to get network list %s') % e
LOG.info(msg)
LOG.info('Faield to get network list: %s', e)
msg = _('Failed to get network list: %s') % e
messages.error(request, msg)
redirect = reverse(self.failure_url)
exceptions.handle(request, msg, redirect=redirect)
@ -190,11 +190,11 @@ class SetGatewayForm(forms.SelfHandlingForm):
data['router_id'],
data['network_id'])
msg = _('Gateway interface is added')
LOG.debug(msg)
messages.success(request, msg)
return True
except Exception as e:
msg = _('Failed to set gateway %s') % e
LOG.info(msg)
LOG.info('Failed to set gateway to router %(id)s: %(exc)s',
{'id': data['router_id'], 'exc': e})
msg = _('Failed to set gateway: %s') % e
redirect = reverse(self.failure_url)
exceptions.handle(request, msg, redirect=redirect)

View File

@ -81,9 +81,10 @@ class RemoveInterface(policy.PolicyTargetMixin, tables.DeleteAction):
api.neutron.router_remove_interface(request,
router_id,
port_id=obj_id)
except Exception:
except Exception as e:
LOG.info('Failed to delete interface %(id)s: %(exc)s',
{'id': obj_id, 'exc': e})
msg = _('Failed to delete interface %s') % obj_id
LOG.info(msg)
router_id = self.table.kwargs['router_id']
redirect = reverse(self.failure_url,
args=[router_id])

View File

@ -64,16 +64,23 @@ class DeleteRouter(policy.PolicyTargetMixin, tables.DeleteAction):
port_id=port.id)
api.neutron.router_delete(request, obj_id)
except q_ext.NeutronClientException as e:
msg = _('Unable to delete router "%s"') % e
LOG.info(msg)
messages.error(request, msg)
redirect = reverse(self.redirect_url)
raise exceptions.Http302(redirect, message=msg)
except Exception:
# TODO(amotoki): Revisit why Http302 needs to be raised.
# We have this pattern ONLY HERE.
# Can't we merge two except clauses?
LOG.info('Unable to delete router %(id)s: %(exc)s',
{'id': obj_id, 'exc': e})
obj = self.table.get_object_by_id(obj_id)
name = self.table.get_object_display(obj)
msg = _('Unable to delete router "%s"') % name
messages.error(request, msg)
redirect = reverse(self.redirect_url)
raise exceptions.Http302(redirect, message=msg)
except Exception as e:
LOG.info('Unable to delete router %(id)s: %(exc)s',
{'id': obj_id, 'exc': e})
obj = self.table.get_object_by_id(obj_id)
name = self.table.get_object_display(obj)
msg = _('Unable to delete router "%s"') % name
LOG.info(msg)
exceptions.handle(request, msg)
def allowed(self, request, router=None):
@ -158,10 +165,11 @@ class ClearGateway(policy.PolicyTargetMixin, tables.BatchAction):
try:
api.neutron.router_remove_gateway(request, obj_id)
except Exception as e:
LOG.info('Unable to clear gateway for router %(id)s: %(exc)s',
{'id': obj_id, 'exc': e})
msg = (_('Unable to clear gateway for router '
'"%(name)s": "%(msg)s"')
% {"name": name, "msg": e})
LOG.info(msg)
redirect = reverse(self.redirect_url)
exceptions.handle(request, msg, redirect=redirect)

View File

@ -49,12 +49,12 @@ class UpdateVPNService(forms.SelfHandlingForm):
request, context['vpnservice_id'], **data)
msg = (_('VPN Service %s was successfully updated.')
% context['name'])
LOG.debug(msg)
messages.success(request, msg)
return vpnservice
except Exception as e:
LOG.info('Failed to update VPN Service %(id)s: %(exc)s',
{'id': context['vpnservice_id'], 'exc': e})
msg = _('Failed to update VPN Service %s') % context['name']
LOG.info('%(msg)s: %(exception)s', {'msg': msg, 'exception': e})
redirect = reverse(self.failure_url)
exceptions.handle(request, msg, redirect=redirect)
@ -128,12 +128,12 @@ class UpdateIKEPolicy(forms.SelfHandlingForm):
request, context['ikepolicy_id'], **data)
msg = (_('IKE Policy %s was successfully updated.')
% context['name'])
LOG.debug(msg)
messages.success(request, msg)
return ikepolicy
except Exception as e:
LOG.info('Failed to update IKE Policy %(id)s: %(exc)s',
{'id': context['ikepolicy_id'], 'exc': e})
msg = _('Failed to update IKE Policy %s') % context['name']
LOG.info('%(msg)s: %(exception)s', {'msg': msg, 'exception': e})
redirect = reverse(self.failure_url)
exceptions.handle(request, msg, redirect=redirect)
@ -206,12 +206,12 @@ class UpdateIPSecPolicy(forms.SelfHandlingForm):
request, context['ipsecpolicy_id'], **data)
msg = (_('IPSec Policy %s was successfully updated.')
% context['name'])
LOG.debug(msg)
messages.success(request, msg)
return ipsecpolicy
except Exception as e:
LOG.info('Failed to update IPSec Policy %(id)s: %(exc)s',
{'id': context['ipsecpolicy_id'], 'exc': e})
msg = _('Failed to update IPSec Policy %s') % context['name']
LOG.info('%(msg)s: %(exception)s', {'msg': msg, 'exception': e})
redirect = reverse(self.failure_url)
exceptions.handle(request, msg, redirect=redirect)
@ -312,12 +312,12 @@ class UpdateIPSecSiteConnection(forms.SelfHandlingForm):
request, context['ipsecsiteconnection_id'], **data)
msg = (_('IPSec Site Connection %s was successfully updated.')
% context['name'])
LOG.debug(msg)
messages.success(request, msg)
return ipsecsiteconnection
except Exception as e:
LOG.info('Failed to update IPSec Site Connection %(id)s: %(exc)s',
{'id': context['ipsecsiteconnection_id'], 'exc': e})
msg = (_('Failed to update IPSec Site Connection %s')
% context['name'])
LOG.info('%(msg)s: %(exception)s', {'msg': msg, 'exception': e})
redirect = reverse(self.failure_url)
exceptions.handle(request, msg, redirect=redirect)