]> xenbits.xensource.com Git - osstest/openstack-nova.git/commitdiff
Catching OverQuota Exception
authorAbhishek Sharma <abmsharm@in.ibm.com>
Wed, 26 Apr 2017 20:38:15 +0000 (16:38 -0400)
committerAbhishek Sharma M <abmsharm@in.ibm.com>
Sat, 6 May 2017 18:55:10 +0000 (18:55 +0000)
When any vm creation fails because of exceeding 'gigabytes',
'volumes', 'per_volume_gigabytes' quotas, the error message
generated is specific to 'volumes' quota which says
"Volume resource quota exceeded". Instead, the error message
should be specific to the quota which failed.

Change-Id: I9c1ac2cd4752d5aac20d06407792647b4549ad3d
Closes-Bug: 1680457
(cherry picked from commit 510371d526bd45195be806fb153646abdc269b70)

nova/compute/manager.py
nova/tests/functional/regressions/test_bug_1554631.py
nova/tests/unit/compute/test_compute.py
nova/volume/cinder.py

index ed58725df3c769df86f2c487d1011da3cb714589..e84c3b8338617bac39f96e70ab51595f8a45f23e 100644 (file)
@@ -1586,11 +1586,11 @@ class ComputeManager(manager.Manager):
             self._block_device_info_to_legacy(block_device_info)
             return block_device_info
 
-        except exception.OverQuota:
-            msg = _LW('Failed to create block device for instance due to '
-                      'being over volume resource quota')
-            LOG.warning(msg, instance=instance)
-            raise exception.VolumeLimitExceeded()
+        except exception.OverQuota as e:
+            LOG.warning(_LW('Failed to create block device for instance due'
+                            ' to exceeding volume related resource quota.'
+                            ' Error: %s'), e.message, instance=instance)
+            raise
 
         except Exception:
             LOG.exception(_LE('Instance failed block device setup'),
@@ -2104,8 +2104,7 @@ class ComputeManager(manager.Manager):
                 if network_info is not None:
                     network_info.wait(do_raise=False)
         except (exception.UnexpectedTaskStateError,
-                exception.VolumeLimitExceeded,
-                exception.InvalidBDM) as e:
+                exception.OverQuota, exception.InvalidBDM) as e:
             # Make sure the async call finishes
             if network_info is not None:
                 network_info.wait(do_raise=False)
index 24b9260a239f81b00bf776fb67c12d293328ccea..8263a3818cc9021087d9f2383e64a261876f3f0e 100644 (file)
@@ -57,16 +57,17 @@ class TestCinderOverLimit(test.TestCase):
         self.api = api_fixture.api
 
     @mock.patch('nova.volume.cinder.cinderclient')
-    def test_over_limit_volumes(self, mock_cinder):
-        """Regression test for bug #1554631.
+    def test_over_limit_volumes_with_message(self, mock_cinder):
+        """Regression test for bug #1680457.
 
         When the Cinder client returns OverLimit when trying to create
-        a volume, an OverQuota exception should be raised with the value being
-        volumes.
+        a volume, an OverQuota exception should be raised.
         """
         cinder_client = mock.Mock()
         mock_cinder.return_value = cinder_client
-        exc = cinder_exceptions.OverLimit(413)
+        msg = ("VolumeSizeExceedsLimit: Requested volume size XG is larger"
+               " than maximum allowed limit YG.")
+        exc = cinder_exceptions.OverLimit(413, message=msg)
         cinder_client.volumes.create.side_effect = exc
 
         volume = {'display_name': 'vol1', 'size': 3}
@@ -74,7 +75,7 @@ class TestCinderOverLimit(test.TestCase):
                               self.api.post_volume, {'volume': volume})
         self.assertEqual(403, e.response.status_code)
         # Make sure we went over on volumes
-        self.assertIn('volumes', e.response.text)
+        self.assertIn('VolumeSizeExceedsLimit', e.response.text)
 
     @mock.patch('nova.volume.cinder.cinderclient')
     def test_over_limit_snapshots(self, mock_cinder):
index 7db8964f423ffe9ab96c5b1b2940acc3f54df247..be414feaf181d4268b32ea4cca1f68a1793d3132 100644 (file)
@@ -1214,7 +1214,7 @@ class ComputeVolumeTestCase(BaseTestCase):
                 self.instance_object, 'fake_id', 'fake_id2', {})
 
     @mock.patch.object(cinder.API, 'create',
-                       side_effect=exception.OverQuota(overs='volumes'))
+                       side_effect=exception.OverQuota(overs='something'))
     def test_prep_block_device_over_quota_failure(self, mock_create):
         instance = self._create_fake_instance_obj()
         bdms = [
@@ -1231,7 +1231,7 @@ class ComputeVolumeTestCase(BaseTestCase):
             })]
         bdms = block_device_obj.block_device_make_list_from_dicts(
             self.context, bdms)
-        self.assertRaises(exception.VolumeLimitExceeded,
+        self.assertRaises(exception.OverQuota,
                           compute_manager.ComputeManager()._prep_block_device,
                           self.context, instance, bdms)
         self.assertTrue(mock_create.called)
index 0199562758568761ee43cf4b4c7cd4f74ec1301f..91195efdb454753ff519730338e88f4bc81635be 100644 (file)
@@ -190,8 +190,8 @@ def translate_volume_exception(method):
             res = method(self, ctx, volume_id, *args, **kwargs)
         except (keystone_exception.NotFound, cinder_exception.NotFound):
             _reraise(exception.VolumeNotFound(volume_id=volume_id))
-        except cinder_exception.OverLimit:
-            _reraise(exception.OverQuota(overs='volumes'))
+        except cinder_exception.OverLimit as e:
+            _reraise(exception.OverQuota(message=e.message))
         return res
     return translate_cinder_exception(wrapper)