100 Commits

Author SHA1 Message Date
hussainchachuliya
a862aa0f3d hacking: Use uuidutils or uuidsentinel to generate UUID
Added hacking check to ensure that UUID is being generated from
oslo_utils.uuidutils or uuidsentinel(in case of test cases)
instead of uuid4().

Change-Id: I73ee63fbd4f451d3aa5dc1a2a734d68c308b4440
2016-11-29 11:49:24 +05:30
Stephen Finucane
09e2bcf3f5 hacking: Use assertIs(Not), assert(True|False)
This is per the OpenStack style guidelines.

Change-Id: Iec102872e2d5b004255ce897cc22c4d1a41c6f9e
Co-authored-by: Gabor Antal <antal@inf.u-szeged.hu>
2016-10-12 11:14:33 +01:00
Takashi NATSUME
4eb89c206e Add a hacking rule for string interpolation at logging
String interpolation should be delayed to be handled
by the logging code, rather than being done
at the point of the logging call.
So add the following hacking rule for it.

- [N354] String interpolation should be delayed at logging calls.

See the oslo i18n guideline.

* http://docs.openstack.org/developer/oslo.i18n/guidelines.html

Change-Id: Ief6d3ee3539c0857098fffdb7acfeec3e0fed6eb
Closes-Bug: #1596829
2016-10-11 08:39:48 +00:00
Sivasathurappan Radhakrishnan
b3d58ed718 Remove context object in oslo.log method
Removed context object while logging as Nova uses oslo.context's
RequestContext which means the context object is in scope when doing
logging. Added hack to notify, in case if someone uses it in logging
statements in future.

Change-Id: I5aaa869f2e6155964827e659d18e2bcaad9d866b
Closes-Bug:#1500896
2016-09-27 18:02:08 +00:00
Stephen Finucane
ebc0219a50 hacking: Always use 'assertIs(Not)None'
This is per the OpenStack style guidelines.

Change-Id: Ia706045fe3524b6b5e1db0140672776d481a0c01
2016-09-23 15:40:35 +01:00
sonu.kumar
059d257b94 Add hacking checks for xrange()
Partially-Implements: blueprint goal-python35

Change-Id: Iea2e9e5d5782b898ba5b18314745962cc059a213
2016-09-22 04:16:53 +00:00
Markus Zoeller
0b0e7dacf5 Remove hacking check [N347] for config options.
The check for help texts (N347) can be better done by humans.
This change removes it.

Change-Id: I0861c94f764d559be8f188d3e4b54b2b8ad39ea5
2016-08-11 14:23:21 +02:00
yatin karel
ecb24c5f1b Replace deprecated LOG.warn with LOG.warning
LOG.warn is deprecated. It is still used in few modules.
Replaced with non-deprecated LOG.warning.

Change-Id: Ia6acc11eca60c652844175a5742f626732e295e3
Closes-Bug: #1508442
2016-07-20 14:39:15 +05:30
Andrew Laski
219d970d13 Hacking check for _ENFORCER.enforce()
In order to ensure that only registered policies are used for
authorization checks _ENFORCER.authorize should be used rather than
_ENFORCER.enforce. This adds a check to look for instances of
_ENFORCER.enforce being used.

Change-Id: Iee78e93a3e1d4c6c30681b18698b7fc9cb6fa982
Implements: bp policy-in-code
2016-07-01 14:16:06 -04:00
Andrew Laski
f8f83b4751 Hacking check for policy registration
Ensure that policy registration happens in the centralized
nova/policies/ directory. There is an exception for the test_policy unit
tests because some of them register rules for testing.

Change-Id: Ia51eeb09eff86f82528b27bdc11a71762dfaed1a
Partially-Implements: bp policy-in-code
2016-07-01 13:54:36 -04:00
Jenkins
0c172d5c6f Merge "Add a hacking check for test method closures" 2016-04-04 11:08:43 +00:00
Anh Tran
a2d0d65a29 Removes some redundant words
This patch removes some redundant words.

Change-Id: I1461ad1d98272b0d6223fd989861885902c12617
2016-03-25 09:10:36 +07:00
Dan Smith
f6e4713bf6 Add a hacking check for test method closures
A recurring pattern when using multiple mocks is to create a closure
decorated with mocks like:

    def test_thing(self):
            @mock.patch.object(self.compute, 'foo')
            @mock.patch.object(self.compute, 'bar')
            def _do_test(mock_bar, mock_foo):
                # Test things
        _do_test()

However it is easy to leave off the _do_test() and have the test pass
because nothing runs. This check looks for that pattern.

Co-Authored-By: Andrew Laski <andrew@lascii.com>
Change-Id: I4c2395a01470acc7c9e5bcf1d3578d00270a2c07
2016-03-17 15:49:55 -04:00
kairoaraujo
b4a3193c20 Hacking: check for deprecated os.popen()
Add hacking check for deprecated library function os.popen().
This hacking prevents new os.popen() in the code.

Closes-Bug: 1529836

Change-Id: I09ad101861b790d2f9bec45757b8c921e68b696e
2016-02-19 21:55:20 -02:00
Markus Zoeller
1216449dc4 config options: add hacking check for help text length
Adds a hacking check if a config option provides enough help text.
To do so, the check counts the length of the help text. It uses
a low number in order to avoid a break. As soon as we have agreed
on a higher standard and changed the options accordingly, we can
increase that number.

Change-Id: If31339c428953c6a7bf721ff92e5999e8cb5b569
2016-02-03 11:31:23 +01:00
abhishekkekane
e8f82596b8 Python3: Replace dict.iteritems with six.iteritems
This also adds a check to nova/hacking/checks.py that
should check dict.iteritems, dict.itervalues and
dict.iterkeys should not be used in the future.

NOTE:
In _dict_from_object() method of test_db_api.py items() method
is called on dict and iteritems() method is called if object is
other than dict. Changed it to directly use obj.items as obj can
either be dict or object of nova.db.sqlalchemy.models.<Class> and
both have items() method.

Partially-Implements: blueprint nova-python3-mitaka

Change-Id: Ib0fe3066199b92e4f013bb15312ada7515fa3d7b
2016-01-21 21:41:52 -08:00
Daniel P. Berrange
aaff356e18 hacking: check for common double word typos
Adds a local hacking check for common double word typos
like "the the", "to to", etc.

Change-Id: I824a4a4b0f3bc18a16d5df50bd66cc626888ebaf
2016-01-14 12:21:03 +00:00
Markus Zoeller
adf268def3 add hacking check for config options location
This adds a hackign check which raises a pep8 error if a config
option was found in location where it shouldn't be.

Change-Id: I75df3404cc6178aa179e96d75f154e389c3008af
2015-11-26 19:24:19 +01:00
Davanum Srinivas
32246daee4 hacking check for contextlib.nested for py34 support
Removed use of contextlib.nested call from codebase as
contextlib.nested is not compatible with Python 3.

Added hacking check to catch if any new instances are added
to the codebase.

Change-Id: Ib78102bc013e4cc91ba54d79aa2815f4cf9f446d
2015-10-16 17:26:27 +00:00
Jenkins
55251dbb96 Merge "Add hacking check for eventlet.spawn()" 2015-10-08 03:43:00 +00:00
Simon Pasquier
aa13d01a90 Fix typo in HACKING.rst
Change-Id: Ib4d0beb033211db63148d3de0a46e9f6e11904f9
2015-09-16 13:10:12 +02:00
Ryan Rossiter
6179854ae7 Add hacking check for eventlet.spawn()
Change Id52c30bb5ded2184d772e6026b0f04f9a0efeb55 added a hacking check
for greenthread.spawn(). Since eventlet.spawn() calls
greenthread.spawn() under the covers, it should also be checked. Because
there are still occurrences of eventlet.spawn(), these were also cleaned
up in order to pass the added hacking check.

Co-Authored-By: Qin Zhao <chaochin@gmail.com>

Change-Id: Ia125b4ad5e84bf48091af5a7a483b89629f0ec31
Related-Bug: #1404268
Closes-Bug: #1468513
2015-08-13 20:44:41 +00:00
Ryan Rossiter
97821a9c7e Add hacking check for greenthread.spawn()
Because greenthread.spawn() and spawn_n() are missing a nova context
(see I3623e60c49e442e2431cf017540422aa59bc285a and
Ia5175c9729069df3d779237ba6039cf5bc920018), nova.utils.spawn() and
spawn_n() should be used when spawning threads. This change adds a
hacking check to assert this is being done during pep8.

Change-Id: Id52c30bb5ded2184d772e6026b0f04f9a0efeb55
Related-Bug: #1404268
Closes-Bug: #1468513
2015-08-11 16:09:48 +00:00
Davanum Srinivas
83d6548bbe Remove unnecessary oslo namespace import checks
Latest oslo libraries do not support the old oslo
namespace based imports, so the import check in our hacking
rules are redundant as CI jobs will fail for sure if someone
tries to use oslo namespace based imports.

Change-Id: I49c74ade374582f53a3678a1bc7df194c24e892e
2015-07-23 11:01:19 +00:00
Jenkins
7d39811f74 Merge "Update HACKING.rst for running tests and building docs" 2015-07-20 16:03:32 +00:00
Matthew Treinish
62575dd40e
Add tool to build a doc latex pdf
The sphinx latex generation generates invalid latex that won't compile
when you try to use it.[1][2] This commit adds a helper script to generate
the sphinx latex and then modify it so it'll work. It depends on
ImageMagick convert and sed being available to work.

[1] https://github.com/sphinx-doc/sphinx/issues/1907
[2] https://github.com/sphinx-doc/sphinx/issues/1959

Change-Id: Id289c10907aaddae2483f18b39063852ec699d66
2015-07-14 16:13:47 -04:00
Matt Riedemann
f72b7e35c8 Update HACKING.rst for running tests and building docs
There are three updates here:

1. Point to the correct path of development.environment.rst.
2. Update the path to test_wsgi.py after the test restructure
   that happened in Kilo.
3. Just tell people to use `tox -e docs` for building docs.

Change-Id: I03295a6d9c90e9a2962999726d254bc4971c4909
2015-07-14 11:56:45 -07:00
Ken'ichi Ohmichi
198a3bea23 Add a hacking rule for consistent HTTP501 message
There is raise_feature_not_supported() for returning a HTTP501
response with consistent error message, and this patch adds a rule
for enforcing to use the method on v2.1 API.

Partially implements blueprint v2-on-v3-api

Change-Id: I06f254fd9c8d8b6aac4ed135c6c407f3a993431f
2015-06-08 03:06:49 +00:00
Jenkins
e9200ba51f Merge "Add note on running single tests to HACKING.rst" 2015-03-03 15:55:42 +00:00
Jenkins
36619550fb Merge "Treat LOG.warning and LOG.warn same" 2015-02-06 20:44:57 +00:00
Jenkins
9e304ebe26 Merge "Added hacking rule for assertEqual(a in b, True/False)." 2015-02-05 17:13:04 +00:00
jichenjc
4dddcf3643 Treat LOG.warning and LOG.warn same
8510d3aaeeb18bdbe333d2d5d4c335f3732c4848 removed N331
checking, so now we need treat LOG.warn and LOG.warning
same, so this patch adds the same checking to LOG.warn.

Change-Id: Ifb3addfe116f8f7abb8750826b0217dfbd766439
2015-02-05 15:05:18 +08:00
jichenjc
8510d3aaee Remove N331 hacking rules
Per discussion in
https://review.openstack.org/#/c/145506/
https://review.openstack.org/#/c/135888/
there is no need to check whether warn or warning usage since
py3 support both. So according to the suggestion, this patch
removes N331 check.

Change-Id: I20a62c1d1e953f52a63565b8446f1561d178d5af
2015-01-27 06:10:19 +08:00
Kashyap Chamarthy
cf472ab15c HACKING.rst: Update the location of unit tests' README.rst
As part of this commit 89cd6a0c493e26b5a9e017c99d731464292abbaf ("move
all tests to nova/tests/unit") README.rst was moved from nova/tests/ to
nova/tests/unit/. Update HACKING.rst to reflect that.

Change-Id: I282baac560d6035e453542812c36b505ddc07bc1
2015-01-23 14:14:03 +01:00
Jenkins
f7270765a1 Merge "Remove non existent rule N327 from HACKING.rst" 2015-01-22 21:07:35 +00:00
Sergey Nikitin
16774b6d33 Added hacking rule for assertEqual(a in b, True/False).
The following replacements were done in tests to have
clearer messages in case of failure:
- assertEqual(a in b, True) with assertIn(a, b)
- assertEqual(a in b, False) with assertNotIn(a, b)

The error message would now be like:
   'abc' not in ['a', 'b', 'c']
rather than:
   MismatchError: False != True

Change-Id: I514daca3a470feef5d332a1a319cba15256fc6ea
2015-01-22 11:57:44 +03:00
Mike Durnosvistov
6ab942dd19 Don't translate exceptions in tests
Exception lines in unit tests won't ever be run in production, no reason to
translate them.

Added hacking rule for not importing i18n translation in tests.

Change-Id: I92f546166d4e0b2fa8dc2018c6d3e268b8ec4c0b
2015-01-21 14:39:11 +02:00
ChangBo Guo(gcb)
69fef14509 Performance: leverage dict comprehension in PEP-0274
PEP-0274 introduced dict comprehensions to replace dict constructor
with a sequence of length-2 sequences, these are benefits copied
from [1]:
  The dictionary constructor approach has two distinct disadvantages
  from the proposed syntax though.  First, it isn't as legible as a
  dict comprehension.  Second, it forces the programmer to create an
  in-core list object first, which could be expensive.
Nova dropped python 2.6 support, we can leverage this now.
There is deep dive about PEP-0274[2] and basic tests about
performance[3].
Note: This commit doesn't handle dict constructor with kwagrs.
This commit also adds a hacking rule.

[1]http://legacy.python.org/dev/peps/pep-0274/
[2]http://doughellmann.com/2012/11/12/the-performance-impact-of-using-dict-instead-of-in-cpython-2-7-2.html
[3]http://paste.openstack.org/show/154798/

Change-Id: Ifb5cb05b9cc2b8758d5a8e34f7792470a73d7c40
2015-01-16 10:06:13 +08:00
Davanum Srinivas
c3d10b7a62 Do not use deprecated assertRaisesRegexp()
The unit test log ends up with DeprecationWarning(s) from the outdated
calls to assertRaisesRegexp. We should switch to using assertRaisesRegex
instead. This commit eliminates these warnings from the log and the hacking
rule N344 ensures that folks don't end up adding fresh code down the line
with the outdated assertRaisesRegexp as well

Partial-Bug: #1407736

Change-Id: Ifba672f7568d5159c63bf88c534812e4e3a26d5a
2015-01-14 22:04:45 -05:00
Jenkins
efe19fab90 Merge "Added hacking rule for assertTrue/False(A in B)" 2015-01-13 15:23:11 +00:00
Joe Gordon
fe9072edde Remove non existent rule N327 from HACKING.rst
N327 was removed in e0d22ba4dea6d7b70faba14c6918fbc2151983a5

Change-Id: Ie433b4708d9df7fb3c6ac230c48dc953402b2055
2015-01-10 21:45:08 +00:00
Joe Gordon
571893ab42 Replace Hacking N315 with H105
Don't use author tags is H105 in hacking 0.10, so drop local rule N315
in favor of H105.

Change-Id: I38bf2ff5247817d58723f28e87607f16f3d9c374
2015-01-10 21:45:08 +00:00
Sergey Nikitin
b6d30549c6 Added hacking rule for assertTrue/False(A in B)
The following replacements were done in tests to have
clearer messages in case of failure:
- assertTrue(a in b) with assertIn(a, b)
- assertTrue(a not in b) with assertNotIn(a, b)
- assertFalse(a in b) with assertNotIn(a, b)

The error message would now be like:
   'abc' not in ['a', 'b', 'c']
rather than:
   'False is not True'.

Change-Id: I92d039731f17b731d302c35fb619300078b8a638
2015-01-07 12:25:53 +03:00
Davanum Srinivas
19aa89149c Prevent new code from using namespaced oslo imports
Ib63da2d845843410634a1df0261af33b973daf32 is an example where
new code had to be fixed for oslo_concurrency imports. Let us
add a hacking check to prevent such regression. When we update
to new oslo libraries with non-namespace'd imports, we should
update the regexp in this hacking rule

Change-Id: I44536d477d06ddc1205b824bcb888b666405dce3
2014-12-28 16:00:47 +00:00
Matthew Gilliard
f5c29e98c2 Adds hacking check for api_version decorator
Because of the implementation of this decorator and the controller's metaclass,
the api_version decorator must be the outermost (ie first) decorator wherever
it is used. This patch adds a hacking check to ensure that this is the case.

This decorator is intended to be used on multiple methods with the same name
which offends F811, so '#noqa' is needed too. This will be fixed in a separate
patch.

Bad:
    @some_decorator # noqa  <-- '# noqa' to avoid F811
    @api_version("2.5")     <-- Error, needs to be the first decorator
    def my_api_method...

Good:
    @api_version("2.5") # noqa   <-- this line still needs '# noqa' for F811
    @some_decorator
    def my_api_method...

Change-Id: I579c0061f03d788c477c5424d4d00ec7a6e721e1
2014-12-08 08:35:38 +00:00
Mike Durnosvistov
e8c0b822f0 Replacement _ on _LW in all LOG.warning part 1
oslo.i18n uses different marker functions to separate the
translatable messages into different catalogs, which the translation
teams can prioritize translating. For details, please refer to:
http://docs.openstack.org/developer/oslo.i18n/guidelines.html#guidelines-for-use-in-openstack

There were not marker fuctions some places in directory network.
This commit makes changes:
* Add missing marker functions
* Use ',' instead of '%' while adding variables to log messages

Added a hacking rule for the warning about checking
translation for it and checking logging level `warning` instead
alias `warn`.

Change-Id: I2bced49dc5a0408a94d5d20d85b20c682886edbe
2014-11-20 11:19:16 +02:00
Mike Durnosvistov
b7535793af Replacement _ on _LE in all LOG.exception
oslo.i18n uses different marker functions to separate the
translatable messages into different catalogs, which the translation
teams can prioritize translating.  For details, please refer to:
http://docs.openstack.org/developer/oslo.i18n/guidelines.html#guidelines-for-use-in-openstack

There were not marker fuctions some places in directory network.
This commit makes changes:
* Add missing marker functions
* Use ',' instead of '%' while adding variables to log messages

Added a hacking rule for the log exception about checking
translation for it.

Change-Id: If80ea6f177bb65afcdffce71550bb38fedcc54eb
2014-11-20 11:19:09 +02:00
Mike Durnosvistov
8431670ef8 Replacement _ on _LI in all LOG.info - part 1
oslo.i18n uses different marker functions to separate the
translatable messages into different catalogs, which the translation
teams can prioritize translating. For details, please refer to:
http://docs.openstack.org/developer/oslo.i18n/guidelines.html#guidelines-for-use-in-openstack

There were not marker fuctions some places in directory network.
This commit makes changes:
* Add missing marker functions
* Use ',' instead of '%' while adding variables to log messages

Added a hacking rule for the log info about checking
translation for it.

Change-Id: I96766d723b01082339876ed94bbaa77783322b8c
2014-11-20 10:19:17 +02:00
Ian Wienand
b971870d64 Add note on running single tests to HACKING.rst
I haven't done this in a while, and I went through a number of false
starts forgetting the "--", trying to specify "filename:TestClass"
etc. before I got it to work.  Hopefully this saves someone else some
time.

Change-Id: I94590009157cce8d42002089304c66c164bcd6ec
2014-10-31 20:14:59 +11:00
James Carey
6683905b53 Remove use of unicode on exceptions
Casting exceptions to unicode using unicode() can interfere
with the proper translation of the exception message.  This
is especially true when lazy translation is enabled, since it
causes the exception message to be translated immediately using
the default locale.

This is the same problem caused by using str on exceptions,
which was fixed by https://review.openstack.org/#/c/116054/

In addition to fixing these cases, this patch updates
hacking check N325, which checks for the use of str() on
exceptions, to also check for the use of unicode().

In order to make it clear which cases that cannot be caught
by the hacking check have been inspected, they have been
converted to using six.text_type() instead of unicode().

Closes-bug: #1380806
Change-Id: I87bb94fa76458e028beba28d092320057b53f70a
2014-10-22 18:05:48 +00:00