Improved keystone error handling in syspanel.
* Added "AuthorizationFailure" to the recoverable errors list since keystoneclient raises it anytime it can't talk to keystone. Fixes bug 971249. * Used proper exception handling for the users index view. Fixed some tests that had been failiing but masked previously. Fixes bug 971250. Change-Id: Iec8c1fc7bf8585a529fa15af55f807abc0f84d42
This commit is contained in:
parent
0bf1e5e953
commit
289fc72168
@ -45,7 +45,8 @@ class IndexView(tables.DataTableView):
|
||||
try:
|
||||
tenants = api.keystone.tenant_list(self.request, admin=True)
|
||||
except:
|
||||
exceptions.handle(self.request)
|
||||
exceptions.handle(self.request,
|
||||
_("Unable to retrieve project list."))
|
||||
tenants.sort(key=lambda x: x.id, reverse=True)
|
||||
return tenants
|
||||
|
||||
@ -67,7 +68,7 @@ class UpdateView(forms.ModalFormView):
|
||||
except:
|
||||
redirect = reverse("horizon:syspanel:projects:index")
|
||||
exceptions.handle(self.request,
|
||||
_('Unable to retrieve tenant.'),
|
||||
_('Unable to retrieve project.'),
|
||||
redirect=redirect)
|
||||
|
||||
def get_initial(self):
|
||||
|
@ -34,8 +34,8 @@ USER_UPDATE_URL = reverse('horizon:syspanel:users:update', args=[1])
|
||||
|
||||
class UsersViewTests(test.BaseAdminViewTests):
|
||||
def test_index(self):
|
||||
self.mox.StubOutWithMock(api, 'user_list')
|
||||
api.user_list(IgnoreArg()).AndReturn(self.users.list())
|
||||
self.mox.StubOutWithMock(api.keystone, 'user_list')
|
||||
api.keystone.user_list(IgnoreArg()).AndReturn(self.users.list())
|
||||
self.mox.ReplayAll()
|
||||
|
||||
res = self.client.get(USERS_INDEX_URL)
|
||||
@ -176,6 +176,8 @@ class UsersViewTests(test.BaseAdminViewTests):
|
||||
def test_enable_user(self):
|
||||
user = self.users.get(id="2")
|
||||
self.mox.StubOutWithMock(api.keystone, 'user_update_enabled')
|
||||
self.mox.StubOutWithMock(api.keystone, 'user_list')
|
||||
api.keystone.user_list(IgnoreArg()).AndReturn(self.users.list())
|
||||
api.keystone.user_update_enabled(IgnoreArg(),
|
||||
user.id,
|
||||
True).AndReturn(user)
|
||||
@ -183,11 +185,14 @@ class UsersViewTests(test.BaseAdminViewTests):
|
||||
|
||||
formData = {'action': 'users__enable__%s' % user.id}
|
||||
res = self.client.post(USERS_INDEX_URL, formData)
|
||||
self.assertRedirects(res, USERS_INDEX_URL)
|
||||
self.assertRedirectsNoFollow(res, USERS_INDEX_URL)
|
||||
|
||||
def test_disable_user(self):
|
||||
user = self.users.get(id="2")
|
||||
|
||||
self.mox.StubOutWithMock(api.keystone, 'user_update_enabled')
|
||||
self.mox.StubOutWithMock(api.keystone, 'user_list')
|
||||
api.keystone.user_list(IgnoreArg()).AndReturn(self.users.list())
|
||||
api.keystone.user_update_enabled(IgnoreArg(),
|
||||
user.id,
|
||||
False).AndReturn(user)
|
||||
@ -195,11 +200,13 @@ class UsersViewTests(test.BaseAdminViewTests):
|
||||
|
||||
formData = {'action': 'users__disable__%s' % user.id}
|
||||
res = self.client.post(USERS_INDEX_URL, formData)
|
||||
self.assertRedirects(res, USERS_INDEX_URL)
|
||||
self.assertRedirectsNoFollow(res, USERS_INDEX_URL)
|
||||
|
||||
def test_enable_disable_user_exception(self):
|
||||
user = self.users.get(id="2")
|
||||
self.mox.StubOutWithMock(api.keystone, 'user_update_enabled')
|
||||
self.mox.StubOutWithMock(api.keystone, 'user_list')
|
||||
api.keystone.user_list(IgnoreArg()).AndReturn(self.users.list())
|
||||
api_exception = keystone_exceptions.ClientException('apiException',
|
||||
message='apiException')
|
||||
api.keystone.user_update_enabled(IgnoreArg(),
|
||||
@ -210,15 +217,15 @@ class UsersViewTests(test.BaseAdminViewTests):
|
||||
formData = {'action': 'users__enable__%s' % user.id}
|
||||
res = self.client.post(USERS_INDEX_URL, formData)
|
||||
|
||||
self.assertRedirects(res, USERS_INDEX_URL)
|
||||
self.assertRedirectsNoFollow(res, USERS_INDEX_URL)
|
||||
|
||||
def test_shoot_yourself_in_the_foot(self):
|
||||
self.mox.StubOutWithMock(api, 'user_list')
|
||||
self.mox.StubOutWithMock(api.keystone, 'user_list')
|
||||
# Four times... one for each post and one for each followed redirect
|
||||
api.user_list(IgnoreArg()).AndReturn(self.users.list())
|
||||
api.user_list(IgnoreArg()).AndReturn(self.users.list())
|
||||
api.user_list(IgnoreArg()).AndReturn(self.users.list())
|
||||
api.user_list(IgnoreArg()).AndReturn(self.users.list())
|
||||
api.keystone.user_list(IgnoreArg()).AndReturn(self.users.list())
|
||||
api.keystone.user_list(IgnoreArg()).AndReturn(self.users.list())
|
||||
api.keystone.user_list(IgnoreArg()).AndReturn(self.users.list())
|
||||
api.keystone.user_list(IgnoreArg()).AndReturn(self.users.list())
|
||||
|
||||
self.mox.ReplayAll()
|
||||
|
||||
|
@ -20,10 +20,8 @@
|
||||
|
||||
import logging
|
||||
|
||||
from django.contrib import messages
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from keystoneclient import exceptions as api_exceptions
|
||||
|
||||
from horizon import api
|
||||
from horizon import exceptions
|
||||
@ -43,17 +41,10 @@ class IndexView(tables.DataTableView):
|
||||
def get_data(self):
|
||||
users = []
|
||||
try:
|
||||
users = api.user_list(self.request)
|
||||
except api_exceptions.AuthorizationFailure, e:
|
||||
LOG.exception("Unauthorized attempt to list users.")
|
||||
messages.error(self.request,
|
||||
_('Unable to get user info: %s') % e.message)
|
||||
except Exception, e:
|
||||
LOG.exception('Exception while getting user list')
|
||||
if not hasattr(e, 'message'):
|
||||
e.message = str(e)
|
||||
messages.error(self.request,
|
||||
_('Unable to get user info: %s') % e.message)
|
||||
users = api.keystone.user_list(self.request)
|
||||
except:
|
||||
exceptions.handle(self.request,
|
||||
_('Unable to retrieve user list.'))
|
||||
return users
|
||||
|
||||
|
||||
|
@ -143,6 +143,8 @@ 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.GlanceException,
|
||||
swiftclient.Error,
|
||||
|
Loading…
x
Reference in New Issue
Block a user