diff --git a/openstack_dashboard/test/tests/quotas.py b/openstack_dashboard/test/tests/quotas.py index 1a18bb2cd2..db7ae5316d 100644 --- a/openstack_dashboard/test/tests/quotas.py +++ b/openstack_dashboard/test/tests/quotas.py @@ -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) diff --git a/openstack_dashboard/usage/quotas.py b/openstack_dashboard/usage/quotas.py index 4e5e128988..2329b5dec0 100644 --- a/openstack_dashboard/usage/quotas.py +++ b/openstack_dashboard/usage/quotas.py @@ -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)