run.sh 2.5 KB

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