Exemple #1
0
def setup(service, config, setup_db=True, register_mq_exchanges=True,
          register_signal_handlers=True, run_migrations=True):
    """
    Common setup function.

    Currently it performs the following operations:

    1. Parses config and CLI arguments
    2. Establishes DB connection
    3. Set log level for all the loggers to DEBUG if --debug flag is present
    4. Registers RabbitMQ exchanges
    5. Registers common signal handlers

    :param service: Name of the service.
    :param config: Config object to use to parse args.
    """
    # Set up logger which logs everything which happens during and before config
    # parsing to sys.stdout
    logging.setup(DEFAULT_LOGGING_CONF_PATH)

    # Parse args to setup config.
    config.parse_args()

    config_file_paths = cfg.CONF.config_file
    config_file_paths = [os.path.abspath(path) for path in config_file_paths]
    LOG.debug('Using config files: %s', ','.join(config_file_paths))

    # Setup logging.
    logging_config_path = config.get_logging_config_path()
    logging_config_path = os.path.abspath(logging_config_path)

    LOG.debug('Using logging config: %s', logging_config_path)
    logging.setup(logging_config_path)

    if cfg.CONF.debug:
        set_log_level_for_all_loggers(level=stdlib_logging.DEBUG)

    # All other setup which requires config to be parsed and logging to
    # be correctly setup.
    if setup_db:
        db_setup()

    if register_mq_exchanges:
        register_exchanges()

    if register_signal_handlers:
        register_common_signal_handlers()

    # TODO: This is a "not so nice" workaround until we have a proper migration system in place
    if run_migrations:
        insert_system_roles()

    if cfg.CONF.rbac.enable and not cfg.CONF.auth.enable:
        msg = ('Authentication is not enabled. RBAC only works when authentication is enabled.'
               'You can either enable authentication or disable RBAC.')
        raise Exception(msg)
Exemple #2
0
def setup(service,
          config,
          setup_db=True,
          register_mq_exchanges=True,
          register_signal_handlers=True):
    """
    Common setup function.

    Currently it performs the following operations:

    1. Parses config and CLI arguments
    2. Establishes DB connection
    3. Set log level for all the loggers to DEBUG if --debug flag is present
    4. Registers RabbitMQ exchanges
    5. Registers common signal handlers

    :param service: Name of the service.
    :param config: Config object to use to parse args.
    """
    # Set up logger which logs everything which happens during and before config
    # parsing to sys.stdout
    logging.setup(DEFAULT_LOGGING_CONF_PATH)

    # Parse args to setup config.
    config.parse_args()

    config_file_paths = cfg.CONF.config_file
    config_file_paths = [os.path.abspath(path) for path in config_file_paths]
    LOG.debug('Using config files: %s', ','.join(config_file_paths))

    # Setup logging.
    logging_config_path = config.get_logging_config_path()
    logging_config_path = os.path.abspath(logging_config_path)

    LOG.debug('Using logging config: %s', logging_config_path)
    logging.setup(logging_config_path)

    if cfg.CONF.debug:
        set_log_level_for_all_loggers(level=stdlib_logging.DEBUG)

    # All other setup which requires config to be parsed and logging to
    # be correctly setup.
    if setup_db:
        db_setup()

    if register_mq_exchanges:
        register_exchanges()

    if register_signal_handlers:
        register_common_signal_handlers()
Exemple #3
0
def _setup(argv):
    config.parse_args()

    log_level = logging.DEBUG
    logging.basicConfig(format="%(asctime)s %(levelname)s [-] %(message)s", level=log_level)

    if not cfg.CONF.verbose:
        # Note: We still want to print things at the following log levels: INFO, ERROR, CRITICAL
        exclude_log_levels = [logging.AUDIT, logging.DEBUG]
        handlers = logging.getLoggerClass().manager.root.handlers

        for handler in handlers:
            handler.addFilter(LogLevelFilter(log_levels=exclude_log_levels))

    db_setup()
    register_exchanges()
Exemple #4
0
def setup(service, config, setup_db=True, register_mq_exchanges=True,
          register_signal_handlers=True):
    """
    Common setup function.

    Currently it performs the following operations:

    1. Parses config and CLI arguments
    2. Establishes DB connection
    3. Set log level for all the loggers to DEBUG if --debug flag is present
    4. Registers RabbitMQ exchanges
    5. Registers common signal handlers

    :param service: Name of the service.
    :param config: Config object to use to parse args.
    """
    # Set up logger which logs everything which happens during and before config
    # parsing to sys.stdout
    logging.setup(DEFAULT_LOGGING_CONF_PATH)

    # Parse args to setup config.
    config.parse_args()

    config_file_paths = cfg.CONF.config_file
    config_file_paths = [os.path.abspath(path) for path in config_file_paths]
    LOG.debug('Using config files: %s', ','.join(config_file_paths))

    # Setup logging.
    logging_config_path = config.get_logging_config_path()
    logging_config_path = os.path.abspath(logging_config_path)

    LOG.debug('Using logging config: %s', logging_config_path)
    logging.setup(logging_config_path)

    if cfg.CONF.debug:
        set_log_level_for_all_loggers(level=stdlib_logging.DEBUG)

    # All other setup which requires config to be parsed and logging to
    # be correctly setup.
    if setup_db:
        db_setup()

    if register_mq_exchanges:
        register_exchanges()

    if register_signal_handlers:
        register_common_signal_handlers()
Exemple #5
0
def _setup(argv):
    config.parse_args()

    log_level = logging.DEBUG
    logging.basicConfig(format='%(asctime)s %(levelname)s [-] %(message)s',
                        level=log_level)

    if not cfg.CONF.verbose:
        # Note: We still want to print things at the following log levels: INFO, ERROR, CRITICAL
        exclude_log_levels = [logging.AUDIT, logging.DEBUG]
        handlers = logging.getLoggerClass().manager.root.handlers

        for handler in handlers:
            handler.addFilter(LogLevelFilter(log_levels=exclude_log_levels))

    db_setup()
    register_exchanges()
Exemple #6
0
def setup(config, setup_db=True, register_mq_exchanges=True):
    """
    Common setup function.

    Currently it performs the following operations:

    1. Parses config and CLI arguments
    2. Establishes DB connection
    3. Suppress DEBUG log level if --verbose flag is not used
    4. Registers RabbitMQ exchanges

    :param config: Config object to use to parse args.
    """
    # Register common CLI options
    register_common_cli_options()

    # Parse args to setup config
    config.parse_args()

    # Set up logging
    log_level = stdlib_logging.DEBUG
    stdlib_logging.basicConfig(format='%(asctime)s %(levelname)s [-] %(message)s', level=log_level)

    if not cfg.CONF.verbose:
        # Note: We still want to print things at the following log levels: INFO, ERROR, CRITICAL
        exclude_log_levels = [stdlib_logging.AUDIT, stdlib_logging.DEBUG]
        handlers = stdlib_logging.getLoggerClass().manager.root.handlers

        for handler in handlers:
            handler.addFilter(LogLevelFilter(log_levels=exclude_log_levels))

    # All other setup code which requires config to be parsed and logging to be correctly setup
    if setup_db:
        db_setup()

    if register_mq_exchanges:
        register_exchanges()
Exemple #7
0
    def test_register_exchanges_predeclare_queues(self, mock_declare):
        # Verify that queues are correctly pre-declared
        self.assertEqual(mock_declare.call_count, 0)

        register_exchanges()
        self.assertEqual(mock_declare.call_count, len(QUEUES))
Exemple #8
0
def setup(service,
          config,
          setup_db=True,
          register_mq_exchanges=True,
          register_signal_handlers=True,
          register_internal_trigger_types=False,
          run_migrations=True,
          config_args=None):
    """
    Common setup function.

    Currently it performs the following operations:

    1. Parses config and CLI arguments
    2. Establishes DB connection
    3. Set log level for all the loggers to DEBUG if --debug flag is present
    4. Registers RabbitMQ exchanges
    5. Registers common signal handlers
    6. Register internal trigger types

    :param service: Name of the service.
    :param config: Config object to use to parse args.
    """
    # Set up logger which logs everything which happens during and before config
    # parsing to sys.stdout
    logging.setup(DEFAULT_LOGGING_CONF_PATH)

    # Parse args to setup config.
    if config_args:
        config.parse_args(config_args)
    else:
        config.parse_args()

    config_file_paths = cfg.CONF.config_file
    config_file_paths = [os.path.abspath(path) for path in config_file_paths]
    LOG.debug('Using config files: %s', ','.join(config_file_paths))

    # Setup logging.
    logging_config_path = config.get_logging_config_path()
    logging_config_path = os.path.abspath(logging_config_path)

    LOG.debug('Using logging config: %s', logging_config_path)
    logging.setup(logging_config_path)

    if cfg.CONF.debug:
        set_log_level_for_all_loggers(level=stdlib_logging.DEBUG)

    # All other setup which requires config to be parsed and logging to
    # be correctly setup.
    if setup_db:
        db_setup()

    if cfg.CONF.debug or cfg.CONF.profile:
        enable_profiling()

    if register_mq_exchanges:
        register_exchanges()

    if register_signal_handlers:
        register_common_signal_handlers()

    if register_internal_trigger_types:
        triggers.register_internal_trigger_types()

    # TODO: This is a "not so nice" workaround until we have a proper migration system in place
    if run_migrations:
        run_all_rbac_migrations()

    if cfg.CONF.rbac.enable and not cfg.CONF.auth.enable:
        msg = (
            'Authentication is not enabled. RBAC only works when authentication is enabled.'
            'You can either enable authentication or disable RBAC.')
        raise Exception(msg)
Exemple #9
0
    def test_register_exchanges_predeclare_queues(self, mock_declare):
        # Verify that queues are correctly pre-declared
        self.assertEqual(mock_declare.call_count, 0)

        register_exchanges()
        self.assertEqual(mock_declare.call_count, len(QUEUES))
Exemple #10
0
def main():
    _setup()
    register_exchanges()