From dea6f95c155f0508d23a2063bc83c24fca1fa672 Mon Sep 17 00:00:00 2001 From: Ghanshyam Mann Date: Sun, 20 Dec 2020 18:07:22 -0600 Subject: [PATCH] [goal] Deprecate the JSON formatted policy file As per the community goal of migrating the policy file the format from JSON to YAML[1], we need to do two things: 1. Change the default value of '[oslo_policy] policy_file'' config option from 'policy.json' to 'policy.yaml' with upgrade checks. 2. Deprecate the JSON formatted policy file on the project side via warning in doc and releasenotes. Also replace policy.json to policy.yaml ref from doc and tests. [1]https://governance.openstack.org/tc/goals/selected/wallaby/migrate-policy-format-from-json-to-yaml.html Change-Id: Ibfb162f88cb04c0b2af3fbf41cfcd96bc7e351be --- docker/monasca-api.conf.j2 | 2 +- lower-constraints.txt | 16 +++++++-------- monasca_api/cmd/status.py | 10 +++------- monasca_api/common/policy/policy_engine.py | 8 ++++++++ monasca_api/tests/cmd/test_status.py | 15 +++++++++----- ...ormatted-policy-file-2f00c9efa9e274af.yaml | 20 +++++++++++++++++++ requirements.txt | 10 +++++----- tox.ini | 2 +- 8 files changed, 56 insertions(+), 27 deletions(-) create mode 100644 releasenotes/notes/deprecate-json-formatted-policy-file-2f00c9efa9e274af.yaml diff --git a/docker/monasca-api.conf.j2 b/docker/monasca-api.conf.j2 index 65b93e91d..3e2015e4c 100644 --- a/docker/monasca-api.conf.j2 +++ b/docker/monasca-api.conf.j2 @@ -753,7 +753,7 @@ driver = monasca_api.common.messaging.kafka_publisher:KafkaPublisher #enforce_scope = false # The file that defines policies (string value) -#policy_file = policy.json +#policy_file = policy.yaml # Default rule. Enforced when a requested rule is not found (string value) #policy_default_rule = default diff --git a/lower-constraints.txt b/lower-constraints.txt index bf5c2fca4..e6bf2d0bb 100644 --- a/lower-constraints.txt +++ b/lower-constraints.txt @@ -54,16 +54,16 @@ os-api-ref==1.4.0 os-client-config==1.28.0 os-testr==1.0.0 oslo.concurrency==3.25.0 -oslo.config==5.2.0 -oslo.context==2.19.2 +oslo.config==6.8.0 +oslo.context==2.22.0 oslo.db==6.0.0 oslo.i18n==3.15.3 oslo.log==3.36.0 oslo.middleware==3.31.0 -oslo.policy==1.30.0 +oslo.policy==3.6.0 oslo.serialization==2.18.0 -oslo.utils==3.33.0 -oslo.upgradecheck==0.1.0 # Apache-2.0 +oslo.utils==4.5.0 +oslo.upgradecheck==1.3.0 # Apache-2.0 oslotest==3.2.0 paramiko==2.0.0 PasteDeploy==1.5.0 @@ -85,13 +85,13 @@ python-keystoneclient==3.8.0 python-mimeparse==1.6.0 python-subunit==1.0.0 pytz==2013.6 -PyYAML==3.13 +PyYAML==5.1 reno==3.1.0 -requests==2.14.2 +requests==2.20.0 requestsexceptions==1.2.0 requests-mock==1.2.0 restructuredtext-lint==1.1.1 -rfc3986==0.3.1 +rfc3986==1.2.0 simplejson==3.8.1 six==1.12.0 smmap==0.9.0 diff --git a/monasca_api/cmd/status.py b/monasca_api/cmd/status.py index 97f1a1e74..b27fb7f27 100644 --- a/monasca_api/cmd/status.py +++ b/monasca_api/cmd/status.py @@ -20,6 +20,7 @@ https://governance.openstack.org/tc/goals/stein/upgrade-checkers.html import sys from oslo_config import cfg +from oslo_upgradecheck import common_checks from oslo_upgradecheck import upgradecheck @@ -34,11 +35,6 @@ class Checks(upgradecheck.UpgradeCommands): and added to _upgrade_checks tuple. """ - def _check_placeholder(self): - # This is just a placeholder for upgrade checks, it should be - # removed when the actual checks are added - return upgradecheck.Result(upgradecheck.Code.SUCCESS) - # The format of the check functions is to return an # oslo_upgradecheck.upgradecheck.Result # object with the appropriate @@ -47,8 +43,8 @@ class Checks(upgradecheck.UpgradeCommands): # in the returned Result's "details" attribute. The # summary will be rolled up at the end of the check() method. _upgrade_checks = ( - # In the future there should be some real checks added here - (_('Placeholder'), _check_placeholder), + (_('Policy File JSON to YAML Migration'), + (common_checks.check_policy_json, {'conf': cfg.CONF})), ) diff --git a/monasca_api/common/policy/policy_engine.py b/monasca_api/common/policy/policy_engine.py index 2a1eb002f..3f9d4abdc 100644 --- a/monasca_api/common/policy/policy_engine.py +++ b/monasca_api/common/policy/policy_engine.py @@ -22,6 +22,7 @@ import sys import logging from oslo_config import cfg +from oslo_policy import opts from oslo_policy import policy from monasca_api.common.policy.i18n import _LW @@ -41,6 +42,13 @@ _ENFORCER = None saved_file_rules = [] +# TODO(gmann): Remove setting the default value of config policy_file +# once oslo_policy change the default value to 'policy.yaml'. +# https://github.com/openstack/oslo.policy/blob/a626ad12fe5a3abd49d70e3e5b95589d279ab578/oslo_policy/opts.py#L49 +DEFAULT_POLICY_FILE = 'policy.yaml' +opts.set_defaults(cfg.CONF, DEFAULT_POLICY_FILE) + + def reset(): """Reset Enforcer class.""" global _ENFORCER diff --git a/monasca_api/tests/cmd/test_status.py b/monasca_api/tests/cmd/test_status.py index 23c20ede6..93a6855a1 100644 --- a/monasca_api/tests/cmd/test_status.py +++ b/monasca_api/tests/cmd/test_status.py @@ -15,6 +15,7 @@ import unittest +from oslo_config import cfg from oslo_upgradecheck.upgradecheck import Code from monasca_api.cmd import status @@ -25,9 +26,13 @@ class TestUpgradeChecks(unittest.TestCase): def setUp(self): super(TestUpgradeChecks, self).setUp() self.cmd = status.Checks() + cfg.CONF(args=[], project='magnum') - def test__check_placeholder(self): - check_result = self.cmd._check_placeholder() - self.assertEqual( - Code.SUCCESS, check_result.code, - "Placeholder should always succeed.") + def test_checks(self): + for name, func in self.cmd._upgrade_checks: + if isinstance(func, tuple): + func_name, kwargs = func + result = func_name(self, **kwargs) + else: + result = func(self) + self.assertEqual(Code.SUCCESS, result.code) diff --git a/releasenotes/notes/deprecate-json-formatted-policy-file-2f00c9efa9e274af.yaml b/releasenotes/notes/deprecate-json-formatted-policy-file-2f00c9efa9e274af.yaml new file mode 100644 index 000000000..c9c530004 --- /dev/null +++ b/releasenotes/notes/deprecate-json-formatted-policy-file-2f00c9efa9e274af.yaml @@ -0,0 +1,20 @@ +--- +upgrade: + - | + The default value of ``[oslo_policy] policy_file`` config option has + been changed from ``policy.json`` to ``policy.yaml``. + Operators who are utilizing customized or previously generated + static policy JSON files (which are not needed by default), should + generate new policy files or convert them in YAML format. Use the + `oslopolicy-convert-json-to-yaml + `_ + tool to convert a JSON to YAML formatted policy file in + backward compatible way. +deprecations: + - | + Use of JSON policy files was deprecated by the ``oslo.policy`` library + during the Victoria development cycle. As a result, this deprecation is + being noted in the Wallaby cycle with an anticipated future removal of support + by ``oslo.policy``. As such operators will need to convert to YAML policy + files. Please see the upgrade notes for details on migration of any + custom policy files. diff --git a/requirements.txt b/requirements.txt index a7b0ba890..5f3656564 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,14 +2,14 @@ # of appearance. Changing the order has an impact on the overall integration # process, which may cause wedges in the gate later. oslo.db>=6.0.0 # Apache-2.0 -oslo.config>=5.2.0 # Apache-2.0 -oslo.context>=2.19.2 # Apache-2.0 +oslo.config>=6.8.0 # Apache-2.0 +oslo.context>=2.22.0 # Apache-2.0 oslo.log>=3.36.0 # Apache-2.0 oslo.middleware>=3.31.0 # Apache-2.0 -oslo.policy>=1.30.0 # Apache-2.0 +oslo.policy>=3.6.0 # Apache-2.0 oslo.serialization!=2.19.1,>=2.18.0 # Apache-2.0 -oslo.upgradecheck>=0.1.0 # Apache-2.0 -oslo.utils>=3.33.0 # Apache-2.0 +oslo.upgradecheck>=1.3.0 # Apache-2.0 +oslo.utils>=4.5.0 # Apache-2.0 python-keystoneclient>=3.8.0 # Apache-2.0 diff --git a/tox.ini b/tox.ini index 22a2a0d3c..8645dec41 100644 --- a/tox.ini +++ b/tox.ini @@ -138,7 +138,7 @@ description = Generates sample configuration file for monasca-api commands = oslo-config-generator --config-file=config-generator/monasca-api.conf [testenv:genpolicy] -description = Generates sample policy.json file for monasca-api +description = Generates sample policy.yaml file for monasca-api commands = oslopolicy-sample-generator --config-file=config-generator/policy.conf [testenv:venv]