Beispiel #1
0
    def block_until_db_starts(cls, context):
        ''' Wait for database to start if the database was
        started by this client and polling is possible. '''

        tries_count = 0

        while not database_handler.is_database_running(cls.database_host,
                cls.database_port, context.db_username, cls.run_env) and \
                tries_count < 5:
            tries_count += 1
            time.sleep(3)

        if tries_count >= 5 or not cls._database.poll():
            # last chance to start
            if cls._database.returncode is None:
                # it is possible that the database starts really slow
                time.sleep(20)
                if not database_handler.is_database_running(cls.host,
                        cls.database_port, context.db_username, cls.run_env):

                    LOG.error('Failed to start database.')
                    sys.exit(1)

        else:
            LOG.error('Failed to start database server.')
            LOG.error('Database server exit code: '+str(cls._server.returncode))
            sys.exit(1)
Beispiel #2
0
    def start_postgres(cls, context, init_db=True):
        """
        init_db : Initialize database locally if possible
        """

        dbusername = context.db_username

        LOG.info("Checking for database")
        if not database_handler.is_database_running(cls.database_host, cls.database_port, dbusername, cls.run_env):
            LOG.info("Database is not running yet")
            # On remote host we cannot initialize a new database
            if not util.is_localhost(cls.database_host):
                sys.exit(1)

            db_path = context.database_path
            if init_db:
                if not database_handler.is_database_exist(db_path) and not database_handler.initialize_database(
                    db_path, dbusername, cls.run_env
                ):
                    # The database does not exist and cannot create
                    LOG.error("Database is missing and the initialization " "of a new failed!")
                    LOG.error("Please check your configuration!")
                    sys.exit(1)
            else:
                if not database_handler.is_database_exist(db_path):
                    # The database does not exists
                    LOG.error("Database is missing!")
                    LOG.error("Please check your configuration!")
                    sys.exit(1)

            LOG.info("Starting database")
            cls._database = database_handler.start_database(db_path, cls.database_host, cls.database_port, cls.run_env)
            atexit.register(cls._database.terminate)
Beispiel #3
0
    def block_until_db_start_proc_free(cls, context):
        ''' Wait for database if the database process was stared
        with a different client. No polling is possible.'''

        tries_count = 0
        max_try = 20
        timeout = 5
        while not database_handler.is_database_running(cls.database_host,
                cls.database_port, context.db_username, cls.run_env) and \
                tries_count < max_try:
            tries_count += 1
            time.sleep(timeout)

            if tries_count >= max_try:
                LOG.error('Failed to start database.')
                sys.exit(1)