Skip to content

Commit

Permalink
Cleans up error handling for index view api calls. Prevents 500 errors.
Browse files Browse the repository at this point in the history
Also brings buildout config for glance into line with pip-requires.

Fixes bug 893795.

Change-Id: Ia5cc1d480cf160c682a6ec7a3d0bed9057e7acc9
  • Loading branch information
gabrielhurley committed Dec 9, 2011
1 parent 9e84bae commit f068f9e
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 44 deletions.
9 changes: 7 additions & 2 deletions horizon/buildout.cfg
Expand Up @@ -3,6 +3,7 @@ download-cache = /tmp/.buildout_cache/
parts =
django
openstackx
glance
quantum
python-novaclient
python-keystoneclient
Expand All @@ -20,7 +21,6 @@ pep8 = 0.5.0
sqlalchemy = 0.6.3
sqlalchemy-migrate = 0.6
webob = 1.0.8
glance = 2011.3
pycrypto = 2.3


Expand All @@ -33,7 +33,6 @@ eggs =
httplib2
python-cloudfiles
coverage
glance
django-nose-selenium
CherryPy
pycrypto
Expand Down Expand Up @@ -95,6 +94,12 @@ repository = git://github.com/cloudbuilders/openstackx.git
as_egg = True


[glance]
recipe = zerokspot.recipe.git
repository = git://github.com/openstack/glance.git
as_egg = True


[quantum]
recipe = zerokspot.recipe.git
repository = git://github.com/openstack/quantum.git
Expand Down
9 changes: 8 additions & 1 deletion horizon/horizon/dashboards/nova/containers/views.py
Expand Up @@ -24,6 +24,7 @@
import logging

from django import http
from django.contrib import messages
from django.contrib.auth.decorators import login_required
from django import shortcuts

Expand All @@ -43,7 +44,13 @@ def index(request):
if handled:
return handled

containers, more = api.swift_get_containers(request, marker=marker)
try:
containers, more = api.swift_get_containers(request, marker=marker)
except Exception, e:
containers, more = None, None
msg = _('Error retrieving container list: %s') % e
LOG.exception(msg)
messages.error(request, msg)

return shortcuts.render(request,
'nova/containers/index.html',
Expand Down
14 changes: 1 addition & 13 deletions horizon/horizon/dashboards/nova/images/tests.py
Expand Up @@ -100,10 +100,6 @@ def test_index_no_images(self):
self.mox.StubOutWithMock(api, 'image_list_detailed')
api.image_list_detailed(IsA(http.HttpRequest)).AndReturn([])

self.mox.StubOutWithMock(api, 'tenant_quota_get')
api.tenant_quota_get(IsA(http.HttpRequest), self.TEST_TENANT) \
.AndReturn({})

self.mox.StubOutWithMock(messages, 'info')
messages.info(IsA(http.HttpRequest), IsA(basestring))

Expand All @@ -118,10 +114,6 @@ def test_index_client_conn_error(self):
exception = glance_exception.ClientConnectionError('clientConnError')
api.image_list_detailed(IsA(http.HttpRequest)).AndRaise(exception)

self.mox.StubOutWithMock(api, 'tenant_quota_get')
api.tenant_quota_get(IsA(http.HttpRequest), self.TEST_TENANT) \
.AndReturn({})

self.mox.StubOutWithMock(messages, 'error')
messages.error(IsA(http.HttpRequest), IsA(basestring))

Expand All @@ -134,13 +126,9 @@ def test_index_client_conn_error(self):

def test_index_glance_error(self):
self.mox.StubOutWithMock(api, 'image_list_detailed')
exception = glance_exception.Error('glanceError')
exception = glance_exception.GlanceException('glanceError')
api.image_list_detailed(IsA(http.HttpRequest)).AndRaise(exception)

self.mox.StubOutWithMock(api, 'tenant_quota_get')
api.tenant_quota_get(IsA(http.HttpRequest), self.TEST_TENANT) \
.AndReturn({})

self.mox.StubOutWithMock(messages, 'error')
messages.error(IsA(http.HttpRequest), IsA(basestring))

Expand Down
16 changes: 8 additions & 8 deletions horizon/horizon/dashboards/nova/images/views.py
Expand Up @@ -54,24 +54,24 @@ def index(request):
except glance_exception.ClientConnectionError, e:
LOG.exception("Error connecting to glance")
messages.error(request, _("Error connecting to glance: %s") % str(e))
except glance_exception.Error, e:
except glance_exception.GlanceException, e:
LOG.exception("Error retrieving image list")
messages.error(request, _("Error retrieving image list: %s") % str(e))
except api_exceptions.ApiException, e:
except Exception, e:
msg = _("Unable to retrieve image info from glance: %s") % str(e)
LOG.exception(msg)
messages.error(request, msg)

images = [im for im in all_images
if im['container_format'] not in ['aki', 'ari']]

quotas = api.tenant_quota_get(request, request.user.tenant_id)
context = {'delete_form': DeleteImage(), 'images': images}

return shortcuts.render(request,
'nova/images/index.html', {
'delete_form': DeleteImage(),
'quotas': quotas,
'images': images})
if images:
quotas = api.tenant_quota_get(request, request.user.tenant_id)
context['quotas'] = quotas

return shortcuts.render(request, 'nova/images/index.html', context)


@login_required
Expand Down
2 changes: 1 addition & 1 deletion horizon/horizon/dashboards/nova/instances/views.py
Expand Up @@ -51,7 +51,7 @@ def index(request):
instances = []
try:
instances = api.server_list(request)
except api_exceptions.ApiException as e:
except Exception as e:
LOG.exception(_('Exception in instance index'))
messages.error(request, _('Unable to get instance list: %s')
% e.message)
Expand Down
2 changes: 1 addition & 1 deletion horizon/horizon/dashboards/nova/snapshots/tests.py
Expand Up @@ -106,7 +106,7 @@ def test_index_client_conn_error(self):

def test_index_glance_error(self):
self.mox.StubOutWithMock(api, 'snapshot_list_detailed')
exception = glance_exception.Error('glanceError')
exception = glance_exception.GlanceException('glanceError')
api.snapshot_list_detailed(IsA(http.HttpRequest)).AndRaise(exception)

self.mox.StubOutWithMock(messages, 'error')
Expand Down
2 changes: 1 addition & 1 deletion horizon/horizon/dashboards/nova/snapshots/views.py
Expand Up @@ -52,7 +52,7 @@ def index(request):
msg = _('Error connecting to glance: %s') % str(e)
LOG.exception(msg)
messages.error(request, msg)
except glance_exception.Error, e:
except glance_exception.GlanceException, e:
msg = _('Error retrieving image list: %s') % str(e)
LOG.exception(msg)
messages.error(request, msg)
Expand Down
11 changes: 7 additions & 4 deletions horizon/horizon/dashboards/syspanel/flavors/views.py
Expand Up @@ -24,7 +24,7 @@
from django.contrib import messages
from django.contrib.auth.decorators import login_required
from django.utils.translation import ugettext as _
from openstackx.api import exceptions as api_exceptions
from novaclient import exceptions as api_exceptions

from horizon import api
from horizon import forms
Expand All @@ -48,9 +48,12 @@ def index(request):
flavors = []
try:
flavors = api.flavor_list(request)
except api_exceptions.ApiException, e:
LOG.exception('ApiException while fetching usage info')
messages.error(request, _('Unable to get usage info: %s') % e.message)
except api_exceptions.Unauthorized, e:
LOG.exception('Unauthorized attempt to access flavor list.')
messages.error(request, _('Unauthorized.'))
except Exception, e:
LOG.exception('Exception while fetching usage info')
messages.error(request, _('Unable to get flavor list: %s') % e.message)

flavors.sort(key=lambda x: x.id, reverse=True)
return shortcuts.render(request,
Expand Down
2 changes: 1 addition & 1 deletion horizon/horizon/dashboards/syspanel/images/views.py
Expand Up @@ -55,7 +55,7 @@ def index(request):
LOG.exception("Error connecting to glance")
messages.error(request,
_("Error connecting to glance: %s") % e.message)
except glance_exception.Error, e:
except glance_exception.GlanceException, e:
LOG.exception("Error retrieving image list")
messages.error(request,
_("Error retrieving image list: %s") % e.message)
Expand Down
18 changes: 14 additions & 4 deletions horizon/horizon/dashboards/syspanel/quotas/views.py
Expand Up @@ -18,18 +18,28 @@
# License for the specific language governing permissions and limitations
# under the License.

import logging

from django import shortcuts
from django.contrib import messages
from django.contrib.auth.decorators import login_required
from openstackx.api import exceptions as api_exceptions

from horizon import api


LOG = logging.getLogger(__name__)


@login_required
def index(request):
quotas = api.admin_api(request).quota_sets.get(True)._info
quotas['ram'] = int(quotas['ram']) / 100
quotas.pop('id')
try:
quotas = api.admin_api(request).quota_sets.get(True)._info
quotas['ram'] = int(quotas['ram']) / 100
quotas.pop('id')
except Exception, e:
quotas = None
LOG.exception('Exception while getting quota info')
messages.error(request, _('Unable to get quota info: %s') % e.message)

return shortcuts.render(request,
'syspanel/quotas/index.html', {
Expand Down
10 changes: 7 additions & 3 deletions horizon/horizon/dashboards/syspanel/tenants/views.py
Expand Up @@ -25,7 +25,7 @@
from django.contrib import messages
from django.contrib.auth.decorators import login_required
from django.utils.translation import ugettext as _
from openstackx.api import exceptions as api_exceptions
from keystoneclient import exceptions as api_exceptions

from horizon import api
from horizon.dashboards.syspanel.tenants.forms import (AddUser, RemoveUser,
Expand All @@ -46,9 +46,13 @@ def index(request):
tenants = []
try:
tenants = api.tenant_list(request)
except api_exceptions.ApiException, e:
LOG.exception('ApiException while getting tenant list')
except api_exceptions.AuthorizationFailure, e:
LOG.exception("Unauthorized attempt to list tenants.")
messages.error(request, _('Unable to get tenant info: %s') % e.message)
except Exception, e:
LOG.exception('Exception while getting tenant list')
messages.error(request, _('Unable to get tenant info: %s') % e.message)

tenants.sort(key=lambda x: x.id, reverse=True)
return shortcuts.render(request,
'syspanel/tenants/index.html', {
Expand Down
11 changes: 7 additions & 4 deletions horizon/horizon/dashboards/syspanel/users/views.py
Expand Up @@ -25,7 +25,7 @@
from django.contrib import messages
from django.contrib.auth.decorators import login_required
from django.utils.translation import ugettext as _
from openstackx.api import exceptions as api_exceptions
from keystoneclient import exceptions as api_exceptions

from horizon import api
from horizon.dashboards.syspanel.users.forms import (UserForm, UserUpdateForm,
Expand All @@ -45,9 +45,12 @@ def index(request):
users = []
try:
users = api.user_list(request)
except api_exceptions.ApiException, e:
messages.error(request, _('Unable to list users: %s') %
e.message)
except api_exceptions.AuthorizationFailure, e:
LOG.exception("Unauthorized attempt to list users.")
messages.error(request, _('Unable to get user info: %s') % e.message)
except Exception, e:
LOG.exception('Exception while getting user list')
messages.error(request, _('Unable to get user info: %s') % e.message)

user_delete_form = UserDeleteForm()
toggle_form = UserEnableDisableForm()
Expand Down
2 changes: 1 addition & 1 deletion run_tests.sh
Expand Up @@ -6,7 +6,7 @@ set -o errexit
# Increment me any time the environment should be rebuilt.
# This includes dependncy changes, directory renames, etc.
# Simple integer secuence: 1, 2, 3...
environment_version=4
environment_version=5
#--------------------------------------------------------#

function usage {
Expand Down

0 comments on commit f068f9e

Please sign in to comment.