From 9471282626e004296351a4a97fb51209a53e7f42 Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Thu, 8 Nov 2012 15:37:44 -0800 Subject: [PATCH] Ban db import from nova/virt This makes hacking.py complain if someone adds something like: from nova import db into any of the files in nova/virt/* (aside from the fake.py file). It also removes the rest of the dangling db imports that are no longer needed. Yay! Change-Id: Iba3d53b87e65e33a55f8e5033b5d1d33b28d12f7 --- HACKING.rst | 1 + nova/virt/hyperv/vmops.py | 1 - nova/virt/virtapi.py | 3 --- nova/virt/xenapi/driver.py | 1 - nova/virt/xenapi/host.py | 1 - nova/virt/xenapi/pool.py | 1 - tools/hacking.py | 7 +++++++ 7 files changed, 8 insertions(+), 7 deletions(-) diff --git a/HACKING.rst b/HACKING.rst index 52dc38bf88df..bf8274ceada1 100644 --- a/HACKING.rst +++ b/HACKING.rst @@ -33,6 +33,7 @@ Imports - Do not import objects, only modules (*) - Do not import more than one module per line (*) - Do not make relative imports +- Do not make new nova.db imports in nova/virt/* - Order your imports by the full module path - Organize your imports according to the following template diff --git a/nova/virt/hyperv/vmops.py b/nova/virt/hyperv/vmops.py index d252fbfb3ce6..11cc8b80d64f 100644 --- a/nova/virt/hyperv/vmops.py +++ b/nova/virt/hyperv/vmops.py @@ -22,7 +22,6 @@ import os import uuid from nova import config -from nova import db from nova import exception from nova import flags from nova.openstack.common import cfg diff --git a/nova/virt/virtapi.py b/nova/virt/virtapi.py index 4cf769be1671..85e638add109 100644 --- a/nova/virt/virtapi.py +++ b/nova/virt/virtapi.py @@ -15,9 +15,6 @@ # under the License. -from nova import db - - class VirtAPI(object): def instance_update(self, context, instance_uuid, updates): """Perform an instance update operation on behalf of a virt driver diff --git a/nova/virt/xenapi/driver.py b/nova/virt/xenapi/driver.py index 0ebec1d8a98c..0703a9b155b7 100644 --- a/nova/virt/xenapi/driver.py +++ b/nova/virt/xenapi/driver.py @@ -48,7 +48,6 @@ from eventlet import timeout from nova import config from nova import context -from nova import db from nova import exception from nova import flags from nova.openstack.common import cfg diff --git a/nova/virt/xenapi/host.py b/nova/virt/xenapi/host.py index 923213e65849..30d085fe22ac 100644 --- a/nova/virt/xenapi/host.py +++ b/nova/virt/xenapi/host.py @@ -24,7 +24,6 @@ import logging from nova.compute import task_states from nova.compute import vm_states from nova import context -from nova import db from nova import exception from nova import notifications from nova.openstack.common import jsonutils diff --git a/nova/virt/xenapi/pool.py b/nova/virt/xenapi/pool.py index a42f50274542..e236528fe1bd 100644 --- a/nova/virt/xenapi/pool.py +++ b/nova/virt/xenapi/pool.py @@ -23,7 +23,6 @@ import urlparse from nova.compute import rpcapi as compute_rpcapi from nova import config -from nova import db from nova import exception from nova import flags from nova.openstack.common import cfg diff --git a/tools/hacking.py b/tools/hacking.py index a22e1c6ffdb6..91d8fde60e64 100755 --- a/tools/hacking.py +++ b/tools/hacking.py @@ -271,6 +271,13 @@ def nova_import_alphabetical(logical_line, line_number, lines): % (split_previous[1], split_line[1])) +def nova_import_no_db_in_virt(logical_line, filename): + if ("nova/virt" in filename and + not filename.endswith("fake.py") and + "nova import db" in logical_line): + yield (0, "NOVA N307: nova.db import not allowed in nova/virt/*") + + def nova_docstring_start_space(physical_line): """Check for docstring not start with space.