From: Roey Chen Date: Wed, 29 Jul 2015 11:45:29 +0000 (-0700) Subject: Move away nested transaction from _ensure_default_security_group X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=3fe38d049f9c25045baff138ed82dd5e3ac8ad30;p=openstack-build%2Fneutron-build.git Move away nested transaction from _ensure_default_security_group This patch remove the nested transaction started in _ensure_default_security_group, before calling create_security_group. Instead, a nested transaction will be started inside create_security_group. The purpose of this change is to reduce the time period in which the db transaction is open (to avoid races, db lock timeouts, etc), when creating the default security-group. Closes-Bug: #1479558 Change-Id: Ia0efa72c70c2f405c851370b0b26770008e5ff95 --- diff --git a/neutron/db/securitygroups_db.py b/neutron/db/securitygroups_db.py index 49b4f0913..c769beba4 100644 --- a/neutron/db/securitygroups_db.py +++ b/neutron/db/securitygroups_db.py @@ -151,7 +151,7 @@ class SecurityGroupDbMixin(ext_sg.SecurityGroupPluginBase): if not default_sg: self._ensure_default_security_group(context, tenant_id) - with context.session.begin(subtransactions=True): + with db_api.autonested_transaction(context.session): security_group_db = SecurityGroup(id=s.get('id') or ( uuidutils.generate_uuid()), description=s['description'], @@ -663,9 +663,8 @@ class SecurityGroupDbMixin(ext_sg.SecurityGroupPluginBase): 'description': _('Default security group')} } try: - with db_api.autonested_transaction(context.session): - ret = self.create_security_group( - context, security_group, default_sg=True) + ret = self.create_security_group( + context, security_group, default_sg=True) except exception.DBDuplicateEntry as ex: LOG.debug("Duplicate default security group %s was " "not created", ex.value)