test-e2e-node.sh 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. #!/bin/bash
  2. # Copyright 2016 The Kubernetes 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. KUBE_ROOT=$(dirname "${BASH_SOURCE}")/../..
  16. source "${KUBE_ROOT}/hack/lib/init.sh"
  17. focus=${FOCUS:-""}
  18. skip=${SKIP:-""}
  19. # The number of tests that can run in parallel depends on what tests
  20. # are running and on the size of the node. Too many, and tests will
  21. # fail due to resource contention. 8 is a reasonable default for a
  22. # n1-standard-1 node.
  23. # Currently, parallelism only affects when REMOTE=true. For local test,
  24. # ginkgo default parallelism (cores - 1) is used.
  25. parallelism=${PARALLELISM:-8}
  26. report=${REPORT:-"/tmp/"}
  27. artifacts=${ARTIFACTS:-"/tmp/_artifacts"}
  28. remote=${REMOTE:-"false"}
  29. run_until_failure=${RUN_UNTIL_FAILURE:-"false"}
  30. test_args=${TEST_ARGS:-""}
  31. # Parse the flags to pass to ginkgo
  32. ginkgoflags=""
  33. if [[ $parallelism > 1 ]]; then
  34. ginkgoflags="$ginkgoflags -nodes=$parallelism "
  35. fi
  36. if [[ $focus != "" ]]; then
  37. ginkgoflags="$ginkgoflags -focus=$focus "
  38. fi
  39. if [[ $skip != "" ]]; then
  40. ginkgoflags="$ginkgoflags -skip=$skip "
  41. fi
  42. if [[ $run_until_failure != "" ]]; then
  43. ginkgoflags="$ginkgoflags -untilItFails=$run_until_failure "
  44. fi
  45. if [ $remote = true ] ; then
  46. # The following options are only valid in remote run.
  47. images=${IMAGES:-""}
  48. hosts=${HOSTS:-""}
  49. image_project=${IMAGE_PROJECT:-"kubernetes-node-e2e-images"}
  50. metadata=${INSTANCE_METADATA:-""}
  51. list_images=${LIST_IMAGES:-false}
  52. if [[ $list_images == "true" ]]; then
  53. gcloud compute images list --project="${image_project}" | grep "e2e-node"
  54. exit 0
  55. fi
  56. gubernator=${GUBERNATOR:-"false"}
  57. if [[ $hosts == "" && $images == "" ]]; then
  58. image_project=${IMAGE_PROJECT:-"google-containers"}
  59. gci_image=$(gcloud compute images list --project $image_project \
  60. --no-standard-images --regexp="gci-dev.*" --format="table[no-heading](name)")
  61. images=$gci_image
  62. metadata="user-data<${KUBE_ROOT}/test/e2e_node/jenkins/gci-init.yaml"
  63. fi
  64. instance_prefix=${INSTANCE_PREFIX:-"test"}
  65. cleanup=${CLEANUP:-"true"}
  66. delete_instances=${DELETE_INSTANCES:-"false"}
  67. # Setup the directory to copy test artifacts (logs, junit.xml, etc) from remote host to local host
  68. if [[ $gubernator = true && -d "${artifacts}" ]]; then
  69. echo "Removing artifacts directory at ${artifacts}"
  70. rm -r ${artifacts}
  71. fi
  72. if [ ! -d "${artifacts}" ]; then
  73. echo "Creating artifacts directory at ${artifacts}"
  74. mkdir -p ${artifacts}
  75. fi
  76. echo "Test artifacts will be written to ${artifacts}"
  77. # Get the compute zone
  78. zone=$(gcloud info --format='value(config.properties.compute.zone)')
  79. if [[ $zone == "" ]]; then
  80. echo "Could not find gcloud compute/zone when running:\ngcloud info --format='value(config.properties.compute.zone)'"
  81. exit 1
  82. fi
  83. # Get the compute project
  84. project=$(gcloud info --format='value(config.project)')
  85. if [[ $project == "" ]]; then
  86. echo "Could not find gcloud project when running:\ngcloud info --format='value(config.project)'"
  87. exit 1
  88. fi
  89. # Check if any of the images specified already have running instances. If so reuse those instances
  90. # by moving the IMAGE to a HOST
  91. if [[ $images != "" ]]; then
  92. IFS=',' read -ra IM <<< "$images"
  93. images=""
  94. for i in "${IM[@]}"; do
  95. if [[ $(gcloud compute instances list "${instance_prefix}-$i" | grep $i) ]]; then
  96. if [[ $hosts != "" ]]; then
  97. hosts="$hosts,"
  98. fi
  99. echo "Reusing host ${instance_prefix}-$i"
  100. hosts="${hosts}${instance_prefix}-${i}"
  101. else
  102. if [[ $images != "" ]]; then
  103. images="$images,"
  104. fi
  105. images="$images$i"
  106. fi
  107. done
  108. fi
  109. # Output the configuration we will try to run
  110. echo "Running tests remotely using"
  111. echo "Project: $project"
  112. echo "Image Project: $image_project"
  113. echo "Compute/Zone: $zone"
  114. echo "Images: $images"
  115. echo "Hosts: $hosts"
  116. echo "Ginkgo Flags: $ginkgoflags"
  117. echo "Instance Metadata: $metadata"
  118. # Invoke the runner
  119. go run test/e2e_node/runner/remote/run_remote.go --logtostderr --vmodule=*=4 --ssh-env="gce" \
  120. --zone="$zone" --project="$project" --gubernator="$gubernator" \
  121. --hosts="$hosts" --images="$images" --cleanup="$cleanup" \
  122. --results-dir="$artifacts" --ginkgo-flags="$ginkgoflags" \
  123. --image-project="$image_project" --instance-name-prefix="$instance_prefix" --setup-node="true" \
  124. --delete-instances="$delete_instances" --test_args="$test_args" --instance-metadata="$metadata" \
  125. 2>&1 | tee "${artifacts}/build-log.txt"
  126. exit $?
  127. else
  128. # Refresh sudo credentials if not running on GCE.
  129. if ! ping -c 1 -q metadata.google.internal &> /dev/null; then
  130. sudo -v || exit 1
  131. fi
  132. # If the flag --disable-kubenet is not set, set true by default.
  133. if ! [[ $test_args =~ "--disable-kubenet" ]]; then
  134. test_args="$test_args --disable-kubenet=true"
  135. fi
  136. # On selinux enabled systems, it might
  137. # require to relabel /var/lib/kubelet
  138. if which selinuxenabled &> /dev/null && \
  139. selinuxenabled && \
  140. which chcon > /dev/null ; then
  141. mkdir -p /var/lib/kubelet
  142. if [[ ! $(ls -Zd /var/lib/kubelet) =~ svirt_sandbox_file_t ]] ; then
  143. echo "Applying SELinux label to /var/lib/kubelet directory."
  144. if ! sudo chcon -Rt svirt_sandbox_file_t /var/lib/kubelet; then
  145. echo "Failed to apply selinux label to /var/lib/kubelet."
  146. fi
  147. fi
  148. fi
  149. # Test using the host the script was run on
  150. # Provided for backwards compatibility
  151. go run test/e2e_node/runner/local/run_local.go --ginkgo-flags="$ginkgoflags" \
  152. --test-flags="--alsologtostderr --v 4 --report-dir=${report} --node-name $(hostname) \
  153. $test_args" --build-dependencies=true
  154. exit $?
  155. fi