nova/HACKING.rst
James Carey 298b0328d2 Remove use of str on exceptions
An exception's message can be a translatable message.  If it is, the message
can contain unicode characters which will cause str to fail.

In cases where the message is explicity needed, the use of str is replaced
with the use of six.text_type.  When an exception is used as a replacement
string in a format string, the logger correctly handles it without the
need for str, so it is removed.

In addition to the case where a translatable message contains unicode,
enabling lazy translation in the oslo.i18n library causes translatable
messages to be replaced with an object that does not support str, this
causes all calls to str on a translatable message to fail.  Thus this patch
is also needed to support blueprint: i18n-enablement.

This patch includes a hacking check for use of str() on exceptions identified
in except statements.

Change-Id: Idb426d7f710ea69b835f70d0e883e93e9b9111d2
Partially-Implements: blueprint i18n-enablement
2014-08-27 13:55:34 +01:00

98 lines
4.5 KiB
ReStructuredText

Nova Style Commandments
=======================
- Step 1: Read the OpenStack Style Commandments
http://docs.openstack.org/developer/hacking/
- Step 2: Read on
Nova Specific Commandments
---------------------------
- ``nova.db`` imports are not allowed in ``nova/virt/*``
- [N309] no db session in public API methods (disabled)
This enforces a guideline defined in ``nova.openstack.common.db.sqlalchemy.session``
- [N310] timeutils.utcnow() wrapper must be used instead of direct calls to
datetime.datetime.utcnow() to make it easy to override its return value in tests
- [N311] importing code from other virt drivers forbidden
Code that needs to be shared between virt drivers should be moved
into a common module
- [N312] using config vars from other virt drivers forbidden
Config parameters that need to be shared between virt drivers
should be moved into a common module
- [N313] capitalize help string
Config parameter help strings should have a capitalized first letter
- [N314] vim configuration should not be kept in source files.
- [N315] We do not use @authors tags in source files. We have git to track
authorship.
- [N316] Change assertTrue(isinstance(A, B)) by optimal assert like
assertIsInstance(A, B).
- [N317] Change assertEqual(type(A), B) by optimal assert like
assertIsInstance(A, B)
- [N318] Change assertEqual(A, None) or assertEqual(None, A) by optimal assert like
assertIsNone(A)
- [N319] Validate that debug level logs are not translated.
- [N320] Setting CONF.* attributes directly in tests is forbidden. Use
self.flags(option=value) instead.
- [N321] Validate that LOG messages, except debug ones, have translations
- [N322] Method's default argument shouldn't be mutable
- [N323] Ensure that the _() function is explicitly imported to ensure proper translations.
- [N324] Ensure that jsonutils.%(fun)s must be used instead of json.%(fun)s
- [N325] str() cannot be used on an exception. Remove use or use six.text_type()
Creating Unit Tests
-------------------
For every new feature, unit tests should be created that both test and
(implicitly) document the usage of said feature. If submitting a patch for a
bug that had no unit test, a new passing unit test should be added. If a
submitted bug fix does have a unit test, be sure to add a new one that fails
without the patch and passes with the patch.
For more information on creating unit tests and utilizing the testing
infrastructure in OpenStack Nova, please read ``nova/tests/README.rst``.
Running Tests
-------------
The testing system is based on a combination of tox and testr. The canonical
approach to running tests is to simply run the command ``tox``. This will
create virtual environments, populate them with dependencies and run all of
the tests that OpenStack CI systems run. Behind the scenes, tox is running
``testr run --parallel``, but is set up such that you can supply any additional
testr arguments that are needed to tox. For example, you can run:
``tox -- --analyze-isolation`` to cause tox to tell testr to add
--analyze-isolation to its argument list.
Python packages may also have dependencies that are outside of tox's ability
to install. Please refer to doc/source/devref/development.environment.rst for
a list of those packages on Ubuntu, Fedora and Mac OS X.
It is also possible to run the tests inside of a virtual environment
you have created, or it is possible that you have all of the dependencies
installed locally already. In this case, you can interact with the testr
command directly. Running ``testr run`` will run the entire test suite. ``testr
run --parallel`` will run it in parallel (this is the default incantation tox
uses.) More information about testr can be found at:
http://wiki.openstack.org/testr
Building Docs
-------------
Normal Sphinx docs can be built via the setuptools ``build_sphinx`` command. To
do this via ``tox``, simply run ``tox -evenv -- python setup.py build_sphinx``,
which will cause a virtualenv with all of the needed dependencies to be
created and then inside of the virtualenv, the docs will be created and
put into doc/build/html.
If you'd like a PDF of the documentation, you'll need LaTeX installed, and
additionally some fonts. On Ubuntu systems, you can get what you need with::
apt-get install texlive-latex-recommended texlive-latex-extra texlive-fonts-recommended
Then run ``build_sphinx_latex``, change to the build dir and run ``make``.
Like so::
tox -evenv -- python setup.py build_sphinx_latex
cd build/sphinx/latex
make
You should wind up with a PDF - Nova.pdf.