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/tests | |
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/tests')
-rw-r--r-- | oslo_policy/tests/test_generator.py | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/oslo_policy/tests/test_generator.py b/oslo_policy/tests/test_generator.py index a0beeae..147ef2d 100644 --- a/oslo_policy/tests/test_generator.py +++ b/oslo_policy/tests/test_generator.py @@ -500,8 +500,9 @@ class GeneratorRaiseErrorTestCase(testtools.TestCase): def test_generator_call_with_no_arguments_raises_error(self): testargs = ['oslopolicy-sample-generator'] with mock.patch('sys.argv', testargs): + local_conf = cfg.ConfigOpts() self.assertRaises(cfg.RequiredOptError, generator.generate_sample, - []) + [], local_conf) class GeneratePolicyTestCase(base.PolicyBaseTestCase): @@ -655,6 +656,8 @@ class UpgradePolicyTestCase(base.PolicyBaseTestCase): plugin=None, obj=[self.new_policy]) self.extensions.append(ext) + # Just used for cli opt parsing + self.local_conf = cfg.ConfigOpts() def test_upgrade_policy_json_file(self): test_mgr = stevedore.named.NamedExtensionManager.make_test_instance( @@ -669,7 +672,7 @@ class UpgradePolicyTestCase(base.PolicyBaseTestCase): self.get_config_file_fullname('new_policy.json'), '--format', 'json'] with mock.patch('sys.argv', testargs): - generator.upgrade_policy() + generator.upgrade_policy(conf=self.local_conf) new_file = self.get_config_file_fullname('new_policy.json') new_policy = jsonutils.loads(open(new_file, 'r').read()) self.assertIsNotNone(new_policy.get('new_policy_name')) @@ -688,7 +691,7 @@ class UpgradePolicyTestCase(base.PolicyBaseTestCase): self.get_config_file_fullname('new_policy.yaml'), '--format', 'yaml'] with mock.patch('sys.argv', testargs): - generator.upgrade_policy() + generator.upgrade_policy(conf=self.local_conf) new_file = self.get_config_file_fullname('new_policy.yaml') new_policy = yaml.safe_load(open(new_file, 'r')) self.assertIsNotNone(new_policy.get('new_policy_name')) @@ -706,7 +709,7 @@ class UpgradePolicyTestCase(base.PolicyBaseTestCase): '--namespace', 'test_upgrade', '--format', 'json'] with mock.patch('sys.argv', testargs): - generator.upgrade_policy() + generator.upgrade_policy(conf=self.local_conf) expected = '''{ "new_policy_name": "rule:admin" }''' @@ -724,7 +727,7 @@ class UpgradePolicyTestCase(base.PolicyBaseTestCase): '--namespace', 'test_upgrade', '--format', 'yaml'] with mock.patch('sys.argv', testargs): - generator.upgrade_policy() + generator.upgrade_policy(conf=self.local_conf) expected = '''new_policy_name: rule:admin ''' self.assertEqual(expected, stdout.getvalue()) |