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 16set -eo pipefail 17 18XDS_K8S_DRIVER_DIR="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )" 19readonly XDS_K8S_DRIVER_DIR 20readonly XDS_K8S_CONFIG="${XDS_K8S_CONFIG:-$XDS_K8S_DRIVER_DIR/config/local-dev.cfg}" 21 22display_usage() { 23 cat <<EOF >/dev/stderr 24Convenience script to execute tests/ and helper bin/ scripts. 25 26USAGE: $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 30ENVIRONMENT: 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 36DESCRIPTION: 37This tool performs the following: 381) Ensures python virtual env installed and activated 392) Exports test driver root in PYTHONPATH 403) Automatically appends --flagfile="\$XDS_K8S_CONFIG" argument 41 42EXAMPLES: 43$0 bin/run_td_setup.py --help # list script-specific options 44$0 bin/run_td_setup.py --helpfull # list all available options 45XDS_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 49EOF 50 exit 1 51} 52 53if [[ "$#" -eq 0 || "$1" = "-h" || "$1" = "--help" ]]; then 54 display_usage 55fi 56 57# Relative paths not yet supported by shellcheck. 58# shellcheck source=/dev/null 59source "${XDS_K8S_DRIVER_DIR}/bin/ensure_venv.sh" 60 61cd "${XDS_K8S_DRIVER_DIR}" 62export PYTHONPATH="${XDS_K8S_DRIVER_DIR}" 63# Split path to python file from the rest of the args. 64readonly PY_FILE="$1" 65shift 66# Append args after --flagfile, so they take higher priority. 67exec python "${PY_FILE}" --flagfile="${XDS_K8S_CONFIG}" "$@" 68