Add the following hacking rule.
* N372: Don't use the setDaemon method.
Use the daemon attribute instead.
Change-Id: Idb45421205f76d2d3b0576bd0504d261ed249edd
Related-Bug: 1987191
Signed-off-by: Takashi Natsume <takanattie@gmail.com>
Since we dropped support for python 2 [1], we no longer need to use the
mock library, which existed to backport py3 functionality into py2.
Change Ib44b5bff657c8e76c4f701e14d51a4efda3f6d32 cut over to importing
the stock mock, which must be done by saying::
from unittest import mock
...because if you say::
import mock
...you will be using the third party mock library instead, which may or
may not be installed.
This commit adds hacking check N371 to enforce the former.
[1] https://review.opendev.org/#/c/687954/
Change-Id: I71439580e80d33cff62aba807df2b35164a47cbe
Spotted this in a review recently. We don't want people using six
anymore.
Change-Id: Ie107a95bc06390ab519d3b3af9b07103a9a14316
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This is a follow up change to I168fffac8002f274a905cfd53ac4f6c9abe18803
which added a hackaround to enable our tests to pass with
fasteners>=0.15 which was upgraded recently as part of a
openstack/requirements update.
The ReaderWriterLock from fasteners (and thus lockutils) cannot work
correctly with eventlet patched code, so this adds a wrapper containing
the aforementioned hackaround along with a hacking check to do our best
to ensure that future use of ReaderWriterLock will be through the
wrapper.
Change-Id: Ia7bcb40a21a804c7bc6b74f501d95ce2a88b09b5
As the bug and fix If71620e808744736cb4fe3abda76d81a6335311b showed
it is dangerous to forget instantiating the Mock class before it is
used in the test as changes on the class directly leaks out from the
test. In almost all the cases using Mock class directly is a bug and the
author original intention is to use an instance instead, just forgot
about the parents. So this patch adds two new hacking rules:
N367: catches the case when Mock class is aliased in the test:
self.mock_mystuff = mock.Mock
N368: catches when mock.patch instructed to use the Mock class as
replacement value during patching:
mock.patch('Bar.foo', new=mock.Mock)
For N367 the previous patch removed the last hit. For N368 this patch
removes the two hits exists.
Change-Id: Id42ca571b1569886ef47aa350369e9d2068e77bc
Related-Bug: #1936849
Merge these, removing an unnecessary layer of abstraction, and place
them in the new 'nova.db.main' directory. The resulting change is huge,
but it's mainly the result of 's/sqlalchemy import api/main import api/'
and 's/nova.db.api/nova.db.main.api/' with some necessary cleanup. We
also need to rework how we do the blocking of API calls since we no
longer have a 'DBAPI' object that we can monkey patch as we were doing
before. This is now done via a global variable that is set by the 'main'
function of 'nova.cmd.compute'.
The main impact of this change is that it's no longer possible to set
'[database] use_db_reconnect' and have all APIs automatically wrapped in
a DB retry. Seeing as this behavior is experimental, isn't applied to
any of the API DB methods (which don't use oslo.db's 'DBAPI' helper),
and is used explicitly in what would appear to be the critical cases
(via the explicit 'oslo_db.api.wrap_db_retry' decorator), this doesn't
seem like a huge loss.
Change-Id: Iad2e4da4546b80a016e477577d23accb2606a6e4
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
Add the following hacking rule.
* N366: The assert_has_calls is a method rather than a variable.
Not correct: mock_method.assert_has_calls = [mock.call(0)]
Correct: mock_method.assert_has_calls([mock.call(0)])
This patch is a follow-up patch for
Id094dd90efde09b9a835d4492f4a92b8f8ad296e.
Change-Id: I892f8c23ee44f2b3518776a9705e3543f3115cae
Signed-off-by: Takashi Natsume <takanattie@gmail.com>
This module was removed in I1b64ea1f5906b0c4dd1d5e311095cfe41e884ff7 and
no longer needs to be worried about.
Change-Id: I6cb74210934f71bb77ad775ea6671b4e2792f8c0
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
The Python 2.7 Support has been dropped since Ussuri.
So remove hacking rules for compatibility between python 2 and 3.
- [N325] str() and unicode() cannot be used on an exception.
Remove or use six.text_type()
- [N327] Do not use xrange(). xrange() is not compatible with Python 3.
Use range() or six.moves.range() instead.
- [N344] Python 3: do not use dict.iteritems.
- [N345] Python 3: do not use dict.iterkeys.
- [N346] Python 3: do not use dict.itervalues.
See also line 414 in https://etherpad.opendev.org/p/nova-victoria-ptg
Change-Id: If4335b2e8ef5bbabba37598110c1aa8269635c2f
Implements: blueprint six-removal
Signed-off-by: Takashi Natsume <takanattie@gmail.com>
The N319 check previously asserted that debug-level logs were not
translated. Now that we've removed all log translations, we can
generalize this to all logs. We reuse the same number since these
numbers are really just metadata and not public contracts.
This also allows us to update the N323 and N326 checks, which ensure we
import the translation function, '_', wherever it's used and don't
concatenate translated and non-translated strings. Since we're no longer
translating logs and the '_LE', '_LW' and '_LI' symbols are no longer
provided, we don't need to consider logs in either of these cases.
Change-Id: I64d139ad660bc382e8b9d7c8cd03352b26aadafd
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
Once again, do what we did for '_LE' and '_LW' and remove the final
remnants of the log translation effort.
Change-Id: Id6cf7a9bfbe69d6d3e65303e62403d1db9188a84
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This bumps the version of flake8 and pycodestyle to something much
newer, which resolves a long-standing warning about nested sets and
allows us to use new fangled features like f-strings if we so choose.
Change-Id: I0bb9077f1cea2243b7945e87cfa140f9cf89d558
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
Strip out everything matching '(is|use)_neutron', except the tests for
nova-network code and two other places that these tests rely on. Along
the way, remove a whole load of apparently unnecessary mocking that
clearly wasn't caught when we switched over the bulk of testing to use
the neutron network driver.
Change-Id: Ifa9c5c468400261a5e1f66b72c575845173a4f8f
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
Firewall support is not needed with neutron, which supports both
security groups for per-port filtering and FWaaS for per-network
filtering. Remove both the generic firewalls and the hypervisor-specific
implementations.
This part focuses on removing the firewall drivers themselves, which are
now unused. It also updates the release note to note the two additional
config options that are removed here, '[DEFAULT] firewall_driver' and
'[DEFAULT] allow_same_net_traffic'.
Change-Id: I2dccf1610d6cbbb076fda393f1ef695d0be84b13
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
Add a hacking rule for non-existent mock assertion methods and
attributes.
[N364] Non existent mock assertion method or attribute (<name>) is used.
Check a typo or whether the assertion method should begin with
'assert_'.
Change-Id: Ic6860e373120086a1a2ae9953f09a7bbaa032a7b
This one's actually important since it will be an error in future
versions of Python.
Change-Id: Ib9f735216773224f91ac7f49fbe2eee119670872
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
A few places in the code had conditionals including:
if something in (element):
which was clearly intended to be
if something in (element,):
(I.e. `in $tuple`, not `in element` with redundant parens) or just
if something == element:
Fix those [1] and introduce hacking rule N363 to disallow this kind of
thing in the future.
[1] NOTE: These weren't actually latent bugs because
'foo' in ('foo')
which is the same as
'foo' in 'foo'
returns True. In order to be a bug, the left operand would have to be
able to be a substring of the right:
'foo' in ('foobar') # True
'foo' in ('foobar',) # False
...which I don't think is possible in any of the scenarios found.
Change-Id: I950d07eb533e0d43466c58e36b314aaaf8560251
This finalizes the removal of the placement code from nova.
This change primarily removes code and makes fixes to cmd,
test and migration tooling to adapt to the removal.
Placement tests and documention were already removed in
early patches.
A database migration that calls
consumer_obj.create_incomplete_consumers in nova-manage has been
removed.
A functional test which confirms the default incomplete
consumer user and project id has been changes so its its use of
conf.placement.incomplete_* (now removed) is replaced with a
constant. The placement server, running in the functional
test, provides its own config.
placement-related configuration is updated to only register those
opts which are relevant on the nova side. This mostly means
ksa-related opts. placement-database configuration is removed
from nova/conf/database.
tox.ini is updated to remove the group_regex required by the
placement gabbi tests. This should probably have gone when the
placement functional tests went, but was overlooked.
A release note is added which describes that this is cleanup,
the main action already happened, but points people to the
nova to placement upgrade instructions in case they haven't
done it yet.
Change-Id: I4181f39dea7eb10b84e6f5057938767b3e422aff
This brings in a couple of new checks which must be addressed, many of
which involve a rather large amount of changes, so these are ignored for
now. A series of follow-up changes will resolved these.
'pycodestyle' is added as a dependency rather than it being pulled in
transitively. This is necessary since we're using it in tests.
Change-Id: I35c654bd39f343417e0a1124263ff31dcd0b05c9
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
As noted in [1]:
We always import privsep modules like this:
import nova.privsep.libvirt
Not like this:
from nova.privsep import libvirt
This is because it makes it obvious at the caller that a priviledged
operation is occuring:
nova.privsep.libvirt.destroy_root_filesystem()
Not just:
libvirt.destroy_root_filesystem()
This is especially true when the imported module is called "libvirt",
which is a very common term in the codebase and super hard to grep
for specific uses of.
This commit introduces hacking rule N362 to enforce the above.
Change-Id: I9b6aefa015acbf28e49a9ff1713a8bb544586579
Co-Authored-By: Eric Fried <openstack@fried.cc>
Add a hacking rule for the following deprecated methods(*)
in Python 3.
* assertRegexpMatches
* assertNotRegexpMatches
[N361] assertRegex/assertNotRegex must be used instead of
assertRegexpMatches/assertNotRegexpMatches.
*: https://docs.python.org/3.6/library/unittest.html#deprecated-aliases
Change-Id: Icfbaf26a7db6986820e264d1888982b985d613a1
nova/db/__init__.py was importing * from nova.db.api. This meant that
any time any code anywhere within the nova.db package was imported
then nova.db.api was too, leading to a cascade of imports that may
not have been desired. Also, in general, code in __init__.py is a pain.
Therefore, this change adjusts code that so that either:
* nova.db.api is used directly
* nova.db.api is imported as 'db'
In either case, the functionality remains the same.
The primary goal of this change was to make it possible to import the
model files without having to import the db api. Moving the model files
to a different place in the directory hierarchy was considered, but
given that "code in __init__.py is a pain" this mode was chosen.
This looks like a very large change, but it is essentially adjusting
package names, many in mocks.
Change-Id: Ic1fd7c87ceda05eeb96735da2a415ef37060bb1a
This adds a granular policy checking framework for
placement based on nova.policy but with a lot of
the legacy cruft removed, like the is_admin and
context_is_admin rules.
A new PlacementPolicyFixture is added along with
a new configuration option, [placement]/policy_file,
which is needed because the default policy file
that gets used in config is from [oslo_policy]/policy_file
which is being used as the nova policy file. As
far as I can tell, oslo.policy doesn't allow for
multiple policy files with different names unless
I'm misunderstanding how the policy_dirs option works.
With these changes, we can have something like:
/etc/nova/policy.json - for nova policy rules
/etc/nova/placement-policy.yaml - for placement rules
The docs are also updated to include the placement
policy sample along with a tox builder for the sample.
This starts by adding granular rules for CRUD operations
on the /resource_providers and /resource_providers/{uuid}
routes which use the same descriptions from the placement
API reference. Subsequent patches will add new granular
rules for the other routes.
Part of blueprint granular-placement-policy
Change-Id: I17573f5210314341c332fdcb1ce462a989c21940
Two different hacking checks were reporting N357. This changes the
second to report N358 (as comments indicate it was meant to) and
fixes the unit tests to check this.
Change-Id: I35614c61d3a01e31cbcaa193cf7a04c58bdcb310
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 executable is 'nova-policy' - not 'nova-policy-check'.
Change-Id: I3e875a3284935cbb9607f01c7139982da0e11945
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
Starting from oslo.utils 3.20.0,
oslo_utils.uuidutils.generate_uuid can return
"uuid.uuid4().hex" string.
So the following rule has been amended
to use "oslo_utils.uuidutils.generate_uuid(dashed=False)"
instead of "uuid.uuid4().hex".
* N357: Use oslo_utils.uuidutils or uuidsentinel
(in case of test cases) to generate UUID
instead of uuid4().
Change-Id: I990cbfcefb33cc52d70e9be80c780593c536397a
Variables log_translation, log_translation_info, log_translation_exception,
log_translation_LW are no longer used in nova. This patch removes the dead
code in nova
Change-Id: Ia06904e6915012c52352746d09b93826abd576fb
All of the po files for log translation have been deleted from the
Nova tree as of I3206d8bcbffe7ef1d84acf0fac6b423a26fccf94 which has
made all of this infrastructure unused. The mailing list discussions
are pretty much all coming back to the fact that no one ever really
wanted this feature, and it was pushed in purely as a product
requirement checklist.
This removes hacking enforcement of this now unused feature, and will
allow people to start deleting the i18n markup without coming afoul of
hacking.
Change-Id: I9c334162fe1799e7b24563fdc11256b91bbafc9f
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
1.As mentioned in [1], we should avoid using
six.iteritems to achieve iterators. We can
use dict.items instead, as it will return
iterators in PY3 as well. And dict.items/keys
will more readable. 2.In py2, the performance
about list should be negligible, see the link [2].
[1] https://wiki.openstack.org/wiki/Python3
[2] http://lists.openstack.org/pipermail/openstack-dev/2015-June/066391.html
The patch list:
1. cells.
2. compute api.
3. image.
4. network.
5. objects.
6. scheduler.
7. virt.
8. other resources.
Partial-Implements: blueprint replace-iteritems-with-items
Change-Id: Ic6e469eb80ee1774de1374bb36f38b5134b6b311
This adds the basic framework for the nova-status
upgrade check commands. Follow up patches will flesh
this out to perform cells v2 and placement API related
upgrade status checks.
A man page is added for the new CLI and as part of that
the man page index is sorted.
Part of blueprint cells-scheduling-interaction
Part of blueprint resource-providers-scheduler-db-filters
Change-Id: I687dd7317703a1bb76c197ebba849ca368c0872e
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
Updated check_config_option_in_central_place. All options with one exception
were moved to central location. Added list that tracks these exceptions.
Also nova/tests should be treated as an exception - there is another check
that validates if config options are not registered in tests.
Closes-Bug: #1613411
Blueprint centralize-config-options-ocata
Change-Id: I802aaf61e711eb4cfa206e4a52e969128dee2189