e2e.sh 4.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #!/bin/bash
  2. # Licensed to the LF AI & Data foundation under one
  3. # or more contributor license agreements. See the NOTICE file
  4. # distributed with this work for additional information
  5. # regarding copyright ownership. The ASF licenses this file
  6. # to you under the Apache License, Version 2.0 (the
  7. # "License"); you may not use this file except in compliance
  8. # with the License. You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS,
  14. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. # See the License for the specific language governing permissions and
  16. # limitations under the License.
  17. # Exit immediately for non zero status
  18. set -e
  19. # Print commands
  20. set -x
  21. MILVUS_HELM_RELEASE_NAME="${MILVUS_HELM_RELEASE_NAME:-milvus-testing}"
  22. MILVUS_CLUSTER_ENABLED="${MILVUS_CLUSTER_ENABLED:-false}"
  23. MILVUS_HELM_NAMESPACE="${MILVUS_HELM_NAMESPACE:-default}"
  24. PARALLEL_NUM="${PARALLEL_NUM:-6}"
  25. MILVUS_CLIENT="${MILVUS_CLIENT:-pymilvus}"
  26. SOURCE="${BASH_SOURCE[0]}"
  27. while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
  28. DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
  29. SOURCE="$(readlink "$SOURCE")"
  30. [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
  31. done
  32. ROOT="$( cd -P "$( dirname "$SOURCE" )/../.." && pwd )"
  33. if [[ "${TEST_ENV:-}" =~ ^kind* ]]; then
  34. if [[ "${MILVUS_CLUSTER_ENABLED}" == "false" ]]; then
  35. MILVUS_LABELS="app.kubernetes.io/instance=${MILVUS_HELM_RELEASE_NAME},component=standalone"
  36. else
  37. MILVUS_LABELS="app.kubernetes.io/instance=${MILVUS_HELM_RELEASE_NAME},component=proxy"
  38. fi
  39. SERVICE_TYPE=$(kubectl get service --namespace "${MILVUS_HELM_NAMESPACE}" -l "${MILVUS_LABELS}" -o jsonpath='{.items[0].spec.type}')
  40. if [[ "${SERVICE_TYPE}" == "LoadBalancer" ]]; then
  41. MILVUS_SERVICE_IP=$(kubectl get service --namespace "${MILVUS_HELM_NAMESPACE}" -l "${MILVUS_LABELS}" -o jsonpath='{.items[0].status.loadBalancer.ingress[0].ip}')
  42. MILVUS_SERVICE_PORT=$(kubectl get service --namespace "${MILVUS_HELM_NAMESPACE}" -l "${MILVUS_LABELS}" -o jsonpath='{.items[0].spec.ports[0].port}')
  43. elif [[ "${SERVICE_TYPE}" == "NodePort" ]]; then
  44. MILVUS_SERVICE_IP=$(kubectl get nodes --namespace "${MILVUS_HELM_NAMESPACE}" -o jsonpath='{.items[0].status.addresses[0].address}')
  45. MILVUS_SERVICE_PORT=$(kubectl get service --namespace "${MILVUS_HELM_NAMESPACE}" -l "${MILVUS_LABELS}" -o jsonpath='{.items[0].spec.ports[0].nodePort}')
  46. else
  47. #[remove-kind] use service ip when disable kind to run ci test
  48. if [[ -n "${DISABLE_KIND:-}" ]]; then
  49. MILVUS_SERVICE_IP=$(kubectl get service --namespace "${MILVUS_HELM_NAMESPACE}" -l "${MILVUS_LABELS}" -o jsonpath='{.items[0].spec.clusterIP}')
  50. MILVUS_SERVICE_PORT=$(kubectl get service --namespace "${MILVUS_HELM_NAMESPACE}" -l "${MILVUS_LABELS}" -o jsonpath='{.items[0].spec.ports[0].port}')
  51. else
  52. MILVUS_SERVICE_IP="127.0.0.1"
  53. POD_NAME=$(kubectl get pods --namespace "${MILVUS_HELM_NAMESPACE}" -l "${MILVUS_LABELS}" -o jsonpath='{.items[0].metadata.name}')
  54. MILVUS_SERVICE_PORT=$(kubectl get service --namespace "${MILVUS_HELM_NAMESPACE}" -l "${MILVUS_LABELS}" -o jsonpath='{.items[0].spec.ports[0].port}')
  55. kubectl --namespace "${MILVUS_HELM_NAMESPACE}" port-forward "${POD_NAME}" "${MILVUS_SERVICE_PORT}" &
  56. PORT_FORWARD_PID=$!
  57. trap "kill -TERM ${PORT_FORWARD_PID}" EXIT
  58. fi
  59. fi
  60. fi
  61. pushd "${ROOT}/tests/docker"
  62. if [[ "${TEST_ENV:-}" =~ ^kind* ]]; then
  63. export PRE_EXIST_NETWORK="true"
  64. export PYTEST_NETWORK="kind"
  65. fi
  66. export MILVUS_SERVICE_IP="${MILVUS_SERVICE_IP:-127.0.0.1}"
  67. export MILVUS_SERVICE_PORT="${MILVUS_SERVICE_PORT:-19530}"
  68. if [[ "${MANUAL:-}" == "true" ]]; then
  69. docker compose up -d
  70. else
  71. if [[ "${MILVUS_CLIENT}" == "pymilvus" ]]; then
  72. # Better to run pytest under pytest workspace
  73. export MILVUS_PYTEST_WORKSPACE="/milvus/tests/python_client"
  74. docker compose run --rm pytest /bin/bash -c "pytest -n ${PARALLEL_NUM} --host ${MILVUS_SERVICE_IP} --port ${MILVUS_SERVICE_PORT} \
  75. --html=\${CI_LOG_PATH}/report.html --self-contained-html ${@:-}"
  76. fi
  77. fi
  78. popd