]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Use convenience method from db api to create nested transaction
authorEugene Nikanorov <enikanorov@mirantis.com>
Thu, 19 Mar 2015 00:59:48 +0000 (04:59 +0400)
committerEugene Nikanorov <enikanorov@mirantis.com>
Tue, 19 May 2015 02:46:49 +0000 (06:46 +0400)
Instead of dealing with conditional nesting, use method that
creates nested transaction if possible.

Change-Id: Icb1fbd5d35dcbecce54426b9ef1e1be18b706d8b

neutron/db/db_base_plugin_v2.py

index 74dabca7ffaef7b5bcccd2ad9b38622c966da6c8..2fc10657d076957c2c19f81081bb2e84b8edb580 100644 (file)
@@ -1772,9 +1772,11 @@ class NeutronDbPluginV2(neutron_plugin_base_v2.NeutronPluginBaseV2,
         return self._create_bulk('port', context, ports)
 
     def _create_port_with_mac(self, context, network_id, port_data,
-                              mac_address, nested=False):
+                              mac_address):
         try:
-            with context.session.begin(subtransactions=True, nested=nested):
+            # since this method could either be used within or outside the
+            # transaction, use convenience method to avoid passing a flag
+            with db_api.autonested_transaction(context.session):
                 db_port = models_v2.Port(mac_address=mac_address, **port_data)
                 context.session.add(db_port)
                 return db_port
@@ -1786,12 +1788,8 @@ class NeutronDbPluginV2(neutron_plugin_base_v2.NeutronPluginBaseV2,
         for i in range(max_retries):
             mac = self._generate_mac()
             try:
-                # nested = True frames an operation that may potentially fail
-                # within a transaction, so that it can be rolled back to the
-                # point before its failure while maintaining the enclosing
-                # transaction
                 return self._create_port_with_mac(
-                    context, network_id, port_data, mac, nested=True)
+                    context, network_id, port_data, mac)
             except n_exc.MacAddressInUse:
                 LOG.debug('Generated mac %(mac_address)s exists on '
                           'network %(network_id)s',