Debian Codegraph @

tools/internal_ci/linux/grpc_xds_k8s_xlang.sh

raw
1 #!/usr/bin/env bash
2 # Copyright 2021 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"
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 server/client Docker images
22 readonly IMAGE_REPO="gcr.io/grpc-testing/xds-interop"
23 readonly SERVER_LANG="cpp go java"
24 readonly CLIENT_LANG="cpp go java"
25 readonly VERSION_TAG="master v1.50.x"
26
27 #######################################
28 # Executes the test case
29 # Globals:
30 # TEST_DRIVER_FLAGFILE: Relative path to test driver flagfile
31 # KUBE_CONTEXT: The name of kubectl context with GKE cluster access
32 # TEST_XML_OUTPUT_DIR: Output directory for the test xUnit XML report
33 # SERVER_IMAGE_NAME: Test server Docker image name
34 # CLIENT_IMAGE_NAME: Test client Docker image name
35 # GIT_COMMIT: SHA-1 of git commit being built
36 # TESTING_VERSION: version branch under test: used by the framework to determine the supported PSM
37 # features.
38 # Arguments:
39 # Test case name
40 # Outputs:
41 # Writes the output of test execution to stdout, stderr
42 # Test xUnit report to ${TEST_XML_OUTPUT_DIR}/${test_name}/sponge_log.xml
43 #######################################
44 run_test() {
45 # Test driver usage:
46 # https://github.com/grpc/grpc/tree/master/tools/run_tests/xds_k8s_test_driver#basic-usage
47 local tag="${1:?Usage: run_test tag server_lang client_lang}"
48 local slang="${2:?Usage: run_test tag server_lang client_lang}"
49 local clang="${3:?Usage: run_test tag server_lang client_lang}"
50 local server_image_name="${IMAGE_REPO}/${slang}-server:${tag}"
51 local client_image_name="${IMAGE_REPO}/${clang}-client:${tag}"
52 # TODO(sanjaypujare): skip test if image not found (by using gcloud_gcr_list_image_tags)
53 local out_dir="${TEST_XML_OUTPUT_DIR}/${tag}/${clang}-${slang}"
54 mkdir -pv "${out_dir}"
55 set -x
56 python -m "tests.security_test" \
57 --flagfile="${TEST_DRIVER_FLAGFILE}" \
58 --kube_context="${KUBE_CONTEXT}" \
59 --server_image="${server_image_name}" \
60 --client_image="${client_image_name}" \
61 --testing_version="${TESTING_VERSION}" \
62 --nocheck_local_certs \
63 --force_cleanup \
64 --collect_app_logs \
65 --log_dir="${out_dir}" \
66 --xml_output_file="${out_dir}/sponge_log.xml" \
67 |& tee "${out_dir}/sponge_log.log"
68 }
69
70 #######################################
71 # Main function: provision software necessary to execute tests, and run them
72 # Globals:
73 # KOKORO_ARTIFACTS_DIR
74 # GITHUB_REPOSITORY_NAME
75 # SRC_DIR: Populated with absolute path to the source repo
76 # TEST_DRIVER_REPO_DIR: Populated with the path to the repo containing
77 # the test driver
78 # TEST_DRIVER_FULL_DIR: Populated with the path to the test driver source code
79 # TEST_DRIVER_FLAGFILE: Populated with relative path to test driver flagfile
80 # TEST_XML_OUTPUT_DIR: Populated with the path to test xUnit XML report
81 # GIT_ORIGIN_URL: Populated with the origin URL of git repo used for the build
82 # GIT_COMMIT: Populated with the SHA-1 of git commit being built
83 # GIT_COMMIT_SHORT: Populated with the short SHA-1 of git commit being built
84 # KUBE_CONTEXT: Populated with name of kubectl context with GKE cluster access
85 # Arguments:
86 # None
87 # Outputs:
88 # Writes the output of test execution to stdout, stderr
89 #######################################
90 main() {
91 local script_dir
92 script_dir="$(dirname "$0")"
93
94 # Source the test driver from the master branch.
95 echo "Sourcing test driver install script from: ${TEST_DRIVER_INSTALL_SCRIPT_URL}"
96 source /dev/stdin <<< "$(curl -s "${TEST_DRIVER_INSTALL_SCRIPT_URL}")"
97
98 activate_gke_cluster GKE_CLUSTER_PSM_SECURITY
99
100 set -x
101 if [[ -n "${KOKORO_ARTIFACTS_DIR}" ]]; then
102 kokoro_setup_test_driver "${GITHUB_REPOSITORY_NAME}"
103 cd "${TEST_DRIVER_FULL_DIR}"
104 else
105 local_setup_test_driver "${script_dir}"
106 cd "${SRC_DIR}/${TEST_DRIVER_PATH}"
107 fi
108
109 local failed_tests=0
110 local successful_string
111 local failed_string
112 # Run tests
113 for TAG in ${VERSION_TAG}
114 do
115 for CLANG in ${CLIENT_LANG}
116 do
117 for SLANG in ${SERVER_LANG}
118 do
119 if [ "${CLANG}" != "${SLANG}" ]; then
120 if run_test "${TAG}" "${SLANG}" "${CLANG}"; then
121 successful_string="${successful_string} ${TAG}/${CLANG}-${SLANG}"
122 else
123 failed_tests=$((failed_tests+1))
124 failed_string="${failed_string} ${TAG}/${CLANG}-${SLANG}"
125 fi
126 fi
127 done
128 echo "Failed test suites: ${failed_tests}"
129 done
130 done
131 set +x
132 echo "Failed test suites list: ${failed_string}"
133 echo "Successful test suites list: ${successful_string}"
134 if (( failed_tests > 0 )); then
135 exit 1
136 fi
137 }
138
139 main "$@"