]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
policy: don't hack around oslo.config path search algorithm
authorIhar Hrachyshka <ihrachys@redhat.com>
Fri, 27 Feb 2015 14:37:32 +0000 (15:37 +0100)
committerIhar Hrachyshka <ihrachys@redhat.com>
Fri, 27 Feb 2015 16:00:47 +0000 (17:00 +0100)
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
neutron/tests/base.py

index d1c7b42d2693184631ee2642b8af7dd42db1e108..8fa8a38780d64f22289c7ddd60780b3914a24d73 100644 (file)
@@ -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)
 
 
index 5edb73845726a5f9d9765d7e9beca68d757321cb..740119581e710e2d47e9fca6a187f72f5080f8a8 100644 (file)
@@ -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: