diff --git a/doc/source/configuration/index.rst b/doc/source/configuration/index.rst index cca3bc963..9f7135ab9 100644 --- a/doc/source/configuration/index.rst +++ b/doc/source/configuration/index.rst @@ -3,7 +3,7 @@ Configuration Guide =================== The static configuration for Placement lives in two main files: ``placement.conf`` and -``policy.json``. These are described below. +``policy.yaml``. These are described below. Configuration ------------- diff --git a/doc/source/configuration/policy.rst b/doc/source/configuration/policy.rst index 08d250eb4..1b07e13ca 100644 --- a/doc/source/configuration/policy.rst +++ b/doc/source/configuration/policy.rst @@ -2,6 +2,14 @@ Placement Policies ================== +.. warning:: + + JSON formatted policy file is deprecated since Placement 5.0.0 (Wallaby). + The `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 Placement. For a sample configuration file, refer to :doc:`/configuration/sample-policy`. diff --git a/doc/source/configuration/sample-policy.rst b/doc/source/configuration/sample-policy.rst index 12e21c52a..e2e2bdc44 100644 --- a/doc/source/configuration/sample-policy.rst +++ b/doc/source/configuration/sample-policy.rst @@ -2,6 +2,14 @@ Sample Placement Policy File ============================ +.. warning:: + + JSON formatted policy file is deprecated since Placement 5.0.0 (Wallaby). + The `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 placement policy file for adaptation and use. The sample policy can also be viewed in :download:`file form diff --git a/lower-constraints.txt b/lower-constraints.txt index fb4397da5..5071c34f4 100644 --- a/lower-constraints.txt +++ b/lower-constraints.txt @@ -36,16 +36,16 @@ os-service-types==1.2.0 os-traits==2.4.0 oslo.concurrency==3.26.0 oslo.config==6.7.0 -oslo.context==2.21.0 +oslo.context==2.22.0 oslo.db==4.40.0 oslo.i18n==3.20.0 oslo.log==4.3.0 oslo.middleware==3.31.0 -oslo.policy==1.35.0 +oslo.policy==3.6.0 oslo.serialization==2.25.0 -oslo.upgradecheck==0.2.0 -oslo.utils==3.37.0 -oslotest==3.4.0 +oslo.upgradecheck==1.3.0 +oslo.utils==4.5.0 +oslotest==3.5.0 osprofiler==1.4.0 pbr==3.1.1 pep8==1.5.7 @@ -64,7 +64,7 @@ python-keystoneclient==3.15.0 python-mimeparse==1.6.0 python-subunit==1.2.0 pytz==2018.3 -PyYAML==3.13 +PyYAML==5.1 repoze.lru==0.7 requests==2.25.0 requestsexceptions==1.4.0 diff --git a/placement/cmd/status.py b/placement/cmd/status.py index e6d0d3f68..721d17dcb 100644 --- a/placement/cmd/status.py +++ b/placement/cmd/status.py @@ -14,6 +14,7 @@ import sqlalchemy as sa import sys from oslo_config import cfg +from oslo_upgradecheck import common_checks from oslo_upgradecheck import upgradecheck from placement import conf @@ -105,6 +106,8 @@ class Checks(upgradecheck.UpgradeCommands): _upgrade_checks = ( ('Missing Root Provider IDs', _check_root_provider_ids), ('Incomplete Consumers', _check_incomplete_consumers), + ("Policy File JSON to YAML Migration", + (common_checks.check_policy_json, {'conf': cfg.CONF})), ) diff --git a/placement/conf/base.py b/placement/conf/base.py index 86dd4cdc1..b1e671ffe 100644 --- a/placement/conf/base.py +++ b/placement/conf/base.py @@ -16,6 +16,7 @@ # under the License. from oslo_config import cfg +from oslo_policy import opts as policy_opts base_options = [ cfg.StrOpt( @@ -24,6 +25,19 @@ base_options = [ ] +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 + """ + + # Update default value of oslo.policy policy_file config option. + policy_opts.set_defaults(cfg.CONF, 'policy.yaml') + + def register_opts(conf): conf.register_opts(base_options) diff --git a/placement/policy.py b/placement/policy.py index 03a5040ca..1710f29e2 100644 --- a/placement/policy.py +++ b/placement/policy.py @@ -48,7 +48,10 @@ def get_enforcer(): # files from overrides on disk and defaults in code. We can just pass an # empty list and let oslo do the config lifting for us. cfg.CONF([], project='placement') - policy_opts.set_defaults(cfg.CONF) + # 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 + policy_opts.set_defaults(cfg.CONF, 'policy.yaml') return _get_enforcer(cfg.CONF) diff --git a/releasenotes/notes/deprecate-json-formatted-policy-file-dbec7a29325316de.yaml b/releasenotes/notes/deprecate-json-formatted-policy-file-dbec7a29325316de.yaml new file mode 100644 index 000000000..c9c530004 --- /dev/null +++ b/releasenotes/notes/deprecate-json-formatted-policy-file-dbec7a29325316de.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 90c1a14ec..fdc4d409f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -12,14 +12,14 @@ requests>=2.25.0 # Apache-2.0 setuptools!=24.0.0,!=34.0.0,!=34.0.1,!=34.0.2,!=34.0.3,!=34.1.0,!=34.1.1,!=34.2.0,!=34.3.0,!=34.3.1,!=34.3.2,!=36.2.0,>=21.0.0 # PSF/ZPL oslo.concurrency>=3.26.0 # Apache-2.0 oslo.config>=6.7.0 # Apache-2.0 -oslo.context>=2.21.0 # Apache-2.0 +oslo.context>=2.22.0 # Apache-2.0 oslo.log>=4.3.0 # Apache-2.0 oslo.serialization>=2.25.0 # Apache-2.0 -oslo.utils>=3.37.0 # Apache-2.0 +oslo.utils>=4.5.0 # Apache-2.0 oslo.db>=4.40.0 # Apache-2.0 -oslo.policy>=1.35.0 # Apache-2.0 +oslo.policy>=3.6.0 # Apache-2.0 oslo.middleware>=3.31.0 # Apache-2.0 -oslo.upgradecheck>=0.2.0 # Apache-2.0 +oslo.upgradecheck>=1.3.0 # Apache-2.0 # NOTE(efried): Sync lower-constraints.txt for os-traits & os-resource-classes. os-resource-classes>=0.5.0 # Apache-2.0 os-traits>=2.4.0 # Apache-2.0 diff --git a/setup.cfg b/setup.cfg index 9477ab833..b3f6d7221 100644 --- a/setup.cfg +++ b/setup.cfg @@ -36,6 +36,9 @@ packages = oslo.config.opts = placement.conf = placement.conf.opts:list_opts +oslo.config.opts.defaults = + nova.conf = placement.conf.base:set_lib_defaults + oslo.policy.enforcer = placement = placement.policy:get_enforcer diff --git a/test-requirements.txt b/test-requirements.txt index 12c74efea..bbcc35fff 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -12,7 +12,7 @@ fixtures>=3.0.0 # Apache-2.0/BSD # don't use it here to keep the consistency with global requirements. psycopg2>=2.8 # LGPL/ZPL PyMySQL>=0.8.0 # MIT License -oslotest>=3.4.0 # Apache-2.0 +oslotest>=3.5.0 # Apache-2.0 stestr>=1.0.0 # Apache-2.0 testtools>=2.2.0 # MIT bandit>=1.1.0 # Apache-2.0