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
This commit is contained in:
parent
9d5e2b9b01
commit
1404f33b50
@ -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)
|
||||
|
||||
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user