Commit Graph

53 Commits

Author SHA1 Message Date
Eric Harney 7f629facb4 Hacking: Remove C306, C308 checks
These block usage of methods that no longer
exist in oslo.utils 6.0.0+.  Since they have
been removed, we don't need a hacking check
for this.

Change-Id: If0345c863b1750eaca3097f240fde9b976ac442e
2023-09-14 15:18:58 -04:00
Takashi Kajinami a03e10ceb0 Use LOG.warning instead of deprecated LOG.warn
The LOG.warn method is deprecated[1] and the LOG.warning method should
be used instead.

[1] https://docs.python.org/3/library/logging.html#logging.warning

Change-Id: I87d33f215a064a70cea989d524dc26affeea0c3e
2022-02-09 08:29:02 +09:00
Sean McGinnis b9cf3acfcc Update HACKING document to match current checks
The HACKING document had gotten out of date with a few removals and
additions of hacking checks. This gets it synced up with the current
state of our checks.

Change-Id: I8ace7662bb11d5708dd507b79f4a2476c9875ac5
Signed-off-by: Sean McGinnis <sean.mcginnis@gmail.com>
2020-04-17 15:09:13 +00:00
Andreas Jaeger a144fa3474 Re-enable local hacking checks
With the switch to hacking 2.0, the local checks are not enabled
anymore, update repo to use the new way of registering local checks.

Remove local vi check since hacking has this now as H106.

Change-Id: I4d03f4c7eff959017e907cac974c394af0559643
2020-03-29 12:11:18 +02:00
Jay S. Bryant e387452419 Remove hacking check N325
This hacking check was added back when the str()
function couldn't handle unicode characters.  With
Python3 this is no longer an issue.  As a result we
can now remove this check.

Change-Id: I926732062dbbd1242cd382e2593e07b4caf4ffec
2020-01-10 12:53:44 -06:00
Sean McGinnis d5b539be36
Doc8: Stop skipping D001: Line too long
This cleans up the cases where we had D001 violations so we can stop
skipping that check in doc8 runs.

Change-Id: Ie52f6ecac1a645fcbcc643b9ca63e033b622d830
Signed-off-by: Sean McGinnis <sean.mcginnis@gmail.com>
2019-02-19 16:51:56 -06:00
Chuck Short 324e9ba11e Remove note about mox
Remove the note about using mox in unit tests since
mox has been removed in cinder.

Change-Id: If7fa5f86ff5008d338f70db6dc30190f81786979
Signed-off-by: Chuck Short <chucks@redhat.com>
2018-07-16 08:36:07 -04:00
yanghuichan 8a490fb6df Fix wrong links in Cinder
Some docs links have changed.
We should update the wrong links in our codes.

Change-Id: I5046be23703192ed6fad805355c8c50b9b4a71c8
2017-09-07 11:55:44 +08:00
dongdongpei cc859fdde6 Update the documentation link
Change-Id: I9ba09cb59ad6710edeeff21294b16f64ee1d4c38
2017-08-26 06:52:48 -07:00
loooosy 9b6208cfc9 Update the documentation link
This patch is proposed according to the Direction 10 of doc
migration(https://etherpad.openstack.org/p/doc-migration-tracking).

Change-Id: I4b0b2ef3c927ffe1604f218f20474444e794a577
2017-08-23 16:42:00 +08:00
Ngo Quoc Cuong 7b71585aa1 Update log translation hacking rule
Starting with the Pike series, OpenStack no longer supports log
translation.
Update hacking rule to prevent log translation in all log level instead
of only debug level.

Since all log translations are invalidated, check_explicit_underscore_import
can be simplified.

Change-Id: I1105fcb7e25549017ed7fcad8f932abc1b635129
Related-Bug: #1701195
2017-06-29 04:05:52 -04:00
jeremy.zhang 85a1b8d40b Enable some off-by-default checks
Some of the available checks are disabled by default in flake8, like:
[H106] Don’t put vim configuration in source files
[H203] Use assertIs(Not)None to check for None

This patch is to enable the H106 and H203 checks in Cinder project.
The C312 hacking rule will be removed when turn on H203.

Change-Id: I2e883c301b64d5977bbb907b63c9c144bc6f959d
2017-06-22 02:17:54 +00:00
Eric Harney a68a057de0 Revert "Using assertFalse(A) instead of assertEqual(False, A)"
This is not correct, because assertEqual(False, A) is a stricter check than assertFalse(A).

assertFalse(None) passes, but assertEqual(False, None) will fail.  Therefore, this patch weakened our tests.

This reverts commit bcad8a84c0.

Change-Id: Ib7e2096c94f28d81bbf80bd2f21355a74541d9f8
2017-06-06 19:43:10 +00:00
jeremy.zhang bcad8a84c0 Using assertFalse(A) instead of assertEqual(False, A)
This patch is to replace assertEqual(False, A) with assertFalse(A), which
the latter is more straightforward and easier to understand. Also the
relevant hacking rule is added.

Change-Id: Idd09acc6820e54c4388e183963d405b8990bc533
2017-06-06 11:04:27 +08:00
Sean McGinnis 872ff1e25e Remove hacking check for log translation
The I18n translation team has removed log translations, so our
enforcement of the _Lx translation markers is no longer required.

See:
http://lists.openstack.org/pipermail/openstack-dev/2017-March/113365.html
http://lists.openstack.org/pipermail/openstack-i18n/2016-November/002574.html

Change-Id: I54a57ed832d440f6e0c7c39cb59f03ca443dfeda
2017-03-18 03:00:12 -05:00
Eric Harney eca603bdd9 Hacking: Remove N333 oslo namespace import check
This is no longer needed, as current oslo libraries
don't export this namespace any longer, so other
tests will fail and catch this problem.

Related: I49c74ade374582f53a3678a1bc7df194c24e892e
Change-Id: I2af1679f1e2e82ba18d01e092ff8d01fa1537ca1
2016-12-12 10:08:31 -05:00
Vipin Balachandran afbb085a10 Fix broken link in HACKING.rst
This patch fixes the broken link to 'testing' in HACKING.rst.

Change-Id: I9ecab0223885d1bd91fedd186d125618d785d2d8
2016-07-01 15:08:43 +05:30
Eric Harney c96be71fd6 Revert "Add hacking check to prevent assert_called_once"
This reverts commit 9400cee06f.

Calling assert_called_once seems to fail as expected
using mock 1.3.0.

Change-Id: Ie382989e03b31564a3bfb4e8d010a8a93467f71b
2016-05-24 12:36:22 -04:00
Sean McGinnis 9400cee06f Add hacking check to prevent assert_called_once
We've had a few patches now over the last few releases to fix invalid
mock assertions for assert_called_once. Rather than keep letting these
creep back in to the code, this adds a hacking check to watch for this
specific call and block it.

Change-Id: I3cf4df523ddba49f57dd1d4d23e95e6d62d03c9e
2016-05-23 09:29:43 -05:00
Kendall Nelson 635440c90c Hacking Checks for assertTrue/IsNone()
This patch adds a hacking check to make sure that assertEquals isn't
comparing the result value to True or None. When developers
use assertEquals(None, return_value) the check will catch it when
pep8 runs and suggest using assertIsNone(return_value) instead.
Similar situations will occur when trying to use assertTrue(True,
return_value).

This patch also makes the necessary changes that get caught by the
new hacking check.

Change-Id: I56cc8121784eee617c09fb4e92b4ebb5877a0553
2015-11-25 11:22:35 -06:00
Kendall Nelson 391d18dc64 Hacking check for opt name registration
Depending on how opts are registered (either with register_opt() or
register_opts()), the name needs to be singular or plural to match
the method.  This patch adds a hacking check to make sure the names
of the opts and opt lists (or tuples) are correct given how they are
being registered.  The check also verifies that a single option is
sent when register_opt() is used and a list is used when using
register_opts().

Includes fixes to files that don't meet the naming convention and a
addition to the generate_cinder_opts.py file in order to skip
checks.py in the generation of the opts.py file.

Closes-Bug: 1495752
Change-Id: Ia795915c6e3d46272acc30407961d5d876f783ce
2015-10-06 08:35:48 -05:00
Derrick J. Wippler b7fc72c688 Hacking log format arg check
Added hacking check for log lines that accidently pass a tuple as the
second argument when providing format arguments.

Change-Id: Ifba23948f9fb49e9f6a1ee7e743aba0cd864c827
Closes-Bug: 1415241
2015-09-09 15:25:05 -05:00
JuPing a69d5fffb5 Fix description for "Barbarism of editting a file"
There are some barbarism located in the file cinder/HACKING.rst.
  line11 and line21 : there is no full point at the end of a sentence.
  line14 and line23 : after a sentence, there are two space between
  the full point and the first letter of the second sentence.
I think the correct format of the above question as blow.
   - [N319] Validate that debug level logs are not translated.
   - [C302] six.text_type should be used instead of unicode.
   - [N325] str() and unicode() cannot be used on
   an exception. Remove or use six.text_type().
   - [C304] Enforce no use of LOG.audit
   messages. LOG.info should be used instead.

Change-Id: I2896bacc5379786ed115d47e520bf5bc2af0028a
Closes-Bug: #1487665
2015-08-22 07:45:47 +00:00
Sean McGinnis 46e1f1741d Remove useless logging from unit tests
It has been discussed that there really isn't much point in having
unit tests making any kind of logger calls. Some usage has already
been cleaned up. This patch removes the remaining instances of log
calls under the cinder/tests directory.

Also cleaned up a lot of cases where the source files would import
oslo_logging and declare a LOG variable which was never actually
used.

Leaving logging in the cinder/tests/unit/integrated tree for now
until a plan is decided as to what to do with all of these type of
tests.

Added hacking check to prevent new instances from slipping by code
reviews.

Change-Id: If177394486d5c92fa5466cd3825b15d30cf5fb18
2015-07-13 17:39:44 +00:00
Eric Harney ee6576c4eb Remove hacking check N327
With mock 1.1.0+, mock will fail when nonexistent
methods are called, so this check is no longer
necessary.

Related-Bug: #1473454

Change-Id: I9cb8b4a5eab78e51728aa8f83668f5979c0b9be1
2015-07-10 10:44:47 -04:00
Julien Danjou d106e6f61b Stop using deprecated timeutils.isotime()
oslo_utils.timeutils.isotime() has been deprecated, stop using it, see:

  http://docs.openstack.org/developer/oslo.utils/api/timeutils.html#oslo_utils.timeutils.isotime

Change-Id: I0176f498db89a3a10c2474e4ae5c4b0929c65ece
2015-05-27 08:28:39 +02:00
ChangBo Guo(gcb) 5800f25f7e Leverage dict comprehension in PEP-0274
PEP-0274 introduced dict comprehensions to replace dict constructor
with a sqeuence of key-pairs[1], these are benefits:
  First, it makes the code look neater.
  Second, it gains a micro-optimization.

Cinder dropped python 2.6 support in Kilo, we can leverage this now.
Note: This commit doesn't handle dict constructor with kwargs.
This commit also adds a hacking rule.

[1]http://legacy.python.org/dev/peps/pep-0274/

Change-Id: Ie65796438160b1aa1f47c8519fb9943e81bff3e9
2015-05-22 10:06:00 +08:00
Sean McGinnis adfff0b141 Remove use of deprecated LOG.warn
LOG.warn is deprecated and LOG.warning should be used.

This patch fixes up instances of LOG.warn usage and adds a
hacking check to make sure it doesn't creep back in.

See Logger.warning note here for background:
https://docs.python.org/3/library/logging.html

Also cleaned up some remaining instances where logging was
preformatting strings rather than passing in formatting
arguments to the logger to handle.

Change-Id: Id2e6cba489d8509601820b5aed83652f71be2bdc
2015-05-13 10:51:45 -05:00
Jenkins 92fce883bf Merge "Add hacking check for str and unicode in exceptions" 2015-05-03 17:18:38 +00:00
Jay S. Bryant e3973fe202 Add hacking check for str and unicode in exceptions
One of the comments we are frequently having to make
on reviews is with regards to the use of str() or
unicode() on exceptions.  This hacking check pulled
from Nova will catch this problem earlier and avoid
conflicting comments being made in reviews.

Change-Id: I09eaf7b066f3e29733e6cbe16b2997edb6bc5e23
2015-04-27 16:27:52 -05:00
Julien Danjou dbe13b17e8 Leverage timeutils, drop strtime() usage
This patch remove some code that tried to parse time in different way by
leveraging timeutils instead. It also drops strtime() usage as it's
going to be deprecated in oslo_utils (see
I8b5119e64369ccac3423dccc04421f99912df733).

Change-Id: Icb2906ccd4b381f80064e0f1348fc64e389031dd
2015-04-23 10:33:55 +02:00
Jay S. Bryant c80c5c4f4c Correct cinder hacking check numbering
We have a couple of hacking checks that are specific to
Cinder that were written a while back.  Unfortunately, when
they were written the numbering scheme for hacking checks was
not understood.  We used N3xx when we should have used C3xx.

This patch corrects that mistake.

Change-Id: Ia17797005d444ab53a45b47b80b97799114001ee
Closes-bug: 1440833
2015-04-07 19:43:11 +00:00
Jay S. Bryant c2658d9c09 Add hacking check for print() statements
We are frequently having to -1 patches because people
forget print() statements that were used for debug in
their development.  Can save everyone time and trouble by
adding this simple hacking check.

The check excluded the cinder/cmd directory as the files in there
legitimately need to use the print() command.  Also wsgi.py and
the test_hds_nas_backend.py files make use of print, so I have
excluded those from checking as well.

Change-Id: I2066eeb2bdc6c9af294d0b9befb7e0b32abd1378
2015-04-07 14:38:37 -05:00
Ivan Kolodyazhny 319bddcc03 Use six.text_type instead of unicode
Add hacking checks for unicode() calls

Change-Id: I27062986e69a90e3f4fc26a76080b146e825149b
Closes-Bug: #1380806
2015-04-02 19:07:58 +03:00
Sean McGinnis 3578d9e341 Logging not using oslo.i18n guidelines
Part of multi-patch set for easier chunks.

There have been quite a few instances found where the
i18n guidelines are not being followed. I believe this
has helped lead to some of the confusion around how to
correctly do this. Other developers see this code and
assume it is an example of the correct usage.

This patch attempts to clean up most of those violations
in the existing codebase to hopefully help avoid some of
that confusion in reviews.

Some issues address:
* Correct log translation markers for different log levels
* Passing format values as arguments to call, not preformatting
* Not forcing translation via six.text_type and others

Guidelines can be found here:
http://docs.openstack.org/developer/oslo.i18n/guidelines.html

Hacking checks will not be able to identify all violations of
the guidelines, but it could be useful for catching obvious ones
such as LOG.info("No markers!").

Change-Id: I38f52c6408b47ccb59ec2064b360f7d4427d6830
Partial-bug: 1433216
2015-03-19 12:28:12 -05:00
Yuriy Nesenenko 931c34d38b Change datetime.now() to timeutils.utcnow() from oslo_utils
We use an UTC time to avoid the difference with time zones.

Change-Id: I15aa3b5d3337b90ccdcc6c4ac5d3c7d78108fe21
Related-Bug: #1288979
2015-03-19 14:12:57 +02:00
Sean McGinnis ddbcdbb2d0 Remove use of contextlib.nested
The contextlib.nested call has been deprecated
in Python 2.7. This causes DeprecationWarning
messages in the unit tests.

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.

Since Cinder no longer supports 2.6 we can remove
the use of these contextlib.nested calls.

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

Note: 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 it is not a requirement.

Partial-Bug: 1428424
Change-Id: I7bb7d201d31ff239be3402fb64e5f202ede019b0
2015-03-12 13:45:29 -05:00
Jay S. Bryant d8301e58bf Add hacking check for oslo namespace usage
We want to make sure that we don't have usage of the old
oslo.concurrency naming slipping in with new changes where
we should be using the oslo_concurrency namespace.  This change
adds a hacking check to avoid use of the deprecated namespace.
As we convert more oslo libraries to the new namespace the check
will be updated to enforce use of the new namespace.

This hacking check is based upon the same N333 hacking check
in Cinder.

Change-Id: Ibec6d09e9d313c9e723f7542cedb9da5772d3de2
2015-01-14 09:09:58 -06:00
git-harry 322126212e Fix calls to assert_called_once in unit tests
Mock has a method called assert_called_once_with to check that a mock
was called and the arguments it took were as expected. Mock does not
have a method called assert_called_once and calling it just creates a
mock bound to that name. This means that not only is nothing tested
when assert_called_once is used, the tests also don't warn about this.

This commit attempts to address this in two ways:
    - all occurrences of assert_called_once are replaced with a real
      assertion.
    - the hacking check that nova uses to guard against this has been
      copied to cinder's local hacking checks.

Fixing the assert_called_once issues also highlighted other mistakes
in certain tests which were addressed to make the tests pass.

Due to the nature of mock, this issue is also possible if a method is
misspelt or just mistakenly used and so the hacking check is only
addressing one very specific case. That said, it does appear to be a
common mistake and so is worth singling out.

Change-Id: Iedcc3f48d91f7ebd8878ccc3bca3d023503774bd
Closes-Bug: #1394544
2014-11-24 16:56:10 +00:00
Jay S. Bryant 79b6b98f21 Updated HACKING.rst so that it is accurate
We haven't been very good at enforcing putting new hacking checks
into HACKING.rst.  This change brings the file up to date.

Change-Id: I95ef533d031d333da5615ead997b54c6506c2c2a
2014-08-09 22:07:11 -05:00
Jay S. Bryant 097d3d7910 Add hacking check for use of LOG.audit
Commit 4dc37abc removes the few instances of LOG.audit that
were in Cinder.  Given that the plan is to remove LOG.audit messages
from OpenStack, I am adding this hacking check to ensure that such
messages do not sneak their way back into Cinder.

Unit tests are included with this change.

Change-Id: Icc416a68f958f60260f1c55af0d8605c95913bf1
2014-08-09 10:22:03 -05:00
Jay S. Bryant 5347439142 Improve regex for _ import hacking check
Commit 3e2b1117 added a check to make sure that the _
function was being explicitly imported so that translation would
work properly.

I have discovered that those regexes/code would not work in some cases.
Particularly if the import line imported multiple things from
gettextutils or i18n.  Also the check being used to find lines using
the _ function was not right.

This commit fixes the issues and adds appropriate tests.  It also
adds the hacking check to HACKING.rst which should have been done the
first time around.

Change-Id: I7227bb0051836e537bff2f0f97662c06452d5af6
2014-08-07 15:55:58 -05:00
Christian Berendt 5061ab9586 debug level logs should not be translated
According to the OpenStack translation policy available at
https://wiki.openstack.org/wiki/LoggingStandards debug messages
should not be translated. Like mentioned in several changes in
Nova by garyk this is to help prioritize log translation.

This patch adds a new hacking check - N319 - that ensures all
debug log messages don't have translations.

Change-Id: Id9c2715f25c8f2ea52235aba4bd1583655391584
Implements: blueprint debug-translation-removal
Closes-Bug: #1318713
2014-06-18 09:03:02 -06:00
Avishay Traeger 96420a1e26 Update HACKING.rst with regard to mock usage
Add a sentence about using mock rather than mox for unit tests.

Change-Id: If3c175d986f3ebed6d949df5c473e0cf9177ef6e
2014-01-21 18:01:02 +02:00
chadlung ed19770844 Adding helpful URL links to README.rst and HACKING.rst
Change-Id: Id9d3606616993c50bf6ab29880efa495999b9ce4
2013-12-27 19:29:17 -06:00
Joe Gordon 20d177db37 Update URL for global HACKING document and remove duplicate section
* Related to I579e7c889f3addc2cd40bce0c584bbc70bf435e2

* Remove section on locals since its already in global hacking doc
  (http://git.openstack.org/cgit/openstack-dev/hacking/tree/doc/source/index.rst#n154)

Change-Id: I5acb06dfde6eb7f579d8d52bc31fafbdab8c726d
2013-11-11 11:39:23 -08:00
Mike Perez 3cd21880af Update OpenStack Style Commandments link
The current link in the HACKING file is broken. This references the
correct location for contributors to view.

Change-Id: I614f78fdea32025c2c5cf9599c698dde9c81ab21
2013-09-28 23:02:23 -07:00
Joe Gordon 242976b4b8 Cleanup and make HACKING.rst DRYer
Reference the OpenStack hacking guide in HACKING.rst and remove
duplicate entries.  Add placeholder section for cinder specific rules.
cinder specific rules can be created using hacking's local check
support.

Change-Id: Ia74da70363e3fe602405a440c1d2ec75052e9193
2013-07-13 09:16:23 -07:00
Sergey Vilgelm 33f6d78c3a Do not raise NEW exceptions
Raising NEW exception is bad practice, because we lose TraceBack.
So all places like:

except SomeException as e:
    raise e

should be replaced by

except SomeException:
    raise

If we are doing some other actions before reraising we should
store information about exception then do all actions and then
reraise it. This is caused by eventlet bug. It lost information
about exception if it switch threads.

fixes bug 1191730
Change-Id: Ic2be96e9f03d2ca46d060caf6f6f7f713a1d6b82
2013-06-25 17:25:07 +04:00
Mike Perez 6251df9068 Updating HACKING to disallow the use of locals()
Change-Id: I7bf2720bdb0456274dc81a73d91296dff0e3fced
2013-05-31 01:14:37 -07:00