ovsdbapp/TESTING.rst
Terry Wilson ed2184fad8 Add ability to debug OVS virtual environments
When writing tests, it is useful to be able to look at the database
being modified. Since we use OVS virtual environments and delete
them when the test ends, this is difficult to do.

This patch adds the ability to pass KEEP_ENV=1 when running tox to
keep the virtual environment around and adds tools/debug_venv to
launch an OVS sandbox using the OVS virtual environment.

Change-Id: Idbec2d544d913ffa8888a050b8a53d016c0315f2
2017-07-13 19:51:31 +00:00

59 lines
2.0 KiB
ReStructuredText

ovsdbapp testing
================
Test preferences
----------------
Most ovsdbapp tests will be functional tests. Unit tests are reserved primarily
for functions that produce a given output for their inputs, regardless of
externalities. Unit tests using mock are acceptable if something is hard to
test without it. BUT, please think carefully before writing a test that makes
heavy use of mock.assert_called_once_with() as those tests *very* often tend
to test what a function *currently does* and not what a function *should do*.
Running tests
-------------
Tests are run with tox. Generally in the form of:
.. code-block:: shell
tox -e <test-type>
Functional tests
----------------
Run the functional tests with:
.. code-block:: shell
tox -e functional
The ovsdbapp functional tests create an OVS virtual environment similar to a
Python virtualenv. OVS will be checked out from git and placed in
.tox/functional/src/ovs and a virtual environment directory will be created.
Various OVS servers will be launched and will store their runtime files in
the virtual environment directory. The tests will then be run against these
servers. Upon test completion, the servers will be killed and the virtual
environment directory deleted. Note that one environment is created per test
process, by default one per-core.
In the event that debugging tests is necessary, it is possible to keep the
virtual environment directories by running:
.. code-block:: shell
KEEP_VENV=1 tox -e functional
This will also write an informational file .tox/functional/ovsvenv.$pid for
each process. The first line of this file is the virtual environment directory
and additional lines are the tests run by this process. To load an OVS
virtualenv for debugging for a particular test (e.g. test_ls_add_name), call:
.. code-block:: shell
tools/debug_venv test_ls_add_name
This will spawn a shell where you can run ovs-vsctl, ovn-nbctl, etc. on the db
used by the test. When finished, type 'exit'. See the debug_venv help for more
options.