deb-ceilometer/doc/source/contributing/source.rst
Chris Dent 552c63849e Declarative HTTP testing for the Ceilometer API
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
2015-02-03 13:03:39 +00:00

3.8 KiB
Raw Blame History

Working with the Source

Setting up a Development Sandbox

  1. Set up a server or virtual machine to run OpenStack using devstack.

  2. Clone the ceilometer project to the machine:

    $ cd /opt/stack
    $ git clone https://git.openstack.org/openstack/ceilometer
    $ cd ./ceilometer
  3. Once this is done, you need to setup the review process:

    $ git remote add gerrit ssh://<username>@review.openstack.org:29418/openstack/ceilometer.git
  4. If 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.

  1. Install tox:

    $ sudo pip install tox
  2. On Ubuntu install mongodb and libmysqlclient-dev packages:

    $ sudo apt-get install mongodb
    $ sudo apt-get install libmysqlclient-dev

    For Fedora20 there is no libmysqlclient-dev package, so youll need to install mariadb-devel.x86-64 (or mariadb-devel.i386) instead:

    $ sudo yum install mongodb
    $ sudo yum install mariadb-devel.x86_64
  3. Install the test dependencies:

    $ sudo pip install -r /opt/stack/ceilometer/test-requirements.txt
  4. Run the unit and code-style tests:

    $ cd /opt/stack/ceilometer
    $ tox -e py27,pep8

    As 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.v2

    To 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_bin

    For reference, the debug tox environment implements the instructions here: https://wiki.openstack.org/wiki/Testr#Debugging_.28pdb.29_Tests

  5. There 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 py27 tox target but if desired they can be run by themselves:

    $ tox -e gabbi

    The 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.