test.sh 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. #!/usr/bin/env bash
  2. # Licensed to the Apache Software Foundation (ASF) 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. set -e
  18. DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
  19. RESULT_DIR=result
  20. #delete previous results
  21. rm -rf "${DIR:?}/$RESULT_DIR"
  22. mkdir -p "$DIR/$RESULT_DIR"
  23. #Should be writeable from the docker containers where user is different.
  24. chmod ogu+w "$DIR/$RESULT_DIR"
  25. ## @description wait until 3 datanodes are up (or 30 seconds)
  26. ## @param the docker-compose file
  27. wait_for_datanodes(){
  28. #Reset the timer
  29. SECONDS=0
  30. #Don't give it up until 30 seconds
  31. while [[ $SECONDS -lt 30 ]]; do
  32. #This line checks the number of HEALTHY datanodes registered in scm over the
  33. # jmx HTTP servlet
  34. datanodes=$(docker-compose -f "$1" exec scm curl -s 'http://localhost:9876/jmx?qry=Hadoop:service=SCMNodeManager,name=SCMNodeManagerInfo' | jq -r '.beans[0].NodeCount[] | select(.key=="HEALTHY") | .value')
  35. if [[ "$datanodes" == "3" ]]; then
  36. #It's up and running. Let's return from the function.
  37. echo "$datanodes datanodes are up and registered to the scm"
  38. return
  39. else
  40. #Print it only if a number. Could be not a number if scm is not yet started
  41. if [[ "$datanodes" ]]; then
  42. echo "$datanodes datanode is up and healhty (until now)"
  43. fi
  44. fi
  45. sleep 2
  46. done
  47. echo "WARNING! Datanodes are not started successfully. Please check the docker-compose files"
  48. }
  49. ## @description Execute selected test suites in a specified docker-compose engironment
  50. ## @param the name of the docker-compose env relative to ../compose
  51. ## @param the name of the tests (array of subdir names of the dir of this script)
  52. execute_tests(){
  53. COMPOSE_DIR=$1
  54. COMPOSE_FILE=$DIR/../compose/$COMPOSE_DIR/docker-compose.yaml
  55. TESTS=$2
  56. echo "-------------------------------------------------"
  57. echo "Executing test(s): [${TESTS[*]}]"
  58. echo ""
  59. echo " Cluster type: $COMPOSE_DIR"
  60. echo " Compose file: $COMPOSE_FILE"
  61. echo " Output dir: $DIR/$RESULT_DIR"
  62. echo " Command to rerun: ./test.sh --keep --env $COMPOSE_DIR $TESTS"
  63. echo "-------------------------------------------------"
  64. docker-compose -f "$COMPOSE_FILE" down
  65. docker-compose -f "$COMPOSE_FILE" up -d --scale datanode=3
  66. wait_for_datanodes "$COMPOSE_FILE"
  67. for TEST in "${TESTS[@]}"; do
  68. TITLE="Ozone $TEST tests with $COMPOSE_DIR cluster"
  69. set +e
  70. OUTPUT_NAME="$COMPOSE_DIR-${TEST//\//_}"
  71. docker-compose -f "$COMPOSE_FILE" exec ozoneManager python -m robot --log NONE --report NONE "${OZONE_ROBOT_OPTS[@]}" --output "smoketest/$RESULT_DIR/robot-$OUTPUT_NAME.xml" --logtitle "$TITLE" --reporttitle "$TITLE" "smoketest/$TEST"
  72. set -e
  73. docker-compose -f "$COMPOSE_FILE" logs > "$DIR/$RESULT_DIR/docker-$OUTPUT_NAME.log"
  74. done
  75. if [ "$KEEP_RUNNING" = false ]; then
  76. docker-compose -f "$COMPOSE_FILE" down
  77. fi
  78. }
  79. RUN_ALL=true
  80. KEEP_RUNNING=false
  81. POSITIONAL=()
  82. while [[ $# -gt 0 ]]
  83. do
  84. key="$1"
  85. case $key in
  86. --env)
  87. DOCKERENV="$2"
  88. RUN_ALL=false
  89. shift # past argument
  90. shift # past value
  91. ;;
  92. --keep)
  93. KEEP_RUNNING=true
  94. shift # past argument
  95. ;;
  96. --help|-h|-help)
  97. cat << EOF
  98. Acceptance test executor for ozone.
  99. This is a lightweight test executor for ozone.
  100. You can run it with
  101. ./test.sh
  102. Which executes all the tests in all the available environments.
  103. Or you can run manually one test with
  104. ./test.sh --keep --env ozone-hdfs basic
  105. --keep means that docker cluster won't be stopped after the test (optional)
  106. --env defines the subdirectory under the compose dir
  107. The remaining parameters define the test suites under smoketest dir.
  108. Could be any directory or robot file relative to the smoketest dir.
  109. EOF
  110. exit 0
  111. ;;
  112. *)
  113. POSITIONAL+=("$1") # save it in an array for later
  114. shift # past argument
  115. ;;
  116. esac
  117. done
  118. if [ "$RUN_ALL" = true ]; then
  119. #
  120. # This is the definition of the ozone acceptance test suite
  121. #
  122. # We select the test suites and execute them on multiple type of clusters
  123. #
  124. DEFAULT_TESTS=("basic")
  125. execute_tests ozone "${DEFAULT_TESTS[@]}"
  126. TESTS=("ozonefs")
  127. execute_tests ozonefs "${TESTS[@]}"
  128. TESTS=("ozone-hdfs")
  129. execute_tests ozone-hdfs "${DEFAULT_TESTS[@]}"
  130. TESTS=("s3")
  131. execute_tests ozones3 "${TESTS[@]}"
  132. else
  133. execute_tests "$DOCKERENV" "${POSITIONAL[@]}"
  134. fi
  135. #Generate the combined output and return with the right exit code (note: robot = execute test, rebot = generate output)
  136. docker run --rm -it -v "$DIR/..:/opt/hadoop" apache/hadoop-runner rebot -d "smoketest/$RESULT_DIR" "smoketest/$RESULT_DIR/robot-*.xml"