Debian Codegraph @

oslo_upgradecheck/common_checks.py

raw symbols SCIP
1 # Licensed under the Apache License, Version 2.0 (the "License"); you may
2 # not use this file except in compliance with the License. You may obtain
3 # a copy of the License at
4 #
5 # http://www.apache.org/licenses/LICENSE-2.0
6 #
7 # Unless required by applicable law or agreed to in writing, software
8 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10 # License for the specific language governing permissions and limitations
11 # under the License.
12
13 from oslo_config import cfg # type: ignore
14 from oslo_policy import opts as policy_opts # type: ignore
15 from oslo_utils import fileutils
16
17 from oslo_upgradecheck import upgradecheck
18
19 """
20 Common checks which can be used by multiple services.
21 """
22
23
24 def check_policy_json(
25 self: upgradecheck.UpgradeCommands, conf: cfg.ConfigOpts
26 ) -> upgradecheck.Result:
27 "Checks to see if policy file is JSON-formatted policy file."
28
29 # NOTE(gmann): This method need [oslo_policy].policy_file
30 # config value so register those options in case they
31 # are not register by services.
32 conf.register_opts(policy_opts._options, group=policy_opts._option_group)
33
34 msg = (
35 "Your policy file is JSON-formatted which is "
36 "deprecated. You need to switch to YAML-formatted file. "
37 "Use the ``oslopolicy-convert-json-to-yaml`` "
38 "tool to convert the existing JSON-formatted files to "
39 "YAML in a backwards-compatible manner: "
40 "https://docs.openstack.org/oslo.policy/"
41 "latest/cli/oslopolicy-convert-json-to-yaml.html."
42 )
43 status = upgradecheck.Result(upgradecheck.Code.SUCCESS)
44 # Check if policy file exist and is JSON-formatted.
45 policy_path = conf.find_file(conf.oslo_policy.policy_file)
46 if policy_path and fileutils.is_json(policy_path):
47 status = upgradecheck.Result(upgradecheck.Code.FAILURE, msg)
48 return status