Skip to content

Commit 72398f1

Browse files
author
Sean M. Collins
committed
Developer documentation
* Turns TESTING into a rst file, that we include in the developer documentation, for instructions on how to run the unit tests. * Link to a Vagrant project that sets up Neutron inside a VM. * Adds a section for how to debug with Nose * Add new section for Neutron Internals * Neutron L2 Agent documentation - currently only OVS * Make the Security Group API extension an example of how an API extension is implemented Implements bp developer-documentation Change-Id: I9b452abc9da3b1a41ae65cff727967de0eab12fe
1 parent 0d78a25 commit 72398f1

14 files changed

+506
-160
lines changed

TESTING

-100
This file was deleted.

TESTING.rst

+180
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
Testing Neutron
2+
=============================================================
3+
4+
Overview
5+
--------
6+
7+
The unit tests are meant to cover as much code as possible and should
8+
be executed without the service running. They are designed to test
9+
the various pieces of the neutron tree to make sure any new changes
10+
don't break existing functionality.
11+
12+
The functional tests are intended to validate actual system
13+
interaction. Mocks should be used sparingly, if at all. Care
14+
should be taken to ensure that existing system resources are not
15+
modified and that resources created in tests are properly cleaned
16+
up.
17+
18+
Development process
19+
-------------------
20+
21+
It is expected that any new changes that are proposed for merge
22+
come with tests for that feature or code area. Ideally any bugs
23+
fixes that are submitted also have tests to prove that they stay
24+
fixed! In addition, before proposing for merge, all of the
25+
current tests should be passing.
26+
27+
Virtual environments
28+
~~~~~~~~~~~~~~~~~~~~
29+
30+
Testing OpenStack projects, including Neutron, is made easier with `DevStack <https://github.com/openstack-dev/devstack>`_.
31+
32+
Create a machine (such as a VM or Vagrant box) running a distribution supported
33+
by DevStack and install DevStack there. For example, there is a Vagrant script
34+
for DevStack at https://github.com/bcwaldon/vagrant_devstack.
35+
36+
.. note::
37+
38+
If you prefer not to use DevStack, you can still check out source code on your local
39+
machine and develop from there.
40+
41+
42+
Running unit tests
43+
------------------
44+
45+
There are three mechanisms for running tests: run_tests.sh, tox,
46+
and nose. Before submitting a patch for review you should always
47+
ensure all test pass; a tox run is triggered by the jenkins gate
48+
executed on gerrit for each patch pushed for review.
49+
50+
With these mechanisms you can either run the tests in the standard
51+
environment or create a virtual environment to run them in.
52+
53+
By default after running all of the tests, any pep8 errors
54+
found in the tree will be reported.
55+
56+
57+
With `run_tests.sh`
58+
~~~~~~~~~~~~~~~~~~~
59+
60+
You can use the `run_tests.sh` script in the root source directory to execute
61+
tests in a virtualenv::
62+
63+
./run_tests -V
64+
65+
66+
With `nose`
67+
~~~~~~~~~~~
68+
69+
You can use `nose`_ to run individual tests, as well as use for debugging
70+
portions of your code::
71+
72+
source .venv/bin/activate
73+
pip install nose
74+
nosetests
75+
76+
There are disadvantages to running Nose - the tests are run sequentially, so
77+
race condition bugs will not be triggered, and the full test suite will
78+
take significantly longer than tox & testr. The upside is that testr has
79+
some rough edges when it comes to diagnosing errors and failures, and there is
80+
no easy way to set a breakpoint in the Neutron code, and enter an
81+
interactive debugging session while using testr.
82+
83+
.. _nose: https://nose.readthedocs.org/en/latest/index.html
84+
85+
With `tox`
86+
~~~~~~~~~~
87+
88+
Neutron, like other OpenStack projects, uses `tox`_ for managing the virtual
89+
environments for running test cases. It uses `Testr`_ for managing the running
90+
of the test cases.
91+
92+
Tox handles the creation of a series of `virtualenvs`_ that target specific
93+
versions of Python (2.6, 2.7, 3.3, etc).
94+
95+
Testr handles the parallel execution of series of test cases as well as
96+
the tracking of long-running tests and other things.
97+
98+
Running unit tests is as easy as executing this in the root directory of the
99+
Neutron source code::
100+
101+
tox
102+
103+
For more information on the standard Tox-based test infrastructure used by
104+
OpenStack and how to do some common test/debugging procedures with Testr,
105+
see this wiki page:
106+
107+
https://wiki.openstack.org/wiki/Testr
108+
109+
.. _Testr: https://wiki.openstack.org/wiki/Testr
110+
.. _tox: http://tox.readthedocs.org/en/latest/
111+
.. _virtualenvs: https://pypi.python.org/pypi/virtualenv
112+
113+
114+
Running individual tests
115+
~~~~~~~~~~~~~~~~~~~~~~~~
116+
117+
For running individual test modules or cases, you just need to pass
118+
the dot-separated path to the module you want as an argument to it.
119+
120+
For executing a specific test case, specify the name of the test case
121+
class separating it from the module path with a colon.
122+
123+
For example, the following would run only the JSONV2TestCase tests from
124+
neutron/tests/unit/test_api_v2.py::
125+
126+
$ ./run_tests.sh neutron.tests.unit.test_api_v2:JSONV2TestCase
127+
128+
or::
129+
130+
$ ./tox neutron.tests.unit.test_api_v2:JSONV2TestCase
131+
132+
Adding more tests
133+
~~~~~~~~~~~~~~~~~
134+
135+
Neutron has a fast growing code base and there is plenty of areas that
136+
need to be covered by unit and functional tests.
137+
138+
To get a grasp of the areas where tests are needed, you can check
139+
current coverage by running::
140+
141+
$ ./run_tests.sh -c
142+
143+
Debugging
144+
---------
145+
146+
By default, calls to pdb.set_trace() will be ignored when tests
147+
are run. For pdb statements to work, invoke run_tests as follows::
148+
149+
$ ./run_tests.sh -d [test module path]
150+
151+
It's possible to debug tests in a tox environment::
152+
153+
$ tox -e venv -- python -m testtools.run [test module path]
154+
155+
Tox-created virtual environments (venv's) can also be activated
156+
after a tox run and reused for debugging::
157+
158+
$ tox -e venv
159+
$ . .tox/venv/bin/activate
160+
$ python -m testtools.run [test module path]
161+
162+
Tox packages and installs the neutron source tree in a given venv
163+
on every invocation, but if modifications need to be made between
164+
invocation (e.g. adding more pdb statements), it is recommended
165+
that the source tree be installed in the venv in editable mode::
166+
167+
# run this only after activating the venv
168+
$ pip install --editable .
169+
170+
Editable mode ensures that changes made to the source tree are
171+
automatically reflected in the venv, and that such changes are not
172+
overwritten during the next tox run.
173+
174+
Post-mortem debugging
175+
~~~~~~~~~~~~~~~~~~~~~
176+
177+
Setting OS_POST_MORTEM_DEBUG=1 in the shell environment will ensure
178+
that pdb.post_mortem() will be invoked on test failure::
179+
180+
$ OS_POST_MORTEM_DEBUG=1 ./run_tests.sh -d [test module path]

doc/source/devref/api_extensions.rst

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
==============
2+
API Extensions
3+
==============
4+
5+
API extensions is the standard way of introducing new functionality
6+
to the Neutron project, it allows plugins to
7+
determine if they wish to support the functionality or not.
8+
9+
Examples
10+
========
11+
12+
The easiest way to demonstrate how an API extension is written, is
13+
by studying an existing API extension and explaining the different layers.
14+
15+
.. toctree::
16+
:maxdepth: 1
17+
18+
security_group_api

doc/source/devref/api_layer.rst

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Neutron WSGI/HTTP API layer
2+
===========================
3+
4+
`Yong Sheng Gong: Deep Dive into Neutron <http://www.slideshare.net/gongys2004/inside-neutron-2>`_

doc/source/devref/db_layer.rst

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Neutron Database Layer
2+
======================

doc/source/devref/development.environment.rst

+1-59
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,6 @@ that describes `setting up Neutron using DevStack`_.
3737
.. _DevStack: https://github.com/openstack-dev/devstack
3838
.. _setting up Neutron using Devstack: https://wiki.openstack.org/wiki/NeutronDevstack
3939

40-
Virtual environments
41-
--------------------
42-
43-
Testing OpenStack projects, including Neutron, is made easier with `DevStack`_.
44-
45-
Create a machine (such as a VM or Vagrant box) running a distribution supported
46-
by DevStack and install DevStack there. For example, there is a Vagrant script
47-
for DevStack at https://github.com/jogo/DevstackUp.
48-
49-
.. note::
50-
51-
If you prefer not to use DevStack, you can still check out source code on your local
52-
machine and develop from there.
53-
5440
Getting the code
5541
----------------
5642

@@ -60,48 +46,4 @@ Grab the code from GitHub::
6046
cd neutron
6147

6248

63-
Running unit tests
64-
------------------
65-
66-
With `run_tests.sh`
67-
~~~~~~~~~~~~~~~~~~~
68-
69-
You can use the `run_tests.sh` script in the root source directory to execute
70-
tests in a virtualenv:
71-
72-
./run_tests -V
73-
74-
With `tox`
75-
~~~~~~~~~~
76-
77-
Neutron, like other OpenStack projects, uses `tox`_ for managing the virtual
78-
environments for running test cases. It uses `Testr`_ for managing the running
79-
of the test cases.
80-
81-
Tox handles the creation of a series of `virtualenvs`_ that target specific
82-
versions of Python (2.6, 2.7, 3.3, etc).
83-
84-
Testr handles the parallel execution of series of test cases as well as
85-
the tracking of long-running tests and other things.
86-
87-
Running unit tests is as easy as executing this in the root directory of the
88-
Neutron source code::
89-
90-
tox
91-
92-
For more information on the standard Tox-based test infrastructure used by
93-
OpenStack and how to do some common test/debugging procedures with Testr,
94-
see this wiki page:
95-
96-
https://wiki.openstack.org/wiki/Testr
97-
98-
.. _Testr: https://wiki.openstack.org/wiki/Testr
99-
.. _tox: http://tox.readthedocs.org/en/latest/
100-
.. _virtualenvs: https://pypi.python.org/pypi/virtualenv
101-
102-
103-
Using a remote debugger
104-
-----------------------
105-
106-
.. todo:: Beef up and add examples to content at
107-
https://wiki.openstack.org/wiki/NeutronDevelopment#How_to_debug_Neutron_.28and_other_OpenStack_projects_probably_.29
49+
.. include:: ../../../TESTING.rst

0 commit comments

Comments
 (0)