Merge "Do not log on missing or empty policy_dirs"
This commit is contained in:
commit
c659312936
|
@ -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.
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue