From f926d86530f9d656de7e602304579b18f972a7db Mon Sep 17 00:00:00 2001 From: Mark McLoughlin Date: Fri, 4 May 2012 10:46:06 +0100 Subject: Use ConfigOpts.find_file() to locate policy.json Use cfg's new helper method to find policy config file. The basic behavior is "look alongside the config file" with a fall back to the standard default config paths. Change-Id: I763097107c53fc9b7d4e783ee92bf16989d92cff --- nova/policy.py | 8 +++++++- nova/tests/fake_flags.py | 1 - nova/utils.py | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/nova/policy.py b/nova/policy.py index b9f81cf5b..e976831f3 100644 --- a/nova/policy.py +++ b/nova/policy.py @@ -17,6 +17,8 @@ """Policy Engine For Nova""" +import os.path + from nova.common import policy from nova import exception from nova import flags @@ -52,7 +54,11 @@ def init(): global _POLICY_PATH global _POLICY_CACHE if not _POLICY_PATH: - _POLICY_PATH = utils.find_config(FLAGS.policy_file) + _POLICY_PATH = FLAGS.policy_file + if not os.path.exists(_POLICY_PATH): + _POLICY_PATH = FLAGS.find_file(_POLICY_PATH) + if not _POLICY_PATH: + raise exception.ConfigNotFound(path=FLAGS.policy_file) utils.read_cached_file(_POLICY_PATH, _POLICY_CACHE, reload_func=_set_brain) diff --git a/nova/tests/fake_flags.py b/nova/tests/fake_flags.py index 0da6ff69d..598fb3afc 100644 --- a/nova/tests/fake_flags.py +++ b/nova/tests/fake_flags.py @@ -43,4 +43,3 @@ FLAGS.set_default('flat_network_bridge', 'br100') FLAGS.set_default('sqlite_synchronous', False) flags.DECLARE('policy_file', 'nova.policy') flags.DECLARE('compute_scheduler_driver', 'nova.scheduler.multi') -FLAGS.set_default('policy_file', 'nova/tests/policy.json') diff --git a/nova/utils.py b/nova/utils.py index c57833c54..195b441e0 100644 --- a/nova/utils.py +++ b/nova/utils.py @@ -1332,6 +1332,7 @@ def read_cached_file(filename, cache_info, reload_func=None): """ mtime = os.path.getmtime(filename) if not cache_info or mtime != cache_info.get('mtime'): + LOG.debug(_("Reloading cached file %s") % filename) with open(filename) as fap: cache_info['data'] = fap.read() cache_info['mtime'] = mtime -- cgit