Commit Graph

30 Commits

Author SHA1 Message Date
Stephen Finucane 456bd8521f Remove six
There are only two uses of this. Oddly, we never specified this
dependency directly and were instead relying on it being included
indirectly.

Change-Id: I3229750f3c47689c6b8d9db80a962a755b5a5da9
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2021-02-11 12:01:55 +00:00
Ghanshyam Mann 9f95a6e19b Register oslo policy opts explicitly for check_policy_json
check_policy_json() common check need [oslo_policy].policy_file
config value and it is better to register those options explicitly
in check_policy_json() in case they are not register by services.

Currently it work as oslo.policy opts are registered via some import
in service side code path for upgradechecks which are not so safe
when these code import path change.

Change-Id: I16fcce119698c7375e4b58558fdce89e78a79a9b
2020-12-07 21:12:03 +00:00
Ghanshyam Mann c705067278 Add common checks for json to yaml policy file migration
As part of community goal[1] for migrating the policy file
from JSON format to YAML we need to add upgrade check to
detect any JSON formatted file. That check needs to be
done in each service side which are deprecating the JSON
format. So to avoid duplicate code, this commit add that
check in oslo_upgradechecks and that can be enabled from
service side during they migrate to YAML format.

Service will enable it like below:

    _upgrade_checks = (
        (_('Policy File JSON to YAML Migration'),
            (common_checks.check_policy_json, {'conf': CONF})),
    )

Also modify the check() method to accept the **kwargs for checks.

[1] https://governance.openstack.org/tc/goals/selected/wallaby/migrate-policy-format-from-json-to-yaml.html

Change-Id: Ifa71c20879c964f794a40b981744d95db4ab1602
2020-11-21 19:11:55 +00:00
Sean McGinnis d00f48987f
Use unittest.mock instead of third party mock
Now that we don't need to support py27, we can use the standard library
unittest.mock module instead of the third party mock lib.

Change-Id: I67b86898cb443dc02c6b41a78bfe54f43f8d6c74
Signed-off-by: Sean McGinnis <sean.mcginnis@gmail.com>
2020-03-13 11:44:15 -05:00
Ben Nemec 3113a9a9a4 Address nits from json change
Remove the unnecessary global definition, remove the TODO comment
that is no longer relevant since we've added JSON support, and
move the comment about lazy translation back to the code that it
refers to.

Change-Id: I6d4e60f94c53a6f922a39dca7afee4793a7be304
2019-06-25 15:54:57 +00:00
Sean McGinnis 3a92c6e0b6
Enable JSON results output
This takes a lighter weight approach to allowing output to be formatted
as JSON than switching over to using cliff. This adds the --json flag
argument that will format the printed results in a much more compact
JSON format.

Change-Id: I54f3f347b0d7da4385ffcbfa5da61c83657f390c
Signed-off-by: Sean McGinnis <sean.mcginnis@gmail.com>
2019-06-11 10:04:58 -05:00
Zuul b7b4cf2b8e Merge "Add doc params to run and register_cli_opts" 2019-02-18 17:03:17 +00:00
Chris Dent dbe50ea95c Add doc params to run and register_cli_opts
The run and register_cli_opts methods were extracted to public
in I3d7e28d2432f5b04d4154793025786dc289b0cb2 but were not as
clearly documented as they should have been. This change improves
the situation by adding param descriptions.

Change-Id: I889bc08cda3b3850ccf7d9460851bae211272a4c
2019-02-13 10:19:54 +00:00
Zuul 4634ae4d95 Merge "Separate opt registration from command running" 2019-02-13 10:09:28 +00:00
Slawek Kaplonski 1829c08e5a Move displayed checker title to be in variable
Title of check command displayed to user is now moved
to be defined as atribute of UpgradeCommands class.
This will allow to override this command for projects which
inherits from this class.

This will be usefull for Neutron to use same class in new
sanity-check tool which will be implemented in same way as
upgrade-check is done.

Change-Id: I8218b21a219db3a3198750fd98033aff244b7002
Related-Bug: #1809878
2019-02-07 16:32:29 +01:00
Chris Dent fd6bd23457 Separate opt registration from command running
In some scenarios, it is useful for the caller of upgradecheck
to be responsible for parsing the conf (see [1]). Since
registering command line options must come before parsing,
we must separate registation from running the commands.

This change enables that by making `register_cli_options` public
and extracting a public `run` method. `main` continues to work
as before by calling these new methods.

[1] I2eea00343d1bbdf486985daeaf6707358b6a2708

Change-Id: I3d7e28d2432f5b04d4154793025786dc289b0cb2
2019-01-25 13:43:32 +00:00
Ben Nemec c4283dd0eb Force translation of table header
Concatenation of lazily translated strings using + is not supported,
but prettytable is doing that internally with one of the translated
strings that we pass in. Use six.text_type to force immediate
translation of the string before passing it to prettytable.

Change-Id: I73929f9df85a9856bb70b37ee08f5399f98fdb00
Closes-Bug: 1801761
2018-11-05 18:38:22 +00:00
Ben Nemec c5079cbc7a Move example implementation to docs
This moves the example implementation from __main__.py to the docs
tree so it isn't confused for production code. A unit test is also
added to ensure that the example is kept up to date with any changes
in the API.

Change-Id: I92aa685f410ae0e56d5d55a15812edaae83c8ff1
2018-10-09 21:56:06 +00:00
Ben Nemec 052f9ded88 Add database access details to UpgradeCommands docstring
Per the original Nova code, these checks need to be able to run on
n-1 database data, so they can't rely on the service's object model
for database access. Add details about that to the docstring for
UpgradeCommands.

Also removes a nova-ism from the check docstring.

Change-Id: I4fe84988397ae9bd2305811f10fa3d1449c4ac9f
2018-10-08 12:59:47 -04:00
Doug Hellmann ac97329770 tighten API for main()
Have the caller set up any of their options before passing a
ConfigOpts instance to main() and then let main() take over processing
from there.

Change the check callback argument to take an UpgradeCommands instance
so in the future if there are more commands we can get the callbacks
out of it ourself.

Add a default_config_files option to main() so that applications can
pass locations oslo.config won't find by default.

Change 'category' to 'command'.

Use a closure in _register_cli_options instead of a separate function
that requires a partial.

Change-Id: Ic4f25fd23d424acfcfe185a85bb63abf7d25c39e
Signed-off-by: Doug Hellmann <doug@doughellmann.com>
2018-10-08 12:57:32 -04:00
Ben Nemec a2c3f8b81d Improve config handling
Many projects need a specific config object (usually the global one)
populated for project code that relies on it. Additionally, we want
to make the code used to initialize the object overrideable so projects
can use their existing code for that. The primary benefit is that
project code has sane defaults for config file locations so in many
cases it won't be necessary to explicitly specify the location. A
very simple default implementation is also provided so the module
still works out of the box too.

Change-Id: If8ce7202bd73793688a0446f069bb4e03547c99e
2018-10-02 14:16:13 -04:00
Ben Nemec a45e26a3f0 Shorten UpgradeCheck class names
When this library is used, the classes get referred to as something
like upgradecheck.UpgradeCheckResult, which is redundant and wordy.
Shortening the class names to remove the "UpgradeCheck" part fixes
both problems.

Change-Id: I621434585ed84256b9fe44d88a516d8c27eb05b3
2018-09-21 21:36:01 +00:00
Ben Nemec 15a5d69812 Add proper documentation
Replace the cookiecutter docs with actual docs that describe the api
and explain how to use the project.

Change-Id: Ica2c76809d22a387993da1e19c75b33f9fe263d4
2018-09-21 21:35:56 +00:00
Ben Nemec c2972eb22d Add success test case
Most of the test cases ended in an error condition. This adds one
that does not.
2018-09-13 20:00:47 +00:00
Ben Nemec 3d2a3bc23f Handle exceptions from checks
The original check code in Nova behaves this way, so for consistency
do it here too.
2018-09-13 17:24:57 +00:00
Ben Nemec d3877b9087 Propagate return code
Previously the results were only being printed, but the return code
for the checks wasn't propagated up.
2018-09-13 17:19:36 +00:00
Ben Nemec 8d76949735 Add more unit tests
This gets the coverage of the upgradecheck module to 98%.
2018-09-13 17:04:50 +00:00
Ben Nemec 1f5d31a272 Test _get_details 2018-09-13 16:36:20 +00:00
Ben Nemec 18b94499d8 Get coverage job working
Add a simple test that imports the module so there is coverage data
available and fix the coverage config so it is looking at the
correct locations.
2018-09-13 16:17:56 +00:00
Ben Nemec db30bd3082 Add docstring to main() 2018-09-12 22:48:46 +00:00
Ben Nemec a2b7d05255 Fix pep8 failures 2018-09-12 22:46:06 +00:00
Ben Nemec 29c724b80c Add _i18n module
This was missed in the previous commit
2018-09-12 22:39:07 +00:00
Ben Nemec 1f333e1aea Add i18n support
There are translatable strings in this library and we need to
support that properly. Replace the stub _() with a proper
implementation based on oslo.i18n.
2018-09-12 22:28:44 +00:00
Ben Nemec 302c40a857 Initial implementation 2018-09-12 18:20:50 +00:00
Ben Nemec d671294399 Initial commit 2018-09-12 17:35:58 +00:00