Commit Graph

45 Commits (master)

Author SHA1 Message Date
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 <>
Change-Id: I86202f36f1b7c0bce8b29558ad1e377c336b7258
2021-06-03 16:04:07 +00: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
Hervé Beraud 3df1679658 Use unittest.mock instead of mock
The mock third party library was needed for mock support in py2
runtimes. Since we now only support py36 and later, we can use the
standard lib unittest.mock module instead.

Also enabled the hacking check that should have caught this, it
was missing from tox.ini along with most of the other in-tree
hacking checks we have added over the years.

Change-Id: Id91175d0db8b8edc72f0dd98925ddbf7415bb881
2020-06-17 14:42:03 +00: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.


Change-Id: I7d55adc262280c0c2f13b9b81ecc582e1729afa0
Closes-Bug: #1859190
2020-01-14 09:03:26 +00:00
Akihiro Motoki d3c393ff6b Update the documentation link for doc migration
* Update the URLs affected by the doc-migration
  (/developer/<project>/ to <project>/latest/)
* Follow content rearrangement
* Convert links to local documents into :doc: or :ref:
* Use https instead of http for the updated links on

Part of the doc-migration work.

Change-Id: I62e317d9198f175a43d73bbfd419b6878de90d5a
2017-07-22 18:46:13 +09:00
Jakub Libosvar e56e6b6b0f hacking: Remove dead code
Checks for logs translation were removed. Code in this patch is not used

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
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.


Change-Id: Idc6b8e5b1cb594e130d4cc0cbcfffd362f9ab86a
2016-11-08 03:36:00 +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.

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.


Change-Id: I83d22108c02f8da007a7233e71a4a7fb833170ec
2016-09-14 16:23:32 +07: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.


Change-Id: I91e8d59d508c594256d5f74514e62f8f928d1df5
Closes-Bug: #1596829
2016-07-11 22:54:56 +00: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:
so we prefer to use warning to avoid DeprecationWarning.

Closes-Bugs: #1529913

Change-Id: Icc01ce5fbd10880440cf75a2e0833394783464a0
Co-Authored-By: Gary Kotton <>
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
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
Gary Kotton b318c2b0e8 HACKING: update HACKING.rst file to include latest changes
Commit 3491cbc0c5 updated a hacking
check but did not update the HACKING.rst file.

Change-Id: Ie9be701f61da93686b79df23f1acf14008e4d486
2016-01-14 16:03:51 +00:00
Gary Kotton acc7450d4b HACKING: align the underline text and header
Beautify the HACKING.rst file


Change-Id: Ide187ba409f57f5cc451f0b774b55a2b09e93c1c
2015-11-29 05:19:17 -08: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

This code was taken from commit 0bea84ac20fe498bd08f7212a0017196c8cb0812
in Nova.

Change-Id: I36d07cade687690dc02a8f6cc3d70f5d00caf112
Co-Authored-By: ChangBo Guo(gcb) <>
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
Cyril Roelandt 3751f9ab34 Python3: use six.iteritems() instead of dict.iteritems()
This also adds a check to neutron/hacking/ that should catch this
error in the future.

Blueprint: neutron-python3
Change-Id: Ie7b833ffa173772d39b85ee3ecaddace18e1274f
2015-06-01 23:13:42 +02:00
Cyril Roelandt 6c1cb05302 Python 3: use six.string_types instead of basestring
In Python 3, there is no "basestring". In Python 3, "six.string_types" is
"basestring", and "str" in Python 3.

Change-Id: Ic22e932cbf3c4b75cd424f4b41428da869f197cf
Blueprint: neutron-python3
2015-05-21 04:03:17 +02:00
Adrien Vergé 5836bbca83 Python 3: Use six.moves.range
The function `xrange` was renamed to `range` in Python 3.

* Remove `xrange` occurences so that Python 3 tests can pass. Use
  `six.moves.range` instead to get the right function in both cases.
* Generalize the use of the efficient `range` (ex-`xrange`) in
  critical sections (when iterating over large lists).
* Simplify code.
* Add a hacking check to prevent future usage of `xrange`.

Change-Id: I080acaaa1d4753619fbbb76dddba6d946d84e73f
Partially implements: blueprint neutron-python3
2015-05-19 17:32:17 +02:00
ankitagrawal 4cd1600b25 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
contextlib.nested is also not compatible with Python 3.

This is the first patch in a series for removing use of

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

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: I171fbdb89892a3d4548bf2ca52f4a7dd9ef8dccb
2015-05-06 04:43:01 -07:00
Ihar Hrachyshka 7a2a85623d oslo: migrate to namespace-less import paths
Oslo project decided to move away from using oslo.* namespace for all their
libraries [1], so we should migrate to new import path.

This patch applies new paths for:
- oslo.config
- oslo.db
- oslo.i18n
- oslo.messaging
- oslo.middleware
- oslo.rootwrap
- oslo.serialization
- oslo.utils

Added hacking check to enforce new import paths for all oslo libraries.

Updated setup.cfg entry points.

We'll cleanup old imports from oslo-incubator modules on demand or
if/when oslo officially deprecates old namespace in one of the next



Closes-Bug: #1409733
Change-Id: If0dce29a0980206ace9866112be529436194d47e
2015-02-05 15:09:32 +01:00
Ihar Hrachyshka 1de25088b4 Update hacking to 0.10
Release notes:

* Remove references in tox.ini to removed rules.
* Remove custom @author check since it's now implemented in hacking.
* Move N323 to N322 that is freed due to @author check removal.
* Temporarily skip W292 (no newline at the end of file).
* Temporarily skip H238 (old style classes).

Change-Id: I6d990a564df6a312bd09b2a152315bbdba732082
2015-01-12 23:46:06 +01:00
YAMAMOTO Takashi dd39a3eda3 test_dhcp_agent: Fix no-op tests
Fix some uses of assertCalledOnceWith, which seems like a mistake of

Also, add a hacking check to prevent the mistake.

Closes-Bug: #1397184
Change-Id: I12d077e2724d52eff65d55aff1130fbbb69671b1
2014-12-02 12:13:08 +09:00
Gary Kotton e16b3a8f37 Update i18n translation for neutron.agents log msg's
Don't translate debug level logs and enforce log hints
Our translation policy
( calls
for not translating debug level logs. This is to help prioritize log
translation. Furthermore translation has a performance overhead, even if
the log isn't used (since neutron doesn't support lazy translation yet).

NOTE: this is done on a directory by directory basis to ensure that we
do not have too many conflicts and rebases.

Add a local hacking rule to enforce this.

This patch set enforces the directory neutron/agents

Partial-bug: #1320867

Change-Id: I4bd562e5138c2d2850072440aa121f27e902463a
2014-11-15 00:08:20 -08:00
Jacek Swiderski e40c2ed58c mock.assert_called_once() is not a valid method
mock.assert_called_once() is a no-op that tests nothing. Instead
mock.assert_called_once_with() should be used (or use
assertEqual(1, mock_obj.call_count) if you don't want to check

Borrowed HACKING rule from Davanum Srinivas's nova patch to
prevent it from appearing again.

Change-Id: Idac1d3c89c07e13c9a209663f4e557fcb7547821
Closes-Bug: #1365751
Closes-Bug: #1300265
2014-10-13 12:36:49 +02:00
Gary Kotton 7edf58495e Remove @author(s) from copyright statements
We have git to track authorship, so let's not pad source files
with it as well.

A hacking check has been added for this. The value is N322.

Change-Id: Iab0b64d417e0bb41a6b455e2ac377deee64ec3ee
2014-09-15 21:40:09 +09:00
Ihar Hrachyshka 0a75865b1f Use jsonutils instead of stdlib json
jsonutils provides multiple benefits in comparison to pure stdlib json
(like using simplejson on Python 2.6).

Similar patch was already merged before [1], but since it lacked hacking
rule to enforce jsonutils usage, new occurrences of stdlib json module
usage were introduced.

This patch switches all the code to using jsonutils and adds a hacking
rule to enforce the rule.

The hacking rule requires that jsonutils module does not mimic as 'json'
thru using import renames, so the code was updated not to rename the
module when doing import.

The hacking rule was shamelessly copied from the corresponding nova
review [2].


Change-Id: Ie7a5bb76445e15cde9fbf9ff3d2101a014637b37
2014-08-14 12:45:58 +02:00
Gary Kotton 61a7b58423 Add missing translation support
Update a number of files to add missing translation support.

The patch adds a new hacking check - N320. This ensures that
all log messages, except debug ones, have translations.

A '# noqa' indicates that the validation will not be done on
the specific log message. This should be used in cases where
the translations do not need to be done, for example, the log
message is logging raw data.

Change-Id: I3e1fdd04d87b09dff50950b5e85f5cacfb29afdc
Closes-bug: #1314994
2014-05-19 12:16:56 +02:00
Joe Gordon dad4a1d8f1 Cleanup HACKING.rst
* Point to new location for hacking doc
* Remove openstack-common section because already in main hacking doc

Change-Id: I7fbcfe13469a75fed08700ccbe07fefbee33db22
2013-11-11 10:32:34 -08:00
Keshava Bharadwaj 62bfbf22df Cleanup and make HACKING.rst DRYer
Reference the OpenStack hacking guide in HACKING.rst and remove
duplicate entries. Adds placeholder section for neutron specific

Change-Id: I4bfbab50b77e7592178dda44c7f4f52edc7fdc21
2013-10-16 16:33:08 +05:30
ZhiQiang Fan b719f21cd9 Fix wrong example in HACKING.rst
Example of Human Alphabetical Order Examples section in HACKING.rst
is wrong, this patch fixes it to the right order.

Closes-Bug: #1213568

Change-Id: Ib7f8baf20c437c3fa776201998c36f33bdde2f78
2013-08-18 14:26:36 +08:00
Mark McClain ee3fe4e836 Rename Quantum to Neutron
This change renames everything to Neutron while providing backwards
compatible adjustments for Grizzly configuration files.

implements blueprint: remove-use-of-quantum

Change-Id: Ie7d07ba7c89857e13d4ddc8f0e9b68de020a3d19
2013-07-06 15:02:43 -04:00
Gary Kotton c117074a4b Remove locals() from strings substitutions
Fixes bug 1168988

Change-Id: Ifd1e7a027f16062ff35e777cf2d953f652a806a7
2013-04-20 11:56:26 +00:00
Monty Taylor cea9e39dd7 Add common test base class to hold common things.
There are several common fixtures that every test case wants. Following
the pattern in Nova, add a common base test case class to hold these things.

Change-Id: I2d2cd91e5051d9cbf230e6f48985d6eddcb7b58a
2013-03-05 18:07:14 -05:00
Monty Taylor 511ac76cf2 Use testtools instead of unittest or unittest2.
As part of the move towards testr and parallel test running, we
start to use testtools and fixtures to make the test suite
resilient and more pedantic.

Part of blueprint grizzly-testtools

Change-Id: I90250de9fe21237db34f6a50b89b15863e270aa5
2013-02-26 19:32:30 +09:00
Zhongyue Luo f78b0f9b05 Logging module cleanup
Replaced logging with openstack.common.log
Removed imports where logging is not used

Fixes bug #1095541

Change-Id: I5b03d9697dde3ef3520f67d1d8166f7af7689551
2013-01-03 16:20:56 +08:00
Zhongyue Luo 92b25faf91 Import order clean-up
Reorder imports by full module path

Change-Id: I50bc2a5ff6cea939049fed8066471b15e84adbe6
2012-11-02 09:52:12 +08:00
Maru Newby 5f4dfbb6fa Add HACKING.rst coding style doc
* Addresses bug 977685

Change-Id: Id04cad3021f015abe965f79b8930da55e092ada1
2012-04-09 21:09:30 -07:00