Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / test / run-cli-tests
1 #!/bin/sh
2 set -e
3
4 if ! command -v virtualenv >/dev/null; then
5     echo "$0: virtualenv not installed, skipping python-using tests." 1>&2
6     exit 1
7 fi
8
9 SRCDIR="$(dirname "$0")"
10
11 # build directory, if different, can be passed as an argument;
12 # it is expected to point to the equivalent subdirectory of the
13 # tree as where this script is stored
14 BUILDDIR="$SRCDIR"
15 case "$1" in
16     ''|-*)
17         # not set or looks like a flag to cram
18         ;;
19     *)
20         # looks like the builddir
21         BUILDDIR="$1"
22         shift
23         ;;
24 esac
25
26 VENV="$BUILDDIR/virtualenv"
27 CRAM_BIN="$VENV/bin/cram"
28 if [ ! -e "$CRAM_BIN" ]; then
29     # With "make distcheck", the source directory must be read-only. I
30     # patched cram to support that. See upstream ticket at
31     # https://bitbucket.org/brodie/cram/issue/9/allow-read-only-directories-for-t
32     # -- tv@inktank.com
33     virtualenv "$VENV" && $VENV/bin/pip --log "$VENV"/log.txt install "$SRCDIR/downloads/cram-0.5.0ceph.2011-01-14.tar.gz"
34 fi
35
36 SRCDIR_ABS="$(readlink -f "$SRCDIR")"
37 BUILDDIR_ABS="$(readlink -f "$BUILDDIR")"
38 FAKE_HOME="$BUILDDIR_ABS/fake_home"
39 mkdir -p "$FAKE_HOME"
40
41 # cram doesn't like seeing the same foo.t basename twice on the same
42 # run, so run it once per directory
43 FAILED=0
44 FAILEDTOOLS=""
45 for tool in "$SRCDIR"/cli/*; do
46     toolname="$(basename "$tool")"
47     install -d -m0755 -- "$BUILDDIR/cli/$toolname"
48     if ! env -i \
49         PATH="$BUILDDIR_ABS/..:$SRCDIR_ABS/..:$PATH" \
50         CEPH_CONF=/dev/null \
51         CCACHE_DIR="$CCACHE_DIR" \
52         CC="$CC" \
53         CXX="$CXX" \
54         HOME="$FAKE_HOME" \
55         "$SRCDIR/run-cli-tests-maybe-unset-ccache" \
56         "$CRAM_BIN" -v "$@"  --error-dir="$BUILDDIR/cli/$toolname" -- "$tool"/*.t
57     then
58         FAILED=1
59         FAILEDTOOLS="$FAILEDTOOLS $toolname"
60     fi
61 done
62
63 if [ $FAILED -eq 1 ]; then
64     echo "Tests that failed: $FAILEDTOOLS"
65 fi
66
67 exit "$FAILED"