2012-05-03 10:48:26 -07:00
|
|
|
Cinder Style Commandments
|
2013-07-12 16:47:01 +01:00
|
|
|
=========================
|
2012-05-03 10:48:26 -07:00
|
|
|
|
2013-07-12 16:47:01 +01:00
|
|
|
- Step 1: Read the OpenStack Style Commandments
|
2013-11-11 11:28:18 -08:00
|
|
|
http://docs.openstack.org/developer/hacking/
|
2013-07-12 16:47:01 +01:00
|
|
|
- Step 2: Read on
|
2012-05-03 10:48:26 -07:00
|
|
|
|
2013-07-12 16:47:01 +01:00
|
|
|
Cinder Specific Commandments
|
|
|
|
----------------------------
|
2014-08-03 12:46:45 -05:00
|
|
|
- [N314] Check for vi editor configuration in source files.
|
2015-08-22 07:45:47 +00:00
|
|
|
- [N319] Validate that debug level logs are not translated.
|
2014-08-03 12:46:45 -05:00
|
|
|
- [N322] Ensure default arguments are not mutable.
|
2014-08-02 18:06:38 -05:00
|
|
|
- [N323] Add check for explicit import of _() to ensure proper translation.
|
2015-08-22 07:45:47 +00:00
|
|
|
- [N325] str() and unicode() cannot be used on an exception. Remove or use six.text_type().
|
2015-03-19 08:37:49 -05:00
|
|
|
- [N328] LOG.info messages require translations `_LI()`.
|
|
|
|
- [N329] LOG.exception and LOG.error messages require translations `_LE()`.
|
|
|
|
- [N330] LOG.warning messages require translations `_LW()`.
|
2014-12-24 22:42:58 +08:00
|
|
|
- [N336] Must use a dict comprehension instead of a dict constructor with a sequence of key-value pairs.
|
2015-02-27 16:06:03 +02:00
|
|
|
- [C301] timeutils.utcnow() from oslo_utils should be used instead of datetime.now().
|
2015-08-22 07:45:47 +00:00
|
|
|
- [C302] six.text_type should be used instead of unicode.
|
2015-04-06 11:22:09 -05:00
|
|
|
- [C303] Ensure that there are no 'print()' statements in code that is being committed.
|
2015-08-22 07:45:47 +00:00
|
|
|
- [C304] Enforce no use of LOG.audit messages. LOG.info should be used instead.
|
2015-04-06 14:02:31 -05:00
|
|
|
- [C305] Prevent use of deprecated contextlib.nested.
|
2015-03-19 13:24:00 +01:00
|
|
|
- [C306] timeutils.strtime() must not be used (deprecated).
|
2015-05-13 09:30:20 -05:00
|
|
|
- [C307] LOG.warn is deprecated. Enforce use of LOG.warning.
|
2015-05-16 14:39:23 +02:00
|
|
|
- [C308] timeutils.isotime() must not be used (deprecated).
|
2015-07-01 15:14:57 -05:00
|
|
|
- [C309] Unit tests should not perform logging.
|
2015-09-03 12:07:19 -05:00
|
|
|
- [C310] Check for improper use of logging format arguments.
|
2015-09-14 20:37:00 -05:00
|
|
|
- [C311] Check for proper naming and usage in option registration.
|
2015-11-17 12:39:58 -06:00
|
|
|
- [C312] Check that assertIsNone(value) is used and not assertEqual(None, value).
|
|
|
|
- [C313] Check that assertTrue(value) is used and not assertEqual(True, value).
|
2014-08-01 15:43:51 -05:00
|
|
|
|
2012-05-03 10:48:26 -07:00
|
|
|
General
|
|
|
|
-------
|
2013-06-24 15:19:50 +04:00
|
|
|
- Use 'raise' instead of 'raise e' to preserve original traceback or exception being reraised::
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
...
|
|
|
|
raise e # BAD
|
|
|
|
|
|
|
|
except Exception:
|
|
|
|
...
|
|
|
|
raise # OKAY
|
2012-05-03 10:48:26 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
2014-01-21 18:00:05 +02:00
|
|
|
Cinder is transitioning to use mock, rather than mox, and so new tests should
|
|
|
|
use mock only.
|
|
|
|
|
2012-05-03 10:48:26 -07:00
|
|
|
For more information on creating unit tests and utilizing the testing
|
2016-07-01 15:08:43 +05:30
|
|
|
infrastructure in OpenStack Cinder, please see
|
|
|
|
http://docs.openstack.org/developer/cinder/devref/testing.html
|