From 1404f33b50452d4c0e0ef8c748011ce80303c2fd Mon Sep 17 00:00:00 2001 From: Ihar Hrachyshka Date: Fri, 27 Feb 2015 15:37:32 +0100 Subject: [PATCH] policy: don't hack around oslo.config path search algorithm Instead, pass proper --config-file when running tests. This should make oslo_config.ConfigOpts.find_file work even when running from the source tree. Change-Id: I24e36170e6f289ac08c9ba7b6ac48d595cea0ab9 --- neutron/policy.py | 7 ------- neutron/tests/base.py | 13 +++++++++---- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/neutron/policy.py b/neutron/policy.py index d1c7b42d269..8fa8a38780d 100644 --- a/neutron/policy.py +++ b/neutron/policy.py @@ -22,14 +22,12 @@ import itertools import logging import re -from oslo_config import cfg from oslo_utils import excutils from oslo_utils import importutils from neutron.api.v2 import attributes from neutron.common import constants as const from neutron.common import exceptions -import neutron.common.utils as utils from neutron.i18n import _LE, _LI, _LW from neutron.openstack.common import log from neutron.openstack.common import policy @@ -71,11 +69,6 @@ def init(): global _ENFORCER if not _ENFORCER: _ENFORCER = policy.Enforcer() - # NOTE: Method _get_policy_path in common.policy can not always locate - # neutron policy file (when init() is called in tests), - # so set it explicitly. - _ENFORCER.policy_path = utils.find_config_file({}, - cfg.CONF.policy_file) _ENFORCER.load_rules(True) diff --git a/neutron/tests/base.py b/neutron/tests/base.py index 5edb7384572..740119581e7 100644 --- a/neutron/tests/base.py +++ b/neutron/tests/base.py @@ -41,12 +41,12 @@ CONF = cfg.CONF CONF.import_opt('state_path', 'neutron.common.config') LOG_FORMAT = sub_base.LOG_FORMAT -ROOTDIR = os.path.dirname(__file__) -ETCDIR = os.path.join(ROOTDIR, 'etc') +ROOT_DIR = os.path.join(os.path.dirname(__file__), '..', '..') +TEST_ROOT_DIR = os.path.dirname(__file__) -def etcdir(*p): - return os.path.join(ETCDIR, *p) +def etcdir(filename, root=TEST_ROOT_DIR): + return os.path.join(root, 'etc', filename) def fake_use_fatal_exceptions(*args): @@ -68,6 +68,11 @@ class BaseTestCase(sub_base.SubBaseTestCase): # neutron.conf.test includes rpc_backend which needs to be cleaned up if args is None: args = ['--config-file', etcdir('neutron.conf.test')] + # this is needed to add ROOT_DIR to the list of paths that oslo.config + # will try to traverse when searching for a new config file (it's + # needed so that policy module can locate policy_file) + args += ['--config-file', etcdir('neutron.conf', root=ROOT_DIR)] + if conf is None: config.init(args=args) else: