Commit Graph

21 Commits

Author SHA1 Message Date
Goutham Pacha Ravi fba472e3a6 Move hacking checks to tests dir
The test code isn't part of the service.

Corresponding cinder change: I7b18453269cfc57bfbc9bd143d72948e88e60836

Change-Id: I71cc8b3154828f4aeea0afdf3fb59a79b8a8e707
Signed-off-by: Goutham Pacha Ravi <gouthampravi@gmail.com>
2020-07-29 15:17:24 -07:00
Goutham Pacha Ravi 598223985a Use unittest.mock instead of third party lib
mock was adopted into standard python
in version 3.3 [1]. Since manila no longer
supports python2.7, we can use the inbuilt
mock package rather than the third party
lib.

Fix some issues with imports that weren't
following our import conventions of grouping
imports [3]

Add a hacking test to ensure we don't regress
on this.

[1] https://docs.python.org/3/library/unittest.mock.html
[2] http://lists.openstack.org/pipermail/openstack-discuss/2020-March/013281.html
[3] https://docs.openstack.org/hacking/latest/user/hacking.html#imports

Co-Authored-By: Sean McGinnis <sean.mcginnis@gmail.com>
Change-Id: If857a49fbf526983e712282a25d7e8bef5093533
Signed-off-by: Goutham Pacha Ravi <gouthampravi@gmail.com>
2020-04-17 16:24:27 -07:00
Andreas Jaeger 3ac1870e85 Update hacking for Python3
The repo is Python 3 now, so update hacking to version 3.0 which
supports Python 3.

Update local hacking checks for new flake8.

Many tests are failing, so disable all that fail and fix most of them in a
followup.

Change-Id: I34a767406ed9110fc6e0cf5015b88cf1e7f43801
2020-04-01 09:20:58 +02:00
junboli ca712cb0bd Fix the duplicate hacking check M312 and H203
The hacking "[H203] Use assertIs(Not)None to check for None" is already enabled
in tox. But the local hacking M312 is also avaliable, there is no need to check
twice here for the same check.

Change-Id: I56e19c6dd8905e439247c3b142e74913b5d0d7a6
Closes-Bug: #1710426
2017-08-13 08:01:42 +08:00
Tom Barron 0a3df6f99e Hacking: do not translate log messages
Log messages are no longer being translated.

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

Change-Id: I422fa934b27da1c252f72ac3bf94ef468f0d7ef6
2017-04-09 11:07:09 -04:00
Tom Barron 66a6505d79 remove hacking rule that enforces log translation
Log translation is no longer being done [1] [2] so there
is no point in enforcing it going forwards.

Remove the hacking enforcement so that new commits need
not include this unused feature and so that we can remove
this unused il8n markup in existing code.

[1] http://lists.openstack.org/pipermail/openstack-dev/2017-March/thread.html#113365
[2] https://review.openstack.org/#/c/446762/

Change-Id: I31f35b0597e161a1654467f5a0a2348789292d83
2017-03-17 05:54:03 -04:00
Ha Van Tu 8407f72c2c [hacking] Ensure not to use LOG.warn
This patchs ensures not to use LOG.warn because LOG.warn deprecated
in Python 3 [1], use LOG.warning instead.

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

TrivialFix

Change-Id: I50e44a89092e0ee15f5be294837a87c321427921
2016-11-30 06:36:51 +00:00
Tom Barron f2ffae1870 hacking: Use uuidutils to generate UUID
Added hacking check to ensure that UUIDs are not generated
by uuid4() since we should do this using oslo_utils.uuidutils.

Based on this nova change [1].

[1] I73ee63fbd4f451d3aa5dc1a2a734d68c308b4440

Change-Id: Ic7783c29fbd838c827ccc8ee44aa757fef8e9169
2016-11-16 16:06:40 -05:00
Tom Barron 467321bceb Do not supply logging arguments as tuple.
Logging format arguments are not supposed to be tuples, but
are rather to be supplied separately - i.e., use
   LOG.debug('%s is %s', arg1, arg2)
instead of
   LOG.debug('%s is %s', (arg1, arg2))

Rid the manila codebase of this logging format error and
add a hacking check for this.  The hacking check will not
catch all corner cases but should help prevent this error
in most cases.

Change-Id: Ibea39f1f90c0444eae5cfcd6090b2a00d84ab923
Closes-Bug: #1585394
2016-06-09 17:22:36 -04:00
Tom Barron 528ee090bf Hacking check for str in exception breaks in py34
So change [1] skips this check in python34 tests.

Replace CheckForStrExc with CheckForStrUnicodeEx
and quit skipping unit test for this hacking check.

Partially-Implements: bp py3-compatibility

[1] Id3d196d6006e7b2e5e56343bd7ba207c5196b61d

Change-Id: I9fdd035a61715039b737bf65df5c5636e8a55f54
2016-05-25 10:23:05 -04:00
Tom Barron 2b7a755af4 Add hacking rule for assertEqual(None, *)
Several bugs have been raised and fixed to convert
assertEqual(None, *) with assertIsNone in tests.

Install a hacking rule to prevent new occurrences of
this problem.

Change-Id: Ib157f911e2f6a90d21c3886b3139f9b109962052
2016-05-24 21:13:53 +00:00
Tom Barron b85248bce6 Use assertTrue rather than assertEqual(True, ...)
Manila unit tests contain several occurences of
assertEqual(True, ...) instead of assertTrue(...).

Fix these occurences and add hacking check so new
occurences don't creep into the codebase.

Closes-Bug: #1584948

Change-Id: Ib586590b9efcb5253e8c09ee735a8ffb62b44d74
2016-05-23 19:07:54 -04:00
Tin Lam bcb0f3133f Add hacking check to ensure not to use xrange()
Added hacking check to ensure not to use xrange for python3
compatibility.

Change-Id: I1aa510660a25936dbf1b2fc5971e7571090a42d0
Closes-Bug: #1538118
2016-03-17 18:02:44 +00:00
Marc Koderer 068d6ee34b Fix issue in hacking with underscore imports
Hacking rule for underscore imports _() are not working correctly.
It also matches _.* imports like "import _LE"

See review: https://review.openstack.org/#/c/270754/

Change-Id: Ibdef35e1896882a8dfe3165dba989255639e61ba
2016-02-05 08:01:50 +01:00
houming-wang 51069d5390 Performance: leverage dict comprehension in PEP-0274
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.
Manila does not support python 2.6, we can leverage this.
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/480757/

Change-Id: I87d26a46ef0d494f92afb1d3bebda2797a12413c
Closes-Bug: #1524771
2015-12-11 19:24:56 -05:00
houming-wang 5bd39bad8b Fix wrong check message
From the hacking guidelines, the numbers should be M3xx. N333
should be M333. Fix it.

Change-Id: I67b8d0e15fa6c68ab59774864165941051ab8649
Closes-Bug: #1524808
2015-12-10 08:31:24 -05:00
Marc Koderer 09798caae1 Use Tempest plugin interface
Make use of the Tempest plugin interface instead of copying Manila
files into Tempest. This will remove the burden to port Manila
tests onto Tempest master recurrently.

This ports all existing Manila Tempest test to the new structure.

It uses manila_tempest_tests as new top folder for all Tempest
tests. It follow the model of Heat (see [1]).

[1]: https://github.com/openstack/heat/tree/master/heat_integrationtests

Change-Id: Ie5ed64a6777ed1acf8dd56522c26705ae897596d
Partly-implements: bp tempest-plugin-interface
Depends-On: I26dd32b1de8cceeaa6dc674092efec683df71889
2015-09-05 00:36:33 +00:00
Thomas Bechtold 0eedb98a9a Remove hacking exception for oslo.messaging import
olso.messaging moved away from namespace packages so this check is no
longer needed.

Change-Id: I76ac67cf38a22350bdb68351f5bb3f38cb9763c5
2015-03-02 08:00:44 +01:00
Thomas Bechtold 071d0b59c1 Switch to using oslo_* instead of oslo.*
The oslo team is recommending everyone to switch to the
non-namespaced versions of libraries. Updating the hacking
rule to include a check to prevent oslo.* import from
creeping back in.
oslo.messaging is the only exception because this package doesn't
currently support non-namespaced imports.

Change-Id: I3987e651bc880c8ffa7c0105df0298679dcd3a43
2015-01-27 09:19:50 +01:00
Andreas Jaeger 15641fba88 Convert files to use _LE and friends
LOG.warn etc. should be translated separately and thus messages need to
be marked with _LW for LOG.warn, _LI for LOG.info and _LE for LOG.errors
and LOG.exception.

Mark all LOG invocations with proper translation marker.

Use ',' instead of '%' when adding variables to log messages to allow
lazy evaluation.

Add new hacking checks for these.

Change-Id: I31d3ee50f30c63d7d647b1c2b1eae50bf96f0c74
2014-10-31 09:47:59 +01:00
Andreas Jaeger f039a76868 Add manila specific hacking checks
Add manila specific hacking checks (copied over from nova) to test:
- [M319] Validate that debug level logs are not translated.
- [M323] Ensure that the _() function is explicitly imported to ensure
  proper translations.
- [M325] str() cannot be used on an exception.  Remove use or use
  six.text_type()
- [M326] Translated messages cannot be concatenated.  String should be
  included in translated message.

Also include some tests for the above (copied from nova and adjusted).

Rework HACKING.rst to remove the content that is in the global hacking
file and add in the manila specific rules.

Change-Id: I530609a183c81ba942623b73d5f62cd338b04211
2014-10-21 09:34:59 +02:00