]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Fix volume limit exceeded exception
authorVipin Balachandran <vbala@vmware.com>
Tue, 4 Aug 2015 06:33:25 +0000 (12:03 +0530)
committerVipin Balachandran <vbala@vmware.com>
Wed, 5 Aug 2015 05:54:36 +0000 (11:24 +0530)
The VolumeLimitExceeded exception contains the wrong limit when
the number of volumes exceeds the quota corresponding to a volume
type. It always contains the limit of quota 'volumes'. This patch
fixes the limit in both exception and log message. It also adds
the quota name to exception and log message for better clarity.

Change-Id: I3e2d4fa00fe49f64b2153930e901fccd8015483e
Closes-Bug: #1481182

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

index efaf1b3f0bb8bd589d854badf1c2a7feceebfea8..a3f2df68011083a9e12f7d4b1e71c8c8c874b93d 100644 (file)
@@ -468,7 +468,12 @@ class VolumeBackupSizeExceedsAvailableQuota(QuotaError):
 
 
 class VolumeLimitExceeded(QuotaError):
-    message = _("Maximum number of volumes allowed (%(allowed)d) exceeded")
+    message = _("Maximum number of volumes allowed (%(allowed)d) exceeded for "
+                "quota '%(name)s'.")
+
+    def __init__(self, message=None, **kwargs):
+        kwargs.setdefault('name', 'volumes')
+        super(VolumeLimitExceeded, self).__init__(message, **kwargs)
 
 
 class SnapshotLimitExceeded(QuotaError):
index 22978c7f1b5c10db4a45518ea0d9c87113920fc5..fdb4176b854669ea14fad7a45ef1e0e19b49ff7b 100644 (file)
@@ -1213,10 +1213,10 @@ class BackupsAPITestCase(test.TestCase):
         res = req.get_response(fakes.wsgi_app())
         res_dict = json.loads(res.body)
 
-        self.assertEqual(res.status_int, 413)
-        self.assertEqual(res_dict['overLimit']['code'], 413)
-        self.assertEqual(res_dict['overLimit']['message'],
-                         'Maximum number of volumes allowed (1) exceeded')
+        self.assertEqual(413, res.status_int)
+        self.assertEqual(413, res_dict['overLimit']['code'])
+        self.assertEqual("Maximum number of volumes allowed (1) exceeded for"
+                         " quota 'volumes'.", res_dict['overLimit']['message'])
 
     def test_restore_backup_to_undersized_volume(self):
         backup_size = 10
index 9d86c06181fbc0bc24741d92d00d3ffbce961dfe..a026a7e7a5ba3b5e0c8b0dccc92ab266d31208ab 100644 (file)
@@ -589,6 +589,6 @@ class VolumeTransferAPITestCase(test.TestCase):
 
         self.assertEqual(413, res.status_int)
         self.assertEqual(413, res_dict['overLimit']['code'])
-        self.assertEqual('VolumeLimitExceeded: Maximum number of volumes '
-                         'allowed (1) exceeded',
+        self.assertEqual("VolumeLimitExceeded: Maximum number of volumes "
+                         "allowed (1) exceeded for quota 'volumes'.",
                          res_dict['overLimit']['message'])
index 983a21c69af067736d5c35ff0a3c630e38cc2a92..e4fd9e931a0c1cbe403e49c3fb046030c2bfe39b 100644 (file)
@@ -21,6 +21,7 @@ import datetime
 import mock
 from oslo_config import cfg
 from oslo_utils import timeutils
+import six
 
 from cinder import backup
 from cinder import context
@@ -114,10 +115,13 @@ class QuotaIntegrationTestCase(test.TestCase):
         for _i in range(CONF.quota_volumes):
             vol_ref = self._create_volume()
             volume_ids.append(vol_ref['id'])
-        self.assertRaises(exception.VolumeLimitExceeded,
-                          volume.API().create,
-                          self.context, 1, '', '',
-                          volume_type=self.volume_type)
+        ex = self.assertRaises(exception.VolumeLimitExceeded,
+                               volume.API().create,
+                               self.context, 1, '', '',
+                               volume_type=self.volume_type)
+        msg = ("Maximum number of volumes allowed (%d) exceeded for"
+               " quota 'volumes'." % CONF.quota_volumes)
+        self.assertEqual(msg, six.text_type(ex))
         for volume_id in volume_ids:
             db.volume_destroy(self.context, volume_id)
 
@@ -130,10 +134,13 @@ class QuotaIntegrationTestCase(test.TestCase):
         }
         self.flags(**flag_args)
         vol_ref = self._create_volume()
-        self.assertRaises(exception.VolumeLimitExceeded,
-                          volume.API().create,
-                          self.context, 1, '', '',
-                          volume_type=self.volume_type)
+        ex = self.assertRaises(exception.VolumeLimitExceeded,
+                               volume.API().create,
+                               self.context, 1, '', '',
+                               volume_type=self.volume_type)
+        msg = ("Maximum number of volumes allowed (1) exceeded for"
+               " quota '%s'." % resource)
+        self.assertEqual(msg, six.text_type(ex))
         db.volume_destroy(self.context, vol_ref['id'])
 
     def test_too_many_snapshots_of_type(self):
index 5f1a4adfcbb5b22d6f107ba73e1194d430a90a39..e10582e9b94fb3b19e88ec930366403bfb382958 100644 (file)
@@ -547,6 +547,7 @@ class QuotaReserveTask(flow_utils.CinderTask):
                 return None
 
             over_name = _get_over('gigabytes')
+            exceeded_vol_limit_name = _get_over('volumes')
             if over_name:
                 msg = _LW("Quota exceeded for %(s_pid)s, tried to create "
                           "%(s_size)sG volume (%(d_consumed)dG "
@@ -560,13 +561,18 @@ class QuotaReserveTask(flow_utils.CinderTask):
                     requested=size,
                     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)")
-                LOG.warning(msg, {'s_pid': context.project_id,
-                                  'd_consumed': _consumed('volumes')})
-                raise exception.VolumeLimitExceeded(allowed=quotas['volumes'])
+            elif exceeded_vol_limit_name:
+                msg = _LW("Quota %(s_name)s exceeded for %(s_pid)s, tried "
+                          "to create volume (%(d_consumed)d volume(s) "
+                          "already consumed).")
+                LOG.warning(msg,
+                            {'s_name': exceeded_vol_limit_name,
+                             's_pid': context.project_id,
+                             'd_consumed':
+                             _consumed(exceeded_vol_limit_name)})
+                raise exception.VolumeLimitExceeded(
+                    allowed=quotas[exceeded_vol_limit_name],
+                    name=exceeded_vol_limit_name)
             else:
                 # If nothing was reraised, ensure we reraise the initial error
                 raise