]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Correct overquota error message
authorForest Romain <romain.forest@thalesgroup.com>
Thu, 18 Jun 2015 08:58:25 +0000 (10:58 +0200)
committerForest Romain <romain.forest@thalesgroup.com>
Mon, 29 Jun 2015 09:41:01 +0000 (11:41 +0200)
When an overquota is raised, VolumeSizeExceedsAvailableQuota returns
gigabytes quota instead of the related property quota. This change
correct values in order to match with related property quota.

Change-Id: I82fb676007a820a1890fde488ffe25320e035ff5
Closes-Bug: #1463798

cinder/exception.py
cinder/tests/unit/test_quota.py
cinder/volume/flows/api/create_volume.py

index a8db1b040667053cc4054ee5942678e1eaa8b682..87997dc99dcba5accbd1f9919d1c12b511063c76 100644 (file)
@@ -446,10 +446,15 @@ class QuotaError(CinderException):
 
 
 class VolumeSizeExceedsAvailableQuota(QuotaError):
-    message = _("Requested volume or snapshot exceeds allowed gigabytes "
+    message = _("Requested volume or snapshot exceeds allowed %(name)s "
                 "quota. Requested %(requested)sG, quota is %(quota)sG and "
                 "%(consumed)sG has been consumed.")
 
+    def __init__(self, message=None, **kwargs):
+        kwargs.setdefault('name', 'gigabytes')
+        super(VolumeSizeExceedsAvailableQuota, self).__init__(
+            message, **kwargs)
+
 
 class VolumeSizeExceedsLimit(QuotaError):
     message = _("Requested volume size %(size)d is larger than "
index 98fb1404b5ef1f06d9cf2f37324426e175bde12c..d6610ae5c0a96182d4542432afc0b84a7ee5b5b6 100644 (file)
@@ -181,10 +181,12 @@ class QuotaIntegrationTestCase(test.TestCase):
         volume_ids = []
         vol_ref = self._create_volume(size=20)
         volume_ids.append(vol_ref['id'])
-        self.assertRaises(exception.VolumeSizeExceedsAvailableQuota,
-                          volume.API().create,
-                          self.context, 1, '', '',
-                          volume_type=self.volume_type)
+        raised_exc = self.assertRaises(
+            exception.VolumeSizeExceedsAvailableQuota, volume.API().create,
+            self.context, 1, '', '', volume_type=self.volume_type)
+        expected = exception.VolumeSizeExceedsAvailableQuota(
+            requested=1, quota=20, consumed=20)
+        self.assertEqual(str(expected), str(raised_exc))
         for volume_id in volume_ids:
             db.volume_destroy(self.context, volume_id)
 
@@ -280,10 +282,12 @@ class QuotaIntegrationTestCase(test.TestCase):
         }
         self.flags(**flag_args)
         vol_ref = self._create_volume(size=10)
-        self.assertRaises(exception.VolumeSizeExceedsAvailableQuota,
-                          volume.API().create,
-                          self.context, 1, '', '',
-                          volume_type=self.volume_type)
+        raised_exc = self.assertRaises(
+            exception.VolumeSizeExceedsAvailableQuota, volume.API().create,
+            self.context, 1, '', '', volume_type=self.volume_type)
+        expected = exception.VolumeSizeExceedsAvailableQuota(
+            requested=1, quota=10, consumed=10, name=resource)
+        self.assertEqual(str(expected), str(raised_exc))
         db.volume_destroy(self.context, vol_ref['id'])
 
 
index 6d3b8077f948b703b8672af2650f8229f1dee9fd..ac6bc9b19289e9a303a11c02af0c8fac82463774 100644 (file)
@@ -540,25 +540,27 @@ class QuotaReserveTask(flow_utils.CinderTask):
             def _consumed(name):
                 return usages[name]['reserved'] + usages[name]['in_use']
 
-            def _is_over(name):
+            def _get_over(name):
                 for over in overs:
                     if name in over:
-                        return True
-                return False
+                        return over
+                return None
 
-            if _is_over('gigabytes'):
+            over_name = _get_over('gigabytes')
+            if over_name:
                 msg = _LW("Quota exceeded for %(s_pid)s, tried to create "
                           "%(s_size)sG volume (%(d_consumed)dG "
                           "of %(d_quota)dG already consumed)")
                 LOG.warning(msg, {'s_pid': context.project_id,
                                   's_size': size,
-                                  'd_consumed': _consumed('gigabytes'),
-                                  'd_quota': quotas['gigabytes']})
+                                  'd_consumed': _consumed(over_name),
+                                  'd_quota': quotas[over_name]})
                 raise exception.VolumeSizeExceedsAvailableQuota(
+                    name=over_name,
                     requested=size,
-                    consumed=_consumed('gigabytes'),
-                    quota=quotas['gigabytes'])
-            elif _is_over('volumes'):
+                    consumed=_consumed(over_name),
+                    quota=quotas[over_name])
+            elif _get_over('volumes'):
                 msg = _LW("Quota exceeded for %(s_pid)s, tried to create "
                           "volume (%(d_consumed)d volumes "
                           "already consumed)")