Handle multiple default SG creation in all plugins

Creating the default security group for the same tenant simultaniously
may result in a DB error.
This patch adds try/catch in the common plugin code to handle it.

Change-Id: Ie756ee721627395de026085e40833b45522864c6
This commit is contained in:
Adit Sarfaty 2019-04-03 10:09:14 +03:00
parent 8b48578f69
commit d4549e14cc
1 changed files with 11 additions and 0 deletions

View File

@ -14,6 +14,7 @@
# under the License.
from oslo_log import log as logging
from sqlalchemy.orm import exc
from neutron.db import address_scope_db
from neutron.db import db_base_plugin_v2
@ -403,6 +404,16 @@ class NsxPluginBase(db_base_plugin_v2.NeutronDbPluginV2,
self.set_extra_attr_value(context, router_db,
extra_attr, r[extra_attr])
def _ensure_default_security_group(self, context, tenant_id):
try:
return super(NsxPluginBase, self)._ensure_default_security_group(
context, tenant_id)
except exc.FlushError:
# This means that another worker already created this default SG
LOG.info("_ensure_default_security_group fail for project %s. "
"Default security group already created", tenant_id)
return self._get_default_sg_id(context, tenant_id)
def get_housekeeper(self, context, name, fields=None):
# run the job in readonly mode and get the results
self.housekeeper.run(context, name, readonly=True)