Skip to content

Commit

Permalink
Add GBR flag which produces g8r link for node e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mnshaw committed Aug 11, 2016
1 parent ea69570 commit 659f64a
Show file tree
Hide file tree
Showing 3 changed files with 163 additions and 7 deletions.
28 changes: 21 additions & 7 deletions hack/make-rules/test-e2e-node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ remote=${REMOTE:-"false"}
images=${IMAGES:-""}
hosts=${HOSTS:-""}
metadata=${INSTANCE_METADATA:-""}
gubernator=${GBR:-"false"}
gci_image=$(gcloud compute images list --project google-containers \
--no-standard-images --regexp="gci-dev.*" --format="table[no-heading](name)")
if [[ $hosts == "" && $images == "" ]]; then
Expand Down Expand Up @@ -129,13 +130,26 @@ if [ $remote = true ] ; then
echo "Ginkgo Flags: $ginkgoflags"
echo "Instance Metadata: $metadata"
# Invoke the runner
go run test/e2e_node/runner/run_e2e.go --logtostderr --vmodule=*=4 --ssh-env="gce" \
--zone="$zone" --project="$project" \
--hosts="$hosts" --images="$images" --cleanup="$cleanup" \
--results-dir="$artifacts" --ginkgo-flags="$ginkgoflags" \
--image-project="$image_project" --instance-name-prefix="$instance_prefix" --setup-node="true" \
--delete-instances="$delete_instances" --test_args="$test_args" --instance-metadata="$metadata"
exit $?
if [[ $gubernator = false || $remote = false ]]; then
go run test/e2e_node/runner/run_e2e.go --logtostderr --vmodule=*=2 --ssh-env="gce" \
--zone="$zone" --project="$project" --gubernator="$gubernator" \
--hosts="$hosts" --images="$images" --cleanup="$cleanup" \
--results-dir="$artifacts" --ginkgo-flags="$ginkgoflags" \
--image-project="$image_project" --instance-name-prefix="$instance_prefix" --setup-node="true" \
--delete-instances="$delete_instances" --test_args="$test_args" --instance-metadata="$metadata"
exit $?
else
echo "GBR flag on"
go run test/e2e_node/runner/run_e2e.go --logtostderr --vmodule=*=2 --ssh-env="gce" \
--zone="$zone" --project="$project" --gubernator="$gubernator" \
--hosts="$hosts" --images="$images" --cleanup="$cleanup" \
--results-dir="$artifacts" --ginkgo-flags="$ginkgoflags" \
--image-project="$image_project" --instance-name-prefix="$instance_prefix" --setup-node="true" \
--delete-instances="$delete_instances" --test_args="$test_args" --instance-metadata="$metadata" \
2>&1 | tee build-log.txt
./test/e2e_node/g8r.sh
exit $?
fi

else
# Refresh sudo credentials if not running on GCE.
Expand Down
133 changes: 133 additions & 0 deletions test/e2e_node/g8r.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
#!/bin/bash

# Copyright 2016 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Make bucket and a folder for e2e-node test logs.
# Populate the folder from the logs stored in /tmp/_artifacts/ in the same way as a
# jenkins build would, and then print the URL to view the test results on Gubernator

bucket_name="${USER}-g8r-logs"
echo ""
echo "Using bucket ${bucket_name}"
gsutil mb gs://${bucket_name}/

GCS_JOBS_PATH="gs://${bucket_name}/logs/e2e-node"

TMP_LOG_PATH="/tmp/_artifacts/"
BUILD_LOG_PATH="/tmp/build-log.txt"
readonly gcs_acl="public-read"

if [[ -e "build-log.txt" ]]; then
echo "Moving build-log.txt"
mv build-log.txt /tmp/
fi

# Keep build number updated
if ! gsutil -q stat "${GCS_JOBS_PATH}/latest-build.txt"; then
BUILD_NUMBER=1
else
BUILD_NUMBER=$(gsutil cat "${GCS_JOBS_PATH}/latest-build.txt")
let "BUILD_NUMBER += 1"
fi

GCS_LOGS_PATH="gs://${bucket_name}/logs/e2e-node/${BUILD_NUMBER}"

# Upload log files
for f in $TMP_LOG_PATH
do
if [[ -d "${TMP_LOG_PATH}" && -n $(ls -A "${TMP_LOG_PATH}") ]]; then
echo "Uploading artifacts"
gsutil -m -q -o "GSUtil:use_magicfile=True" cp -a "${gcs_acl}" -r -c \
-z log,xml,xml "${TMP_LOG_PATH}" "${GCS_LOGS_PATH}/artifacts" || continue
fi
done

if [[ -e "${BUILD_LOG_PATH}" ]]; then
echo "Uploading build log"
gsutil -q cp -Z -a "${gcs_acl}" "${BUILD_LOG_PATH}" "${GCS_LOGS_PATH}"
fi

# Find the k8s version and timestamps needed for started.json and finished.json
version=""
if [[ -e "version" ]]; then
version=$(cat "version")
elif [[ -e "hack/lib/version.sh" ]]; then
version=$(
export KUBE_ROOT="."
source "hack/lib/version.sh"
kube::version::get_version_vars
echo "${KUBE_GIT_VERSION-}"
)
fi
if [[ -n "${version}" ]]; then
echo "Found Kubernetes version: ${version}"
else
echo "Could not find Kubernetes version"
fi

start_line=$(grep -n -m 1 "==============" /tmp/build-log.txt |sed 's/\([0-9]*\).*/\1/')
start_time=$(tail -n +${start_line} /tmp/build-log.txt | grep -m 1 -o '[0-9][0-9][0-9][0-9][[:blank:]][0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9]*' | sed 's/^.\{2\}/&\//')
end_time=$(grep -o '[0-9][0-9][0-9][0-9][[:blank:]][0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9]*' /tmp/build-log.txt | tail -1 | sed 's/^.\{2\}/&\//')
start_time_epoch=$(date -d "${start_time}" +%s)
end_time_epoch=$(date -d "${end_time}" +%s)

# Upload started.json and finished.json
echo "Making started.json file"
echo "Run starting at ${start_time}"
json_file="${GCS_LOGS_PATH}/started.json"

for upload_attempt in $(seq 3); do
echo "Uploading version to: ${json_file} (attempt ${upload_attempt})"
gsutil -q -h "Content-Type:application/json" cp -a "${gcs_acl}" <(
echo "{"
echo " \"version\": \"${version}\","
echo " \"timestamp\": ${start_time_epoch},"
echo " \"jenkins-node\": \"${NODE_NAME:-}\""
echo "}"
) "${json_file}" || continue
break
done

echo "Making finished.json file"
if grep -Fxq "Test Suite Passed" "${BUILD_LOG_PATH}"
then
build_result="SUCCESS"
else
build_result="FAILURE"
fi

echo "Build result is ${build_result}"

for upload_attempt in $(seq 3); do
echo "Uploading to ${GCS_LOGS_PATH} (attempt ${upload_attempt})"
gsutil -q -h "Content-Type:application/json" cp -a "${gcs_acl}" <(
echo "{"
echo " \"result\": \"${build_result}\","
echo " \"timestamp\": ${end_time_epoch}"
echo "}"
) "${GCS_LOGS_PATH}/finished.json" || continue
break
done


# Mark this build as the latest completed.
echo "Marking build ${BUILD_NUMBER} as the latest completed build"
echo "${BUILD_NUMBER}" | \
gsutil -q -h "Content-Type:text/plain" -h "Cache-Control:private, max-age=0, no-transform" \
cp -a "${gcs_acl}" - "${GCS_JOBS_PATH}/latest-build.txt"

#TODO: Change localhost:8080 to k8s-gubernator.appspot.com
echo "Gubernator linked below:"
echo "localhost:8080/build/${bucket_name}/logs/e2e-node/${BUILD_NUMBER}?local=on"
9 changes: 9 additions & 0 deletions test/e2e_node/runner/run_e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"math/rand"
"net/http"
"os"
"os/exec"
"regexp"
"sort"
"strings"
Expand Down Expand Up @@ -56,6 +57,7 @@ var deleteInstances = flag.Bool("delete-instances", true, "If true, delete any i
var buildOnly = flag.Bool("build-only", false, "If true, build e2e_node_test.tar.gz and exit.")
var setupNode = flag.Bool("setup-node", false, "When true, current user will be added to docker group on the test machine")
var instanceMetadata = flag.String("instance-metadata", "", "key/value metadata for instances separated by '=' or '<', 'k=v' means the key is 'k' and the value is 'v'; 'k<p' means the key is 'k' and the value is extracted from the local path 'p', e.g. k1=v1,k2<p2")
var gubernator = flag.Bool("gubernator", false, "If true, output Gubernator link to view logs")

var computeService *compute.Service

Expand Down Expand Up @@ -247,6 +249,13 @@ func main() {
// Set the exit code if there were failures
if !exitOk {
fmt.Printf("Failure: %d errors encountered.", errCount)
if *gubernator{
output, err := exec.Command("./test/e2e_node/g8r.sh").Output()
if err != nil {
return
}
fmt.Printf("%s", output)
}
os.Exit(1)
}
}
Expand Down

0 comments on commit 659f64a

Please sign in to comment.