Cleans up error handling for index view api calls. Prevents 500 errors.

Also brings buildout config for glance into line with pip-requires.

Fixes bug 893795.

Change-Id: Ia5cc1d480cf160c682a6ec7a3d0bed9057e7acc9
This commit is contained in:
Gabriel Hurley 2011-12-09 13:37:00 -08:00
parent 9e84bae97a
commit f068f9e790
13 changed files with 64 additions and 44 deletions

View File

@ -3,6 +3,7 @@ download-cache = /tmp/.buildout_cache/
parts =
django
openstackx
glance
quantum
python-novaclient
python-keystoneclient
@ -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
@ -33,7 +33,6 @@ eggs =
httplib2
python-cloudfiles
coverage
glance
django-nose-selenium
CherryPy
pycrypto
@ -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

View File

@ -24,6 +24,7 @@ Views for managing Swift containers.
import logging
from django import http
from django.contrib import messages
from django.contrib.auth.decorators import login_required
from django import shortcuts
@ -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',

View File

@ -100,10 +100,6 @@ class ImageViewTests(test.BaseViewTests):
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))
@ -118,10 +114,6 @@ class ImageViewTests(test.BaseViewTests):
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))
@ -134,13 +126,9 @@ class ImageViewTests(test.BaseViewTests):
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))

View File

@ -54,10 +54,10 @@ 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)
@ -65,13 +65,13 @@ def index(request):
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

View File

@ -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)

View File

@ -106,7 +106,7 @@ class SnapshotsViewTests(test.BaseViewTests):
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')

View File

@ -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)

View File

@ -24,7 +24,7 @@ from django import shortcuts
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
@ -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,

View File

@ -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)

View File

@ -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', {

View File

@ -25,7 +25,7 @@ from django.conf import settings
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,
@ -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', {

View File

@ -25,7 +25,7 @@ from django.conf import settings
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,
@ -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()

View File

@ -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 {