def main():
    parser = argparse.ArgumentParser(description='Call logs database migrator')
    options = parse_args(parser)

    file_config = {
        key: value
        for key, value in read_config_file_hierarchy(DEFAULT_CONFIG).items()
        if key in ('db_uri', 'cel_db_uri')
    }
    config = ChainMap(file_config, DEFAULT_CONFIG)

    if config['user']:
        change_user(config['user'])

    setup_logging(
        config['logfile'],
        debug=config['debug'] or options.debug,
        log_level=get_log_level_by_name(config['log_level']),
    )
    options = vars(options)
    if options.get('action') == 'call-log':
        if options.get('index'):
            migrate_call_log_index(config)
        else:
            migrate_call_log_tables(config, options.get('max_entries'))
Esempio n. 2
0
def main(argv=None):
    argv = argv or sys.argv[1:]
    with _PreConfigLogger() as logger:
        logger.debug('Starting wazo-dird')

        config = load_config(argv)

        xivo_logging.setup_logging(
            config['log_filename'],
            debug=config['debug'],
            log_level=config['log_level'],
        )
    xivo_logging.silence_loggers(
        ['Flask-Cors', 'amqp', 'urllib3', 'stevedore.extension'],
        logging.WARNING)

    if config['user']:
        change_user(config['user'])

    try:
        set_xivo_uuid(config, logger)
    except UUIDNotFound:
        if config['service_discovery']['enabled']:
            raise

    controller = Controller(config)
    controller.run()
Esempio n. 3
0
def main():
    xivo_logging.silence_loggers(SPAMMY_LOGGERS, logging.WARNING)

    config = get_config(sys.argv[1:])

    xivo_logging.setup_logging(
        config['log_filename'],
        debug=config['debug'],
        log_level=config['log_level'],
    )

    if config['user']:
        change_user(config['user'])

    if config["db_upgrade_on_startup"]:
        database.upgrade(config["db_uri"])

    try:
        set_xivo_uuid(config, logger)
    except UUIDNotFound:
        if config['service_discovery']['enabled']:
            raise

    controller = Controller(config)
    controller.run()
Esempio n. 4
0
def main():
    xivo_logging.silence_loggers(SPAMMY_LOGGERS, logging.WARNING)

    config = get_config(sys.argv[1:])

    xivo_logging.setup_logging(
        config['log_filename'],
        config['foreground'],
        config['debug'],
        config['log_level'],
    )

    user = config.get('user')
    if user:
        change_user(user)

    try:
        set_xivo_uuid(config, logger)
    except UUIDNotFound:
        if config['service_discovery']['enabled']:
            raise

    controller = Controller(config)
    with pidfile_context(config['pid_filename'], config['foreground']):
        try:
            controller.run()
        except KeyboardInterrupt:
            pass
Esempio n. 5
0
def main(argv=None):
    argv = argv or sys.argv[1:]
    config = load_config(argv)

    if config['user']:
        change_user(config['user'])

    xivo_logging.setup_logging(
        config['log_filename'],
        debug=config['debug'],
        log_level=config['log_level']
    )
    xivo_logging.silence_loggers(
        ['amqp', 'Flask-Cors', 'iso8601', 'kombu', 'swaggerpy', 'urllib3', 'ari.model', 'stevedore.extension'],
        logging.WARNING,
    )
    if config['debug']:
        xivo_logging.silence_loggers(['swaggerpy'], logging.INFO)

    set_xivo_uuid(config, logger)

    controller = Controller(config)
    signal.signal(signal.SIGTERM, partial(sigterm, controller))

    controller.run()
Esempio n. 6
0
def main():
    setup_logging('/dev/null', debug=False)
    args = _parse_cli_args(sys.argv[1:])

    if args.user:
        change_user(args.user)

    for _ in range(40):
        try:
            conn = psycopg2.connect(args.pg_db_uri)
            break
        except psycopg2.OperationalError:
            time.sleep(0.25)
    else:
        print('Failed to connect to postgres', file=sys.stderr)
        sys.exit(1)

    conn.autocommit = True
    with conn:
        with conn.cursor() as cursor:
            if not db_helper.db_user_exists(cursor, args.owner):
                db_helper.create_db_user(cursor, args.owner, args.password)
            if not db_helper.db_exists(cursor, args.db):
                db_helper.create_db(cursor, args.db, args.owner)

    conn = psycopg2.connect(args.auth_db_uri)
    with conn:
        with conn.cursor() as cursor:
            db_helper.create_db_extensions(cursor, ['uuid-ossp'])
Esempio n. 7
0
def main():
    cli_config = _parse_args()
    file_config = read_config_file_hierarchy(
        ChainMap(cli_config, _DEFAULT_CONFIG))
    service_key = _load_key_file(
        ChainMap(cli_config, file_config, _DEFAULT_CONFIG))
    config = ChainMap(cli_config, service_key, file_config, _DEFAULT_CONFIG)

    user = config.get('user')
    if user:
        change_user(user)

    xivo_dao.init_db_from_config(config)

    setup_logging(config['logfile'], config['foreground'], config['debug'])
    silence_loggers(['Flask-Cors'], logging.WARNING)
    set_xivo_uuid(config, logger)

    with pidfile_context(config['pidfile'], config['foreground']):
        logger.info('Starting xivo-agentd')
        try:
            _run(config)
        except Exception:
            logger.exception('Unexpected error:')
        except KeyboardInterrupt:
            pass
        finally:
            logger.info('Stopping xivo-agentd')
Esempio n. 8
0
def main():
    cti_config.init_cli_config(sys.argv[1:])
    cti_config.init_config_file()
    cti_config.init_auth_config()
    xivo_dao.init_db_from_config(config)
    cti_config.update_db_config()

    user = config.get('user')
    if user:
        change_user(user)

    setup_logging(config['logfile'], config['foreground'], config['debug'])
    silence_loggers(
        ['amqp', 'urllib3', 'Flask-Cors', 'kombu', 'stevedore.extension'],
        logging.WARNING)

    xivo_uuid = get_xivo_uuid(logger)

    register_class.setup(xivo_uuid)

    ctid = context.get('cti_server')
    ctid.setup()

    with ServiceCatalogRegistration('xivo-ctid', xivo_uuid, config['consul'],
                                    config['service_discovery'], config['bus'],
                                    partial(self_check, config)):
        ctid.run()
Esempio n. 9
0
    def test_setup_logging_with_no_format_then_log_format_is_default(
            self, logging):
        log_file = Mock()

        setup_logging(log_file)

        logging.Formatter.assert_called_once_with(DEFAULT_LOG_FORMAT)
Esempio n. 10
0
def main():
    parsed_args = _parse_args()

    setup_logging(LOGFILENAME, parsed_args.foreground, parsed_args.debug)

    if parsed_args.debug:
        logger.info("Debug mode enabled.")
        flask_http_server.app.debug = True

    flask_http_server.register_blueprints_v1_1()

    if parsed_args.dev_mode:
        logger.info("Starting xivo-restapid in dev mode.")
        config.HOST = parsed_args.listen_addr
        config.PORT = parsed_args.listen_port
        logger.info("Running on %s:%s", config.HOST, config.PORT)
        flask_http_server.app.run(host=config.HOST, port=config.PORT)
    else:
        from flup.server.fcgi import WSGIServer

        if parsed_args.foreground:
            logger.info("Starting xivo-restapid in foreground mode.")
        else:
            logger.info("Starting xivo-restapid in standard mode.")
            _daemonize()

        WSGIServer(flask_http_server.app,
                   bindAddress='/var/www/restws-fcgi.sock',
                   multithreaded=False,
                   multiprocess=True,
                   debug=False).run()
Esempio n. 11
0
    def test_setup_logging_with_no_foreground_then_no_stream_logging(
            self, logging):
        log_file = Mock()

        setup_logging(log_file)

        assert_that(logging.StreamHandler.call_count, equal_to(0))
Esempio n. 12
0
    def test_setup_logging_with_debug_then_log_level_is_debug(self, logging):
        log_file = Mock()
        root_logger = logging.getLogger.return_value

        setup_logging(log_file, debug=True)

        root_logger.setLevel.assert_called_once_with(logging.DEBUG)
Esempio n. 13
0
def main():
    _print_deprecation_notice()
    setup_logging('/dev/null', foreground=True, debug=False)
    silence_loggers(['urllib3.connectionpool'], level=logging.WARNING)
    init_db_from_config(default_config())
    with pidfile_context(PIDFILENAME, foreground=True):
        _generate_call_logs()
Esempio n. 14
0
def main():
    parsed_args = _parse_args()

    setup_logging(LOGFILENAME, parsed_args.foreground, parsed_args.debug)

    if parsed_args.debug:
        logger.info("Debug mode enabled.")
        flask_http_server.app.debug = True

    flask_http_server.register_blueprints_v1_1()

    if parsed_args.dev_mode:
        logger.info("Starting xivo-restapid in dev mode.")
        config.HOST = parsed_args.listen_addr
        config.PORT = parsed_args.listen_port
        logger.info("Running on %s:%s", config.HOST, config.PORT)
        flask_http_server.app.run(host=config.HOST, port=config.PORT)
    else:
        from flup.server.fcgi import WSGIServer

        if parsed_args.foreground:
            logger.info("Starting xivo-restapid in foreground mode.")
        else:
            logger.info("Starting xivo-restapid in standard mode.")
            _daemonize()

        WSGIServer(flask_http_server.app,
                   bindAddress='/var/www/restws-fcgi.sock',
                   multithreaded=False,
                   multiprocess=True,
                   debug=False).run()
Esempio n. 15
0
def main(argv=None):
    argv = argv or sys.argv[1:]
    with _PreConfigLogger() as logger:
        logger.debug('Starting wazo-dird')

        config = load_config(logger, argv)

        xivo_logging.setup_logging(config['log_filename'], config['foreground'],
                                   config['debug'], config['log_level'])
    xivo_logging.silence_loggers(['Flask-Cors', 'urllib3', 'stevedore.extension'], logging.WARNING)

    if config['user']:
        change_user(config['user'])

    try:
        set_xivo_uuid(config, logger)
    except UUIDNotFound:
        if config['service_discovery']['enabled']:
            raise

    controller = Controller(config)

    with pidfile_context(config['pid_filename'], config['foreground']):
        try:
            controller.run()
        except KeyboardInterrupt:
            # exit without stack trace
            pass
Esempio n. 16
0
def main():
    parsed_args = _parse_args()

    setup_logging(LOG_FILE_NAME, parsed_args.foreground, parsed_args.debug)

    with pidfile_context(PIDFILE, parsed_args.foreground):
        agid.init()
        agid.run()
Esempio n. 17
0
    def test_setup_logging_with_no_flags_then_log_level_is_default(
            self, logging):
        log_file = Mock()
        root_logger = logging.getLogger.return_value

        setup_logging(log_file)

        root_logger.setLevel.assert_called_once_with(DEFAULT_LOG_LEVEL)
Esempio n. 18
0
    def test_setup_logging_with_loglevel_then_log_level_is_changed(
            self, logging):
        log_file = Mock()
        root_logger = logging.getLogger.return_value

        setup_logging(log_file, log_level=logging.ERROR)

        root_logger.setLevel.assert_called_once_with(logging.ERROR)
Esempio n. 19
0
    def test_setup_logging_with_format_then_log_format_is_not_default(
            self, logging):
        log_file = Mock()
        log_format = Mock()

        setup_logging(log_file, log_format=log_format)

        logging.Formatter.assert_called_once_with(log_format)
Esempio n. 20
0
    def test_that_setup_logging_adds_excepthook(self, logging):
        log_file = Mock()

        with patch('sys.excepthook') as new_hook:
            setup_logging(log_file)

            assert_that(sys.excepthook, is_not(new_hook))
            assert_that(sys.excepthook, is_(excepthook))
Esempio n. 21
0
    def test_setup_logging_when_log_in_info_level_then_log_in_stdout(
            self, stdout, stderr):
        message = 'test info'

        setup_logging(self.file_name)
        logging.getLogger('test').info(message)

        assert_that(stdout.getvalue(), contains_string(message))
        assert_that(stderr.getvalue(), has_length(0))
Esempio n. 22
0
def main():
    signal.signal(signal.SIGTERM, _handle_sigterm)
    parsed_args = _parse_args()

    config = load_config(config_dir=parsed_args.config)
    setup_logging(log_file=config['log_file'], debug=parsed_args.verbose)

    if parsed_args.prerequisite:
        prerequisite.run(parsed_args.config, parsed_args.instance)
Esempio n. 23
0
    def test_setup_logging_when_log_in_warning_level_then_log_in_stdout(
            self, stdout, stderr):
        message = ''

        setup_logging(self.file_name)
        logging.getLogger('test').warning(message)

        assert_that(stdout.getvalue(), contains_string(message))
        assert_that(stderr.getvalue(), equal_to(''))
Esempio n. 24
0
    def test_setup_logging_when_log_in_error_level_then_log_in_stderr(
            self, stdout, stderr):
        message = 'test error'
        _, file_name = tempfile.mkstemp()

        setup_logging(file_name)
        logging.getLogger('test').error(message)

        assert_that(stderr.getvalue(), contains_string(message))
        assert_that(stdout.getvalue(), has_length(0))
Esempio n. 25
0
    def test_setup_logging_then_stream_logging(self, logging):
        log_file = Mock()
        root_logger = logging.getLogger.return_value
        stream_handler = logging.StreamHandler.return_value
        formatter = logging.Formatter.return_value

        setup_logging(log_file)

        stream_handler.setFormatter.assert_any_call(formatter)
        root_logger.addHandler.assert_any_call(stream_handler)
Esempio n. 26
0
def main():
    config = load_config()

    xivo_logging.setup_logging(config['log_filename'], debug=config['debug'], log_level=config['log_level'])

    xivo_dao.init_db(config['db_uri'])
    f = ConfgendFactory(config['cache'], config)

    reactor.listenTCP(config['listen_port'], f, interface=config['listen_address'])
    reactor.run()
Esempio n. 27
0
def main(argv):
    config = load_config(argv)

    setup_logging(config['log_filename'], config['foreground'], config['debug'], config['log_level'])
    if config['user']:
        change_user(config['user'])

    controller = Controller(config)

    with pidfile_context(config['pid_filename'], config['foreground']):
        controller.run()
Esempio n. 28
0
    def test_setup_logging_with_log_file_then_setup_logging_in_log_file(
            self, logging):
        log_file = 'my_log_file.log'
        root_logger = logging.getLogger.return_value
        file_handler = logging.FileHandler.return_value
        formatter = logging.Formatter.return_value

        setup_logging(log_file)

        logging.FileHandler.assert_called_once_with(log_file)
        file_handler.setFormatter.assert_called_once_with(formatter)
        root_logger.addHandler.assert_any_call(file_handler)
Esempio n. 29
0
def main():
    config = load_config(sys.argv[1:])

    if config.get('user'):
        change_user(config['user'])

    xivo_logging.setup_logging(config['log_filename'], config['foreground'],
                               config['debug'], config['log_level'])

    controller = Controller(config)

    with pidfile_context(config['pid_filename'], config['foreground']):
        controller.run()
Esempio n. 30
0
def main():
    cli_config = _parse_args()
    file_config = read_config_file_hierarchy(ChainMap(cli_config, _DEFAULT_CONFIG))
    config = ChainMap(cli_config, file_config, _DEFAULT_CONFIG)

    setup_logging(config['log_file'], debug=config['debug'])

    xivo_dao.init_db_from_config(config)

    with pidfile_context(config['pid_file']):
        if 'archives' in config.get('enabled_plugins', {}):
            _load_plugins(config)
        _purge_tables(config)
Esempio n. 31
0
def main():
    cli_config = _parse_args()
    file_config = read_config_file_hierarchy(ChainMap(cli_config, _DEFAULT_CONFIG))
    config = ChainMap(cli_config, file_config, _DEFAULT_CONFIG)

    setup_logging(config['logfile'], config['foreground'], config['debug'])
    silence_loggers(['urllib3'], logging.WARNING)

    xivo_dao.init_db_from_config(config)

    with pidfile_context(config['pidfile'], config['foreground']):
        agid.init(config)
        agid.run()
Esempio n. 32
0
def twisted_application():
    config = load_config()

    xivo_logging.setup_logging(config['log_filename'], debug=config['debug'], log_level=config['log_level'])

    xivo_dao.init_db(config['db_uri'])
    f = ConfgendFactory(config['cache'], config)

    application = service.Application('confgend')

    svc = internet.TCPServer(config['listen_port'], f, interface=config['listen_address'])
    svc.setServiceParent(application)

    return application
Esempio n. 33
0
def main():
    config = load_config()

    setup_logging(config['logfile'], debug=config['debug'])

    if config.get('user'):
        change_user(config['user'])

    set_xivo_uuid(config, logger)

    controller = Controller(config)
    signal.signal(signal.SIGTERM, partial(sigterm, controller))

    controller.run()
Esempio n. 34
0
def main():
    config = load_config(sys.argv[1:])

    if config.get('user'):
        change_user(config['user'])

    xivo_logging.setup_logging(
        config['log_filename'],
        debug=config['debug'],
        log_level=config['log_level'],
    )

    controller = Controller(config)
    controller.run()
Esempio n. 35
0
def main(argv):
    config = load_config(argv)

    if config['user']:
        change_user(config['user'])

    xivo_logging.setup_logging(config['log_filename'], config['foreground'], config['debug'], config['log_level'])
    xivo_logging.silence_loggers(['amqp', 'Flask-Cors', 'iso8601', 'kombu', 'swaggerpy', 'urllib3', 'ari.model'], logging.WARNING)

    set_xivo_uuid(config, logger)

    controller = Controller(config)
    signal.signal(signal.SIGTERM, partial(sigterm, controller))

    with pidfile_context(config['pid_filename'], config['foreground']):
        controller.run()
Esempio n. 36
0
def main():
    _init_signal()
    _disable_ssl_cert_verification()
    parsed_args = _parse_args()

    config = load_config(extra_config=parsed_args.config)
    setup_logging(log_file=config['log_file'], foreground=True, debug=parsed_args.verbose)

    feature_manager = FeatureManager(config)

    controller = XiVOAcceptanceController(feature_manager=feature_manager)

    if parsed_args.prerequisite:
        controller.exec_prerequisite(extra_config=parsed_args.config)

    if parsed_args.internal_features:
        controller.internal_features(internal_features=parsed_args.internal_features)
Esempio n. 37
0
def main(argv):
    config = load_config(argv)

    xivo_logging.setup_logging(config['log_filename'], config['foreground'],
                               config['debug'], config['log_level'])
    xivo_logging.silence_loggers(['Flask-Cors'], logging.WARNING)

    if config['user']:
        change_user(config['user'])

    xivo_dao.init_db_from_config(config)
    init_bus_from_config(ChainMap(config, {'uuid': info_dao.get().uuid}))
    setup_sysconfd(config['sysconfd']['host'], config['sysconfd']['port'])

    controller = Controller(config)

    with pidfile_context(config['pid_filename'], config['foreground']):
        controller.run()
Esempio n. 38
0
 def _set_logger(self):
     setup_logging(config['logfile'], config['foreground'], config['debug'])