From 1351816314753e35afde79f044b0bfb3c7ffe3fc Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Tue, 11 Mar 2014 10:49:43 -0700 Subject: [PATCH] Block database access in nova-network binary This mirrors the code we have in cmd/compute.py to wedge the database module so that we can't add any more direct calls, and will highlight any stragglers. Related to blueprint nova-network-objects Change-Id: Ib12415d84de950265626b4a804f33717203d9765 Related-bug: 1290568 --- nova/cmd/network.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/nova/cmd/network.py b/nova/cmd/network.py index 3f0c6adc0db1..fea266ba9082 100644 --- a/nova/cmd/network.py +++ b/nova/cmd/network.py @@ -17,12 +17,16 @@ """Starter script for Nova Network.""" import sys +import traceback from oslo.config import cfg from nova.conductor import rpcapi as conductor_rpcapi from nova import config +import nova.db.api +from nova import exception from nova.objects import base as objects_base +from nova.openstack.common.gettextutils import _ from nova.openstack.common import log as logging from nova.openstack.common.report import guru_meditation_report as gmr from nova import service @@ -34,6 +38,21 @@ CONF.import_opt('network_topic', 'nova.network.rpcapi') CONF.import_opt('use_local', 'nova.conductor.api', group='conductor') +def block_db_access(): + class NoDB(object): + def __getattr__(self, attr): + return self + + def __call__(self, *args, **kwargs): + stacktrace = "".join(traceback.format_stack()) + LOG = logging.getLogger('nova.network') + LOG.error(_('No db access allowed in nova-network: %s'), + stacktrace) + raise exception.DBNotAllowed('nova-network') + + nova.db.api.IMPL = NoDB() + + def main(): config.parse_args(sys.argv) logging.setup("nova") @@ -42,6 +61,7 @@ def main(): gmr.TextGuruMeditation.setup_autorun(version) if not CONF.conductor.use_local: + block_db_access() objects_base.NovaObject.indirection_api = \ conductor_rpcapi.ConductorAPI()