Ejemplo n.º 1
0
    def setUp(self):
        super(DbFixture, self).setUp()

        testresources.setUpResources(self.test, self.test.resources,
                                     testresources._get_result())
        self.addCleanup(testresources.tearDownResources, self.test,
                        self.test.resources, testresources._get_result())

        if not self.test._has_db_resource():
            msg = self.test._get_db_resource_not_available_reason()
            if self.test.SKIP_ON_UNAVAILABLE_DB:
                self.test.skipTest(msg)
            else:
                self.test.fail(msg)

        if self.test.SCHEMA_SCOPE:
            self.test.engine = self.test.transaction_engine
            self.test.sessionmaker = session.get_maker(
                self.test.transaction_engine)
        else:
            self.test.engine = self.test.db.engine
            self.test.sessionmaker = session.get_maker(self.test.engine)

        self.addCleanup(setattr, self.test, 'sessionmaker', None)
        self.addCleanup(setattr, self.test, 'engine', None)

        self.test.enginefacade = enginefacade._TestTransactionFactory(
            self.test.engine, self.test.sessionmaker, apply_global=True)
        self.addCleanup(self.test.enginefacade.dispose_global)
Ejemplo n.º 2
0
    def setUp(self):
        super(DbFixture, self).setUp()

        testresources.setUpResources(self.test, self.test.resources,
                                     testresources._get_result())
        self.addCleanup(testresources.tearDownResources, self.test,
                        self.test.resources, testresources._get_result())
        if not hasattr(self.test, 'db'):
            msg = "backend '%s' unavailable" % self.DRIVER
            if self.skip_on_unavailable_db:
                self.test.skip(msg)
            else:
                self.test.fail(msg)

        if self.test.SCHEMA_SCOPE:
            self.test.engine = self.test.transaction_engine
            self.test.sessionmaker = session.get_maker(
                self.test.transaction_engine)
        else:
            self.test.engine = self.test.db.engine
            self.test.sessionmaker = session.get_maker(self.test.engine)

        self.addCleanup(setattr, self.test, 'sessionmaker', None)
        self.addCleanup(setattr, self.test, 'engine', None)

        self.test.enginefacade = enginefacade._TestTransactionFactory(
            self.test.engine,
            self.test.sessionmaker,
            apply_global=True,
            synchronous_reader=True)
        self.addCleanup(self.test.enginefacade.dispose_global)
Ejemplo n.º 3
0
    def setUp(self):
        super(DbFixture, self).setUp()

        testresources.setUpResources(
            self.test, self.test.resources, testresources._get_result())
        self.addCleanup(
            testresources.tearDownResources,
            self.test, self.test.resources, testresources._get_result()
        )
        if not hasattr(self.test, 'db'):
            msg = "backend '%s' unavailable" % self.DRIVER
            if self.skip_on_unavailable_db:
                self.test.skip(msg)
            else:
                self.test.fail(msg)

        if self.test.SCHEMA_SCOPE:
            self.test.engine = self.test.transaction_engine
            self.test.sessionmaker = session.get_maker(
                self.test.transaction_engine)
        else:
            self.test.engine = self.test.db.engine
            self.test.sessionmaker = session.get_maker(self.test.engine)

        self.addCleanup(setattr, self.test, 'sessionmaker', None)
        self.addCleanup(setattr, self.test, 'engine', None)

        self.test.enginefacade = enginefacade._TestTransactionFactory(
            self.test.engine, self.test.sessionmaker, apply_global=True,
            synchronous_reader=True)
        self.addCleanup(self.test.enginefacade.dispose_global)
Ejemplo n.º 4
0
    def setUp(self):
        super(SqlMigrateBase, self).setUp()
        database.initialize_sql_session()
        conn_str = CONF.database.connection
        if (conn_str != tests.IN_MEM_DB_CONN_STRING and
                conn_str.startswith('sqlite') and
                conn_str[10:] == tests.DEFAULT_TEST_DB_FILE):
            # Override the default with a DB that is specific to the migration
            # tests only if the DB Connection string is the same as the global
            # default. This is required so that no conflicts occur due to the
            # global default DB already being under migrate control. This is
            # only needed if the DB is not-in-memory
            db_file = tests.dirs.tmp('keystone_migrate_test.db')
            self.config_fixture.config(
                group='database',
                connection='sqlite:///%s' % db_file)

        # create and share a single sqlalchemy engine for testing
        self.engine = sql.get_engine()
        self.Session = db_session.get_maker(self.engine, autocommit=False)

        self.initialize_sql()
        self.repo_path = migration_helpers.find_migrate_repo(
            self.repo_package())
        self.schema = versioning_api.ControlledSchema.create(
            self.engine,
            self.repo_path, self.initial_db_version)

        # auto-detect the highest available schema version in the migrate_repo
        self.max_version = self.schema.repository.version().version
Ejemplo n.º 5
0
    def _setUp(self):
        self._init_resources()

        # check if the fixtures failed to get
        # an engine.  The test setUp() itself should also be checking
        # this and raising skipTest.
        if not hasattr(self, 'engine'):
            return

        engine = self.engine
        self.addCleanup(lambda: self._delete_from_schema(engine))

        self.sessionmaker = session.get_maker(engine)

        _restore_factory = db_api.context_manager._root_factory

        self.enginefacade_factory = enginefacade._TestTransactionFactory(
            self.engine,
            self.sessionmaker,
            from_factory=_restore_factory,
            apply_global=False)

        db_api.context_manager._root_factory = self.enginefacade_factory

        engine = db_api.context_manager.writer.get_engine()

        self.addCleanup(lambda: setattr(db_api.context_manager,
                                        "_root_factory", _restore_factory))

        self.useFixture(EnableSQLiteFKsFixture(engine))
Ejemplo n.º 6
0
    def setUp(self):
        super(SqlMigrateBase, self).setUp()
        database.initialize_sql_session()
        conn_str = CONF.database.connection
        if (conn_str != tests.IN_MEM_DB_CONN_STRING
                and conn_str.startswith('sqlite')
                and conn_str[10:] == tests.DEFAULT_TEST_DB_FILE):
            # Override the default with a DB that is specific to the migration
            # tests only if the DB Connection string is the same as the global
            # default. This is required so that no conflicts occur due to the
            # global default DB already being under migrate control. This is
            # only needed if the DB is not-in-memory
            db_file = tests.dirs.tmp('keystone_migrate_test.db')
            self.config_fixture.config(group='database',
                                       connection='sqlite:///%s' % db_file)

        # create and share a single sqlalchemy engine for testing
        self.engine = sql.get_engine()
        self.Session = db_session.get_maker(self.engine, autocommit=False)

        self.initialize_sql()
        self.repo_path = migration_helpers.find_migrate_repo(
            self.repo_package())
        self.schema = versioning_api.ControlledSchema.create(
            self.engine, self.repo_path, self.initial_db_version)

        # auto-detect the highest available schema version in the migrate_repo
        self.max_version = self.schema.repository.version().version
Ejemplo n.º 7
0
    def _setUp(self):
        self._init_resources()

        # check if the fixtures failed to get
        # an engine.  The test setUp() itself should also be checking
        # this and raising skipTest.
        if not hasattr(self, 'engine'):
            return

        engine = self.engine
        self.addCleanup(lambda: self._delete_from_schema(engine))

        self.sessionmaker = session.get_maker(engine)

        self.enginefacade_factory = enginefacade._TestTransactionFactory(
            self.engine, self.sessionmaker, apply_global=False,
            synchronous_reader=True)

        _restore_factory = db_api.context_manager._root_factory

        db_api.context_manager._root_factory = self.enginefacade_factory

        engine = db_api.context_manager.get_legacy_facade().get_engine()

        self.addCleanup(
            lambda: setattr(
                db_api.context_manager,
                "_root_factory", _restore_factory))

        self.useFixture(EnableSQLiteFKsFixture(engine))
Ejemplo n.º 8
0
def main(argv):
    """Main function.

    :param argv: Argument list
    :type argv: List[str]
    :returns: POSIX exit code
    :rtype: int
    """
    program = os.path.basename(argv[0])
    if len(argv) < 2:
        usage(program)
        return os.EX_USAGE
    elif len(argv) < 3 or argv[2] != 'morph':
        print('DRY-RUN, WILL NOT COMMIT TRANSACTION')

    db_engine = session.create_engine(argv[1])
    db_maker = session.get_maker(db_engine, autocommit=False)
    db_session = db_maker(bind=db_engine)

    to_network_type = 'geneve'
    for network_type in ('gre', 'vxlan'):
        n_morphed = morph_networks(db_session, network_type, to_network_type)
        print('Morphed {} networks of type {} to {}.'.format(
            n_morphed, network_type, to_network_type))

    if len(argv) < 3 or argv[2] != 'morph':
        print('DRY-RUN, WILL NOT COMMIT TRANSACTION')
        return os.EX_USAGE

    db_session.commit()
    db_session.close()
    db_engine.dispose()
    return os.EX_OK
Ejemplo n.º 9
0
    def setUp(self):
        super(DbFixture, self).setUp()

        testresources.setUpResources(
            self.test, self.test.resources, testresources._get_result())
        self.addCleanup(
            testresources.tearDownResources,
            self.test, self.test.resources, testresources._get_result()
        )
        if not hasattr(self.test, 'db'):
            self.test.skip("database '%s' unavailable" % self.DRIVER)

        if self.test.SCHEMA_SCOPE:
            self.test.engine = self.test.transaction_engine
            self.test.sessionmaker = session.get_maker(
                self.test.transaction_engine)
        else:
            self.test.engine = self.test.db.engine
            self.test.sessionmaker = session.get_maker(self.test.engine)
        self.addCleanup(setattr, self.test, 'sessionmaker', None)
        self.addCleanup(setattr, self.test, 'engine', None)
Ejemplo n.º 10
0
    def setUp(self):
        super(DbFixture, self).setUp()

        try:
            self.provision = provision.ProvisionedDatabase(self.DRIVER)
            self.addCleanup(self.provision.dispose)
        except exception.BackendNotAvailable:
            msg = '%s backend is not available.' % self.DRIVER
            return self.test.skip(msg)
        else:
            self.test.engine = self.provision.engine
            self.addCleanup(setattr, self.test, 'engine', None)
            self.test.sessionmaker = session.get_maker(self.test.engine)
            self.addCleanup(setattr, self.test, 'sessionmaker', None)
Ejemplo n.º 11
0
    def _setUp(self):
        self.engine = db_api.CONTEXT_WRITER.get_engine()
        self.generate_schema(self.engine)
        self._init_resources()

        self.sessionmaker = session.get_maker(self.engine)

        _restore_factory = db_api.get_context_manager()._root_factory

        self.enginefacade_factory = enginefacade._TestTransactionFactory(
            self.engine,
            self.sessionmaker,
            from_factory=_restore_factory,
            apply_global=False)

        db_api.get_context_manager()._root_factory = self.enginefacade_factory

        self.addCleanup(lambda: self.delete_from_schema(self.engine))
        self.addCleanup(lambda: setattr(db_api.get_context_manager(),
                                        "_root_factory", _restore_factory))

        self.useFixture(_EnableSQLiteFKsFixture(self.engine))