<https://github.com/ricardoasmarques/ceph-dev-docker/>`_, simply run
``./install_deps.sh`` from the toplevel directory to install them.
-Unit Testing and Linting
+Unit Testing
+~~~~~~~~~~~~
+
+In dashboard we have two different kinds of backend tests:
+
+1. Unit tests based on ``tox``
+2. API tests based on Teuthology.
+
+Unit tests based on tox
~~~~~~~~~~~~~~~~~~~~~~~~
We included a ``tox`` configuration file that will run the unit tests under
$ pip install tox
$ pip install coverage
-The unit tests must run against a real Ceph cluster (no mocks are used). This
-has the advantage of catching bugs originated from changes in the internal Ceph
-code.
-
-Our ``tox.ini`` script will start a ``vstart`` Ceph cluster before running the
-python unit tests, and then it stops the cluster after the tests are run. Of
-course this implies that you have built/compiled Ceph previously.
-
-To run tox, run the following command in the root directory (where ``tox.ini``
-is located)::
-
- $ PATH=../../../../build/bin:$PATH tox
+To run the tests, run ``tox`` in the dashboard directory (where ``tox.ini``
+is located).
We also collect coverage information from the backend code. You can check the
coverage information provided by the tox output, or by running the following
You can also run a single step of the tox script (aka tox environment), for
instance if you only want to run the linting tools, do::
- $ PATH=../../../../build/bin:$PATH tox -e lint
+ $ tox -e lint
-How to run a single unit test without using ``tox``?
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+API tests based on Teuthology
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-When developing the code of a controller and respective test code, it's useful
-to be able to run that single test file without going through the whole ``tox``
-workflow.
+To run our API tests against a real Ceph cluster, we leverage the Teuthology framework. This
+has the advantage of catching bugs originated from changes in the internal Ceph
+code.
-Since the tests must run against a real Ceph cluster, the first thing is to have
-a Ceph cluster running. For that we can leverage the tox environment that starts
-a Ceph cluster::
- $ PATH=../../../../build/bin:$PATH tox -e ceph-cluster-start
+Our ``run-backend-api-tests.sh`` script will start a ``vstart`` Ceph cluster before running the
+Teuthology tests, and then it stops the cluster after the tests are run. Of
+course this implies that you have built/compiled Ceph previously.
-The command above uses ``vstart.sh`` script to start a Ceph cluster and
-automatically enables the ``dashboard`` module, and configures its cherrypy
-web server to listen in port ``9865``.
+Start all dashboard tests by running::
-After starting the Ceph cluster we can run our test file using ``py.test`` like
-this::
+ $ ./run-backend-api-tests.sh
- DASHBOARD_PORT=9865 UNITTEST=true py.test -s tests/test_mycontroller.py
+Or, start one or multiple specific tests by specifying the test name::
-You can run tests multiple times without having to start and stop the Ceph
-cluster.
+ $ ./run-backend-api-tests.sh tasks.mgr.dashboard.test_pool.DashboardTest
-After you finish your tests, you can stop the Ceph cluster using another tox
-environment::
+Or, ``source`` the script and run the tests manually::
- $ tox -e ceph-cluster-stop
+ $ source run-backend-api-tests.sh
+ $ run_teuthology_tests [tests]...
+ $ cleanup_teuthology
How to add a new controller?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#!/usr/bin/env bash
-# run from ./
+
+
+# Usage (run from ./):
+# ./run-backend-api-tests.sh
+# ./run-backend-api-tests.sh [tests]...
+#
+# Example:
+# ./run-backend-api-tests.sh tasks.mgr.dashboard.test_pool.DashboardTest
+#
+# Or source this script. Allows to re-run tests faster:
+# $ source run-backend-api-tests.sh
+# $ run_teuthology_tests [tests]...
+# $ cleanup_teuthology
# creating temp directory to store virtualenv and teuthology
-TEMP_DIR=`mktemp -d`
get_cmake_variable() {
local variable=$1
grep "$variable" CMakeCache.txt | cut -d "=" -f 2
}
-read -r -d '' TEUTHOLOFY_PY_REQS <<EOF
+setup_teuthology() {
+ TEMP_DIR=`mktemp -d`
+
+ CURR_DIR=`pwd`
+ BUILD_DIR="$CURR_DIR/../../../../build"
+
+ read -r -d '' TEUTHOLOFY_PY_REQS <<EOF
apache-libcloud==2.2.1 \
asn1crypto==0.22.0 \
bcrypt==3.1.4 \
EOF
-CURR_DIR=`pwd`
-cd $TEMP_DIR
+ cd $TEMP_DIR
-virtualenv --python=/usr/bin/python venv
-source venv/bin/activate
-eval pip install $TEUTHOLOFY_PY_REQS
-pip install -r $CURR_DIR/requirements.txt
-deactivate
+ virtualenv --python=/usr/bin/python venv
+ source venv/bin/activate
+ eval pip install $TEUTHOLOFY_PY_REQS
+ pip install -r $CURR_DIR/requirements.txt
+ deactivate
-git clone https://github.com/ceph/teuthology.git
+ git clone https://github.com/ceph/teuthology.git
-cd $CURR_DIR
-cd ../../../../build
+ cd $BUILD_DIR
-CEPH_MGR_PY_VERSION_MAJOR=$(get_cmake_variable MGR_PYTHON_VERSION | cut -d '.' -f1)
-if [ -n "$CEPH_MGR_PY_VERSION_MAJOR" ]; then
- CEPH_PY_VERSION_MAJOR=${CEPH_MGR_PY_VERSION_MAJOR}
-else
- if [ $(get_cmake_variable WITH_PYTHON2) = ON ]; then
- CEPH_PY_VERSION_MAJOR=2
+ CEPH_MGR_PY_VERSION_MAJOR=$(get_cmake_variable MGR_PYTHON_VERSION | cut -d '.' -f1)
+ if [ -n "$CEPH_MGR_PY_VERSION_MAJOR" ]; then
+ CEPH_PY_VERSION_MAJOR=${CEPH_MGR_PY_VERSION_MAJOR}
else
- CEPH_PY_VERSION_MAJOR=3
+ if [ $(get_cmake_variable WITH_PYTHON2) = ON ]; then
+ CEPH_PY_VERSION_MAJOR=2
+ else
+ CEPH_PY_VERSION_MAJOR=3
+ fi
fi
-fi
-export COVERAGE_ENABLED=true
-export COVERAGE_FILE=.coverage.mgr.dashboard
+ export COVERAGE_ENABLED=true
+ export COVERAGE_FILE=.coverage.mgr.dashboard
+
+ MGR=2 RGW=1 ../src/vstart.sh -n -d
+ sleep 10
+ cd $CURR_DIR
+}
+
+run_teuthology_tests() {
+ cd "$BUILD_DIR"
+ source $TEMP_DIR/venv/bin/activate
+
-MGR=2 RGW=1 ../src/vstart.sh -n -d
-sleep 10
+ if [ "$#" -gt 0 ]; then
+ TEST_CASES=""
+ for t in "$@"; do
+ TEST_CASES="$TEST_CASES $t"
+ done
+ else
+ TEST_CASES=`for i in \`ls $BUILD_DIR/../qa/tasks/mgr/dashboard/test_*\`; do F=$(basename $i); M="${F%.*}"; echo -n " tasks.mgr.dashboard.$M"; done`
+ TEST_CASES="tasks.mgr.test_dashboard $TEST_CASES"
+ fi
-source $TEMP_DIR/venv/bin/activate
-BUILD_DIR=`pwd`
+ export PATH=$BUILD_DIR/bin:$PATH
+ export LD_LIBRARY_PATH=$BUILD_DIR/lib/cython_modules/lib.${CEPH_PY_VERSION_MAJOR}/:$BUILD_DIR/lib
+ export PYTHONPATH=$TEMP_DIR/teuthology:$BUILD_DIR/../qa:$BUILD_DIR/lib/cython_modules/lib.${CEPH_PY_VERSION_MAJOR}/
+ eval python ../qa/tasks/vstart_runner.py $TEST_CASES
-if [ "$#" -gt 0 ]; then
- TEST_CASES=""
- for t in "$@"; do
- TEST_CASES="$TESTS_CASES $t"
- done
-else
- TEST_CASES=`for i in \`ls $BUILD_DIR/../qa/tasks/mgr/dashboard/test_*\`; do F=$(basename $i); M="${F%.*}"; echo -n " tasks.mgr.dashboard.$M"; done`
- TEST_CASES="tasks.mgr.test_dashboard $TEST_CASES"
-fi
+ deactivate
+ cd $CURR_DIR
+}
-export PATH=$BUILD_DIR/bin:$PATH
-export LD_LIBRARY_PATH=$BUILD_DIR/lib/cython_modules/lib.${CEPH_PY_VERSION_MAJOR}/:$BUILD_DIR/lib
-export PYTHONPATH=$TEMP_DIR/teuthology:$BUILD_DIR/../qa:$BUILD_DIR/lib/cython_modules/lib.${CEPH_PY_VERSION_MAJOR}/
-eval python ../qa/tasks/vstart_runner.py $TEST_CASES
+cleanup_teuthology() {
+ cd "$BUILD_DIR"
+ killall ceph-mgr
+ sleep 10
+ ../src/stop.sh
+ sleep 5
+
+ cd $CURR_DIR
+ rm -rf $TEMP_DIR
+
+ unset TEMP_DIR
+ unset CURR_DIR
+ unset BUILD_DIR
+ unset setup_teuthology
+ unset run_teuthology_tests
+ unset cleanup_teuthology
+}
-deactivate
-killall ceph-mgr
-sleep 10
-../src/stop.sh
-sleep 5
+setup_teuthology
-cd $CURR_DIR
-rm -rf $TEMP_DIR
+# End sourced section
+return 2> /dev/null
+run_teuthology_tests "$@"
+cleanup_teuthology