The repo is Python 3 now, so update hacking to version 3.0 which
supports Python 3.
Fix problems found.
Update local hacking checks for new flake8.
Remove hacking and friends from lower-constraints, those are not needed
for co-installing.
Change-Id: I926efaef501f190e78da9cab40c1e94203277258
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.
Change-Id: I35c8978d8e189c894038b8d1e974938ffff71fcc
Added i18n translation to all log messages. Also added
hacking check for this to ensure in future all log
messages are translated.
Change-Id: I77fbb18ffe47b12232125cc1fa7aae97ea9b1214
Closes-Bug: #1603759
When user is not authorized to perform operations defined in policy
file, it should return a 403 error. The 500 error is incorrect.
This patch do the following changes:
1. Raise a PolicyNotAuthorized 403 exception when normal user
without admin privilege run command 'magnum service-list'.
2. Remove unnecessary hacking rule M301 'decorator must be
the first decorator on a method'.
3. Fix failed enforcement test cases introduced by 403
PolicyNotAuthorized exception.
Change-Id: Ie5a7d138cdb8b226686c189ae86f251c0a1329c8
Closes-Bug: #1520311
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.
Magnum 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: I61992fa428d6760449afe3754b02506336e8b421
Developer should use timeutils.utcnow to replace the
datetime.datetime.utcnow.
Change-Id: Ifaca72e286a805632cd17406464175ba6819a9b0
Closes-Bug: #1513308
Tests should use:
self.assertIn(value, list)
self.assertNotIn(value, list)
instead of:
self.assertTrue(value in list)
self.assertFalse(value in list)
because assertIn and assertNotIn raise more meaningful errors:
self.assertIn(3, [1, 2])
>>> MismatchError: 3 not in [1, 2]
self.assertTrue(3 in [1, 2])
>>> AssertionError: False is not true
Closes-Bug: #1510007
Change-Id: If33252cc93c06a85e61871fb7b22b726f4a08500
Developer should use assertIsInstance to replace the
assertTrue(isinstance(a, b)).
Closes-Bug: #1510384
Change-Id: I70f68a5810a6797c7b7e112b46ef2463907bba3e
Developer should use assertIsNotNone to replace the
assertEqual(** is not None).
Closes-Bug: #1510371
Change-Id: I5afd03aaf591e047b855bc416bc60fbc182bdc19
The usage of assertEqual(True/False, ***) should be changed to a more
meaningful format of assertTrue/False(***).
Closes-Bug: #1510001
Change-Id: Ia16af467d5f5bfca029002d9d261540947b0be92
Instead of using assertEqual(None, ***), developers should
use assertIsNone(***) to have more clear messages in case of failure.
Closes-Bug: #1510006
Change-Id: Ib3d09ed651877569a9b940da97662489885f18e9
The best practice in Python is not to use mutable object (i.e. list,
dictionary, or instances of most classes) as value of default argument.
See: https://docs.python.org/2/tutorial/controlflow.html#default-argument-values
This patch also added a hacking rule to enforce this practice.
Change-Id: I4aa8aede57d6fd31b4b30c3f7535b819e591165d
Closes-Bug: 1471349
The hacking rule error code should be start with 'M', which stands for
Magnum.
PS: Error number begins with M301
Closes-Bug: #1465895
Change-Id: Ie9565c4a700a1bf85eed8c5db87a8c4012f5254b
This patch adds hacking rule check framework for magnum, and adds first rule:
policy.enforce_wsgi decorator must be the first decorator on a method.
refer this link for why we need this rule.
`https://review.openstack.org/#/c/190140/`
Closes-Bugs: #1465895
Change-Id: If98e47426b391b75755ca0b559aee1baa93b8503