Upload node e2e test log to gcs

Signed-off-by: Lantao Liu <lantaol@google.com>
This commit is contained in:
Lantao Liu
2017-09-05 05:43:25 +00:00
parent ade5f403d0
commit 49bcfb3665
5 changed files with 59 additions and 3 deletions

View File

@@ -27,6 +27,7 @@ export FOCUS=${FOCUS:-""}
# SKIP skips the test to skip.
export SKIP=${SKIP:-${DEFAULT_SKIP}}
REPORT_DIR=${REPORT_DIR:-"/tmp/test-e2e-node"}
UPLOAD_LOG=${UPLOAD_LOG:-false}
# Check GOPATH
if [[ -z "${GOPATH}" ]]; then
@@ -78,3 +79,13 @@ kill_cri_containerd
sudo iptables-restore < ${ORIGINAL_RULES}
rm ${ORIGINAL_RULES}
# UPLOAD_LOG_PATH is bucket to upload test logs.
UPLOAD_LOG_PATH=cri-containerd_test-e2e-node
if ${UPLOAD_LOG}; then
if [ -z "${VERSION}" ]; then
echo "VERSION is not set"
exit 1
fi
upload_logs_to_gcs "${UPLOAD_LOG_PATH}" "${VERSION}-$(date +%Y%m%d-%H%M%S)" "${REPORT_DIR}"
fi

View File

@@ -51,3 +51,28 @@ start_cri_containerd() {
kill_cri_containerd() {
sudo pkill containerd
}
# upload_logs_to_gcs uploads test logs to gcs.
# Var set:
# 1. Bucket: gcs bucket to upload logs.
# 2. Dir: directory name to upload logs.
# 3. Test Result: directory of the test result.
upload_logs_to_gcs() {
local -r bucket=$1
local -r dir=$2
local -r result=$3
if ! gsutil ls "gs://${bucket}" > /dev/null; then
gsutil mb "gs://${bucket}"
gsutil -m acl ch -g all:R "gs://${bucket}"
gsutil defacl set public-read "gs://${bucket}"
local -r bucket_rule=$(mktemp)
# Set 30 day TTL for logs inside the bucket.
echo '{"rule": [{"action": {"type": "Delete"},"condition": {"age": 30}}]}' > ${bucket_rule}
gsutil lifecycle set "${bucket_rule}" "gs://${bucket}"
rm "${bucket_rule}"
fi
local -r upload_log_path=${bucket}/${dir}
gsutil cp -r "${REPORT_DIR}" "gs://${upload_log_path}"
echo "Test logs are uploaed to:
http://gcsweb.k8s.io/gcs/${upload_log_path}/"
}