github.com/NVIDIA/aistore@v1.3.23-0.20240517131212-7df6609be51d/scripts/bootstrap.sh (about) 1 #!/bin/bash 2 3 run_tests() { 4 SECONDS=0 5 6 if [[ -n "${RE}" ]]; then 7 re="-run=${RE}" 8 fi 9 10 tests_dir="${AISTORE_PATH}/..." 11 if [[ -n "${TESTS_DIR}" ]]; then 12 tests_dir="${AISTORE_PATH}/${TESTS_DIR}" 13 fi 14 15 ## NOTE: when changing, make sure to update .gitlab-ci.yml and GitLab /settings/ci_cd 16 timeout="-timeout=4h" 17 shuffle="-shuffle=on" 18 if [[ -n "${SHORT}" ]]; then 19 short="-short" 20 timeout="-timeout=30m" 21 fi 22 23 # NOTE: cannot run tests in parallel (e.g. `-parallel 4`) because of ginkgo v2 24 # ("Ginkgo detected configuration issues...") 25 failed_tests=$( 26 BUCKET="${BUCKET}" AIS_ENDPOINT="${AIS_ENDPOINT}" \ 27 go test -v -p 1 -tags debug -count 1 ${timeout} ${short} ${shuffle} ${re} "${tests_dir}" 2>&1 \ 28 | tee -a /dev/stderr \ 29 | grep -ae "^---FAIL: Bench\|^--- FAIL: Test\|^FAIL[[:space:]]github.com/NVIDIA/.*$"; \ 30 exit ${PIPESTATUS[0]} # Exit with the status of the first command in the pipe(line). 31 ) 32 exit_code=$? 33 34 echo "Tests took: $((SECONDS/3600))h$(((SECONDS%3600)/60))m$((SECONDS%60))s" 35 36 if [[ $exit_code -ne 0 ]]; then 37 echo "${failed_tests}" 38 exit $exit_code 39 fi 40 } 41 42 AISTORE_PATH="$(cd "$(dirname "$0")/../"; pwd -P)" ## NOTE: this assumes `bootstrap.sh` itself is one level below 43 SCRIPTS_DIR=${AISTORE_PATH}/scripts 44 PYLINT_STYLE="$(dirname ${0})/config/.pylintrc" 45 EXTERNAL_SRC_REGEX=".*\(venv\|build\|3rdparty\|dist\|.idea\|.vscode\)/.*" 46 # This script is used by Makefile to run commands. 47 source ${SCRIPTS_DIR}/utils.sh 48 49 case $1 in 50 lint) 51 echo "Running lint..." >&2 52 golangci-lint --timeout=15m run $(list_all_go_dirs) 53 exit $? 54 ;; 55 56 fmt) 57 err_count=0 58 case $2 in 59 --fix) 60 echo "Running style fixing..." >&2 61 62 echo ${AISTORE_PATH} 63 64 gofmt -s -w ${AISTORE_PATH} 65 python_black_fix 66 ;; 67 *) 68 echo "Running style check..." >&2 69 70 check_gomod 71 check_imports 72 check_deps 73 check_files_headers 74 check_python_formatting 75 ;; 76 esac 77 ;; 78 79 spell) 80 echo "Running spell check..." >&2 81 case $2 in 82 --fix) 83 ${GOPATH}/bin/misspell -i "importas" -w -locale=US ${AISTORE_PATH} 84 ;; 85 *) 86 ${GOPATH}/bin/misspell -i "importas" -error -locale=US ${AISTORE_PATH} 87 ;; 88 esac 89 ;; 90 91 test-env) 92 if [[ -z ${BUCKET} ]]; then 93 echo "Error: missing environment variable: BUCKET=\"bucketname\"" 94 exit 1 95 fi 96 97 hash docker &>/dev/null 98 if [[ $? -eq 0 ]]; then 99 docker_running=$(docker container ls) 100 if [[ $? -ne 0 ]]; then 101 echo "Warning: Can't check if AIS is running from docker, verify that you have permissions for /var/run/docker.sock" >&2 102 elif [[ $(echo ${docker_running} | grep ais) ]]; then 103 echo "AIStore running on docker..." >&2 104 exit 0 105 fi 106 fi 107 108 if [[ -n ${KUBERNETES_SERVICE_HOST} ]]; then 109 echo "AIStore running on Kubernetes..." >&2 110 exit 0 111 fi 112 113 if [[ -n $(pgrep aisnode) ]]; then 114 echo "AIStore running locally..." >&2 115 exit 0 116 fi 117 118 if curl -s -X GET "${AIS_ENDPOINT}/v1/health?readiness=true"; then 119 echo "AIStore detected on $AIS_ENDPOINT" 120 exit 0 121 fi 122 123 echo "AIStore is not running, this causes some tests to fail! (to run, see: https://github.com/NVIDIA/aistore#local-non-containerized)" >&2 124 echo -n "continue? [y/N] " >&2 && read ans && [[ ${ans:-N} =~ ^y(es)?$ ]] 125 exit $? 126 ;; 127 128 test-short) 129 echo "Running short tests..." >&2 130 SHORT="true" run_tests 131 ;; 132 133 test-long) 134 echo "Running long tests..." >&2 135 run_tests 136 ;; 137 138 test-run) 139 echo "Running test with regex (${RE})..." >&2 140 run_tests 141 ;; 142 143 test-docker) 144 docker_state=$(docker info >/dev/null 2>&1) 145 if [[ $? -ne 0 ]]; then 146 echo "Docker does not seem to be running, run it first and retry." 147 exit 1 148 fi 149 150 echo "Running test in Docker..." >&2 151 branch=$(git branch | grep \* | cut -d ' ' -f2) 152 errs=$("${AISTORE_PATH}/deploy/test-in-docker/test.sh" --name=${branch} 2>&1 | tee -a /dev/stderr | grep -e "^--- FAIL: Bench\|^--- FAIL: Test" ) 153 perror $1 "${errs}" 154 ;; 155 156 157 test-bench) 158 echo "Running benchmark tests..." >&2 159 SCRIPTS_DIR=${AISTORE_PATH}/scripts 160 . ${SCRIPTS_DIR}/bench.sh cmp --dir "${AISTORE_PATH}" --verbose --post-checkout "${SCRIPTS_DIR}/clean_deploy.sh --dir ${AISTORE_PATH}" 161 ;; 162 163 bench) 164 shift 165 . ${SCRIPTS_DIR}/bench.sh 166 ;; 167 168 clean-deploy) 169 shift 170 . ${SCRIPTS_DIR}/clean_deploy.sh 171 ;; 172 173 dev-init) 174 if [[ -z ${REMOTE} ]]; then 175 echo "Missing environment variable: REMOTE=\"http://path/to/remote\"" 176 exit 177 fi 178 179 if [[ -z $(command -v git) ]]; then 180 echo "'git' command not installed" 181 exit 1 182 elif [[ -z $(git remote -v | grep origin) ]]; then 183 git remote add origin "${REMOTE}"; 184 else 185 git remote set-url origin "${REMOTE}"; 186 fi 187 exit 0 188 ;; 189 190 *) 191 echo "unsupported argument $1" 192 exit 1 193 ;; 194 esac