From 9f95a6e19bbf17369cf9917480a9fe8b07f245ec Mon Sep 17 00:00:00 2001 From: Ghanshyam Mann Date: Fri, 4 Dec 2020 17:00:29 -0600 Subject: [PATCH] Register oslo policy opts explicitly for check_policy_json check_policy_json() common check need [oslo_policy].policy_file config value and it is better to register those options explicitly in check_policy_json() in case they are not register by services. Currently it work as oslo.policy opts are registered via some import in service side code path for upgradechecks which are not so safe when these code import path change. Change-Id: I16fcce119698c7375e4b58558fdce89e78a79a9b --- lower-constraints.txt | 1 + oslo_upgradecheck/common_checks.py | 8 ++++++++ oslo_upgradecheck/tests/test_common_checks.py | 7 +++---- requirements.txt | 1 + 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lower-constraints.txt b/lower-constraints.txt index 071c7ea..c30a967 100644 --- a/lower-constraints.txt +++ b/lower-constraints.txt @@ -6,3 +6,4 @@ oslotest==3.5.0 stestr==2.0.0 oslo.serialization==2.21.1 oslo.utils==4.5.0 +oslo.policy==2.0.0 diff --git a/oslo_upgradecheck/common_checks.py b/oslo_upgradecheck/common_checks.py index 1881980..6085070 100644 --- a/oslo_upgradecheck/common_checks.py +++ b/oslo_upgradecheck/common_checks.py @@ -10,6 +10,7 @@ # License for the specific language governing permissions and limitations # under the License. +from oslo_policy import opts as policy_opts from oslo_utils import fileutils from oslo_upgradecheck import upgradecheck @@ -21,6 +22,13 @@ Common checks which can be used by multiple services. def check_policy_json(self, conf): "Checks to see if policy file is JSON-formatted policy file." + + # NOTE(gmann): This method need [oslo_policy].policy_file + # config value so register those options in case they + # are not register by services. + conf.register_opts(policy_opts._options, + group=policy_opts._option_group) + msg = ("Your policy file is JSON-formatted which is " "deprecated. You need to switch to YAML-formatted file. " "Use the ``oslopolicy-convert-json-to-yaml`` " diff --git a/oslo_upgradecheck/tests/test_common_checks.py b/oslo_upgradecheck/tests/test_common_checks.py index c5c54a2..da9ec24 100644 --- a/oslo_upgradecheck/tests/test_common_checks.py +++ b/oslo_upgradecheck/tests/test_common_checks.py @@ -17,6 +17,7 @@ import yaml from oslo_config import cfg from oslo_config import fixture as config +from oslo_policy import opts as policy_opts from oslo_serialization import jsonutils from oslotest import base @@ -31,10 +32,8 @@ class TestUpgradeCheckPolicyJSON(base.BaseTestCase): conf_fixture = self.useFixture(config.Config()) conf_fixture.load_raw_values() self.conf = conf_fixture.conf - policy_file_opt = cfg.StrOpt('policy_file', - default='policy.json', - help='policy file') - self.conf.register_opt(policy_file_opt, group="oslo_policy") + self.conf.register_opts(policy_opts._options, + group=policy_opts._option_group) self.cmd = upgradecheck.UpgradeCommands() self.cmd._upgrade_checks = (('Policy File JSON to YAML Migration', diff --git a/requirements.txt b/requirements.txt index 4b13697..2f5f024 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,3 +6,4 @@ oslo.config>=5.2.0 # Apache-2.0 oslo.i18n>=3.15.3 # Apache-2.0 PrettyTable<0.8,>=0.7.1 # BSD oslo.utils>=4.5.0 # Apache-2.0 +oslo.policy>=2.0.0 # Apache-2.0 -- GitLab