grpc_xds_k8s_xlang.sh 5.2 KB

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