summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames E. Blair <jeblair@redhat.com>2018-10-15 11:28:39 -0700
committerJames E. Blair <jeblair@redhat.com>2019-03-07 12:44:36 -0800
commit41298d51ad745d52dac3f629a31cbd6b2fff82cf (patch)
treeea4f604bba992ec5b7150f04581a2459a3f38d8e
parent6a9d02983430cd2cad7b21d13cf21ff874e1e8ce (diff)
SQL: only create tables in scheduler
If the scheduler and web processes are started simultaneously, table creation can error out. Therefore, only create tables within the scheduler process. The scheduler is the only process that calls the onLoad method. Change-Id: Ibb72e5e1af0cdd0db51744767c853318516dc22d
Notes
Notes (review): Code-Review+2: Tobias Henkel <tobias.henkel@bmw.de> Code-Review+2: Monty Taylor <mordred@inaugust.com> Workflow+1: Monty Taylor <mordred@inaugust.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Fri, 08 Mar 2019 19:12:08 +0000 Reviewed-on: https://review.openstack.org/610696 Project: openstack-infra/zuul Branch: refs/heads/master
-rw-r--r--zuul/driver/sql/sqlconnection.py16
1 files changed, 14 insertions, 2 deletions
diff --git a/zuul/driver/sql/sqlconnection.py b/zuul/driver/sql/sqlconnection.py
index 8652e46..27a5b09 100644
--- a/zuul/driver/sql/sqlconnection.py
+++ b/zuul/driver/sql/sqlconnection.py
@@ -161,7 +161,6 @@ class SQLConnection(BaseConnection):
161 self.dburi, 161 self.dburi,
162 poolclass=sqlalchemy.pool.QueuePool, 162 poolclass=sqlalchemy.pool.QueuePool,
163 pool_recycle=self.connection_config.get('pool_recycle', 1)) 163 pool_recycle=self.connection_config.get('pool_recycle', 1))
164 self._migrate()
165 164
166 # If we want the objects returned from query() to be 165 # If we want the objects returned from query() to be
167 # usable outside of the session, we need to expunge them 166 # usable outside of the session, we need to expunge them
@@ -174,7 +173,6 @@ class SQLConnection(BaseConnection):
174 autoflush=False) 173 autoflush=False)
175 self.session = orm.scoped_session(self.session_factory) 174 self.session = orm.scoped_session(self.session_factory)
176 175
177 self.tables_established = True
178 except sa.exc.NoSuchModuleError: 176 except sa.exc.NoSuchModuleError:
179 self.log.exception( 177 self.log.exception(
180 "The required module for the dburi dialect isn't available. " 178 "The required module for the dburi dialect isn't available. "
@@ -205,6 +203,20 @@ class SQLConnection(BaseConnection):
205 tag = {'table_prefix': self.table_prefix} 203 tag = {'table_prefix': self.table_prefix}
206 alembic.command.upgrade(config, 'head', tag=tag) 204 alembic.command.upgrade(config, 'head', tag=tag)
207 205
206 def onLoad(self):
207 try:
208 self._migrate()
209 self.tables_established = True
210 except sa.exc.NoSuchModuleError:
211 self.log.exception(
212 "The required module for the dburi dialect isn't available. "
213 "SQL connection %s will be unavailable." %
214 self.connection_name)
215 except sa.exc.OperationalError:
216 self.log.exception(
217 "Unable to connect to the database or establish the required "
218 "tables. Connection %s is disabled" % self)
219
208 def _setup_models(self): 220 def _setup_models(self):
209 Base = declarative_base(metadata=sa.MetaData()) 221 Base = declarative_base(metadata=sa.MetaData())
210 222