From be461acd6fcd097f554a5a4e95a4aa3f956080a0 Mon Sep 17 00:00:00 2001 From: manchandavishal Date: Mon, 26 Aug 2019 15:38:47 +0000 Subject: [PATCH] Cleanup for Refactor-error-messages This patch is a clean-up patch for refactor-error-messages bp which remove the exception message from base message otherwise the same exception message display twice like this https://ibb.co/XyFWMdz . Partially-Implements blueprint refactor-error-messages Change-Id: I46b632dbb6701785e7d654feff336a27d6ecea9c --- .../dashboards/admin/volume_types/forms.py | 4 ++-- .../identity/application_credentials/forms.py | 4 ++-- .../dashboards/project/images/snapshots/forms.py | 4 ++-- .../dashboards/project/instances/forms.py | 13 ++++--------- .../dashboards/project/instances/utils.py | 4 ++-- .../project/instances/workflows/update_instance.py | 5 +++-- .../project/networks/subnets/workflows.py | 6 ++---- .../dashboards/project/networks/workflows.py | 12 +++++------- .../project/routers/extensions/extraroutes/forms.py | 2 +- .../dashboards/project/routers/ports/forms.py | 6 +++--- .../dashboards/project/routers/views.py | 4 ++-- .../dashboards/project/security_groups/forms.py | 5 ++--- .../dashboards/settings/password/forms.py | 4 ++-- 13 files changed, 32 insertions(+), 41 deletions(-) diff --git a/openstack_dashboard/dashboards/admin/volume_types/forms.py b/openstack_dashboard/dashboards/admin/volume_types/forms.py index e16afdcf3a..15fa1912e7 100644 --- a/openstack_dashboard/dashboards/admin/volume_types/forms.py +++ b/openstack_dashboard/dashboards/admin/volume_types/forms.py @@ -126,10 +126,10 @@ class CreateVolumeTypeEncryption(forms.SelfHandlingForm): messages.success(request, _('Successfully created encryption for ' 'volume type: %s') % volume_type_name) return volume_type - except Exception as ex: + except Exception: redirect = reverse("horizon:admin:volume_types:index") exceptions.handle( - request, _('Unable to create encrypted volume type: %s') % ex, + request, _('Unable to create encrypted volume type.'), redirect=redirect) diff --git a/openstack_dashboard/dashboards/identity/application_credentials/forms.py b/openstack_dashboard/dashboards/identity/application_credentials/forms.py index e9f418b25a..544127f762 100644 --- a/openstack_dashboard/dashboards/identity/application_credentials/forms.py +++ b/openstack_dashboard/dashboards/identity/application_credentials/forms.py @@ -127,9 +127,9 @@ class CreateApplicationCredentialForm(forms.SelfHandlingForm): msg = (_('Application credential name "%s" is already used.') % data['name']) messages.error(request, msg) - except Exception as ex: + except Exception: exceptions.handle( - request, _('Unable to create application credential: %s') % ex) + request, _('Unable to create application credential.')) def clean(self): cleaned_data = super(CreateApplicationCredentialForm, self).clean() diff --git a/openstack_dashboard/dashboards/project/images/snapshots/forms.py b/openstack_dashboard/dashboards/project/images/snapshots/forms.py index 1533294bd9..c425f928a8 100644 --- a/openstack_dashboard/dashboards/project/images/snapshots/forms.py +++ b/openstack_dashboard/dashboards/project/images/snapshots/forms.py @@ -52,7 +52,7 @@ class CreateSnapshot(forms.SelfHandlingForm): redirect = reverse("horizon:project:instances:index") exceptions.handle(request, msg, redirect=redirect) - except Exception as exc: - msg = _('Unable to create snapshot: %s') % exc + except Exception: + msg = _('Unable to create snapshot.') redirect = reverse("horizon:project:instances:index") exceptions.handle(request, msg, redirect=redirect) diff --git a/openstack_dashboard/dashboards/project/instances/forms.py b/openstack_dashboard/dashboards/project/instances/forms.py index 9f9ee85049..069b893b7a 100644 --- a/openstack_dashboard/dashboards/project/instances/forms.py +++ b/openstack_dashboard/dashboards/project/instances/forms.py @@ -234,14 +234,9 @@ class AttachVolume(forms.SelfHandlingForm): "inst": instance_id, "dev": attach.device} messages.info(request, message) - except Exception as ex: + except Exception: redirect = reverse('horizon:project:instances:index') - if isinstance(ex, api.nova.VolumeMultiattachNotSupported): - # Use the specific error from the specific message. - msg = str(ex) - else: - # Use a generic error message. - msg = _('Unable to attach volume: %s') % ex + msg = _('Unable to attach volume.') exceptions.handle(request, msg, redirect=redirect) return True @@ -294,10 +289,10 @@ class DetachVolume(forms.SelfHandlingForm): '%(inst)s.') % {"vol": volume, "inst": instance_id} messages.info(request, message) - except Exception as ex: + except Exception: redirect = reverse('horizon:project:instances:index') exceptions.handle( - request, _("Unable to detach volume: %s") % ex, + request, _("Unable to detach volume."), redirect=redirect) return True diff --git a/openstack_dashboard/dashboards/project/instances/utils.py b/openstack_dashboard/dashboards/project/instances/utils.py index 961cca9fcc..11bd5dc681 100644 --- a/openstack_dashboard/dashboards/project/instances/utils.py +++ b/openstack_dashboard/dashboards/project/instances/utils.py @@ -101,8 +101,8 @@ def network_field_data(request, include_empty_option=False, with_cidr=False, try: networks = api.neutron.network_list_for_tenant( request, tenant_id, **extra_params) - except Exception as e: - msg = _('Failed to get network list {0}').format(e) + except Exception: + msg = _('Failed to get network list.') exceptions.handle(request, msg) _networks = [] diff --git a/openstack_dashboard/dashboards/project/instances/workflows/update_instance.py b/openstack_dashboard/dashboards/project/instances/workflows/update_instance.py index ca164031e5..4fe7f7ef91 100644 --- a/openstack_dashboard/dashboards/project/instances/workflows/update_instance.py +++ b/openstack_dashboard/dashboards/project/instances/workflows/update_instance.py @@ -46,8 +46,9 @@ class UpdateInstanceSecurityGroupsAction(sg_base.BaseSecurityGroupsAction): try: api.neutron.server_update_security_groups(request, instance_id, wanted_groups) - except Exception as e: - exceptions.handle(request, str(e)) + except Exception: + exceptions.handle(request, _('Unable to update instance security' + ' group.')) return False return True diff --git a/openstack_dashboard/dashboards/project/networks/subnets/workflows.py b/openstack_dashboard/dashboards/project/networks/subnets/workflows.py index 0f4366e182..40977caa3f 100644 --- a/openstack_dashboard/dashboards/project/networks/subnets/workflows.py +++ b/openstack_dashboard/dashboards/project/networks/subnets/workflows.py @@ -219,10 +219,8 @@ class UpdateSubnet(network_workflows.CreateNetwork): subnet = api.neutron.subnet_update(request, subnet_id, **params) LOG.debug('Subnet "%s" was successfully updated.', data['cidr']) return subnet - except Exception as e: - msg = (_('Failed to update subnet "%(sub)s": ' - ' %(reason)s') % - {"sub": data['cidr'], "reason": e}) + except Exception: + msg = _('Failed to update subnet "%s".') % data['cidr'] redirect = reverse(self.failure_url, args=(network_id,)) exceptions.handle(request, msg, redirect=redirect) return False diff --git a/openstack_dashboard/dashboards/project/networks/workflows.py b/openstack_dashboard/dashboards/project/networks/workflows.py index 60207fadc1..22ad258b47 100644 --- a/openstack_dashboard/dashboards/project/networks/workflows.py +++ b/openstack_dashboard/dashboards/project/networks/workflows.py @@ -495,8 +495,7 @@ class CreateNetwork(workflows.Workflow): 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}) + msg = _('Failed to create network "%s".') % data['net_name'] redirect = self.get_failure_url() exceptions.handle(request, msg, redirect=redirect) return False @@ -565,19 +564,18 @@ class CreateNetwork(workflows.Workflow): self.context['subnet_id'] = subnet.id LOG.debug('Subnet "%s" was successfully created.', data['cidr']) return subnet - except Exception as e: + except Exception: if network_name: msg = _('Failed to create subnet "%(sub)s" for network ' - '"%(net)s": %(reason)s') + '"%(net)s".') else: - msg = _('Failed to create subnet "%(sub)s": %(reason)s') + msg = _('Failed to create subnet "%(sub)s".') if no_redirect: redirect = None else: redirect = self.get_failure_url() exceptions.handle(request, - msg % {"sub": data['cidr'], "net": network_name, - "reason": e}, + msg % {"sub": data['cidr'], "net": network_name}, redirect=redirect) return False diff --git a/openstack_dashboard/dashboards/project/routers/extensions/extraroutes/forms.py b/openstack_dashboard/dashboards/project/routers/extensions/extraroutes/forms.py index 7e1dac0714..f6fdd06794 100644 --- a/openstack_dashboard/dashboards/project/routers/extensions/extraroutes/forms.py +++ b/openstack_dashboard/dashboards/project/routers/extensions/extraroutes/forms.py @@ -57,6 +57,6 @@ class AddRouterRoute(forms.SelfHandlingForm): exceptions.handle(request, msg, redirect=redirect) except Exception as e: LOG.info('Failed to add route: %s', e) - msg = _('Failed to add route: %s') % e + msg = _('Failed to add route') redirect = reverse(self.failure_url, args=[router_id]) exceptions.handle(request, msg, redirect=redirect) diff --git a/openstack_dashboard/dashboards/project/routers/ports/forms.py b/openstack_dashboard/dashboards/project/routers/ports/forms.py index 5c1bd7f1ec..63429fd532 100644 --- a/openstack_dashboard/dashboards/project/routers/ports/forms.py +++ b/openstack_dashboard/dashboards/project/routers/ports/forms.py @@ -54,7 +54,7 @@ class AddInterface(forms.SelfHandlingForm): for fixed_ip in port.fixed_ips] except Exception as e: LOG.info('Failed to get network list: %s', e) - msg = _('Failed to get network list: %s') % e + msg = _('Failed to get network list.') messages.error(request, msg) if router_id: redirect = reverse(self.failure_url, args=[router_id]) @@ -170,7 +170,7 @@ class SetGatewayForm(forms.SelfHandlingForm): networks = api.neutron.network_list(request, **search_opts) except Exception as e: LOG.info('Failed to get network list: %s', e) - msg = _('Failed to get network list: %s') % e + msg = _('Failed to get network list.') messages.error(request, msg) redirect = reverse(self.failure_url) exceptions.handle(request, msg, redirect=redirect) @@ -198,6 +198,6 @@ class SetGatewayForm(forms.SelfHandlingForm): except Exception as e: LOG.info('Failed to set gateway to router %(id)s: %(exc)s', {'id': self.initial['router_id'], 'exc': e}) - msg = _('Failed to set gateway: %s') % e + msg = _('Failed to set gateway.') redirect = reverse(self.failure_url) exceptions.handle(request, msg, redirect=redirect) diff --git a/openstack_dashboard/dashboards/project/routers/views.py b/openstack_dashboard/dashboards/project/routers/views.py index 35b65cd69e..c43e985ae5 100644 --- a/openstack_dashboard/dashboards/project/routers/views.py +++ b/openstack_dashboard/dashboards/project/routers/views.py @@ -76,8 +76,8 @@ class IndexView(tables.DataTableView): **search_opts) ext_net_dict = OrderedDict((n['id'], n.name_or_id) for n in ext_nets) - except Exception as e: - msg = _('Unable to retrieve a list of external networks "%s".') % e + except Exception: + msg = _('Unable to retrieve a list of external networks.') exceptions.handle(self.request, msg) ext_net_dict = {} return ext_net_dict diff --git a/openstack_dashboard/dashboards/project/security_groups/forms.py b/openstack_dashboard/dashboards/project/security_groups/forms.py index ab461f2c05..d9c88527eb 100644 --- a/openstack_dashboard/dashboards/project/security_groups/forms.py +++ b/openstack_dashboard/dashboards/project/security_groups/forms.py @@ -66,10 +66,9 @@ class GroupBase(forms.SelfHandlingForm): sg = self._call_network_api(request, data) messages.success(request, self.success_message % sg.name) return sg - except Exception as e: + except Exception: redirect = reverse("horizon:project:security_groups:index") - error_msg = self.error_message % e - exceptions.handle(request, error_msg, redirect=redirect) + exceptions.handle(request, self.error_message, redirect=redirect) class CreateGroup(GroupBase): diff --git a/openstack_dashboard/dashboards/settings/password/forms.py b/openstack_dashboard/dashboards/settings/password/forms.py index 719429f77e..cf8d0df847 100644 --- a/openstack_dashboard/dashboards/settings/password/forms.py +++ b/openstack_dashboard/dashboards/settings/password/forms.py @@ -76,9 +76,9 @@ class PasswordForm(forms.SelfHandlingForm): msg = _("Password changed. Please log in again to continue.") utils.add_logout_reason(request, response, msg) return response - except Exception as ex: + except Exception: exceptions.handle(request, - _('Unable to change password: %s') % ex) + _('Unable to change password.')) return False else: messages.error(request, _('Changing password is not supported.'))