Fix unhandled exceptions from cinder in quota code

Enclose calls to Cinder in try except blocks.

Change-Id: Id8559f4936e8ed55078ddc839f2e9bc4ff4152fe
Closes-Bug: 1491309
This commit is contained in:
Frode Nordahl 2015-09-02 11:41:58 +02:00 committed by mavinagi
parent fc1244708b
commit 4994df59ce
2 changed files with 22 additions and 12 deletions

View File

@ -26,6 +26,7 @@ from django.conf import settings
from django.utils.translation import pgettext_lazy
from django.utils.translation import ugettext_lazy as _
from cinderclient.exceptions import ClientException # noqa
from cinderclient.v2.contrib import list_extensions as cinder_list_extensions
from horizon import exceptions

View File

@ -145,7 +145,12 @@ def _get_quota_data(request, method_name, disabled_quotas=None,
if disabled_quotas is None:
disabled_quotas = get_disabled_quotas(request)
if 'volumes' not in disabled_quotas:
quotasets.append(getattr(cinder, method_name)(request, tenant_id))
try:
quotasets.append(getattr(cinder, method_name)(request, tenant_id))
except cinder.ClientException:
disabled_quotas.extend(CINDER_QUOTA_FIELDS)
msg = _("Unable to retrieve volume limit information.")
exceptions.handle(request, msg)
for quota in itertools.chain(*quotasets):
if quota.name not in disabled_quotas:
qs[quota.name] = quota.limit
@ -327,16 +332,20 @@ def _get_tenant_network_usages(request, usages, disabled_quotas, tenant_id):
def _get_tenant_volume_usages(request, usages, disabled_quotas, tenant_id):
if 'volumes' not in disabled_quotas:
if tenant_id:
opts = {'all_tenants': 1, 'project_id': tenant_id}
volumes = cinder.volume_list(request, opts)
snapshots = cinder.volume_snapshot_list(request, opts)
else:
volumes = cinder.volume_list(request)
snapshots = cinder.volume_snapshot_list(request)
usages.tally('gigabytes', sum([int(v.size) for v in volumes]))
usages.tally('volumes', len(volumes))
usages.tally('snapshots', len(snapshots))
try:
if tenant_id:
opts = {'all_tenants': 1, 'project_id': tenant_id}
volumes = cinder.volume_list(request, opts)
snapshots = cinder.volume_snapshot_list(request, opts)
else:
volumes = cinder.volume_list(request)
snapshots = cinder.volume_snapshot_list(request)
usages.tally('gigabytes', sum([int(v.size) for v in volumes]))
usages.tally('volumes', len(volumes))
usages.tally('snapshots', len(snapshots))
except cinder.ClientException:
msg = _("Unable to retrieve volume limit information.")
exceptions.handle(request, msg)
@memoized
@ -385,7 +394,7 @@ def tenant_limit_usages(request):
limits['gigabytesUsed'] = total_size
limits['volumesUsed'] = len(volumes)
limits['snapshotsUsed'] = len(snapshots)
except Exception:
except cinder.ClientException:
msg = _("Unable to retrieve volume limit information.")
exceptions.handle(request, msg)