Prerequisites
=============

For Fedora/CentOS install the following packages:

   $ sudo yum install -y gcc make libaio-devel libblkid-devel libuuid-devel

For Ubuntu/Debian install the following packages:

   $ sudo apt install -y gcc make libaio-dev libblkid-dev uuid-dev


How to test sanlock
===================

To run the python based tests, you need tox. The best way to install a
recent version is to use pip:

    $ pip install tox

To run the tests with python 2.7 and 3.6:

    $ tox

Note: python 3.6 tests will fail now, since sanlock extension module needs
changes to compile on python 3.

To run only python 2.7:

    $ tox -e py27

To run only test from some modules:

    $ tox tests/daemon_test.py

To run only tests matching the substring "foo":

    $ tox -- -k foo

To run basic lint and style check:

    $ tox -e flake8

Sometimes when debugging failing tests verbose mode is useful. You can
enable it using:

    $ tox -e py36 tests/python_test.py -- -vv

Or using environment variable:

    export PYTEST_ADDOPTS=-vv


Testing 4K support
==================

To enable the 4k tests, you need to have userstorage installed.
First, you need to create a virtual environment
(https://docs.python.org/3/library/venv.html), and then install
the userstorage library from the requirements.txt.
This only needs to be done once:

    $ python3 -m venv ~/.venv/sanlock
    $ source ~/.venv/sanlock/bin/activate
    $ pip install --upgrade pip
    $ pip install -r requirements.txt
    $ deactivate

Before running the tests, you need to enter the virtual environment:

    $ source ~/.venv/sanlock/bin/activate

The shell prompt will change to show the virtual environment name:

    (sanlock) [user@hostname sanlock]$

Then, you just need to setup 4k storage for the tests:

    $ userstorage create tests/storage.py

This creates two loop devices with 4k sector size; one for testing sanlock with
4k block device, and the other for testing with a filesystem backed by a 4k
block device.

To teardown the storage:

    $ userstorage delete tests/storage.py

The script unmounts the filesystem and detaches the loop devices.

The storage helper script uses sudo to perform privileged operations. The best
way to use it is to setup the environment once at the start of the session, and
teardown when you finish.

To deactivate the virtual environment:

    $ deactivate
