Commit 9f95a6e1 authored by Ghanshyam Mann's avatar Ghanshyam Mann Committed by Ghanshyam
Browse files

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
parent 9d3bb03f
......@@ -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
......@@ -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`` "
......
......@@ -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',
......
......@@ -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
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment