]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Add the missing arg of RetryRequest exception in _lock_subnetpool
authorYalei Wang <yalei.wang@intel.com>
Wed, 11 Nov 2015 15:50:20 +0000 (23:50 +0800)
committerYalei Wang <yalei.wang@intel.com>
Mon, 16 Nov 2015 23:47:40 +0000 (07:47 +0800)
RetryRequest exception defined in oslo.db need be called with a arg
which describes the inner exception. _lock_subnetpool method missed this
arg, and this patch adds it.

Change-Id: I44869c97ecd7d59d40d8793c71515067a237150b
Closes-Bug: #1506818

neutron/common/exceptions.py
neutron/ipam/subnet_alloc.py
neutron/tests/unit/ipam/test_subnet_alloc.py

index a5752e58de471775985177de03e6f977baae757d..69acf4e36616062aa82a2c915bba8284b0960cdf 100644 (file)
@@ -161,6 +161,16 @@ class SubnetInUse(InUse):
         super(SubnetInUse, self).__init__(**kwargs)
 
 
+class SubnetPoolInUse(InUse):
+    message = _("Unable to complete operation on subnet pool "
+                "%(subnet_pool_id)s. %(reason)s.")
+
+    def __init__(self, **kwargs):
+        if 'reason' not in kwargs:
+            kwargs['reason'] = _("Two or more concurrent subnets allocated.")
+        super(SubnetPoolInUse, self).__init__(**kwargs)
+
+
 class PortInUse(InUse):
     message = _("Unable to complete operation on port %(port_id)s "
                 "for network %(net_id)s. Port already has an attached "
index 9711e89f8ff6370a96e554c1e14b7173421adb2f..60862abfdce914f29d88d71e4a4a2ea8df849689 100644 (file)
@@ -63,7 +63,8 @@ class SubnetAllocator(driver.Pool):
             id=self._subnetpool['id'], hash=current_hash)
         count = query.update({'hash': new_hash})
         if not count:
-            raise db_exc.RetryRequest()
+            raise db_exc.RetryRequest(n_exc.SubnetPoolInUse(
+                                      subnet_pool_id=self._subnetpool['id']))
 
     def _get_allocated_cidrs(self):
         query = self._context.session.query(models_v2.Subnet)
index 79e168cef8806eaa0a2bd54e18a8d6970c3227ed..1c3eaf5958ac57cde3692b86ac30237e15fae7d0 100644 (file)
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
+import mock
 import netaddr
 from oslo_config import cfg
+from oslo_db import exception as db_exc
 from oslo_utils import uuidutils
 
 from neutron.api.v2 import attributes
@@ -183,3 +185,15 @@ class TestSubnetAllocation(testlib_api.SqlTestCase):
         self.assertRaises(n_exc.SubnetPoolQuotaExceeded,
                           sa.allocate_subnet,
                           req)
+
+    def test_subnetpool_concurrent_allocation_exception(self):
+        sp = self._create_subnet_pool(self.plugin, self.ctx, 'test-sp',
+                                      ['fe80::/48'],
+                                      48, 6, default_quota=1)
+        sp = self.plugin._get_subnetpool(self.ctx, sp['id'])
+        sa = subnet_alloc.SubnetAllocator(sp, self.ctx)
+        req = ipam_req.SpecificSubnetRequest(self._tenant_id,
+                                         uuidutils.generate_uuid(),
+                                         'fe80::/63')
+        with mock.patch("sqlalchemy.orm.query.Query.update", return_value=0):
+            self.assertRaises(db_exc.RetryRequest, sa.allocate_subnet, req)