Commit Graph

113 Commits

Author SHA1 Message Date
Brian Haley 542c2ff463 Update hacking version
Update hacking to a more recent version, along with
flake8-import-order.

Remove N347 (import mock library) check as that is the
default with later hacking versions.

Update the builtins override of '_' to be the neutron.i18n
version due to the code triggering a false positive. This
is done in a couple of other projects as well.

Fix a number of new warnings it found.

Added some ignore directives for new whitespace issues
found in the test tree, can fix later.

TrivialFix

Change-Id: I5923255af86cf1fa11ab8e3b03bb9efac7dd7b58
2024-02-08 10:34:10 -05:00
Brian Haley bd0fec95fa Use convert_version_to_tuple() throughout tree
Most code uses convert_version_to_tuple() from
oslo_utils.versionutils to determine minimum version
numbers, but there were two places that used the
packaging.version class instead. Change to always
use the same code throughout the tree.

Also added a flake8 enforcement check for it so we
don't regress.

TrivialFix

Change-Id: Ida4dcd504562646f0a450160e57680a44c387b1d
2023-10-20 18:03:21 -04:00
Brian Haley 86badcfe2d Fix some pylint indentation warnings
Running with a stricter .pylintrc generates a lot of
C0330 warnings (hanging/continued indentation). Fix
some remaining ones in miscellaneous directories.

Also cleanup any remaining code that I missed in this
series, or has changed since I started.

Trivialfix

Change-Id: I17b4779020a7bfb369c3e721ab6638cd4a6ab50c
2022-12-12 11:48:25 -05:00
Rajesh Tailor 8ab5ee1d17 Fix remaining typos in comments and tests
Change-Id: I872422cffd1f9a2e59b5e18a86695e5cb6edc2cd
2022-07-06 21:20:27 +05:30
Takashi Natsume 05ee23ea15 Follow up for replacing assertItemsEqual
The assertItemsEqual has been replaced with assertCountEqual
since I7c20fec08e5dc9f67b34100c925ea6724bbd25f0 .
However the hacking check has not been enabled.

This patch enables the hacking check
and replace remaining assertItemsEqual with assertCountEqual.

Signed-off-by: Takashi Natsume <takanattie@gmail.com>
Change-Id: I86202f36f1b7c0bce8b29558ad1e377c336b7258
2021-06-03 16:04:07 +00:00
Zuul 309639ca89 Merge "Replace assertItemsEqual with assertCountEqual" 2021-04-26 19:12:38 +00:00
gugug 62729d4e74 Replace assertItemsEqual with assertCountEqual
assertItemsEqual was removed from Python's unittest.TestCase in
Python 3.3 [1][2]. We have been able to use them since then, because
testtools required unittest2, which still included it. With testtools
removing Python 2.7 support [3][4], we will lose support for
assertItemsEqual, so we should switch to use assertCountEqual.

NOTE(dmllr): added hacking check

[1] - https://bugs.python.org/issue17866
[2] - https://hg.python.org/cpython/rev/d9921cb6e3cd
[3] - testing-cabal/testtools#286
[4] - testing-cabal/testtools#277

Change-Id: I7c20fec08e5dc9f67b34100c925ea6724bbd25f0
2020-11-30 10:21:57 +01:00
Rodolfo Alonso Hernandez ddd5832323 Remove "six" library
Last step to remove "six" library usage in Neutron.

Change-Id: Idd42e0c51c8c3bd598c9cf91602596be238bccae
2020-07-28 16:55:52 +00:00
Brian Haley 9760f123aa Catch additional invalid mock import statement
As noted in the change to only use unittest.mock,
'from mock import foo' is not treated as invalid, so add it now.

Trivialfix

Change-Id: I256af9316a2a85f91aeb3c511305d006a51d7246
2020-05-19 17:25:33 -04:00
Akihiro Motoki 52e3fee5ef Switch to hacking 3.0.1
In hacking 2.0 or later, local-check-factory was removed as it is not
compatible with flake8 3.x and it is advised to use flake8's local
plugins [1]. neutron-lib provided a factory to register common hacking
rules, but it no longer works with hacking 2, so we need to define rules
defined in neutron-lib as flake8 local check plugin [2] explicitly.
This needs to be done in each neutron related project, so it is the
downside of the migration to hacking 2.x (I explored a way to continue
to use the factory but failed to find a good way to achieve this) but
I believe it is good to migrate the newer libraries.

* flake8ext decorator in neutron/hacking/checks.py is also replaced with
  hacking.core.flake8ext to avoid the copy-and-paste code.
* neutron-lib dependency is updated as neutron-lib 2.3 added hacking 3 support.
* Python modules related to coding style checks (listed in blacklist.txt in
  openstack/requirements repo) are dropped from lower-constraints.txt
  as they are not actually used in tests (other than pep8).
* HackingDocTestCase is now converted into normal test cases.
  HackingDocTestCase depends on the internal of hacking and pycodestyle
  so it looks better to use normal style of writing tests.

[1] https://docs.openstack.org/releasenotes/hacking/unreleased.html#relnotes-2-0-0
[2] https://flake8.pycqa.org/en/3.7.0/user/configuration.html#using-local-plugins

Change-Id: I92cf50a84bb587a0649a7cffee15cce4ce37d086
2020-05-12 16:58:41 -04:00
Brian Haley 8126f88894 Complete removal of dependency on the "mock" package
Now that we are python3 only, we should move to using the built
in version of mock that supports all of our testing needs and
remove the dependency on the "mock" package.

This completes removal of all references to "import mock",
changing to "from unittest import mock" in fullstack and
functional tests.

Added a hacking check to enforce it in future patches.

Change-Id: Ifcaf1c21bea0ec3c35278e49cecc90a101a82113
2020-05-01 12:05:34 -04:00
Igor Malinovskiy 248cdaa6f7 Allow usage of assert_called_once method in unit tests
mock.assert_called_once is valid method since Python 3.6
but it's not allowed to use it in neutron because of
outdated flake8 check.

Change-Id: I8cdcc0e32618613472139ad9094bb19d562d6426
2020-03-02 14:17:26 +02:00
Rodolfo Alonso Hernandez 7e0c44e21f Remove references to unittest2 library
Library "unittest2" has not released a new version since
Jun 30 2015 [1]. Neutron should remove the references to
this library and point to "unittest" instead.

[1] https://pypi.org/project/unittest2/#history

Change-Id: I7d55adc262280c0c2f13b9b81ecc582e1729afa0
Closes-Bug: #1859190
2020-01-14 09:03:26 +00:00
Michael Johnson d1d0a04c37 Remove Neutron LBaaS
Neutron-LBaaS has now been retired and there will be no Train
release[1]. This patch removes neutron-lbaas references from
neutron.

[1] https://review.opendev.org/658494

Closes-Bug: #1833125
Change-Id: I0fe3fbaf4adf7fb104632fd94cd093e701e12289
2019-09-20 07:46:06 +00:00
Boden R 9f41850ba3 remove neutron.db.api references
While the initial version of this patch removed neutron.db.api, a
different duplicate patch [1] landed first.

This patch cleans up the remining references to neutron.db.api
including those in the docs and comments.

[1] https://review.openstack.org/#/c/635978/

Change-Id: I5f911f4c6a1fc582a9c1006ec5e2880853ff2909
2019-03-05 09:14:50 -07:00
Boden R c774930aed use sqla functions from neutron-lib
The public db apis are available in neutron-lib. This patch consumes
the sqla_listen, sqla_remove and sqla_remove_all functions from lib
by removing them from neutron and using lib's version.

There's also a TODO added here so we can eventually rehome the
check_no_sqlalchemy_event_import hacking check to neutron-lib.

NeutronLibImpact

Change-Id: I3b3862016125303fb227b4ff41420a89bb33c917
2018-07-25 21:04:20 +00:00
Jakub Libosvar e56e6b6b0f hacking: Remove dead code
Checks for logs translation were removed. Code in this patch is not used
anywhere.

Change-Id: Ia8b6ce545ed0182825fc9d32eedfdf7b949c27d0
2017-07-19 13:43:44 +02:00
Ihar Hrachyshka 9c1e48e79d Switch to neutron-lib hacking factory
This allows us to kill a bunch of in-tree checks. There are still some
checks that are either not yet in the library, or don't belong there in
the first place, so we still stick to our own factory, just reusing
whatever is there in neutron-lib.

This change skips some new checks. We gotta figure out what to do with
those, that will belong in a separate follow-up.

Change-Id: Ifeb40ec0e0c4ca623b33a6b9f500dec15cec4de0
2017-04-13 07:41:25 -07:00
Inessa Vasilevskaya fb64e7de49 hacking: disable log translations check
In order to stay along with log translation guidelines [1]
N320 check should be disabled.

[1] https://docs.openstack.org/developer/oslo.i18n/guidelines.html#log-translation

Change-Id: If45d8dfe256893194b06d0d1139c907665a0605a
2017-04-04 20:34:33 +03:00
Anna Khmelnitsky 67882e5f19 Fix copy-paste error in hacking checks
N344 was shown as N343

Change-Id: Ia257c3a19751f6d84d33516fe58bfd83b33c15da
2017-03-17 16:01:04 -07:00
Kevin Benton 553ab6d86e Register sqlalchemy events through hook for UT cleanup
Register all sqlalchemy events through a new function in
neutron.db.api so we can keep track of active events and
ensure all are removed at the end of each test run.

Without this, an instance of a plugin may be left around
with the only reference to it existing in SQLAlchemy, where
it will receive events for tests unrelated to it and potentially
interfere.

Change-Id: I8e93eb4e8ef5a13f015db9cd20e44941cdcb72ef
2017-01-20 04:15:01 -08:00
Jenkins 7e8f609b10 Merge "Removed deprecated checks" 2016-11-22 20:53:53 +00:00
Jenkins 0c563b804d Merge "Replace assertEqual(None, *) with assertIsNone in tests" 2016-11-22 02:15:19 +00:00
gengchc2 f276a96d84 Replace assertEqual(None, *) with assertIsNone in tests
Replace assertEqual(None, *) with assertIsNone in tests to
have more clear messages in case of failure.

Change-Id: Ice018dfd3e48326ce9cac58342d03979559b9e82
2016-11-16 03:54:04 +00:00
Ihar Hrachyshka 4e25ba840a Switch to new hacking 0.12
The release includes its own check for delayed string interpolation for
log messages, so we can now remove our own check for the same thing. The
check is off-by-default, so we need to explicitly enable it. Sadly,
select= directive in tox.ini is broken [1] so we need to enable the
check with flake8 argument instead.

[1] https://github.com/PyCQA/pycodestyle/issues/390

Change-Id: Idc6b8e5b1cb594e130d4cc0cbcfffd362f9ab86a
2016-11-08 03:36:00 +00:00
Dariusz Smigiel 1cd0585884 Removed deprecated checks
Change I4644ab087abc441beed52a170df8b5279fed76a4 changed functions
check_asserttrue and check_assertfalse into check_asserttruefalse.
Please use latter.

Change-Id: Ifb38143a0045dd29c81b3507554196ab9b19c787
Related-Bug: #1594756
2016-11-07 20:24:45 +00:00
Ihar Hrachyshka 31e1aeb66b Forbid importing neutron.tests.* from outside tests subtree
neutron-sanity-check tool was importing neutron.tests.base module, which
may be not present on some systems (f.e. RDO splits neutron/tests/
subtree in a separate python-neutron-tests package). It made the tool
not usable in some setups.

https://bugzilla.redhat.com/show_bug.cgi?id=1374282

This is not the first time when we by mistake import from
neutron.tests.* and break distributions. It's time to stop it by
proactively forbidding that pattern via a new hacking check.

Some functions were moved from neutron.tests.base to
neutron.common.utils to fulfill the need requirement. They were moved
using debtcollector, no current consumers should be affected.

Closes-Bug: #1621782
Change-Id: I790777ddcbd1b02218b3db54ae3d5c931d72d4fa
2016-09-15 18:42:45 +00:00
Nguyen Phuong An 9afb9ca598 Prevent use filter(lambda obj: test(obj), data)
In Python3 [1], if we need filter on python3, replace
filter(lambda obj: test(obj), data) with:
[obj for obj in data if test(obj)]. This patch replaces
filter function and introduces a hacking rule to prevent
using filter in future.

[1] https://wiki.openstack.org/wiki/Python3

Change-Id: I83d22108c02f8da007a7233e71a4a7fb833170ec
2016-09-14 16:23:32 +07:00
Victor Morales 7eff6aff42 Fix check_asserttruefalse syntax validator
According to Neutron developer documentation[1], it's better to use
assertTrue/False methods instead of generic assertEqual. The regex
created for check_asserttruefalse was skipping unit tests located on
test_netns_cleanup.py file.  This change includes those scenarios.

[1] http://docs.openstack.org/developer/neutron/devref/effective_neutron.html#mocking-and-testing

Change-Id: Id2eacf14d4b0740f3b044520074c7ab78768b319
2016-08-11 13:49:47 +00:00
Takashi NATSUME 5cef3f726e 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 a hacking rule for it.

See the oslo i18n guideline.

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

Change-Id: I91e8d59d508c594256d5f74514e62f8f928d1df5
Closes-Bug: #1596829
2016-07-11 22:54:56 +00:00
Jakub Libosvar 3ff5b704a7 pep8: Register checks with their code
pep8 searches for check codes in their docstrings [1]. This allows us to
either ignore or select particular checks by their codes.

e.g. flake8 --select=N333

[1] 4438622d0b/pycodestyle.py (L110)

Change-Id: I4644ab087abc441beed52a170df8b5279fed76a4
Closes-bug: 1594756
2016-06-29 10:12:24 +00:00
Gary Kotton 9e4aaaa345 Hacking: make use of neutron lib
Start to make use of code in the neutron_lib for the hacking.

Its really trivial but lets start to remove duplicate code.

TrivialFix

Change-Id: I3e7eee9a35d3d2b120b0a36ac40d0751a702f952
2016-06-08 05:21:39 -07:00
Martin Hickey afaad48aa3 Use unittest2 uniformly across Neutron
unittest2 contains bug fixes to unittest for all versions of Python<3.5.
Move unittest references to unittest2.

Bumped hacking requirement to reflect the version in
openstack/requirements that is the minimal version that supports
off_by_default checks.

Change-Id: I2d26534230ffe5d01aa0aab6ec902f81cfba774d
Depends-On: I883223962426ed8e9cdf4e304dfed17ef0946c8a
2016-05-23 13:13:17 +00:00
Akihiro Motoki 44be13a2a6 Hacking rule to check i18n usage
* Detect neutron.i18n import (neutron._i18n is recommended)
* Check builtins _ usage
* 'builtins = _' in tox.ini is no longer required.
* Introduce hacking rule doctest framework.
  Newly added check_builtins_gettext() hacking check takes
  token as argument. It is not a good idea to pass a tokenized
  line manually. Instead it is reasonable to use docstring based
  tests used in hacking repo.

Change-Id: Ib7464658fc4c8a6f1b03af6ab46f0bd3ee0bfb18
2016-03-30 21:28:37 -04:00
LiuNanke 83ef6b5677 Using LOG.warning replace LOG.warn
Python 3 deprecated the logger.warn method, see:
https://docs.python.org/3/library/logging.html#logging.warning
so we prefer to use warning to avoid DeprecationWarning.

Closes-Bugs: #1529913

Change-Id: Icc01ce5fbd10880440cf75a2e0833394783464a0
Co-Authored-By: Gary Kotton <gkotton@vmware.com>
2016-03-10 11:02:45 -08:00
Ihar Hrachyshka 8a03a20726 hacking: remove oslo.* import check
Oslo libraries don't ship oslo.* namespace anymore (since Liberty). Time
to clean those up.

Change-Id: I86f571c576141d3574a0b5efd0f62670ed6e2dcd
2016-03-03 12:47:53 +01:00
Bo Wang fd0ed209d2 Stop using non-existent method of Mock
There is no method called_once_with() in Mock object.
Use assert_called_once_with() instead.

Change-Id: I263c407ba2a82f53aace5f71cb27ad8974335e24
Closes-Bug: #1544522
2016-02-18 11:32:49 +08:00
lzklibj 0f50d8c06f Add hacking check for assertEqual HTTP code
Add a hacking check for wrong usage, like:
  assertEqual(observed.code, webob.exc.HTTP**.code)
the correct usage should be:
  assertEqual(webob.exc.HTTP**.code, observed.code)

Change-Id: I8c038bae61c528d30af43e904a9bb98ac4cd4d3a
2016-02-06 00:01:08 +08:00
lzklibj d2a1d6fcb7 Unify using assertIsInstance
Use assertIsInstance(A, B) to replace assertTrue(isinstance(A, B)).

Prefer specific assertions such as assert(Not)IsInstance over generic ones
(assertTrue/False, assertEqual) because they raise more meaningful errors.

Change-Id: I56278b1a74108e2765a8a740658f33954f5404c7
Closes-bug: #1268480
2016-01-15 00:06:03 +08:00
lzklibj 3491cbc0c5 Unify assertEqual for empty usages
Update previous assertEqual(observed, *empty) usages to
assertEqual(*empty*, observed).

This patch aslo update hacking check for assertEqual with
empty types.

Change-Id: I981277618f92254a5beb9d3308a317d8c14e125c
2016-01-07 10:06:35 +00:00
Gary Kotton 0ce4510b35 HACKING: fix edge case with log hints
A log message with _() was not raised as an error, for example:
LOG.info(_('who let the dogs out!')).

This should be:
LOG.info(_LI('who who who who!'))

Change-Id: I040f01b19ff5de00467b80be7399b998534d9a57
Closes-bug: #1522054
2015-12-02 06:52:25 -08:00
Hirofumi Ichihara ae1fb6e872 Use assertFalse(observed) instead of assertEqual(False, observed)
The patch also improves the way in which the assertTrue (and
similarly assertFalse) are done,

We should use assertFalse not assertEqual.

Co-Authored-By: Gary Kotton <gkotton@vmware.com>

Closes-Bug: #1503074

Change-Id: I5f527ddf2ca522cdf101de2482d59f059eca010f
2015-11-12 22:50:57 +09:00
Gary Kotton 2b7fb6ff08 Removes the use of mutables as default args
Passing mutable objects as default args is a known Python pitfall.
We'd better avoid this. This commit changes mutable default args with
None, then use 'arg = arg or {}', 'arg = arg or []'. For unit code which
doesn't use the args , just set with None. This commit also adds hacking
check.

This code was taken from commit 0bea84ac20fe498bd08f7212a0017196c8cb0812
in Nova.

Change-Id: I36d07cade687690dc02a8f6cc3d70f5d00caf112
Co-Authored-By: ChangBo Guo(gcb) <glongwave@gmail.com>
2015-10-29 07:57:31 -07:00
Hirofumi Ichihara 2c62cd6ec0 Use assertTrue(observed) instead of assertEqual(True, observed)
We should use assertTrue not assertEqual.

Closes-Bug: #1503071

Change-Id: Ib75dd9f8965fd04fe581f09a5e5df3df43542d89
2015-10-09 23:13:58 +09:00
Kyle Mestery 724c78071d Restructure agent code in preparation for decomp
This commit moves the L2 agents (Linuxbridge and OVS) into the
ML2 directory, while at the same time also moving the ML2 server
bits into toplevel directories. It also moves the configuration
files and unit tests. We also move the l2pop RPC mixin while
here as well.

DocImpact
UpgradeImpact

Partially-Implements: blueprint reference-implementation-split
Partial-Bug: #1468433
Closes-Bug: #1427317
Change-Id: If6feca7b7a6bdd6c3c6feb929fa26fb4b1f72770
Signed-off-by: Kyle Mestery <mestery@mestery.com>
2015-06-26 15:06:49 +00:00
Cyril Roelandt 3751f9ab34 Python3: use six.iteritems() instead of dict.iteritems()
This also adds a check to neutron/hacking/checks.py that should catch this
error in the future.

Blueprint: neutron-python3
Change-Id: Ie7b833ffa173772d39b85ee3ecaddace18e1274f
2015-06-01 23:13:42 +02:00
Adrien Vergé 422588e133 Get completely rid of contextlib.nested
`contextlib.nested` is deprecated since Python 2.7 and incompatible with
Python 3. This patch removes all its occurences by using the helper
script at [1].

This is a necessary step to allow us running all unit tests with
Python 3 (not just a small subset as it is done now).

[1]: https://github.com/adrienverge/context_unnester

Change-Id: I8d1de09ff38ed0af9fb56f423a2c43476408e0fb
Blueprint: neutron-python3
Closes-Bug: #1428424
2015-05-29 23:18:46 +02:00
Jenkins ed8c4ed539 Merge "Fix dhcp _test_sync_state_helper asserting calls wrong" 2015-05-29 17:43:40 +00:00
ankitagrawal 8ee3020c47 Remove use of contextlib.nested (api-tests)
Removed use of contextlib.nested call from codebase, as it has been
deprecated since Python 2.7.

There are also known issues with contextlib.nested that were addressed
by the native support for multiple "with" variables. For instance, if
the first object is created but the second one throws an exception,
the first object's __exit__ is never called. For more information see
https://docs.python.org/2/library/contextlib.html#contextlib.nested
contextlib.nested is also not compatible with Python 3.

Multi-patch set for easier chunks. This one addresses the tests from
neutron/tests/unit/api directory.

Line continuation markers (e.g. '\') had to be used or syntax
errors were thrown. While using parentheses is the preferred way
for multiple line statements, but in case of long with statements
backslashes are acceptable.

Partial-Bug: 1428424
Change-Id: I09673f9d4c7f07d3043804676fef018905dd1239
2015-05-26 02:57:08 -07:00
ankitagrawal 032847b303 Remove use of contextlib.nested
Removed use of contextlib.nested call from codebase, as it has been
deprecated since Python 2.7.

There are also known issues with contextlib.nested that were addressed
by the native support for multiple "with" variables. For instance, if
the first object is created but the second one throws an exception,
the first object's __exit__ is never called. For more information see
https://docs.python.org/2/library/contextlib.html#contextlib.nested
contextlib.nested is also not compatible with Python 3.

Multi-patch set for easier chunks. This one addresses the
neutron/plugins/ml2 directory.

Line continuation markers (e.g. '\') had to be used or syntax
errors were thrown. While using parentheses is the preferred way
for multiple line statements, but in case of long with statements
backslashes are acceptable.

Partial-Bug: 1428424
Change-Id: I7bbe4cec511125b4b2c954aa93e2d9ff6871b9e0
2015-05-21 14:48:28 -07:00