Commit Graph

25 Commits

Author SHA1 Message Date
coldmoment ba8ad5e37f 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.
See the oslo i18n guideline
* https://docs.openstack.org/oslo.i18n/latest/user/guidelines.html#adding-variables-to-log-messages
and
* https://github.com/openstack-dev/hacking/blob/master/hacking/checks/other.py#L39

Change-Id: I8a4f5f896865aebbff88ee894f0081e58cfce9ef
2017-07-15 14:49:45 +08:00
indicoliteplus 37093b2436 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.

Change-Id: I35c8978d8e189c894038b8d1e974938ffff71fcc
2017-06-15 12:46:54 +08:00
jinzhenguo 014da56bbb Remove duplicated hacking rule M318,M319
Change-Id: If0fbeb3f0bf826cac3700ad7f244fc059e83718f
closes-Bug: #1696628
2017-06-08 13:49:48 +08:00
Vivek Jain 28c8014ff0 Add hacking rule for explicit import of _ function
Change-Id: Id0c1610f0b6353a43341f704e0b4b00bd04828bb
Closes-bug: #1490194
2016-07-29 23:17:06 +05:30
Jenkins adeb9cb3c7 Merge "add hacking for assertIsNotNone" 2016-07-27 07:19:41 +00:00
yatinkarel 5c2fc0b392 Added hacking check to ensure LOG.warn is not used
LOG.warn is deprecated. To ensure it is not used later
added hacking check.

Change-Id: Iadd1d4f4588c9d47baefd685a97a73c8b1aee987
Closes-Bug: #1605711
2016-07-24 19:52:16 +05:30
huang.huayong 514dc58906 add hacking for assertIsNotNone
add hacking assertIsNotNone(A),errors = [(1, 0, "M319")]

Change-Id: I08beb689a16f212de4413bc1b888f6dbe4c183c3
2016-07-19 19:27:22 +08:00
Deeksha 4205f39a00 Add hacking check to ensure not use xrange()
Added hacking check to ensure not to use xrange.

Change-Id: I28731e16cf0636f004bf96795c85eecbdf2f8fbd
Closes-Bug: #1538118
2016-03-23 11:19:59 +05:30
ZhouPing 8fd99572e1 Remove unused hacking rule from HACKING.rst
This patch removes unused hacking M334 from HACKING.rst to avoid
confusing for new developers and also make the rule number in order.

Closes-Bug: #1539423
Change-Id: I79a791b39f7988254dd7fee1cb19dd16934475ae
2016-01-29 14:35:51 +08:00
Jenkins 11f26e6c92 Merge "Add the lost M338 in Hacking" 2016-01-09 05:34:56 +00:00
wangqun 0998284810 Add the lost M338 in Hacking
Change-Id: If211d70b005d56c0d3f0206d874f87ee3dc095fe
2016-01-07 02:14:08 +00:00
houming-wang 7b754ae390 WSGI enfore fails should return 403 instead of 500
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
2016-01-04 16:36:30 -05:00
houming-wang 98875345c2 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.
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
2015-12-03 22:02:02 -05:00
wangqun 8c7925a018 timeutils.utcnow should be used instead of datetime.datetime.utcnow
Developer should use timeutils.utcnow to replace the
datetime.datetime.utcnow.

Change-Id: Ifaca72e286a805632cd17406464175ba6819a9b0
Closes-Bug: #1513308
2015-11-05 13:04:00 +00:00
Bertrand Lallau 798c7e35ef Use assertIn and assertNotIn
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
2015-11-02 22:35:04 +01:00
wangqun 87d6056846 Use assertIsInstance instead of assertTrue(isinstance(a, b))
Developer should use assertIsInstance to replace the
assertTrue(isinstance(a, b)).

Closes-Bug: #1510384
Change-Id: I70f68a5810a6797c7b7e112b46ef2463907bba3e
2015-11-02 04:09:47 +00:00
wangqun 082c8ed0b8 Use assertIsNotNone instead of assertEqual(** is not None)
Developer should use assertIsNotNone to replace the
assertEqual(** is not None).

Closes-Bug: #1510371
Change-Id: I5afd03aaf591e047b855bc416bc60fbc182bdc19
2015-10-30 04:33:40 +00:00
Bertrand Lallau 2eea193d77 Use assertTrue/False instead of assertEqual(T/F)
The usage of assertEqual(True/False, ***) should be changed to a more
meaningful format of assertTrue/False(***).

Closes-Bug: #1510001
Change-Id: Ia16af467d5f5bfca029002d9d261540947b0be92
2015-10-29 11:17:01 +01:00
Bertrand Lallau e97f70788c Use assertIsNone instead of assertEqual(None, ***)
Instead of using assertEqual(None, ***), developers should
use assertIsNone(***) to have more clear messages in case of failure.

Closes-Bug: #1510006
Change-Id: Ib3d09ed651877569a9b940da97662489885f18e9
2015-10-28 17:38:13 +01:00
Tom Cammann 6bb1768847 doc8 all documentation and fix doc style
Add doc8 to `tox -edocs` command. doc8 will check syntax/style check
rst documents and fail if not compliant.

Change-Id: Id2e9ed1f96cac27dc5e38f828fd2d824dad31c49
2015-09-16 16:58:11 +01:00
Hongbin Lu 0b9b7de79a Eliminate mutable default arguments
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
2015-07-10 13:33:49 +00:00
Eli Qiao f67e67ec9a Correct Hacking rule code
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
2015-06-17 14:14:25 +08:00
Eli Qiao de7da996b5 Add hacking rule framework for magnum
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
2015-06-17 09:00:06 +08:00
JUNJIE NAN e0f3f02980 Correct doc format
And typo fix

Change-Id: I15119f433975e875cdd6ed9c2df7ca0dce59eafa
2015-02-28 07:06:18 +08:00
digambar 9bd22e2c77 Initial commit from github (squashed)
These were the commits from github repo(s)

  84d943e Initial commit
  3d15bd1 Created the pecan project for containers for API
  b49297b Added rest functionality to the v2 apis
  227e1dd Added rest functionality to the v2 apis
  39500ae Added the base API call like POST, GET, PUT & DELETE.
  e404e94 adding wsme support to pecan
  f90f540 Added wsme support to the magnum apis
  c879329 added changes to api
  24ebc32 Fixed the bugs in the container apis
  01725ef Rename dir from containers to magnum
  1a1375a Add requirements and test-requirements
  f957e2e Add ASL2.0 license
  8f4c0ee Move tests to the proper location
  48dd100 Move setup files to proper directory
  86cc435 Fix the setup so the installation is sanitary
  b766d59 Make the installation and tox testing work
  c477236 This is a new project - start with v1 for api
  cf20cac Remove pep8 errors
  d23b325 Merge with code generated using OpenStack cookie-cutter
  b6b9f34 Ability to run pecan serve from command line

Had to update requirements.txt to get jobs working

Change-Id: I068389412d023c258bda40dfbdff5a40f2e7d175
Co-Authored-By: Digambar Patil <digambarpat@gmail.com>
Co-Authored-By: Steven Dake <sdake@redhat.com>
2014-11-18 09:23:37 -05:00