diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000000000000000000000000000000000000..9d945567450344fa94ec9e6280095e86a6c532b0 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,35 @@ +# We from the Oslo project decided to pin repos based on the +# commit hash instead of the version tag to prevend arbitrary +# code from running in developer's machines. To update to a +# newer version, run `pre-commit autoupdate` and then replace +# the newer versions with their commit hash. + +default_language_version: + python: python3 + +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: ebc15addedad713c86ef18ae9632c88e187dd0af # v3.1.0 + hooks: + - id: trailing-whitespace + # Replaces or checks mixed line ending + - id: mixed-line-ending + args: ['--fix', 'lf'] + exclude: '.*\.(svg)$' + # Forbid files which have a UTF-8 byte-order marker + - id: check-byte-order-marker + # Checks that non-binary executables have a proper shebang + - id: check-executables-have-shebangs + # Check for files that contain merge conflict strings. + - id: check-merge-conflict + # Check for debugger imports and py37+ breakpoint() + # calls in python source + - id: debug-statements + - id: check-yaml + files: .*\.(yaml|yml)$ + - repo: https://gitlab.com/pycqa/flake8 + rev: 181bb46098dddf7e2d45319ea654b4b4d58c2840 # 3.8.3 + hooks: + - id: flake8 + additional_dependencies: + - hacking>=3.0.1,<3.1.0 diff --git a/.zuul.yaml b/.zuul.yaml index 8e3db2791412edf3bbe7a107db2186e8caeb0ec9..b45d2b627c4182712502acdf0075921677dbfc67 100644 --- a/.zuul.yaml +++ b/.zuul.yaml @@ -1,7 +1,7 @@ - project: templates: - publish-openstack-docs-pti - - openstack-python3-victoria-jobs + - openstack-python3-wallaby-jobs - check-requirements - release-notes-jobs-python3 - periodic-stable-jobs diff --git a/doc/source/conf.py b/doc/source/conf.py old mode 100755 new mode 100644 index 4a50d47a08b8bdaae27a19f5c49d453e13290914..51e290e293989d306ecb2bf4674605b065d2b1ca --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -1,4 +1,17 @@ # -*- coding: utf-8 -*- +# Copyright (C) 2020 Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. # # Configuration file for the Sphinx documentation builder. # diff --git a/lower-constraints.txt b/lower-constraints.txt index 622449859cc45fc028e8cdc9e9e2e6e61256a216..c30a9678f8c6a08492789df0811a95f369ae0eb0 100644 --- a/lower-constraints.txt +++ b/lower-constraints.txt @@ -2,5 +2,8 @@ oslo.config==5.2.0 oslo.i18n==3.15.3 enum34==1.0.4 PrettyTable==0.7.1 -oslotest==1.5.1 +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 new file mode 100644 index 0000000000000000000000000000000000000000..6085070fe2016028ec08df806b93d11ba36d0d08 --- /dev/null +++ b/oslo_upgradecheck/common_checks.py @@ -0,0 +1,44 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# 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 + +""" +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`` " + "tool to convert the existing JSON-formatted files to " + "YAML in a backwards-compatible manner: " + "https://docs.openstack.org/oslo.policy/" + "latest/cli/oslopolicy-convert-json-to-yaml.html.") + status = upgradecheck.Result(upgradecheck.Code.SUCCESS) + # Check if policy file exist and is JSON-formatted. + policy_path = conf.find_file(conf.oslo_policy.policy_file) + if policy_path and fileutils.is_json(policy_path): + status = upgradecheck.Result(upgradecheck.Code.FAILURE, msg) + return status diff --git a/oslo_upgradecheck/tests/test_common_checks.py b/oslo_upgradecheck/tests/test_common_checks.py new file mode 100644 index 0000000000000000000000000000000000000000..da9ec24b0737a9a2b637bce08e1e16fbd8555dc3 --- /dev/null +++ b/oslo_upgradecheck/tests/test_common_checks.py @@ -0,0 +1,102 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import fixtures +import os.path +import tempfile +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 + +from oslo_upgradecheck import common_checks +from oslo_upgradecheck import upgradecheck + + +class TestUpgradeCheckPolicyJSON(base.BaseTestCase): + + def setUp(self): + super(TestUpgradeCheckPolicyJSON, self).setUp() + conf_fixture = self.useFixture(config.Config()) + conf_fixture.load_raw_values() + self.conf = conf_fixture.conf + 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', + (common_checks.check_policy_json, + {'conf': self.conf})),) + + self.data = { + 'rule_admin': 'True', + 'rule_admin2': 'is_admin:True' + } + self.temp_dir = self.useFixture(fixtures.TempDir()) + fd, self.json_file = tempfile.mkstemp(dir=self.temp_dir.path) + fd, self.yaml_file = tempfile.mkstemp(dir=self.temp_dir.path) + with open(self.json_file, 'w') as fh: + jsonutils.dump(self.data, fh) + with open(self.yaml_file, 'w') as fh: + yaml.dump(self.data, fh) + + original_search_dirs = cfg._search_dirs + + def fake_search_dirs(dirs, name): + dirs.append(self.temp_dir.path) + return original_search_dirs(dirs, name) + + mock_search_dir = self.useFixture( + fixtures.MockPatch('oslo_config.cfg._search_dirs')).mock + mock_search_dir.side_effect = fake_search_dirs + + def test_policy_json_file_fail_upgrade(self): + # Test with policy json file full path set in config. + self.conf.set_override('policy_file', self.json_file, + group="oslo_policy") + self.assertEqual(upgradecheck.Code.FAILURE, + self.cmd.check()) + + def test_policy_yaml_file_pass_upgrade(self): + # Test with full policy yaml file path set in config. + self.conf.set_override('policy_file', self.yaml_file, + group="oslo_policy") + self.assertEqual(upgradecheck.Code.SUCCESS, + self.cmd.check()) + + def test_no_policy_file_pass_upgrade(self): + # Test with no policy file exist, means use policy from code. + self.conf.set_override('policy_file', 'non_exist_file', + group="oslo_policy") + self.assertEqual(upgradecheck.Code.SUCCESS, + self.cmd.check()) + + def test_default_policy_yaml_file_pass_upgrade(self): + self.conf.set_override('policy_file', 'policy.yaml', + group="oslo_policy") + tmpfilename = os.path.join(self.temp_dir.path, 'policy.yaml') + with open(tmpfilename, 'w') as fh: + yaml.dump(self.data, fh) + self.assertEqual(upgradecheck.Code.SUCCESS, + self.cmd.check()) + + def test_old_default_policy_json_file_fail_upgrade(self): + self.conf.set_override('policy_file', 'policy.json', + group="oslo_policy") + tmpfilename = os.path.join(self.temp_dir.path, 'policy.json') + with open(tmpfilename, 'w') as fh: + jsonutils.dump(self.data, fh) + self.assertEqual(upgradecheck.Code.FAILURE, + self.cmd.check()) diff --git a/oslo_upgradecheck/upgradecheck.py b/oslo_upgradecheck/upgradecheck.py index 744413dfd3e730ce039247a7f8d59205c7984f42..62c9a68b1ea5d9b63955833593a43e17761db8be 100644 --- a/oslo_upgradecheck/upgradecheck.py +++ b/oslo_upgradecheck/upgradecheck.py @@ -99,7 +99,11 @@ class UpgradeCommands(object): # This is a list if 2-item tuples for the check name and it's results. check_results = [] for name, func in self._upgrade_checks: - result = func(self) + if isinstance(func, tuple): + func_name, kwargs = func + result = func_name(self, **kwargs) + else: + result = func(self) # store the result of the check for the summary table check_results.append((name, result)) # we want to end up with the highest level code of all checks diff --git a/releasenotes/source/conf.py b/releasenotes/source/conf.py index c93fca67f8e345d0e2d54b04d463ac48ba90193b..30609032a349e5a938f9b0db1f8d43e1e8d27424 100644 --- a/releasenotes/source/conf.py +++ b/releasenotes/source/conf.py @@ -1,4 +1,17 @@ # -*- coding: utf-8 -*- +# Copyright (C) 2020 Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. # # Configuration file for the Sphinx documentation builder. # diff --git a/releasenotes/source/index.rst b/releasenotes/source/index.rst index 100c70b8022b9a3e086a268bcb217c15bd853dab..e888e66027538ed12ca1ccccd0e151b040b220b2 100644 --- a/releasenotes/source/index.rst +++ b/releasenotes/source/index.rst @@ -5,6 +5,7 @@ oslo.upgradecheck Release Notes :maxdepth: 1 unreleased + victoria ussuri train stein diff --git a/releasenotes/source/victoria.rst b/releasenotes/source/victoria.rst new file mode 100644 index 0000000000000000000000000000000000000000..4efc7b6f3b1117aae27fed2a9a8a9f7cadc7af8b --- /dev/null +++ b/releasenotes/source/victoria.rst @@ -0,0 +1,6 @@ +============================= +Victoria Series Release Notes +============================= + +.. release-notes:: + :branch: stable/victoria diff --git a/requirements.txt b/requirements.txt index a84358766d672eb6c50dcc5b6bb39b01d993484f..2f5f0247a8751b620173bb5bc7f398b10d3342a3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,3 +5,5 @@ 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 diff --git a/test-requirements.txt b/test-requirements.txt index 24bf6084765d87442be1dda149c83ecdc994c58f..ade8eefc072f39e5170e8be24b226e567067c7f6 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -3,5 +3,7 @@ # process, which may cause wedges in the gate later. hacking>=3.0,<3.1.0 # Apache-2.0 -oslotest>=1.5.1 +oslotest>=3.5.0 stestr>=2.0.0 +pre-commit>=2.6.0 # MIT +oslo.serialization>=2.21.1 # Apache-2.0 diff --git a/tox.ini b/tox.ini index 285e284155298bf745f7178b26502d55b1022b58..98cf3871dce9b25880dc0cdd044f3d18b31fb7ea 100644 --- a/tox.ini +++ b/tox.ini @@ -19,7 +19,7 @@ deps = commands = stestr run --slowest {posargs} [testenv:pep8] -commands = flake8 {posargs} +commands = pre-commit run -a [testenv:venv] commands = {posargs}