Debian Codegraph @

tools/run_tests/xds_k8s_test_driver/run.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 XDS_K8S_DRIVER_DIR="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
19 readonly XDS_K8S_DRIVER_DIR
20 readonly XDS_K8S_CONFIG="${XDS_K8S_CONFIG:-$XDS_K8S_DRIVER_DIR/config/local-dev.cfg}"
21
22 display_usage() {
23 cat <<EOF >/dev/stderr
24 Convenience script to execute tests/ and helper bin/ scripts.
25
26 USAGE: $0 script_path [arguments]
27 script_path: path to python script to execute, relative to driver root folder
28 arguments ...: arguments passed to program in sys.argv
29
30 ENVIRONMENT:
31 XDS_K8S_CONFIG: file path to the config flagfile, relative to
32 driver root folder. Default: config/local-dev.cfg
33 Will be appended as --flagfile="config_absolute_path" argument
34 XDS_K8S_DRIVER_VENV_DIR: the path to python virtual environment directory
35 Default: $XDS_K8S_DRIVER_DIR/venv
36 DESCRIPTION:
37 This tool performs the following:
38 1) Ensures python virtual env installed and activated
39 2) Exports test driver root in PYTHONPATH
40 3) Automatically appends --flagfile="\$XDS_K8S_CONFIG" argument
41
42 EXAMPLES:
43 $0 bin/run_td_setup.py --help # list script-specific options
44 $0 bin/run_td_setup.py --helpfull # list all available options
45 XDS_K8S_CONFIG=./path-to-flagfile.cfg ./run.sh bin/run_td_setup.py --resource_suffix=override-suffix
46 $0 tests/baseline_test.py
47 $0 tests/security_test.py --verbosity=1 --logger_levels=__main__:DEBUG,framework:DEBUG
48 $0 tests/security_test.py SecurityTest.test_mtls --nocheck_local_certs
49 EOF
50 exit 1
51 }
52
53 if [[ "$#" -eq 0 || "$1" = "-h" || "$1" = "--help" ]]; then
54 display_usage
55 fi
56
57 # Relative paths not yet supported by shellcheck.
58 # shellcheck source=/dev/null
59 source "${XDS_K8S_DRIVER_DIR}/bin/ensure_venv.sh"
60
61 cd "${XDS_K8S_DRIVER_DIR}"
62 export PYTHONPATH="${XDS_K8S_DRIVER_DIR}"
63 # Split path to python file from the rest of the args.
64 readonly PY_FILE="$1"
65 shift
66 # Append args after --flagfile, so they take higher priority.
67 exec python "${PY_FILE}" --flagfile="${XDS_K8S_CONFIG}" "$@"