| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
from oslo_config import cfg |
| 14 |
from oslo_policy import opts as policy_opts |
| 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 |
|
| 30 |
|
| 31 |
|
| 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 |
|
| 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 |