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
+ # Arguments:
35
+ # None
36
+ # Outputs:
37
+ # Writes the output of `gcloud builds submit` to stdout, stderr
38
+ # ######################################
39
+ build_test_app_docker_images () {
40
+ echo " Building ${LANGUAGE_NAME} xDS interop test app Docker images"
41
+
42
+ pushd " ${SRC_DIR} "
43
+ docker build \
44
+ -f " ${BUILD_APP_PATH} " \
45
+ -t " ${CLIENT_IMAGE_NAME} :${GIT_COMMIT} " \
46
+ .
47
+
48
+ popd
49
+
50
+ gcloud -q auth configure-docker
51
+
52
+ docker push " ${CLIENT_IMAGE_NAME} :${GIT_COMMIT} "
53
+ }
54
+
55
+ # ######################################
56
+ # Builds test app and its docker images unless they already exist
57
+ # Globals:
58
+ # CLIENT_IMAGE_NAME: Test client Docker image name
59
+ # GIT_COMMIT: SHA-1 of git commit being built
60
+ # FORCE_IMAGE_BUILD
61
+ # Arguments:
62
+ # None
63
+ # Outputs:
64
+ # Writes the output to stdout, stderr
65
+ # ######################################
66
+ build_docker_images_if_needed () {
67
+ # Check if images already exist
68
+ client_tags=" $( gcloud_gcr_list_image_tags " ${CLIENT_IMAGE_NAME} " " ${GIT_COMMIT} " ) "
69
+ printf " Client image: %s:%s\n" " ${CLIENT_IMAGE_NAME} " " ${GIT_COMMIT} "
70
+ echo " ${client_tags:- Client image not found} "
71
+
72
+ # Build if any of the images are missing, or FORCE_IMAGE_BUILD=1
73
+ if [[ " ${FORCE_IMAGE_BUILD} " == " 1" || -z " ${client_tags} " ]]; then
74
+ build_test_app_docker_images
75
+ else
76
+ echo " Skipping ${LANGUAGE_NAME} test app build"
77
+ fi
78
+ }
79
+
80
+ # ######################################
81
+ # Executes the test case
82
+ # Globals:
83
+ # TEST_DRIVER_FLAGFILE: Relative path to test driver flagfile
84
+ # KUBE_CONTEXT: The name of kubectl context with GKE cluster access
85
+ # SECONDARY_KUBE_CONTEXT: The name of kubectl context with secondary GKE cluster access, if any
86
+ # TEST_XML_OUTPUT_DIR: Output directory for the test xUnit XML report
87
+ # CLIENT_IMAGE_NAME: Test client Docker image name
88
+ # GIT_COMMIT: SHA-1 of git commit being built
89
+ # Arguments:
90
+ # Test case name
91
+ # Outputs:
92
+ # Writes the output of test execution to stdout, stderr
93
+ # Test xUnit report to ${TEST_XML_OUTPUT_DIR}/${test_name}/sponge_log.xml
94
+ # ######################################
95
+ run_test () {
96
+ # Test driver usage:
97
+ # https://github.com/grpc/grpc/tree/master/tools/run_tests/xds_k8s_test_driver#basic-usage
98
+ local test_name=" ${1:? Usage: run_test test_name} "
99
+ # testing_version is used by the framework to determine the supported PSM
100
+ # features. It's captured from Kokoro job name of the Node repo, which takes
101
+ # the form:
102
+ # grpc/node/<branch name>/<job name>
103
+ python3 -m " tests.${test_name} " \
104
+ --flagfile=" ${TEST_DRIVER_FLAGFILE} " \
105
+ --kube_context=" ${KUBE_CONTEXT} " \
106
+ --secondary_kube_context=" ${SECONDARY_KUBE_CONTEXT} " \
107
+ --client_image=" ${CLIENT_IMAGE_NAME} :${GIT_COMMIT} " \
108
+ --server_image=" ${SERVER_IMAGE_NAME} " \
109
+ --testing_version=$( echo " $KOKORO_JOB_NAME " | sed -E ' s|^grpc/node/([^/]+)/.*|\1|' ) \
110
+ --xml_output_file=" ${TEST_XML_OUTPUT_DIR} /${test_name} /sponge_log.xml"
111
+ }
112
+
113
+ # ######################################
114
+ # Main function: provision software necessary to execute tests, and run them
115
+ # Globals:
116
+ # KOKORO_ARTIFACTS_DIR
117
+ # GITHUB_REPOSITORY_NAME
118
+ # SRC_DIR: Populated with absolute path to the source repo
119
+ # TEST_DRIVER_REPO_DIR: Populated with the path to the repo containing
120
+ # the test driver
121
+ # TEST_DRIVER_FULL_DIR: Populated with the path to the test driver source code
122
+ # TEST_DRIVER_FLAGFILE: Populated with relative path to test driver flagfile
123
+ # TEST_XML_OUTPUT_DIR: Populated with the path to test xUnit XML report
124
+ # GIT_ORIGIN_URL: Populated with the origin URL of git repo used for the build
125
+ # GIT_COMMIT: Populated with the SHA-1 of git commit being built
126
+ # GIT_COMMIT_SHORT: Populated with the short SHA-1 of git commit being built
127
+ # KUBE_CONTEXT: Populated with name of kubectl context with GKE cluster access
128
+ # SECONDARY_KUBE_CONTEXT: Populated with name of kubectl context with secondary GKE cluster access, if any
129
+ # Arguments:
130
+ # None
131
+ # Outputs:
132
+ # Writes the output of test execution to stdout, stderr
133
+ # ######################################
134
+ main () {
135
+ local script_dir
136
+ script_dir=" $( dirname " $0 " ) "
137
+
138
+ # Source the test driver from the master branch.
139
+ echo " Sourcing test driver install script from: ${TEST_DRIVER_INSTALL_SCRIPT_URL} "
140
+ source /dev/stdin <<< " $(curl -s " ${TEST_DRIVER_INSTALL_SCRIPT_URL} " )"
141
+
142
+ activate_gke_cluster GKE_CLUSTER_PSM_SECURITY
143
+ activate_secondary_gke_cluster GKE_CLUSTER_PSM_SECURITY
144
+
145
+ set -x
146
+ if [[ -n " ${KOKORO_ARTIFACTS_DIR} " ]]; then
147
+ kokoro_setup_test_driver " ${GITHUB_REPOSITORY_NAME} "
148
+ else
149
+ local_setup_test_driver " ${script_dir} "
150
+ fi
151
+ build_docker_images_if_needed
152
+
153
+ # Run tests
154
+ cd " ${TEST_DRIVER_FULL_DIR} "
155
+ local failed_tests=0
156
+ test_suites=(" api_listener_test" " change_backend_service_test" " failover_test" " remove_neg_test" " round_robin_test" )
157
+ for test in " ${test_suites[@]} " ; do
158
+ run_test $test || (( failed_tests++ ))
159
+ done
160
+ echo " Failed test suites: ${failed_tests} "
161
+ if (( failed_tests > 0 )) ; then
162
+ exit 1
163
+ fi
164
+ }
165
+
166
+ main " $@ "
0 commit comments