diff options
author | Ben Nemec <bnemec@redhat.com> | 2019-10-23 15:36:42 +0000 |
---|---|---|
committer | Ben Nemec <bnemec@redhat.com> | 2020-01-15 16:48:41 +0000 |
commit | 686aa238f921e8b6dff814d001690e15fa8ccea6 (patch) | |
tree | 504b35a62362d8c54beb06bb0c3e11da8e6fb54b /oslo_policy/generator.py | |
parent | 0f7e144d013155f27f74b0eb91b7ae0f1530a86b (diff) | |
download | oslo-policy-686aa238f921e8b6dff814d001690e15fa8ccea6.tar.gz |
Initialize global config object in cli tools
Currently, passing --config-file to a tool like oslopolicy-list-redundant
is ineffective because the projects pass an empty cli arg list to the
conf object when they initialize it. By registering our cli args on the
global conf object, the projects can safely parse cli args in their
call to the conf object so things like --config-file won't be ignored.
This didn't work before because oslo.policy recognizes cli args like
--namespace that aren't recognized by the consuming projects.
This will require followup changes in each project to stop passing an
empty cli arg list to the conf object initialization. In the meantime,
everything should continue to work as it did before.
Change-Id: Iacd257fc6c351582de45476768e3fd1775317d3c
Closes-Bug: 1849518
Diffstat (limited to 'oslo_policy/generator.py')
-rw-r--r-- | oslo_policy/generator.py | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/oslo_policy/generator.py b/oslo_policy/generator.py index 9e283d9..fad156e 100644 --- a/oslo_policy/generator.py +++ b/oslo_policy/generator.py @@ -334,9 +334,11 @@ def on_load_failure_callback(*args, **kwargs): raise -def generate_sample(args=None): +def generate_sample(args=None, conf=None): logging.basicConfig(level=logging.WARN) - conf = cfg.ConfigOpts() + # Allow the caller to pass in a local conf object for unit testing + if conf is None: + conf = cfg.CONF conf.register_cli_opts(GENERATOR_OPTS + RULE_OPTS) conf.register_opts(GENERATOR_OPTS + RULE_OPTS) conf(args) @@ -345,7 +347,7 @@ def generate_sample(args=None): def generate_policy(args=None): logging.basicConfig(level=logging.WARN) - conf = cfg.ConfigOpts() + conf = cfg.CONF conf.register_cli_opts(GENERATOR_OPTS + ENFORCER_OPTS) conf.register_opts(GENERATOR_OPTS + ENFORCER_OPTS) conf(args) @@ -367,9 +369,11 @@ def _upgrade_policies(policies, default_policies): 'new_name': rule_default.name}) -def upgrade_policy(args=None): +def upgrade_policy(args=None, conf=None): logging.basicConfig(level=logging.WARN) - conf = cfg.ConfigOpts() + # Allow the caller to pass in a local conf object for unit testing + if conf is None: + conf = cfg.CONF conf.register_cli_opts(GENERATOR_OPTS + RULE_OPTS + UPGRADE_OPTS) conf.register_opts(GENERATOR_OPTS + RULE_OPTS + UPGRADE_OPTS) conf(args) @@ -396,7 +400,7 @@ def upgrade_policy(args=None): def list_redundant(args=None): logging.basicConfig(level=logging.WARN) - conf = cfg.ConfigOpts() + conf = cfg.CONF conf.register_cli_opts(ENFORCER_OPTS) conf.register_opts(ENFORCER_OPTS) conf(args) |