[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: Iad942530b5d540af3d3c074e9944687b93bcd7f2
This commit is contained in:
Ghanshyam Mann 2020-12-20 17:24:32 -06:00 committed by Ghanshyam
parent ca6c1525a0
commit 513c29078f
12 changed files with 81 additions and 22 deletions

View File

@ -76,7 +76,7 @@ Configure masakari-api
#. Create directory ``/etc/masakari``
#. Copy ``masakari.conf``, ``api-paste.ini`` and ``policy.json`` file
#. Copy ``masakari.conf``, ``api-paste.ini`` and ``policy.yaml`` file
from ``masakari/etc/`` to ``/etc/masakari`` folder
#. To run masakari-api simply use following binary:

View File

@ -278,7 +278,7 @@ function install_masakaridashboard {
$HORIZON_DIR/openstack_dashboard/local/enabled
ln -fs $MASAKARI_DASHBOARD_DIR/masakaridashboard/local/local_settings.d/_50_masakari.py \
$HORIZON_DIR/openstack_dashboard/local/local_settings.d
ln -fs $MASAKARI_DASHBOARD_DIR/masakaridashboard/conf/masakari_policy.json \
ln -fs $MASAKARI_DASHBOARD_DIR/masakaridashboard/conf/masakari_policy.yaml \
$HORIZON_DIR/openstack_dashboard/conf
}
@ -286,7 +286,7 @@ function install_masakaridashboard {
function uninstall_masakaridashboard {
sudo rm -f $DEST/horizon/openstack_dashboard/local/enabled/_50_masakaridashboard.py
sudo rm -f $DEST/horizon/openstack_dashboard/local/local_settings.d/_50_masakari.py
sudo rm -f $DEST/horizon/openstack_dashboard/conf/masakari_policy.json
sudo rm -f $DEST/horizon/openstack_dashboard/conf/masakari_policy.yaml
restart_apache_server
}

View File

@ -16,13 +16,13 @@ MASAKARI_CONF_DIR=${MASAKARI_CONF_DIR:-/etc/masakari}
MASAKARI_DASHBOARD_DIR=$DEST/masakari-dashboard
MASAKARI_CONF=${MASAKARI_CONF:-${MASAKARI_CONF_DIR}/masakari.conf}
MASAKARI_API_PASTE_INI=${MASAKARI_API_PASTE_INI:-${MASAKARI_CONF_DIR}/api-paste.ini}
MASAKARI_POLICY_JSON=${MASAKARI_POLICY_JSON:-${MASAKARI_CONF_DIR}/policy.json}
MASAKARI_POLICY_JSON=${MASAKARI_POLICY_JSON:-${MASAKARI_CONF_DIR}/policy.yaml}
MASAKARI_MONITORS_CONF_DIR=${MASAKARI_MONITORS_CONF_DIR:-/etc/masakarimonitors}
MASAKARI_MONITORS_CONF=${MASAKARI_MONITORS_CONF:-${MASAKARI_MONITORS_CONF_DIR}/masakarimonitors.conf}
MASAKARI_LOCAL_CONF_DIR=${MASAKARI_LOCAL_CONF_DIR:-${MASAKARI_DIR}/etc/masakari}
MASAKARI_LOCAL_API_PASTE_INI=${MASAKARI_LOCAL_API_PASTE_INI:-${MASAKARI_LOCAL_CONF_DIR}/api-paste.ini}
MASAKARI_LOCAL_POLICY_JSON=${MASAKARI_LOCAL_POLICY_JSON:-${MASAKARI_LOCAL_CONF_DIR}/policy.json}
MASAKARI_LOCAL_POLICY_JSON=${MASAKARI_LOCAL_POLICY_JSON:-${MASAKARI_LOCAL_CONF_DIR}/policy.yaml}
MASAKARI_AUTH_CACHE_DIR=${MASAKARI_AUTH_CACHE_DIR:-/var/cache/masakari}
MASAKARI_SERVICE_HOST=${MASAKARI_SERVICE_HOST:-$SERVICE_HOST}

View File

@ -2,6 +2,14 @@
Masakari Policies
=================
.. warning::
JSON formatted policy file is deprecated since Masakari 11.0.0 (Wallaby).
This `oslopolicy-convert-json-to-yaml`__ tool will migrate your existing
JSON-formatted policy file to YAML in a backward-compatible way.
.. __: https://docs.openstack.org/oslo.policy/latest/cli/oslopolicy-convert-json-to-yaml.html
The following is an overview of all available policies in masakari.
For a sample configuration file, refer to :doc:`sample_policy`.

View File

@ -2,6 +2,14 @@
Sample Masakari Policy File
===========================
.. warning::
JSON formatted policy file is deprecated since Masakari 11.0.0 (Wallaby).
This `oslopolicy-convert-json-to-yaml`__ tool will migrate your existing
JSON-formatted policy file to YAML in a backward-compatible way.
.. __: https://docs.openstack.org/oslo.policy/latest/cli/oslopolicy-convert-json-to-yaml.html
The following is a sample masakari policy file for adaptation and use.
The sample policy can also be viewed in :download:`file form

View File

@ -14,6 +14,7 @@
import sys
from oslo_upgradecheck import common_checks
from oslo_upgradecheck import upgradecheck
from masakari import conf
@ -30,17 +31,9 @@ class Checks(upgradecheck.UpgradeCommands):
and added to _upgrade_checks tuple.
"""
def _sample_check(self):
"""This is sample check added to test the upgrade check framework
It needs to be removed after adding any real upgrade check
"""
return upgradecheck.Result(upgradecheck.Code.SUCCESS, 'Sample detail')
_upgrade_checks = (
# Sample check added for now.
# Whereas in future real checks must be added here in tuple
(_('Sample Check'), _sample_check),
(_('Policy File JSON to YAML Migration'),
(common_checks.check_policy_json, {'conf': CONF})),
)

View File

@ -14,6 +14,24 @@
from oslo_config import cfg
from oslo_middleware import cors
from oslo_policy import opts
def set_lib_defaults():
"""Update default value for configuration options from other namespace.
Example, oslo lib config options. This is needed for
config generator tool to pick these default value changes.
https://docs.openstack.org/oslo.config/latest/cli/
generator.html#modifying-defaults-from-other-namespaces
"""
set_middleware_defaults()
# 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
opts.set_defaults(cfg.CONF, 'policy.yaml')
def set_middleware_defaults():

View File

@ -21,6 +21,7 @@ import re
import sys
from oslo_config import cfg
from oslo_policy import opts
from oslo_policy import policy
from oslo_utils import excutils
@ -31,6 +32,13 @@ from masakari import policies
CONF = cfg.CONF
LOG = logging.getLogger(__name__)
# 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)
_ENFORCER = None
# saved_file_rules and used to compare with new rules to determine the
# rules whether were updated.

View File

@ -24,7 +24,11 @@ class TestUpgradeChecks(test.TestCase):
super(TestUpgradeChecks, self).setUp()
self.cmd = status.Checks()
def test__sample_check(self):
check_result = self.cmd._sample_check()
self.assertEqual(
Code.SUCCESS, check_result.code)
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)

View File

@ -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
<https://docs.openstack.org/oslo.policy/latest/cli/oslopolicy-convert-json-to-yaml.html>`_
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.

View File

@ -15,9 +15,9 @@ oslo.messaging>=5.29.0 # Apache-2.0
oslo.i18n>=3.15.3 # 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.service!=1.28.1,>=1.24.0 # Apache-2.0
oslo.upgradecheck>=0.1.0 # Apache-2.0
oslo.upgradecheck>=1.3.0 # Apache-2.0
oslo.utils>=3.33.0 # Apache-2.0
oslo.versionedobjects>=1.31.2 # Apache-2.0
pbr!=2.1.0,>=2.0.0 # Apache-2.0

View File

@ -32,7 +32,7 @@ oslo.config.opts =
customized_recovery_flow_opts = masakari.conf.opts:list_recovery_workflow_opts
oslo.config.opts.defaults =
masakari.api = masakari.common.config:set_middleware_defaults
masakari.api = masakari.common.config:set_lib_defaults
oslo.policy.enforcer =
masakari = masakari.policy:get_enforcer