Merge pull request #211 from Random-Liu/upload-log-to-gcs

Upload node e2e test log to gcs
This commit is contained in:
Lantao Liu 2017-09-06 16:36:04 -07:00 committed by GitHub
commit 8bc991b545
5 changed files with 59 additions and 3 deletions

View File

@ -5,10 +5,21 @@ sudo: required
services: services:
- docker - docker
cache:
directories:
- "${HOME}/google-cloud-sdk/"
before_install: before_install:
# Workaround to make gsutil work (see travis-ci#7940).
# TODO(random-liu): Remove this after travis-ci#7940 is fixed.
- sudo rm -f /etc/boto.cfg
# libseccomp in trusty is not new enough, need backports version. # libseccomp in trusty is not new enough, need backports version.
- sudo sh -c "echo 'deb http://archive.ubuntu.com/ubuntu trusty-backports main restricted universe multiverse' > /etc/apt/sources.list.d/backports.list" - sudo sh -c "echo 'deb http://archive.ubuntu.com/ubuntu trusty-backports main restricted universe multiverse' > /etc/apt/sources.list.d/backports.list"
- sudo apt-get update - sudo apt-get update
# Encrypted data is not available for pull request for security concern.
- if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then
openssl aes-256-cbc -K $encrypted_b5f8c391f742_key -iv $encrypted_b5f8c391f742_iv -in gcp-secret.json.enc -out gcp-secret.json -d;
fi
install: install:
- sudo apt-get install btrfs-tools - sudo apt-get install btrfs-tools
@ -17,9 +28,19 @@ install:
- sudo apt-get install libapparmor-dev - sudo apt-get install libapparmor-dev
- sudo apt-get install socat - sudo apt-get install socat
- docker run --rm -v /usr/local/bin:/target jpetazzo/nsenter - docker run --rm -v /usr/local/bin:/target jpetazzo/nsenter
# Pull request test doesn't need google cloud sdk.
- if [ "$TRAVIS_PULL_REQUEST" = "false" ] && [ ! -d ${HOME}/google-cloud-sdk ]; then
rm -rf "${HOME}/google-cloud-sdk";
export CLOUDSDK_CORE_DISABLE_PROMPTS=1;
curl https://sdk.cloud.google.com | bash;
gcloud version;
fi
before_script: before_script:
- export PATH=$HOME/gopath/bin:$PATH - export PATH=$HOME/gopath/bin:$PATH
- if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then
gcloud auth activate-service-account --key-file gcp-secret.json --project=k8s-cri-containerd;
fi
jobs: jobs:
include: include:
@ -52,6 +73,5 @@ jobs:
script: script:
- test "${TRAVIS_EVENT_TYPE}" != "cron" && exit 0 || true - test "${TRAVIS_EVENT_TYPE}" != "cron" && exit 0 || true
- make install.deps - make install.deps
- make test-e2e-node - UPLOAD_LOG=true make test-e2e-node
# TODO(random-liu): Upload log to GCS.
go: 1.8.x go: 1.8.x

View File

@ -78,7 +78,7 @@ test-cri: binaries
@./hack/test-cri.sh @./hack/test-cri.sh
test-e2e-node: binaries test-e2e-node: binaries
@./hack/test-e2e-node.sh @VERSION=$(VERSION) ./hack/test-e2e-node.sh
clean: clean:
rm -rf $(BUILD_DIR)/* rm -rf $(BUILD_DIR)/*

BIN
gcp-secret.json.enc Normal file

Binary file not shown.

View File

@ -27,6 +27,7 @@ export FOCUS=${FOCUS:-""}
# SKIP skips the test to skip. # SKIP skips the test to skip.
export SKIP=${SKIP:-${DEFAULT_SKIP}} export SKIP=${SKIP:-${DEFAULT_SKIP}}
REPORT_DIR=${REPORT_DIR:-"/tmp/test-e2e-node"} REPORT_DIR=${REPORT_DIR:-"/tmp/test-e2e-node"}
UPLOAD_LOG=${UPLOAD_LOG:-false}
# Check GOPATH # Check GOPATH
if [[ -z "${GOPATH}" ]]; then if [[ -z "${GOPATH}" ]]; then
@ -78,3 +79,13 @@ kill_cri_containerd
sudo iptables-restore < ${ORIGINAL_RULES} sudo iptables-restore < ${ORIGINAL_RULES}
rm ${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() { kill_cri_containerd() {
sudo pkill 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}/"
}