summaryrefslogtreecommitdiff
path: root/oslo_policy
diff options
context:
space:
mode:
Diffstat (limited to 'oslo_policy')
-rw-r--r--oslo_policy/opts.py7
-rw-r--r--oslo_policy/tests/test_opts.py21
2 files changed, 27 insertions, 1 deletions
diff --git a/oslo_policy/opts.py b/oslo_policy/opts.py
index f4e641a..368fe3a 100644
--- a/oslo_policy/opts.py
+++ b/oslo_policy/opts.py
@@ -122,7 +122,7 @@ def _register(conf):
conf.register_opts(_options, group=_option_group)
-def set_defaults(conf, policy_file=None):
+def set_defaults(conf, policy_file=None, **kwargs):
"""Set defaults for configuration variables.
Overrides default options values.
@@ -133,8 +133,13 @@ def set_defaults(conf, policy_file=None):
:param policy_file: The base filename for the file that
defines policies.
:type policy_file: unicode
+ :param kwargs: Any other configuration variable and their new
+ default value.
"""
_register(conf)
if policy_file is not None:
cfg.set_defaults(_options, policy_file=policy_file)
+
+ if kwargs:
+ cfg.set_defaults(_options, **kwargs)
diff --git a/oslo_policy/tests/test_opts.py b/oslo_policy/tests/test_opts.py
index 7c455ca..5a61b4c 100644
--- a/oslo_policy/tests/test_opts.py
+++ b/oslo_policy/tests/test_opts.py
@@ -37,3 +37,24 @@ class OptsTestCase(test_base.BaseTestCase):
opts.set_defaults(self.conf, policy_file='new-value.json')
self.assertEqual('new-value.json',
self.conf.oslo_policy.policy_file)
+
+ def test_set_defaults_enforce_scope(self):
+ opts._register(self.conf)
+ self.assertEqual(False,
+ self.conf.oslo_policy.enforce_scope)
+ opts.set_defaults(self.conf, enforce_scope=True)
+ self.assertEqual(True,
+ self.conf.oslo_policy.enforce_scope)
+
+ def test_set_defaults_two_opts(self):
+ opts._register(self.conf)
+ self.assertEqual(False,
+ self.conf.oslo_policy.enforce_scope)
+ self.assertEqual(False,
+ self.conf.oslo_policy.enforce_new_defaults)
+ opts.set_defaults(self.conf, enforce_scope=True,
+ enforce_new_defaults=True)
+ self.assertEqual(True,
+ self.conf.oslo_policy.enforce_scope)
+ self.assertEqual(True,
+ self.conf.oslo_policy.enforce_new_defaults)