This commit is the result of running the following search and replace
across the project.
s/nova.db/placement.db/g
Change-Id: If5ea7cfd361288c89db885c26b7c616ce5b596d4
The 'yield' statement is not a function.
So it must always be followed by a space when yielding a value.
Change-Id: Ie2aa1c4822d8adf721ba71d467b63209bede6fb7
This adds a pep8 function that will check for redundant import aliases.
Any imports of the forms below will not be allowed.
from x import y as y
import x as x
import x.y as y
Change-Id: Iff90f0172d97bd1d49d54c811a70c8af11776da4
The testing strategy doc was linking to the hacking repo docs
on creating unit tests, which are very specific to creating
unit tests for hacking rules.
This changes the link to the 'creating unit tests' section in
the HACKING.rst file, which has more information on testing
within nova.
Along with that change, the HACKING.rst testing section is
updated a bit to point out that we use stestr now instead of
testr and adds a proper link to the development environment
quickstart docs.
The nova/tests/unit/README.rst actually needs a lot of work,
but that's left for another day.
Change-Id: Ie5106d87d632286162b31ce132e947c306d21abd
Closes-Bug: #1732024
In this patchset, I set up 'enabled-extensions' in flake8 section
of tox.ini. In newer hacking versions, we can enable some of the
non-default hacking rules (one by one), which are disabled by default
and implemented in the newer versions of hacking. The enabled extensions
are the following:
* [H106] Don’t put vim configuration in source files (off by default).
* [H203] Use assertIs(Not)None to check for None (off by default).
* [H904] Delay string interpolations at logging calls (off by default).
Together with enabling these rules, I also removed the locally
implemented versions of them. Due to limitations of local checking
engine, there were some places in the tests, where pep8 failed.
In this patchset, these codes are also fixed.
Change-Id: I3a9d2dc007a269cdb2cad441e22f5eb9b58ce0a0
Some place in Nova, return value has unnecessary parentheses,
or return keyword is not followed by a space when returning a value,
which is a bad format and might be ambigous. For example:
return(1)
return{
'a': 1
}
As noone would write returns like:
return1
return'(empty)'
In this patchset we get rid of this bad formation.
Also, I've added a hacking rule which helps to prevent this in future.
TrivialFix
Change-Id: I4ff85d0240bf8719188ebd06fc0e98a81c1d1203
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
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
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
LOG.warn is deprecated. It is still used in few modules.
Replaced with non-deprecated LOG.warning.
Change-Id: Ia6acc11eca60c652844175a5742f626732e295e3
Closes-Bug: #1508442
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
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
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
Add hacking check for deprecated library function os.popen().
This hacking prevents new os.popen() in the code.
Closes-Bug: 1529836
Change-Id: I09ad101861b790d2f9bec45757b8c921e68b696e
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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