Ejemplo n.º 1
0
    def _run_tests(self, lock_path, dbpath, test_run_id,
                   cluster_id, ostf_os_access_creds, argv_add, token,
                   results_log):
        cleanup_flag = False

        def raise_exception_handler(signum, stack_frame):
            raise InterruptTestRunException()
        signal.signal(signal.SIGUSR1, raise_exception_handler)

        with engine.contexted_session(dbpath) as session:
            testrun = session.query(models.TestRun)\
                .filter_by(id=test_run_id)\
                .one()

            try:
                if not os.path.exists(lock_path):
                    LOG.error('There is no directory to store locks')
                    raise Exception('There is no directory to store locks')

                aquired_locks = []
                for serie in testrun.test_set.exclusive_testsets:
                    lock_name = serie + str(testrun.cluster_id)
                    fd = open(os.path.join(lock_path, lock_name), 'w')
                    fcntl.flock(fd, fcntl.LOCK_EX)
                    aquired_locks.append(fd)

                nose_test_runner.SilentTestProgram(
                    addplugins=[nose_storage_plugin.StoragePlugin(
                        session, test_run_id, str(cluster_id),
                        ostf_os_access_creds, token, results_log
                    )],
                    exit=False,
                    argv=['ostf_tests'] + argv_add)

            except InterruptTestRunException:
                # (dshulyak) after process is interrupted we need to
                # disable existing handler
                signal.signal(signal.SIGUSR1, lambda *args: signal.SIG_DFL)
                if testrun.test_set.cleanup_path:
                    cleanup_flag = True

            except Exception:
                LOG.exception('Test run ID: %s', test_run_id)
            finally:
                updated_data = {'status': 'finished',
                                'pid': None}

                models.TestRun.update_test_run(
                    session, test_run_id, updated_data)

                for fd in aquired_locks:
                    fcntl.flock(fd, fcntl.LOCK_UN)
                    fd.close()

                if cleanup_flag:
                    self._clean_up(session,
                                   test_run_id,
                                   cluster_id,
                                   testrun.test_set.cleanup_path)
Ejemplo n.º 2
0
def main():

    settings = Ostf_Config()

    cli_args = cli_config.parse_cli()

    config = {
        'server': {
            'host': settings.adapter.server_host or cli_args.host,
            'port': settings.adapter.server_port or cli_args.port
        },
        'dbpath': settings.adapter.dbpath or cli_args.dbpath,
        'debug': cli_args.debug,
        'debug_tests': cli_args.debug_tests,
        'lock_dir': settings.adapter.lock_dir or cli_args.lock_dir,
        'nailgun': {
            'host': settings.adapter.nailgun_host or cli_args.nailgun_host,
            'port': settings.adapter.nailgun_port or cli_args.nailgun_port
        }
    }
    logger.setup(log_file=(
        settings.adapter.log_file or cli_args.log_file))

    log = logging.getLogger(__name__)

    root = app.setup_app(config=config)

    if settings.adapter.after_init_hook or\
            getattr(cli_args, 'after_init_hook'):
        return nailgun_hooks.after_initialization_environment_hook()

    with engine.contexted_session(pecan.conf.dbpath) as session:
        # performing cleaning of expired data (if any) in db
        mixins.clean_db(session)

        # discover testsets and their tests
        CORE_PATH = pecan.conf.debug_tests if \
            pecan.conf.get('debug_tests') else 'fuel_health'

        nose_discovery.discovery(path=CORE_PATH, session=session)

        # cache needed data from test repository
        mixins.cache_test_repository(session)

    host, port = pecan.conf.server.host, pecan.conf.server.port
    srv = pywsgi.WSGIServer((host, int(port)), root)

    log.info('Starting server in PID %s', os.getpid())
    log.info("serving on http://%s:%s", host, port)

    try:
        signal.signal(signal.SIGCHLD, signal.SIG_IGN)
        srv.serve_forever()
    except KeyboardInterrupt:
        pass
Ejemplo n.º 3
0
def main():

    ostf_config.init_config(sys.argv[1:])

    logger.setup(log_file=CONF.adapter.log_file)

    log = logging.getLogger(__name__)
    log.info('Start app configuration')

    root = app.setup_app({})

    # completely clean db (drop tables, constraints and types)
    # plus drop alembic_version table (needed if, for example, head migration
    # script was changed after applying)
    if CONF.clear_db:
        return nailgun_hooks.clear_db(CONF.adapter.dbpath)

    if CONF.after_initialization_environment_hook:
        return nailgun_hooks.after_initialization_environment_hook()

    with engine.contexted_session(CONF.adapter.dbpath) as session:
        # performing cleaning of expired data (if any) in db
        mixins.delete_db_data(session)
        log.info('Cleaned up database.')
        # discover testsets and their tests
        CORE_PATH = CONF.debug_tests or 'fuel_health'

        log.info('Performing nose discovery with {0}.'.format(CORE_PATH))

        nose_discovery.discovery(path=CORE_PATH, session=session)

        # cache needed data from test repository
        mixins.cache_test_repository(session)

    log.info('Discovery is completed')
    host, port = CONF.adapter.server_host, CONF.adapter.server_port
    srv = pywsgi.WSGIServer((host, port), root)

    log.info('Starting server in PID %s', os.getpid())
    log.info("serving on http://%s:%s", host, port)

    try:
        signal.signal(signal.SIGCHLD, signal.SIG_IGN)
        srv.serve_forever()
    except KeyboardInterrupt:
        pass
Ejemplo n.º 4
0
def main():

    ostf_config.init_config(sys.argv[1:])

    logger.setup(log_file=CONF.adapter.log_file)

    log = logging.getLogger(__name__)
    log.info('Start app configuration')

    root = app.setup_app({})

    # completely clean db (drop tables, constraints and types)
    # plus drop alembic_version table (needed if, for example, head migration
    # script was changed after applying)
    if CONF.clear_db:
        return nailgun_hooks.clear_db(CONF.adapter.dbpath)

    if CONF.after_initialization_environment_hook:
        return nailgun_hooks.after_initialization_environment_hook()

    with engine.contexted_session(CONF.adapter.dbpath) as session:
        # performing cleaning of expired data (if any) in db
        mixins.delete_db_data(session)
        log.info('Cleaned up database.')
        # discover testsets and their tests
        CORE_PATH = CONF.debug_tests or 'fuel_health'

        log.info('Performing nose discovery with {0}.'.format(CORE_PATH))

        nose_discovery.discovery(path=CORE_PATH, session=session)

        # cache needed data from test repository
        mixins.cache_test_repository(session)

    log.info('Discovery is completed')
    host, port = CONF.adapter.server_host, CONF.adapter.server_port
    srv = pywsgi.WSGIServer((host, port), root)

    log.info('Starting server in PID %s', os.getpid())
    log.info("serving on http://%s:%s", host, port)

    try:
        signal.signal(signal.SIGCHLD, signal.SIG_IGN)
        srv.serve_forever()
    except KeyboardInterrupt:
        pass