示例#1
0
文件: base.py 项目: AlexeyDeyneko/st2
    def _establish_connection_and_re_create_db(cls):
        username = cfg.CONF.database.username if hasattr(cfg.CONF.database, 'username') else None
        password = cfg.CONF.database.password if hasattr(cfg.CONF.database, 'password') else None
        cls.db_connection = db_setup(
            cfg.CONF.database.db_name, cfg.CONF.database.host, cfg.CONF.database.port,
            username=username, password=password, ensure_indexes=False)
        cls._drop_collections()
        cls.db_connection.drop_database(cfg.CONF.database.db_name)

        # Explicity ensure indexes after we re-create the DB otherwise ensure_indexes could failure
        # inside db_setup if test inserted invalid data
        db_ensure_indexes()
示例#2
0
    def _establish_connection_and_re_create_db(cls):
        username = cfg.CONF.database.username if hasattr(
            cfg.CONF.database, 'username') else None
        password = cfg.CONF.database.password if hasattr(
            cfg.CONF.database, 'password') else None
        cls.db_connection = db_setup(cfg.CONF.database.db_name,
                                     cfg.CONF.database.host,
                                     cfg.CONF.database.port,
                                     username=username,
                                     password=password,
                                     ensure_indexes=False)
        cls._drop_collections()
        cls.db_connection.drop_database(cfg.CONF.database.db_name)

        # Explicity ensure indexes after we re-create the DB otherwise ensure_indexes could failure
        # inside db_setup if test inserted invalid data
        db_ensure_indexes()
示例#3
0
文件: base.py 项目: chadpatt/st2
    def _establish_connection_and_re_create_db(cls):
        username = (
            cfg.CONF.database.username
            if hasattr(cfg.CONF.database, "username")
            else None
        )
        password = (
            cfg.CONF.database.password
            if hasattr(cfg.CONF.database, "password")
            else None
        )
        cls.db_connection = db_setup(
            cfg.CONF.database.db_name,
            cfg.CONF.database.host,
            cfg.CONF.database.port,
            username=username,
            password=password,
            ensure_indexes=False,
        )

        cls._drop_collections()
        cls.db_connection.drop_database(cfg.CONF.database.db_name)

        # Explicitly ensure indexes after we re-create the DB otherwise ensure_indexes could failure
        # inside db_setup if test inserted invalid data.
        # NOTE: This is only needed in distributed scenarios (production deployments) where
        # multiple services can start up at the same time and race conditions are possible.
        if cls.ensure_indexes:
            if (
                len(cls.ensure_indexes_models) == 0
                or len(cls.ensure_indexes_models) > 1
            ):
                msg = (
                    "Ensuring indexes for all the models, this could significantly slow down "
                    "the tests"
                )
                print("#" * len(msg), file=sys.stderr)
                print(msg, file=sys.stderr)
                print("#" * len(msg), file=sys.stderr)

            db_ensure_indexes(cls.ensure_indexes_models)
示例#4
0
文件: base.py 项目: nzlosh/st2
    def _establish_connection_and_re_create_db(cls):
        username = cfg.CONF.database.username if hasattr(cfg.CONF.database, 'username') else None
        password = cfg.CONF.database.password if hasattr(cfg.CONF.database, 'password') else None
        cls.db_connection = db_setup(
            cfg.CONF.database.db_name, cfg.CONF.database.host, cfg.CONF.database.port,
            username=username, password=password, ensure_indexes=False)

        cls._drop_collections()
        cls.db_connection.drop_database(cfg.CONF.database.db_name)

        # Explicitly ensure indexes after we re-create the DB otherwise ensure_indexes could failure
        # inside db_setup if test inserted invalid data.
        # NOTE: This is only needed in distributed scenarios (production deployments) where
        # multiple services can start up at the same time and race conditions are possible.
        if cls.ensure_indexes:
            if len(cls.ensure_indexes_models) == 0 or len(cls.ensure_indexes_models) > 1:
                msg = ('Ensuring indexes for all the models, this could significantly slow down '
                       'the tests')
                print('#' * len(msg), file=sys.stderr)
                print(msg, file=sys.stderr)
                print('#' * len(msg), file=sys.stderr)

            db_ensure_indexes(cls.ensure_indexes_models)