summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2015-02-16 16:47:50 +0000
committerGerrit Code Review <review@openstack.org>2015-02-16 16:47:50 +0000
commitc6593129362ff98a09ec82e21d6e76de5cf99016 (patch)
treeed1dc4c553b397b9a1d5f4d81cf2f7d2cd12dfd8
parent1f0e02c6551de067f15ceeece8ed39c9f3b12f8e (diff)
parentd8129456855a63e124cef8435dc12b5bd4a82d03 (diff)
downloadoslo-policy-c6593129362ff98a09ec82e21d6e76de5cf99016.tar.gz
Merge "Do not log on missing or empty policy_dirs"
-rw-r--r--oslo_policy/policy.py7
-rw-r--r--oslo_policy/tests/test_policy.py18
2 files changed, 19 insertions, 6 deletions
diff --git a/oslo_policy/policy.py b/oslo_policy/policy.py
index 812a981..e461914 100644
--- a/oslo_policy/policy.py
+++ b/oslo_policy/policy.py
@@ -233,7 +233,8 @@ _opts = [
'in the search path defined by the config_dir '
'option, or absolute paths. The file defined by '
'policy_file must exist for these directories to '
- 'be searched.'),
+ 'be searched. Missing or empty directories are'
+ 'ignored.'),
deprecated_group='DEFAULT'),
]
@@ -385,7 +386,6 @@ class Enforcer(object):
try:
path = self._get_policy_path(path)
except cfg.ConfigFilesNotFoundError:
- LOG.info(_LI("Can not find policy directory: %s"), path)
continue
self._walk_through_policy_directory(path,
self._load_policy_file,
@@ -405,7 +405,8 @@ class Enforcer(object):
if reloaded or not self.rules or not overwrite:
rules = Rules.load_json(data, self.default_rule)
self.set_rules(rules, overwrite=overwrite, use_conf=True)
- LOG.debug("Rules successfully reloaded")
+ LOG.debug("Reloaded policy file: %(path)s",
+ {'path': path})
def _get_policy_path(self, path):
"""Locate the policy json data file/path.
diff --git a/oslo_policy/tests/test_policy.py b/oslo_policy/tests/test_policy.py
index 0b3c0ad..96427f8 100644
--- a/oslo_policy/tests/test_policy.py
+++ b/oslo_policy/tests/test_policy.py
@@ -113,14 +113,19 @@ class EnforcerTest(base.PolicyBaseTestCase):
self.assertIn('default', self.enforcer.rules)
self.assertIn('admin', self.enforcer.rules)
- def test_load_directory(self):
+ @mock.patch('oslo_policy.policy.LOG')
+ def test_load_directory(self, mock_log):
self.enforcer.load_rules(True)
self.assertIsNotNone(self.enforcer.rules)
loaded_rules = jsonutils.loads(str(self.enforcer.rules))
self.assertEqual('role:fakeB', loaded_rules['default'])
self.assertEqual('is_admin:True', loaded_rules['admin'])
+ # 3 debug calls showing loading of policy.json,
+ # policy.d/a.conf, policy.d/b.conf
+ self.assertEqual(mock_log.debug.call_count, 3)
- def test_load_multiple_directories(self):
+ @mock.patch('oslo_policy.policy.LOG')
+ def test_load_multiple_directories(self, mock_log):
self.conf.set_override('policy_dirs',
['policy.d', 'policy.2.d'],
group='oslo_policy')
@@ -129,8 +134,12 @@ class EnforcerTest(base.PolicyBaseTestCase):
loaded_rules = jsonutils.loads(str(self.enforcer.rules))
self.assertEqual('role:fakeC', loaded_rules['default'])
self.assertEqual('is_admin:True', loaded_rules['admin'])
+ # 4 debug calls showing loading of policy.json,
+ # policy.d/a.conf, policy.d/b.conf, policy.2.d/fake.conf
+ self.assertEqual(mock_log.debug.call_count, 4)
- def test_load_non_existed_directory(self):
+ @mock.patch('oslo_policy.policy.LOG')
+ def test_load_non_existed_directory(self, mock_log):
self.conf.set_override('policy_dirs',
['policy.d', 'policy.x.d'],
group='oslo_policy')
@@ -138,6 +147,9 @@ class EnforcerTest(base.PolicyBaseTestCase):
self.assertIsNotNone(self.enforcer.rules)
self.assertIn('default', self.enforcer.rules)
self.assertIn('admin', self.enforcer.rules)
+ # 3 debug calls showing loading of policy.json,
+ # policy.d/a.conf, policy.d/b.conf
+ self.assertEqual(mock_log.debug.call_count, 3)
def test_set_rules_type(self):
self.assertRaises(TypeError,