Exemple #1
0
def test_update_logging_config_verbose(context):
    context.config['verbose'] = True
    swlog.update_logging_config(context, log_name=context.config['log_dir'])
    log = logging.getLogger(context.config['log_dir'])
    assert log.level == logging.DEBUG
    assert len(log.handlers) == 3
    close_handlers(log_name=context.config['log_dir'])
Exemple #2
0
def main():
    """Scriptworker entry point: get everything set up, then enter the main loop
    """
    context = Context()
    kwargs = {}
    if len(sys.argv) > 1:
        if len(sys.argv) > 2:
            print("Usage: {} [configfile]".format(sys.argv[0]),
                  file=sys.stderr)
            sys.exit(1)
        kwargs['path'] = sys.argv[1]
    context.config, credentials = create_config(**kwargs)
    update_logging_config(context)
    cleanup(context)
    conn = aiohttp.TCPConnector(limit=context.config["max_connections"])
    loop = asyncio.get_event_loop()
    with aiohttp.ClientSession(connector=conn) as session:
        context.session = session
        context.credentials = credentials
        while True:
            try:
                loop.create_task(async_main(context))
                loop.run_forever()
            except RuntimeError:
                pass
Exemple #3
0
def test_update_logging_config_not_verbose(context):
    context.config['verbose'] = False
    swlog.update_logging_config(context, log_name=context.config['log_dir'])
    log = logging.getLogger(context.config['log_dir'])
    assert log.level == logging.INFO
    assert len(log.handlers) == 2
    close_handlers(log_name=context.config['log_dir'])
Exemple #4
0
def test_update_logging_config_verbose_existing_handler(context):
    log = logging.getLogger(context.config['log_dir'])
    log.addHandler(logging.NullHandler())
    log.addHandler(logging.NullHandler())
    swlog.update_logging_config(context, log_name=context.config['log_dir'])
    assert log.level == logging.DEBUG
    assert len(log.handlers) == 4
def test_update_logging_config_verbose(context):
    context.config['verbose'] = True
    swlog.update_logging_config(context, log_name=context.config['log_dir'])
    log = logging.getLogger(context.config['log_dir'])
    assert log.level == logging.DEBUG
    assert len(log.handlers) == 3
    close_handlers(log_name=context.config['log_dir'])
def test_update_logging_config_not_verbose(context):
    context.config['verbose'] = False
    swlog.update_logging_config(context, log_name=context.config['log_dir'])
    log = logging.getLogger(context.config['log_dir'])
    assert log.level == logging.INFO
    assert len(log.handlers) == 2
    close_handlers(log_name=context.config['log_dir'])
Exemple #7
0
def get_context_from_cmdln(args, desc="Run scriptworker"):
    """Create a Context object from args.

    This was originally part of main(), but we use it in
    `scriptworker.gpg.create_initial_gpg_homedirs` too.

    Args:
        args (list): the commandline args.  Generally sys.argv

    Returns:
        tuple: `scriptworker.context.Context` with populated config, and
            credentials frozendict
    """
    context = Context()
    parser = argparse.ArgumentParser(description=desc)
    parser.add_argument(
        "config_path", type=str, nargs="?", default="scriptworker.json",
        help="the path to the config file"
    )
    parser.add_argument(
        "cot_config_path", type=str, nargs="?",
        help="the path to the chain of trust config file"
    )
    parsed_args = parser.parse_args(args)
    context.config, credentials = create_config(config_path=parsed_args.config_path)
    update_logging_config(context)
    context.cot_config = create_cot_config(context, cot_config_path=parsed_args.cot_config_path)
    return context, credentials
Exemple #8
0
def test_update_logging_config_not_verbose(rw_context):
    rw_context.config["verbose"] = False
    swlog.update_logging_config(rw_context,
                                log_name=rw_context.config["log_dir"])
    log = logging.getLogger(rw_context.config["log_dir"])
    assert log.level == logging.INFO
    assert len(log.handlers) == 2
    close_handlers(log_name=rw_context.config["log_dir"])
Exemple #9
0
def test_update_logging_config_verbose(rw_context):
    rw_context.config["verbose"] = True
    swlog.update_logging_config(rw_context,
                                log_name=rw_context.config["log_dir"])
    log = logging.getLogger(rw_context.config["log_dir"])
    assert log.level == logging.DEBUG
    assert len(log.handlers) == 3
    close_handlers(log_name=rw_context.config["log_dir"])
Exemple #10
0
def test_update_logging_config_verbose_existing_handler(context):
    log = logging.getLogger(context.config['log_dir'])
    log.addHandler(logging.NullHandler())
    log.addHandler(logging.NullHandler())
    context.config['verbose'] = True
    swlog.update_logging_config(context, log_name=context.config['log_dir'])
    assert log.level == logging.DEBUG
    assert len(log.handlers) == 4
    close_handlers(log_name=context.config['log_dir'])
def get_context(config_override):
    context = Context()
    context.config, credentials = build_config(config_override)
    swlog.update_logging_config(context)
    utils.cleanup(context)
    with aiohttp.ClientSession() as session:
        context.session = session
        context.credentials = credentials
        yield context
def get_context(config_override):
    context = Context()
    context.config, credentials = build_config(config_override)
    swlog.update_logging_config(context)
    utils.cleanup(context)
    with aiohttp.ClientSession() as session:
        context.session = session
        context.credentials = credentials
        yield context
Exemple #13
0
def test_update_logging_config_verbose_existing_handler(rw_context):
    log = logging.getLogger(rw_context.config["log_dir"])
    log.addHandler(logging.NullHandler())
    log.addHandler(logging.NullHandler())
    rw_context.config["verbose"] = True
    swlog.update_logging_config(rw_context,
                                log_name=rw_context.config["log_dir"])
    assert log.level == logging.DEBUG
    assert len(log.handlers) == 4
    close_handlers(log_name=rw_context.config["log_dir"])
Exemple #14
0
def get_context(config_override):
    context = Context()
    with tempfile.TemporaryDirectory() as tmp:
        context.config, credentials = build_config(config_override, basedir=tmp)
        swlog.update_logging_config(context)
        utils.cleanup(context)
        with aiohttp.ClientSession() as session:
            context.session = session
            context.credentials = credentials
            yield context
async def get_context(config_override=None):
    context = Context()
    with tempfile.TemporaryDirectory() as tmp:
        context.config, credentials = build_config(config_override, basedir=tmp)
        swlog.update_logging_config(context)
        utils.cleanup(context)
        async with aiohttp.ClientSession() as session:
            context.session = session
            context.credentials = credentials
            yield context
async def get_context(config_override=None):
    context = Context()
    with tempfile.TemporaryDirectory() as tmp:
        context.config = await build_config(config_override, basedir=tmp)
        credentials = read_integration_creds()
        swlog.update_logging_config(context)
        utils.cleanup(context)
        async with aiohttp.ClientSession() as session:
            context.session = session
            context.credentials = credentials
            yield context
Exemple #17
0
def test_watched_log_file(context):
    context.config['watch_log_file'] = True
    context.config["log_fmt"] = "%(levelname)s - %(message)s"
    swlog.update_logging_config(context, log_name=context.config['log_dir'])
    path = os.path.join(context.config['log_dir'], 'worker.log')
    log = logging.getLogger(context.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=context.config['log_dir'])
Exemple #18
0
def test_watched_log_file(context):
    context.config['watch_log_file'] = True
    context.config["log_fmt"] = "%(levelname)s - %(message)s"
    swlog.update_logging_config(context, log_name=context.config['log_dir'])
    path = os.path.join(context.config['log_dir'], 'worker.log')
    log = logging.getLogger(context.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=context.config['log_dir'])
Exemple #19
0
def test_rotating_log_file(rw_context):
    # 500 should be enough to ~fill 2 files
    MAX_SIZE = 500  # bytes
    rw_context.config["watch_log_file"] = False
    rw_context.config["log_max_bytes"] = MAX_SIZE
    rw_context.config["log_max_backups"] = 1
    rw_context.config["log_fmt"] = "%(levelname)s - %(message)s"
    swlog.update_logging_config(rw_context,
                                log_name=rw_context.config["log_dir"])
    path = os.path.join(rw_context.config["log_dir"], "worker.log")
    log = logging.getLogger(rw_context.config["log_dir"])
    for x in range(30):
        log.info(f"{x}" * x)
    assert os.path.getsize(path) < MAX_SIZE
    assert os.path.getsize(path + ".1") < MAX_SIZE
    close_handlers(log_name=rw_context.config["log_dir"])
Exemple #20
0
def get_context_from_cmdln(args, desc="Run scriptworker"):
    """Create a Context object from args.

    Args:
        args (list): the commandline args.  Generally sys.argv

    Returns:
        tuple: ``scriptworker.context.Context`` with populated config, and
            credentials immutabledict

    """
    context = Context()
    parser = argparse.ArgumentParser(description=desc)
    parser.add_argument("config_path", type=str, nargs="?", default="scriptworker.yaml", help="the path to the config file")
    parsed_args = parser.parse_args(args)
    context.config, credentials = create_config(config_path=parsed_args.config_path)
    update_logging_config(context)
    return context, credentials
Exemple #21
0
def get_context_from_cmdln(args, desc="Run scriptworker"):
    """Create a Context object from args.

    Args:
        args (list): the commandline args.  Generally sys.argv

    Returns:
        tuple: ``scriptworker.context.Context`` with populated config, and
            credentials frozendict

    """
    context = Context()
    parser = argparse.ArgumentParser(description=desc)
    parser.add_argument(
        "config_path", type=str, nargs="?", default="scriptworker.yaml",
        help="the path to the config file"
    )
    parsed_args = parser.parse_args(args)
    context.config, credentials = create_config(config_path=parsed_args.config_path)
    update_logging_config(context)
    return context, credentials
Exemple #22
0
def main():
    """Scriptworker entry point: get everything set up, then enter the main loop
    """
    context = Context()
    kwargs = {}
    if len(sys.argv) > 1:
        if len(sys.argv) > 2:
            print("Usage: {} [configfile]".format(sys.argv[0]), file=sys.stderr)
            sys.exit(1)
        kwargs['path'] = sys.argv[1]
    context.config, credentials = create_config(**kwargs)
    update_logging_config(context)
    cleanup(context)
    conn = aiohttp.TCPConnector(limit=context.config["max_connections"])
    loop = asyncio.get_event_loop()
    with aiohttp.ClientSession(connector=conn) as session:
        context.session = session
        context.credentials = credentials
        while True:
            try:
                loop.create_task(async_main(context))
                loop.run_forever()
            except RuntimeError:
                pass
Exemple #23
0
 def test_update_logging_config_verbose(self, context):
     swlog.update_logging_config(context, context.config['log_dir'])
     log = logging.getLogger(context.config['log_dir'])
     assert log.level == logging.DEBUG
     assert len(log.handlers) == 3
Exemple #24
0
 def test_update_logging_config_verbose(self, context):
     swlog.update_logging_config(context, context.config['log_dir'])
     log = logging.getLogger(context.config['log_dir'])
     assert log.level == logging.DEBUG
     assert len(log.handlers) == 3