|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Copyright 2022 gRPC authors. |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | + |
| 16 | +set -eo pipefail |
| 17 | + |
| 18 | +# Constants |
| 19 | +readonly GITHUB_REPOSITORY_NAME="grpc-node" |
| 20 | +readonly TEST_DRIVER_INSTALL_SCRIPT_URL="https://raw.githubusercontent.com/${TEST_DRIVER_REPO_OWNER:-grpc}/grpc/${TEST_DRIVER_BRANCH:-master}/tools/internal_ci/linux/grpc_xds_k8s_install_test_driver.sh" |
| 21 | +## xDS test client Docker images |
| 22 | +readonly SERVER_IMAGE_NAME="gcr.io/grpc-testing/xds-interop/java-server:v1.46.x" |
| 23 | +readonly CLIENT_IMAGE_NAME="gcr.io/grpc-testing/xds-interop/node-client" |
| 24 | +readonly FORCE_IMAGE_BUILD="${FORCE_IMAGE_BUILD:-0}" |
| 25 | +readonly BUILD_APP_PATH="packages/grpc-js-xds/interop/Dockerfile" |
| 26 | +readonly LANGUAGE_NAME="Node" |
| 27 | + |
| 28 | +####################################### |
| 29 | +# Builds test app Docker images and pushes them to GCR |
| 30 | +# Globals: |
| 31 | +# BUILD_APP_PATH |
| 32 | +# CLIENT_IMAGE_NAME: Test client Docker image name |
| 33 | +# GIT_COMMIT: SHA-1 of git commit being built |
| 34 | +# TESTING_VERSION: version branch under test, f.e. v1.42.x, master |
| 35 | +# Arguments: |
| 36 | +# None |
| 37 | +# Outputs: |
| 38 | +# Writes the output of `gcloud builds submit` to stdout, stderr |
| 39 | +####################################### |
| 40 | +build_test_app_docker_images() { |
| 41 | + echo "Building ${LANGUAGE_NAME} xDS interop test app Docker images" |
| 42 | + |
| 43 | + pushd "${SRC_DIR}" |
| 44 | + docker build \ |
| 45 | + -f "${BUILD_APP_PATH}" \ |
| 46 | + -t "${CLIENT_IMAGE_NAME}:${GIT_COMMIT}" \ |
| 47 | + . |
| 48 | + |
| 49 | + gcloud -q auth configure-docker |
| 50 | + docker push "${CLIENT_IMAGE_NAME}:${GIT_COMMIT}" |
| 51 | + if is_version_branch "${TESTING_VERSION}"; then |
| 52 | + tag_and_push_docker_image "${CLIENT_IMAGE_NAME}" "${GIT_COMMIT}" "${TESTING_VERSION}" |
| 53 | + fi |
| 54 | + popd |
| 55 | +} |
| 56 | + |
| 57 | +####################################### |
| 58 | +# Builds test app and its docker images unless they already exist |
| 59 | +# Globals: |
| 60 | +# CLIENT_IMAGE_NAME: Test client Docker image name |
| 61 | +# GIT_COMMIT: SHA-1 of git commit being built |
| 62 | +# FORCE_IMAGE_BUILD |
| 63 | +# Arguments: |
| 64 | +# None |
| 65 | +# Outputs: |
| 66 | +# Writes the output to stdout, stderr |
| 67 | +####################################### |
| 68 | +build_docker_images_if_needed() { |
| 69 | + # Check if images already exist |
| 70 | + client_tags="$(gcloud_gcr_list_image_tags "${CLIENT_IMAGE_NAME}" "${GIT_COMMIT}")" |
| 71 | + printf "Client image: %s:%s\n" "${CLIENT_IMAGE_NAME}" "${GIT_COMMIT}" |
| 72 | + echo "${client_tags:-Client image not found}" |
| 73 | + |
| 74 | + # Build if any of the images are missing, or FORCE_IMAGE_BUILD=1 |
| 75 | + if [[ "${FORCE_IMAGE_BUILD}" == "1" || -z "${client_tags}" ]]; then |
| 76 | + build_test_app_docker_images |
| 77 | + else |
| 78 | + echo "Skipping ${LANGUAGE_NAME} test app build" |
| 79 | + fi |
| 80 | +} |
| 81 | + |
| 82 | +####################################### |
| 83 | +# Executes the test case |
| 84 | +# Globals: |
| 85 | +# TEST_DRIVER_FLAGFILE: Relative path to test driver flagfile |
| 86 | +# KUBE_CONTEXT: The name of kubectl context with GKE cluster access |
| 87 | +# SECONDARY_KUBE_CONTEXT: The name of kubectl context with secondary GKE cluster access, if any |
| 88 | +# TEST_XML_OUTPUT_DIR: Output directory for the test xUnit XML report |
| 89 | +# CLIENT_IMAGE_NAME: Test client Docker image name |
| 90 | +# GIT_COMMIT: SHA-1 of git commit being built |
| 91 | +# Arguments: |
| 92 | +# Test case name |
| 93 | +# Outputs: |
| 94 | +# Writes the output of test execution to stdout, stderr |
| 95 | +# Test xUnit report to ${TEST_XML_OUTPUT_DIR}/${test_name}/sponge_log.xml |
| 96 | +####################################### |
| 97 | +run_test() { |
| 98 | + # Test driver usage: |
| 99 | + # https://github.com/grpc/grpc/tree/master/tools/run_tests/xds_k8s_test_driver#basic-usage |
| 100 | + local test_name="${1:?Usage: run_test test_name}" |
| 101 | + local out_dir="${TEST_XML_OUTPUT_DIR}/${test_name}" |
| 102 | + mkdir -pv "${out_dir}" |
| 103 | + # testing_version is used by the framework to determine the supported PSM |
| 104 | + # features. It's captured from Kokoro job name of the Node repo, which takes |
| 105 | + # the form: |
| 106 | + # grpc/node/<branch name>/<job name> |
| 107 | + python3 -m "tests.${test_name}" \ |
| 108 | + --flagfile="${TEST_DRIVER_FLAGFILE}" \ |
| 109 | + --kube_context="${KUBE_CONTEXT}" \ |
| 110 | + --secondary_kube_context="${SECONDARY_KUBE_CONTEXT}" \ |
| 111 | + --client_image="${CLIENT_IMAGE_NAME}:${GIT_COMMIT}" \ |
| 112 | + --server_image="${SERVER_IMAGE_NAME}" \ |
| 113 | + --testing_version="${TESTING_VERSION}" \ |
| 114 | + --force_cleanup \ |
| 115 | + --collect_app_logs \ |
| 116 | + --log_dir="${out_dir}" \ |
| 117 | + --xml_output_file="${out_dir}/sponge_log.xml" \ |
| 118 | + |& tee "${out_dir}/sponge_log.log" |
| 119 | +} |
| 120 | + |
| 121 | +####################################### |
| 122 | +# Main function: provision software necessary to execute tests, and run them |
| 123 | +# Globals: |
| 124 | +# KOKORO_ARTIFACTS_DIR |
| 125 | +# GITHUB_REPOSITORY_NAME |
| 126 | +# SRC_DIR: Populated with absolute path to the source repo |
| 127 | +# TEST_DRIVER_REPO_DIR: Populated with the path to the repo containing |
| 128 | +# the test driver |
| 129 | +# TEST_DRIVER_FULL_DIR: Populated with the path to the test driver source code |
| 130 | +# TEST_DRIVER_FLAGFILE: Populated with relative path to test driver flagfile |
| 131 | +# TEST_XML_OUTPUT_DIR: Populated with the path to test xUnit XML report |
| 132 | +# GIT_ORIGIN_URL: Populated with the origin URL of git repo used for the build |
| 133 | +# GIT_COMMIT: Populated with the SHA-1 of git commit being built |
| 134 | +# GIT_COMMIT_SHORT: Populated with the short SHA-1 of git commit being built |
| 135 | +# KUBE_CONTEXT: Populated with name of kubectl context with GKE cluster access |
| 136 | +# SECONDARY_KUBE_CONTEXT: Populated with name of kubectl context with secondary GKE cluster access, if any |
| 137 | +# Arguments: |
| 138 | +# None |
| 139 | +# Outputs: |
| 140 | +# Writes the output of test execution to stdout, stderr |
| 141 | +####################################### |
| 142 | +main() { |
| 143 | + local script_dir |
| 144 | + script_dir="$(dirname "$0")" |
| 145 | + |
| 146 | + cd "${script_dir}" |
| 147 | + |
| 148 | + git submodule update --init --recursive |
| 149 | + |
| 150 | + # Source the test driver from the master branch. |
| 151 | + echo "Sourcing test driver install script from: ${TEST_DRIVER_INSTALL_SCRIPT_URL}" |
| 152 | + source /dev/stdin <<< "$(curl -s "${TEST_DRIVER_INSTALL_SCRIPT_URL}")" |
| 153 | + |
| 154 | + activate_gke_cluster GKE_CLUSTER_PSM_LB |
| 155 | + activate_secondary_gke_cluster GKE_CLUSTER_PSM_LB |
| 156 | + |
| 157 | + set -x |
| 158 | + if [[ -n "${KOKORO_ARTIFACTS_DIR}" ]]; then |
| 159 | + kokoro_setup_test_driver "${GITHUB_REPOSITORY_NAME}" |
| 160 | + else |
| 161 | + local_setup_test_driver "${script_dir}" |
| 162 | + fi |
| 163 | + build_docker_images_if_needed |
| 164 | + |
| 165 | + # Run tests |
| 166 | + cd "${TEST_DRIVER_FULL_DIR}" |
| 167 | + local failed_tests=0 |
| 168 | + test_suites=("baseline_test" "api_listener_test" "change_backend_service_test" "failover_test" "remove_neg_test" "round_robin_test" "outlier_detection_test") |
| 169 | + for test in "${test_suites[@]}"; do |
| 170 | + run_test $test || (( failed_tests++ )) |
| 171 | + done |
| 172 | + echo "Failed test suites: ${failed_tests}" |
| 173 | + if (( failed_tests > 0 )); then |
| 174 | + exit 1 |
| 175 | + fi |
| 176 | +} |
| 177 | + |
| 178 | +main "$@" |
0 commit comments