fix ClientException call

We were calling cinder.ClientException even when the import
had changed to be cinder.cinder_exception.ClientException
Adds 3 tests for the methods calling that exception so
failures will be tested as well.

Co-Authored-By: zhurong <aaronzhu1121@gmail.com>
Change-Id: I8c415eb8ef847f6dc34fa56fca3181560ead366b
Closes-Bug: #1537713
Closes-Bug: #1535215
This commit is contained in:
Itxaka 2016-01-25 13:50:01 +01:00
parent 87f7f69cac
commit fb8bedc375
2 changed files with 50 additions and 3 deletions

View File

@ -20,8 +20,10 @@
from __future__ import absolute_import
from django import http
from django.utils.translation import ugettext_lazy as _
from mox3.mox import IsA # noqa
from horizon import exceptions
from openstack_dashboard import api
from openstack_dashboard.api import cinder
from openstack_dashboard.test import helpers as test
@ -263,3 +265,48 @@ class QuotaTests(test.APITestCase):
# Compare internal structure of usages to expected.
self.assertItemsEqual(expected_output, quota_usages.usages)
@test.create_stubs({cinder: ('volume_list',),
exceptions: ('handle',)})
def test_get_tenant_volume_usages_cinder_exception(self):
cinder.volume_list(IsA(http.HttpRequest)) \
.AndRaise(cinder.cinder_exception.ClientException('test'))
exceptions.handle(IsA(http.HttpRequest),
_("Unable to retrieve volume limit information."))
self.mox.ReplayAll()
quotas._get_tenant_volume_usages(self.request, {}, [], None)
@test.create_stubs({api.nova: ('tenant_quota_get',),
api.base: ('is_service_enabled',),
api.cinder: ('tenant_quota_get',),
exceptions: ('handle',)})
def test_get_quota_data_cinder_exception(self):
api.base.is_service_enabled(IsA(http.HttpRequest),
'volume').AndReturn(True)
api.base.is_service_enabled(IsA(http.HttpRequest),
'network').AndReturn(False)
api.nova.tenant_quota_get(IsA(http.HttpRequest), '1') \
.AndReturn(self.quotas.first())
api.cinder.tenant_quota_get(IsA(http.HttpRequest), '1') \
.AndRaise(cinder.cinder_exception.ClientException('test'))
exceptions.handle(IsA(http.HttpRequest),
_("Unable to retrieve volume limit information."))
self.mox.ReplayAll()
quotas._get_quota_data(self.request, 'tenant_quota_get')
@test.create_stubs({api.nova: ('tenant_absolute_limits',),
api.base: ('is_service_enabled',),
api.cinder: ('tenant_absolute_limits',),
exceptions: ('handle',)})
def test_tenant_limit_usages_cinder_exception(self):
api.base.is_service_enabled(IsA(http.HttpRequest),
'volume').AndReturn(True)
api.nova.tenant_absolute_limits(IsA(http.HttpRequest)).AndReturn({})
api.cinder.tenant_absolute_limits(IsA(http.HttpRequest)) \
.AndRaise(cinder.cinder_exception.ClientException('test'))
exceptions.handle(IsA(http.HttpRequest),
_("Unable to retrieve volume limit information."))
self.mox.ReplayAll()
quotas.tenant_limit_usages(self.request)

View File

@ -147,7 +147,7 @@ def _get_quota_data(request, method_name, disabled_quotas=None,
if 'volumes' not in disabled_quotas:
try:
quotasets.append(getattr(cinder, method_name)(request, tenant_id))
except cinder.ClientException:
except cinder.cinder_exception.ClientException:
disabled_quotas.extend(CINDER_QUOTA_FIELDS)
msg = _("Unable to retrieve volume limit information.")
exceptions.handle(request, msg)
@ -349,7 +349,7 @@ def _get_tenant_volume_usages(request, usages, disabled_quotas, tenant_id):
usages.tally('gigabytes', sum([int(v.size) for v in volumes]))
usages.tally('volumes', len(volumes))
usages.tally('snapshots', len(snapshots))
except cinder.ClientException:
except cinder.cinder_exception.ClientException:
msg = _("Unable to retrieve volume limit information.")
exceptions.handle(request, msg)
@ -403,7 +403,7 @@ def tenant_limit_usages(request):
limits['gigabytesUsed'] = vol_size + snap_size
limits['volumesUsed'] = len(volumes)
limits['snapshotsUsed'] = len(snapshots)
except cinder.ClientException:
except cinder.cinder_exception.ClientException:
msg = _("Unable to retrieve volume limit information.")
exceptions.handle(request, msg)