Add HACKING check for db session param
Add a HACKING check to enforce that public db/api and db/sqlalchemy/api methods to not accept a 'session' parameter. This check is initially disabled, since it is failing ~24 times right now, but will be enabled once bp/db-session-cleanup is complete. Change-Id: Ib89eea58555032dd142d4e21e62d66e2726f0d06
This commit is contained in:
parent
88531ada39
commit
f2b4419b9f
@ -9,7 +9,8 @@ Nova Specific Commandments
|
||||
---------------------------
|
||||
|
||||
- ``nova.db`` imports are not allowed in ``nova/virt/*``
|
||||
|
||||
- [N309] no db session in public API methods (disabled)
|
||||
This enforces a guideline defined in ``nova.openstack.common.db.sqlalchemy.session``
|
||||
|
||||
Creating Unit Tests
|
||||
-------------------
|
||||
|
@ -13,6 +13,10 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import re
|
||||
|
||||
session_check = re.compile("\w*def [a-zA-Z0-9].*[(].*session.*[)]")
|
||||
|
||||
|
||||
def import_no_db_in_virt(logical_line, filename):
|
||||
"""Check for db calls from nova/virt
|
||||
@ -50,6 +54,13 @@ def except_python3x_compatible(logical_line, filename):
|
||||
yield(0, "N308: Python 3.x incompatible 'except x,y:' construct")
|
||||
|
||||
|
||||
def no_db_session_in_public_api(logical_line, filename):
|
||||
if "db/api.py" in filename or "db/sqlalchemy/api.py" in filename:
|
||||
if session_check.match(logical_line):
|
||||
yield (0, "N309: public db api methods may not accept session")
|
||||
|
||||
|
||||
def factory(register):
|
||||
register(import_no_db_in_virt)
|
||||
register(except_python3x_compatible)
|
||||
register(no_db_session_in_public_api)
|
||||
|
2
tox.ini
2
tox.ini
@ -39,7 +39,7 @@ commands =
|
||||
commands = {posargs}
|
||||
|
||||
[flake8]
|
||||
ignore = E121,E122,E123,E124,E125,E126,E127,E128,E711,E712,H302,H303,H404,F403,F811,F841
|
||||
ignore = E121,E122,E123,E124,E125,E126,E127,E128,E711,E712,H302,H303,H404,F403,F811,F841,N309
|
||||
builtins = _
|
||||
exclude = .venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build,plugins,tools
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user