diff --git a/horizon/exceptions.py b/horizon/exceptions.py index fa799625e..f31455bb2 100644 --- a/horizon/exceptions.py +++ b/horizon/exceptions.py @@ -28,11 +28,6 @@ from django.utils import termcolors from django.utils.translation import ugettext as _ from django.views.debug import SafeExceptionReporterFilter, CLEANSED_SUBSTITUTE -from cloudfiles import errors as swiftclient -from glanceclient.common import exceptions as glanceclient -from keystoneclient import exceptions as keystoneclient -from novaclient import exceptions as novaclient - from horizon import messages LOG = logging.getLogger(__name__) @@ -200,33 +195,9 @@ class HandledException(HorizonException): HORIZON_CONFIG = getattr(settings, "HORIZON_CONFIG", {}) EXCEPTION_CONFIG = HORIZON_CONFIG.get("exceptions", {}) - - -UNAUTHORIZED = (keystoneclient.Unauthorized, - keystoneclient.Forbidden, - novaclient.Unauthorized, - novaclient.Forbidden, - glanceclient.Unauthorized, - swiftclient.AuthenticationFailed, - swiftclient.AuthenticationError) -UNAUTHORIZED += tuple(EXCEPTION_CONFIG.get('unauthorized', [])) - -NOT_FOUND = (keystoneclient.NotFound, - novaclient.NotFound, - glanceclient.NotFound, - swiftclient.NoSuchContainer, - swiftclient.NoSuchObject) -NOT_FOUND += tuple(EXCEPTION_CONFIG.get('not_found', [])) - - -# NOTE(gabriel): This is very broad, and may need to be dialed in. -RECOVERABLE = (keystoneclient.ClientException, - # AuthorizationFailure is raised when Keystone is "unavailable". - keystoneclient.AuthorizationFailure, - novaclient.ClientException, - glanceclient.ClientException, - swiftclient.Error, - AlreadyExists) +UNAUTHORIZED = tuple(EXCEPTION_CONFIG.get('unauthorized', [])) +NOT_FOUND = tuple(EXCEPTION_CONFIG.get('not_found', [])) +RECOVERABLE = (AlreadyExists,) RECOVERABLE += tuple(EXCEPTION_CONFIG.get('recoverable', [])) diff --git a/horizon/templatetags/branding.py b/horizon/templatetags/branding.py index a7681a5a2..bead29129 100644 --- a/horizon/templatetags/branding.py +++ b/horizon/templatetags/branding.py @@ -24,6 +24,7 @@ Template tags for customizing Horizon. from django import template from django.conf import settings +from django.utils.translation import ugettext as _ register = template.Library() @@ -31,7 +32,7 @@ register = template.Library() class SiteBrandingNode(template.Node): def render(self, context): - return settings.SITE_BRANDING + return getattr(settings, "SITE_BRANDING", _("Horizon")) @register.tag diff --git a/horizon/templatetags/horizon.py b/horizon/templatetags/horizon.py index 71172069f..13169d414 100644 --- a/horizon/templatetags/horizon.py +++ b/horizon/templatetags/horizon.py @@ -17,8 +17,8 @@ from __future__ import absolute_import from django import template -from django.utils.translation import ugettext as _ from django.utils.datastructures import SortedDict +from django.utils.translation import ugettext as _ from horizon.base import Horizon diff --git a/horizon/tests/testsettings.py b/horizon/tests/testsettings.py index 0f2279f48..5b3b29f03 100644 --- a/horizon/tests/testsettings.py +++ b/horizon/tests/testsettings.py @@ -23,6 +23,8 @@ import socket from django.utils.translation import ugettext_lazy as _ +from openstack_dashboard.exceptions import UNAUTHORIZED, RECOVERABLE, NOT_FOUND + socket.setdefaulttimeout(1) LOGIN_URL = '/auth/login/' @@ -116,7 +118,10 @@ HORIZON_CONFIG = { "help_text": _("Password must be between 8 and 18 characters.") }, 'user_home': None, - 'help_url': "http://docs.openstack.org" + 'help_url': "http://docs.openstack.org", + 'exceptions': {'recoverable': RECOVERABLE, + 'not_found': NOT_FOUND, + 'unauthorized': UNAUTHORIZED}, } COMPRESS_ENABLED = False diff --git a/openstack_dashboard/exceptions.py b/openstack_dashboard/exceptions.py new file mode 100644 index 000000000..04b8ef299 --- /dev/null +++ b/openstack_dashboard/exceptions.py @@ -0,0 +1,47 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2012 United States Government as represented by the +# Administrator of the National Aeronautics and Space Administration. +# All Rights Reserved. +# +# Copyright 2012 Nebula, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from cloudfiles import errors as swiftclient +from glanceclient.common import exceptions as glanceclient +from keystoneclient import exceptions as keystoneclient +from novaclient import exceptions as novaclient + + +UNAUTHORIZED = (keystoneclient.Unauthorized, + keystoneclient.Forbidden, + novaclient.Unauthorized, + novaclient.Forbidden, + glanceclient.Unauthorized, + swiftclient.AuthenticationFailed, + swiftclient.AuthenticationError) + +NOT_FOUND = (keystoneclient.NotFound, + novaclient.NotFound, + glanceclient.NotFound, + swiftclient.NoSuchContainer, + swiftclient.NoSuchObject) + +# NOTE(gabriel): This is very broad, and may need to be dialed in. +RECOVERABLE = (keystoneclient.ClientException, + # AuthorizationFailure is raised when Keystone is "unavailable". + keystoneclient.AuthorizationFailure, + novaclient.ClientException, + glanceclient.ClientException, + swiftclient.Error) diff --git a/openstack_dashboard/settings.py b/openstack_dashboard/settings.py index bf8e3d9d5..f3b34a693 100644 --- a/openstack_dashboard/settings.py +++ b/openstack_dashboard/settings.py @@ -22,6 +22,8 @@ import logging import os import sys +from openstack_dashboard import exceptions + ROOT_PATH = os.path.dirname(os.path.abspath(__file__)) BIN_DIR = os.path.abspath(os.path.join(ROOT_PATH, '..', 'bin')) @@ -53,7 +55,10 @@ HORIZON_CONFIG = { 'default_dashboard': 'nova', 'user_home': 'horizon.views.user_home', 'ajax_queue_limit': 10, - 'help_url': "http://docs.openstack.org" + 'help_url': "http://docs.openstack.org", + 'exceptions': {'recoverable': exceptions.RECOVERABLE, + 'not_found': exceptions.NOT_FOUND, + 'unauthorized': exceptions.UNAUTHORIZED}, } MIDDLEWARE_CLASSES = (