From f2b4419b9f5e01038adaae1d0ce856bd0ac9af5b Mon Sep 17 00:00:00 2001 From: Devananda van der Veen Date: Sat, 22 Jun 2013 12:05:46 -0700 Subject: [PATCH] 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 --- HACKING.rst | 3 ++- nova/hacking/checks.py | 11 +++++++++++ tox.ini | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/HACKING.rst b/HACKING.rst index 8ec767b7e96c..dcf71e453774 100644 --- a/HACKING.rst +++ b/HACKING.rst @@ -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 ------------------- diff --git a/nova/hacking/checks.py b/nova/hacking/checks.py index 89ad7c554ef7..aee63dde3683 100644 --- a/nova/hacking/checks.py +++ b/nova/hacking/checks.py @@ -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) diff --git a/tox.ini b/tox.ini index bc2ae8d6a018..d82b949fbfa7 100644 --- a/tox.ini +++ b/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