diff --git a/roles/test-upload-logs-swift/templates/download-logs.sh.j2 b/roles/test-upload-logs-swift/templates/download-logs.sh.j2 new file mode 100644 index 000000000..9a13f17a2 --- /dev/null +++ b/roles/test-upload-logs-swift/templates/download-logs.sh.j2 @@ -0,0 +1,57 @@ +#!/bin/bash + +# Download all logs + +# +# To use this file +# +# curl "{{ base_url }}/download-logs.sh" | bash +# +# Logs will be copied in a temporary directory as described in the +# output. Set DOWNLOAD_DIR to an empty directory if you wish to +# override this. +# + +BASE_URL={{ base_url }} + +function log { + echo "$(date -Iseconds) | $@" +} + +function save_file { + local file="$1" + + curl -s --compressed --create-dirs -o "${file}" "${BASE_URL}/${file}" + + # Using --compressed we will send an Accept-Encoding: gzip header + # and the data will come to us across the network compressed. + # However, sometimes things like OpenStack's log server will send + # .gz files (as stored on its disk) uncompressed, so we check if + # this really looks like an ASCII file and rename for clarity. + if [[ "${file}" == *.gz ]]; then + local type=$(file "${file}") + if [[ "${type}" =~ "ASCII text" ]] || [[ "${type}" =~ "Unicode text" ]]; then + local new_name=${file%.gz} + log "Renaming to ${new_name}" + mv "${file}" "${new_name}" + fi + fi + +} + +if [[ -z "${DOWNLOAD_DIR}" ]]; then + DOWNLOAD_DIR=$(mktemp -d --tmpdir zuul-logs.XXXXXX) +fi +log "Saving logs to ${DOWNLOAD_DIR}" + +pushd "${DOWNLOAD_DIR}" > /dev/null + +{% set total_files = file_list | length %} +{% for file in file_list %} +log "Getting ${BASE_URL}/{{ '%-80s'|format(file) }} [ {{ '%04d'|format(loop.index) }} / {{ '%04d'|format(total_files) }} ]" +save_file "{{ file }}" +{% endfor %} + +popd >/dev/null + +log "Download complete!"