Пример #1
0
def capture_logs_from_instance(instance: Executor) -> None:
    """Retrieve logs from instance.

    :param instance: Instance to retrieve logs from.

    :returns: String of logs.
    """
    # Get a temporary file path.
    tmp_file = tempfile.NamedTemporaryFile(delete=False, prefix="charmcraft-")
    tmp_file.close()

    local_log_path = pathlib.Path(tmp_file.name)
    instance_log_path = get_managed_environment_log_path()

    try:
        instance.pull_file(source=instance_log_path,
                           destination=local_log_path)
    except FileNotFoundError:
        emit.trace("No logs found in instance.")
        return

    emit.trace("Logs captured from managed instance:")
    with open(local_log_path, "rt", encoding="utf8") as fh:
        for line in fh:
            emit.trace(f":: {line.rstrip()}")
    local_log_path.unlink()
Пример #2
0
def capture_logs_from_instance(instance: Executor) -> None:
    """Retrieve logs from instance.

    :param instance: Instance to retrieve logs from.

    :returns: String of logs.
    """
    # Get a temporary file path.
    with tempfile.NamedTemporaryFile(delete=False,
                                     prefix="snapcraft-") as tmp_file:
        local_log_path = pathlib.Path(tmp_file.name)

    instance_log_path = get_managed_environment_log_path()

    try:
        instance.pull_file(source=instance_log_path,
                           destination=local_log_path)
    except FileNotFoundError:
        emit.debug("No logs found in instance.")
        return

    emit.debug("Logs captured from managed instance:")
    with local_log_path.open("rt", encoding="utf8") as logfile:
        for line in logfile:
            emit.debug(":: " + line.rstrip())
    local_log_path.unlink()
Пример #3
0
def capture_logs_from_instance(instance: Executor) -> None:
    """Retrieve logs from instance.

    :param instance: Instance to retrieve logs from.

    :returns: String of logs.
    """
    _, tmp_path = tempfile.mkstemp(prefix="charmcraft-")
    local_log_path = pathlib.Path(tmp_path)
    instance_log_path = get_managed_environment_log_path()

    try:
        instance.pull_file(source=instance_log_path, destination=local_log_path)
    except FileNotFoundError:
        logger.debug("No logs found in instance.")
        return

    logs = local_log_path.read_text()
    local_log_path.unlink()

    logger.debug("Logs captured from managed instance:\n%s", logs)