summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGhanshyam Mann <gmann@ghanshyammann.com>2022-02-07 17:12:45 -0600
committerGhanshyam Mann <gmann@ghanshyammann.com>2022-02-08 08:56:41 -0600
commiteae3dc0032106ac8b3a33c7ced0444810abb311c (patch)
tree364d7076a1ad7c6f738df445a223bd97818e7dae
parent641b4f7ae0a77fe8de935754f2b9d8ae9533e36b (diff)
downloadoslo-policy-eae3dc0032106ac8b3a33c7ced0444810abb311c.tar.gz
Expand set_defaults() to set other config default value
Currently set_defaults() is only able to set the default value of policy_file config option. In future, for example scope config option like enforce_scope also needs to be override the default value per service (service ready with scope enable can set it to True and for other services it will be False as default in oslo.policy). To allow override the other config option, let's expand the existing set_defaults() method to do so. Change-Id: I72120efb7c55aab82b765237904c9ae6e91f6b6f
-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)