def get_engine(): """Return a SQLAlchemy engine.""" """May assign _ENGINE if not already assigned""" global _ENGINE, sa_logger, _CONNECTION, _IDLE_TIMEOUT, _MAX_RETRIES, \ _RETRY_INTERVAL if not _ENGINE: if not _CONNECTION: raise exception.BarbicanException('No _CONNECTION configured') #TODO(jfwood) connection_dict = sqlalchemy.engine.url.make_url(_CONNECTION) engine_args = { 'pool_recycle': _IDLE_TIMEOUT, 'echo': False, 'convert_unicode': True } try: LOG.debug("Sql connection: {0}; Args: {1}".format( _CONNECTION, engine_args)) _ENGINE = sqlalchemy.create_engine(_CONNECTION, **engine_args) #TODO(jfwood): if 'mysql' in connection_dict.drivername: #TODO(jfwood): sqlalchemy.event.listen(_ENGINE, 'checkout', #TODO(jfwood): ping_listener) _ENGINE.connect = wrap_db_error(_ENGINE.connect) _ENGINE.connect() except Exception as err: msg = u._("Error configuring registry database with supplied " "sql_connection. Got error: %s") % err LOG.exception(msg) raise sa_logger = logging.getLogger('sqlalchemy.engine') if CONF.debug: sa_logger.setLevel(logging.DEBUG) if CONF.db_auto_create: meta = sqlalchemy.MetaData() meta.reflect(bind=_ENGINE) tables = meta.tables if tables and 'alembic_version' in tables: # Upgrade the database to the latest version. LOG.info(u._('Updating schema to latest version')) commands.upgrade() else: # Create database tables from our models. LOG.info(u._('Auto-creating barbican registry DB')) models.register_models(_ENGINE) # Sync the alembic version 'head' with current models. commands.stamp() else: LOG.info(u._('not auto-creating barbican registry DB')) return _ENGINE
def get_engine(): """Return a SQLAlchemy engine.""" """May assign _ENGINE if not already assigned""" global _ENGINE, sa_logger, _CONNECTION, _IDLE_TIMEOUT, _MAX_RETRIES, \ _RETRY_INTERVAL if not _ENGINE: if not _CONNECTION: raise exception.BarbicanException('No _CONNECTION configured') #TODO(jfwood) connection_dict = sqlalchemy.engine.url.make_url(_CONNECTION) engine_args = { 'pool_recycle': _IDLE_TIMEOUT, 'echo': False, 'convert_unicode': True} try: LOG.debug("Sql connection: {0}; Args: {1}".format(_CONNECTION, engine_args)) _ENGINE = sqlalchemy.create_engine(_CONNECTION, **engine_args) #TODO(jfwood): if 'mysql' in connection_dict.drivername: #TODO(jfwood): sqlalchemy.event.listen(_ENGINE, 'checkout', #TODO(jfwood): ping_listener) _ENGINE.connect = wrap_db_error(_ENGINE.connect) _ENGINE.connect() except Exception as err: msg = u._("Error configuring registry database with supplied " "sql_connection. Got error: %s") % err LOG.exception(msg) raise sa_logger = logging.getLogger('sqlalchemy.engine') if CONF.debug: sa_logger.setLevel(logging.DEBUG) if CONF.db_auto_create: meta = sqlalchemy.MetaData() meta.reflect(bind=_ENGINE) tables = meta.tables if tables and 'alembic_version' in tables: # Upgrade the database to the latest version. LOG.info(u._('Updating schema to latest version')) commands.upgrade() else: # Create database tables from our models. LOG.info(u._('Auto-creating barbican registry DB')) models.register_models(_ENGINE) # Sync the alembic version 'head' with current models. commands.stamp() else: LOG.info(u._('not auto-creating barbican registry DB')) return _ENGINE
def _auto_generate_tables(engine, tables): if tables and 'alembic_version' in tables: # Upgrade the database to the latest version. LOG.info(u._LI('Updating schema to latest version')) commands.upgrade() else: # Create database tables from our models. LOG.info(u._LI('Auto-creating barbican registry DB')) models.register_models(engine) # Sync the alembic version 'head' with current models. commands.stamp()
def get_engine(): """Return a SQLAlchemy engine.""" """May assign _ENGINE if not already assigned""" global _ENGINE, sa_logger, _CONNECTION, _IDLE_TIMEOUT, _MAX_RETRIES, \ _RETRY_INTERVAL if not _ENGINE: tries = _MAX_RETRIES retry_interval = _RETRY_INTERVAL connection_dict = sqlalchemy.engine.url.make_url(_CONNECTION) engine_args = { 'pool_recycle': _IDLE_TIMEOUT, 'echo': False, 'convert_unicode': True } try: LOG.debug("Sql connection: {0}; Args: {1}".format( _CONNECTION, engine_args)) _ENGINE = sqlalchemy.create_engine(_CONNECTION, **engine_args) #TODO: if 'mysql' in connection_dict.drivername: #TODO: sqlalchemy.event.listen(_ENGINE, 'checkout', ping_listener) _ENGINE.connect = wrap_db_error(_ENGINE.connect) _ENGINE.connect() except Exception as err: msg = _("Error configuring registry database with supplied " "sql_connection. Got error: %s") % err LOG.exception(msg) raise sa_logger = logging.getLogger('sqlalchemy.engine') if CONF.debug: sa_logger.setLevel(logging.DEBUG) if CONF.db_auto_create: LOG.info(_('auto-creating barbican registry DB')) models.register_models(_ENGINE) #TODO: try: #TODO: migration.version_control() #TODO: except exception.DatabaseMigrationError: #TODO: # only arises when the DB exists and is under version control #TODO: pass else: LOG.info(_('not auto-creating barbican registry DB')) return _ENGINE
def get_engine(): """Return a SQLAlchemy engine.""" """May assign _ENGINE if not already assigned""" global _ENGINE, sa_logger, _CONNECTION, _IDLE_TIMEOUT, _MAX_RETRIES, \ _RETRY_INTERVAL if not _ENGINE: tries = _MAX_RETRIES retry_interval = _RETRY_INTERVAL connection_dict = sqlalchemy.engine.url.make_url(_CONNECTION) engine_args = { 'pool_recycle': _IDLE_TIMEOUT, 'echo': False, 'convert_unicode': True} try: LOG.debug("Sql connection: {0}; Args: {1}".format(_CONNECTION, engine_args)) _ENGINE = sqlalchemy.create_engine(_CONNECTION, **engine_args) #TODO: if 'mysql' in connection_dict.drivername: #TODO: sqlalchemy.event.listen(_ENGINE, 'checkout', ping_listener) _ENGINE.connect = wrap_db_error(_ENGINE.connect) _ENGINE.connect() except Exception as err: msg = _("Error configuring registry database with supplied " "sql_connection. Got error: %s") % err LOG.exception(msg) raise sa_logger = logging.getLogger('sqlalchemy.engine') if CONF.debug: sa_logger.setLevel(logging.DEBUG) if CONF.db_auto_create: LOG.info(_('auto-creating barbican registry DB')) models.register_models(_ENGINE) #TODO: try: #TODO: migration.version_control() #TODO: except exception.DatabaseMigrationError: #TODO: # only arises when the DB exists and is under version control #TODO: pass else: LOG.info(_('not auto-creating barbican registry DB')) return _ENGINE
def get_engine(): """Return a SQLAlchemy engine.""" """May assign _ENGINE if not already assigned""" global _ENGINE, sa_logger, _CONNECTION, _IDLE_TIMEOUT, _MAX_RETRIES, \ _RETRY_INTERVAL if not _ENGINE: if not _CONNECTION: raise exception.BarbicanException('No _CONNECTION configured') #TODO: connection_dict = sqlalchemy.engine.url.make_url(_CONNECTION) engine_args = { 'pool_recycle': _IDLE_TIMEOUT, 'echo': False, 'convert_unicode': True } try: LOG.debug("Sql connection: {0}; Args: {1}".format( _CONNECTION, engine_args)) _ENGINE = sqlalchemy.create_engine(_CONNECTION, **engine_args) #TODO: if 'mysql' in connection_dict.drivername: #TODO: sqlalchemy.event.listen(_ENGINE, 'checkout', ping_listener) _ENGINE.connect = wrap_db_error(_ENGINE.connect) _ENGINE.connect() except Exception as err: msg = _("Error configuring registry database with supplied " "sql_connection. Got error: %s") % err LOG.exception(msg) raise sa_logger = logging.getLogger('sqlalchemy.engine') if CONF.debug: sa_logger.setLevel(logging.DEBUG) if CONF.db_auto_create: LOG.info(_('auto-creating barbican registry DB')) models.register_models(_ENGINE) # Upgrade the database to the latest version. commands.upgrade() else: LOG.info(_('not auto-creating barbican registry DB')) return _ENGINE
def get_engine(): """Return a SQLAlchemy engine.""" """May assign _ENGINE if not already assigned""" global _ENGINE, sa_logger, _CONNECTION, _IDLE_TIMEOUT, _MAX_RETRIES, \ _RETRY_INTERVAL if not _ENGINE: if not _CONNECTION: raise exception.BarbicanException('No _CONNECTION configured') #TODO: connection_dict = sqlalchemy.engine.url.make_url(_CONNECTION) engine_args = { 'pool_recycle': _IDLE_TIMEOUT, 'echo': False, 'convert_unicode': True} try: LOG.debug("Sql connection: {0}; Args: {1}".format(_CONNECTION, engine_args)) _ENGINE = sqlalchemy.create_engine(_CONNECTION, **engine_args) #TODO: if 'mysql' in connection_dict.drivername: #TODO: sqlalchemy.event.listen(_ENGINE, 'checkout', ping_listener) _ENGINE.connect = wrap_db_error(_ENGINE.connect) _ENGINE.connect() except Exception as err: msg = _("Error configuring registry database with supplied " "sql_connection. Got error: %s") % err LOG.exception(msg) raise sa_logger = logging.getLogger('sqlalchemy.engine') if CONF.debug: sa_logger.setLevel(logging.DEBUG) if CONF.db_auto_create: LOG.info(_('auto-creating barbican registry DB')) models.register_models(_ENGINE) # Upgrade the database to the latest version. commands.upgrade() else: LOG.info(_('not auto-creating barbican registry DB')) return _ENGINE
def setUp(self): super(Database, self).setUp() repositories.configure_db() engine = repositories.get_engine() models.register_models(engine) self.addCleanup(lambda: models.unregister_models(engine))