Esempio n. 1
0
def test_update_logging_config_not_verbose(config):
    config["verbose"] = False
    npconfig.update_logging_config(config, log_name=config["log_dir"])
    log = logging.getLogger(config["log_dir"])
    assert log.level == logging.INFO
    assert len(log.handlers) == 3
    close_handlers(log_name=config["log_dir"])
Esempio n. 2
0
def test_update_logging_config_verbose_existing_handler(config):
    log = logging.getLogger(config["log_dir"])
    log.addHandler(logging.NullHandler())
    log.addHandler(logging.NullHandler())
    config["verbose"] = True
    npconfig.update_logging_config(config, log_name=config["log_dir"])
    assert log.level == logging.DEBUG
    assert len(log.handlers) == 4
    close_handlers(log_name=config["log_dir"])
Esempio n. 3
0
def test_watched_log_file(config):
    config["watch_log_file"] = True
    config["log_fmt"] = "%(levelname)s - %(message)s"
    npconfig.update_logging_config(config, log_name=config["log_dir"])
    path = os.path.join(config["log_dir"], "worker.log")
    log = logging.getLogger(config["log_dir"])
    log.info("foo")
    os.rename(path, "{}.1".format(path))
    log.info("bar")
    with open(path, "r") as fh:
        assert fh.read().rstrip() == "INFO - bar"
    close_handlers(log_name=config["log_dir"])
Esempio n. 4
0
def main(event_loop=None):
    """Notarization poller entry point: get everything set up, then enter the main loop.

    Args:
        event_loop (asyncio.BaseEventLoop, optional): the event loop to use.
            If None, use ``asyncio.get_event_loop()``. Defaults to None.

    """
    event_loop = event_loop or asyncio.get_event_loop()
    config = get_config_from_cmdln(sys.argv[1:])
    update_logging_config(config)

    log.info("Notarization poller starting up at {} UTC".format(
        arrow.utcnow().format()))
    log.info("Worker FQDN: {}".format(socket.getfqdn()))
    rm(config["work_dir"])
    makedirs(config["work_dir"])
    running_tasks = RunTasks(config)

    async def _handle_sigterm():
        log.info("SIGTERM received; shutting down")
        await running_tasks.cancel()

    def _handle_sigusr1():
        """Stop accepting new tasks."""
        log.info("SIGUSR1 received; no more tasks will be taken")
        running_tasks.is_stopped = True

    event_loop.add_signal_handler(
        signal.SIGTERM, lambda: asyncio.ensure_future(_handle_sigterm()))
    event_loop.add_signal_handler(signal.SIGUSR1, _handle_sigusr1)

    try:
        event_loop.run_until_complete(running_tasks.invoke())
    except Exception:
        log.critical("Fatal exception", exc_info=1)
        raise
    finally:
        log.info("Notarization poller stopped at {} UTC".format(
            arrow.utcnow().format()))
        log.info("Worker FQDN: {}".format(socket.getfqdn()))