A 'gabbi' tox target is added which runs a declarative HTTP tests
described in YAML files in 'ceilometer/tests/gabbi/gabbits' and loaded by
'ceilometer/tests/gabbi/test_gabbi.py'. These are driven by the 'gabbi'
python package (available from PyPI).
tox and testr are configured to start and run the tests efficiently:
* a mongodb server, using multiple databases, is made available
* the API wsgi application is used directly via 'wsgi-intercept', no
web server required
* each YAML file is run as a sequence and where number of processors
allows, in a different test process
* individual tests can be requested in the usual way:
tox -egabbi -- <test pattern>
If this is done, all the tests prior to the one requested, from
its YAML file, will be run as ordered prerequisites.
* tox targets that already run the tests in ceilometer/tests will
also discover gabbi tests. If there is no mongodb, they will
be skipped.
A ConfigFixture does the necessary work of adjusting the configuration
and pipeline to use the mongodb database and nothing else. An
internal InterceptFixture uses wsgi-intercept to access the
ceilometer API. Each yaml file has its own intercepted host.
Fixtures are implemented as nested context managers that are declared
per YAML file, see ceilometer/gabbi/fixtures.py and fixtures-samples.yaml
for an example of how they can be used. Every yaml file uses at
least ConfigFixture.
YAML files can use a variety of strategies for formatting requests
and evaluating the correctness of response. See:
http://gabbi.readthedocs.org/en/latest/format.html
The YAML files included here test simple API features for creating and
retrieving samples. Subsequent patches can (and should) create
additional YAML files to describe more complex scenarios that cover
the entire API (for example alarms are not touched at all by this
patch).
Change-Id: I52551f88bc3beac4bf8a92afa45ac70cd97ffcec
Implements: blueprint declarative-http-tests
3.8 KiB
Working with the Source
Setting up a Development Sandbox
Set up a server or virtual machine to run OpenStack using devstack.
Clone the ceilometer project to the machine:
$ cd /opt/stack $ git clone https://git.openstack.org/openstack/ceilometer $ cd ./ceilometerOnce this is done, you need to setup the review process:
$ git remote add gerrit ssh://<username>@review.openstack.org:29418/openstack/ceilometer.gitIf you are preparing a patch, create a topic branch and switch to it before making any changes:
$ git checkout -b TOPIC-BRANCH
Running the Tests
Ceilometer includes an extensive set of automated unit tests which are run through tox.
Install
tox:$ sudo pip install toxOn Ubuntu install
mongodbandlibmysqlclient-devpackages:$ sudo apt-get install mongodb $ sudo apt-get install libmysqlclient-devFor Fedora20 there is no
libmysqlclient-devpackage, so you’ll need to installmariadb-devel.x86-64(ormariadb-devel.i386) instead:$ sudo yum install mongodb $ sudo yum install mariadb-devel.x86_64Install the test dependencies:
$ sudo pip install -r /opt/stack/ceilometer/test-requirements.txtRun the unit and code-style tests:
$ cd /opt/stack/ceilometer $ tox -e py27,pep8As tox is a wrapper around testr, it also accepts the same flags as testr. See the testr documentation for details about these additional flags.
Use a double hyphen to pass options to testr. For example, to run only tests under tests/api/v2:
$ tox -e py27 -- api.v2To debug tests (ie. break into pdb debugger), you can use ''debug'' tox environment. Here's an example, passing the name of a test since you'll normally only want to run the test that hits your breakpoint:
$ tox -e debug ceilometer.tests.test_binFor reference, the
debugtox environment implements the instructions here: https://wiki.openstack.org/wiki/Testr#Debugging_.28pdb.29_TestsThere is a growing suite of tests which use a tool called gabbi to test and validate the behavior of the Ceilometer API. These tests are run when using the usual
py27tox target but if desired they can be run by themselves:$ tox -e gabbiThe YAML files used to drive the gabbi tests can be found in
ceilometer/tests/gabbi/gabbits. If you are adding to or adjusting the API you should consider adding tests here.
Code Reviews
Ceilometer uses the OpenStack review process for all code and developer documentation contributions. Code reviews are managed through gerrit.