예제 #1
0
파일: conftest.py 프로젝트: ASTROGBAE/POCS
def pytest_configure(config):
    """Set up the testing."""
    logger.info('Setting up the config server.')
    config_file = 'tests/testing.yaml'

    host = 'localhost'
    port = '8765'

    os.environ['PANOPTES_CONFIG_HOST'] = host
    os.environ['PANOPTES_CONFIG_PORT'] = port

    config_server(config_file, host=host, port=port, load_local=False, save_local=False)
    logger.success('Config server set up')
예제 #2
0
def dynamic_config_server(config_host, config_port, config_path, images_dir,
                          db_name):
    """If a test requires changing the configuration we use a function-scoped testing
    server. We only do this on tests that require it so we are not constantly starting and stopping
    the config server unless necessary.  To use this, each test that requires it must use the
    `dynamic_config_server` and `config_port` fixtures and must pass the `config_port` to all
    instances that are created (propogated through PanBase).
    """

    logger = get_root_logger()
    logger.critical(f'Starting config_server for testing function')

    proc = config_server(
        host=config_host,
        port=config_port,
        config_file=config_path,
        ignore_local=True,
    )

    logger.info(f'config_server started with PID={proc.pid}')

    # Give server time to start
    time.sleep(1)

    # Adjust various config items for testing
    unit_name = 'Generic PANOPTES Unit'
    unit_id = 'PAN000'
    logger.info(f'Setting testing name and unit_id to {unit_id}')
    set_config('name', unit_name, port=config_port)
    set_config('pan_id', unit_id, port=config_port)

    logger.info(f'Setting testing database to {db_name}')
    set_config('db.name', db_name, port=config_port)

    fields_file = 'simulator.yaml'
    logger.info(f'Setting testing scheduler fields_file to {fields_file}')
    set_config('scheduler.fields_file', fields_file, port=config_port)

    # TODO(wtgee): determine if we need separate directories for each module.
    logger.info(f'Setting temporary image directory for testing')
    set_config('directories.images', images_dir, port=config_port)

    yield
    logger.critical(f'Killing config_server started with PID={proc.pid}')
    proc.terminate()
예제 #3
0
def static_config_server(config_host, static_config_port, config_path,
                         images_dir, db_name):

    logger = get_root_logger()
    logger.critical(f'Starting config_server for testing session')

    proc = config_server(
        host=config_host,
        port=static_config_port,
        config_file=config_path,
        ignore_local=True,
    )

    logger.info(f'config_server started with PID={proc.pid}')

    # Give server time to start
    time.sleep(1)

    # Adjust various config items for testing
    unit_name = 'Generic PANOPTES Unit'
    unit_id = 'PAN000'
    logger.info(f'Setting testing name and unit_id to {unit_id}')
    set_config('name', unit_name, port=static_config_port)
    set_config('pan_id', unit_id, port=static_config_port)

    logger.info(f'Setting testing database to {db_name}')
    set_config('db.name', db_name, port=static_config_port)

    fields_file = 'simulator.yaml'
    logger.info(f'Setting testing scheduler fields_file to {fields_file}')
    set_config('scheduler.fields_file', fields_file, port=static_config_port)

    # TODO(wtgee): determine if we need separate directories for each module.
    logger.info(f'Setting temporary image directory for testing')
    set_config('directories.images', images_dir, port=static_config_port)

    yield
    logger.critical(f'Killing config_server started with PID={proc.pid}')
    proc.terminate()
예제 #4
0
def run(context,
        config_file=None,
        save_local=True,
        load_local=False,
        heartbeat=True):
    """Runs the config server with command line options.

    This function is installed as an entry_point for the module, accessible
     at `panoptes-config-server`.
    """
    host = context.obj.get('host')
    port = context.obj.get('port')
    server_process = server.config_server(config_file,
                                          host=host,
                                          port=port,
                                          load_local=load_local,
                                          save_local=save_local,
                                          auto_start=False)

    try:
        print(f'Starting config server. Ctrl-c to stop')
        server_process.start()
        print(
            f'Config server started on  server_process.pid={server_process.pid!r}. '
            f'Set "config_server.running=False" or Ctrl-c to stop')

        # Loop until config told to stop.
        while server_is_running():
            time.sleep(heartbeat)

        server_process.terminate()
        server_process.join(30)
    except KeyboardInterrupt:
        logger.info(
            f'Config server interrupted, shutting down {server_process.pid}')
        server_process.terminate()
    except Exception as e:  # pragma: no cover
        logger.error(f'Unable to start config server {e!r}')