Merge "Enable JSON results output"
This commit is contained in:
commit
d77fbb2111
@ -13,6 +13,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import json
|
||||
import sys
|
||||
import textwrap
|
||||
import traceback
|
||||
@ -24,6 +25,8 @@ import six
|
||||
|
||||
from oslo_upgradecheck._i18n import _
|
||||
|
||||
CONF = None
|
||||
|
||||
|
||||
class Code(enum.IntEnum):
|
||||
"""Status codes for the upgrade check command"""
|
||||
@ -92,6 +95,7 @@ class UpgradeCommands(object):
|
||||
|
||||
:returns: Code
|
||||
"""
|
||||
global CONF
|
||||
return_code = Code.SUCCESS
|
||||
# This is a list if 2-item tuples for the check name and it's results.
|
||||
check_results = []
|
||||
@ -121,6 +125,20 @@ class UpgradeCommands(object):
|
||||
# NOTE(bnemec): We use six.text_type on the translated string to
|
||||
# force immediate translation if lazy translation is in use.
|
||||
# See lp1801761 for details.
|
||||
|
||||
# Since registering opts can be overridden by consuming code, we can't
|
||||
# assume that our locally defined option exists.
|
||||
if (hasattr(CONF, 'command') and hasattr(CONF.command, 'json') and
|
||||
CONF.command.json):
|
||||
output = {'name': six.text_type(self.display_title), 'checks': []}
|
||||
for name, result in check_results:
|
||||
output['checks'].append(
|
||||
{'check': name,
|
||||
'result': result.code,
|
||||
'details': result.details}
|
||||
)
|
||||
print(json.dumps(output))
|
||||
else:
|
||||
t = prettytable.PrettyTable([six.text_type(self.display_title)],
|
||||
hrules=prettytable.ALL)
|
||||
t.align = 'l'
|
||||
@ -154,6 +172,11 @@ def register_cli_options(conf, upgrade_command):
|
||||
upgrade_action = subparsers.add_parser('upgrade')
|
||||
upgrade_action.add_argument('check')
|
||||
upgrade_action.set_defaults(action_fn=upgrade_command.check)
|
||||
upgrade_action.add_argument(
|
||||
'--json',
|
||||
action='store_true',
|
||||
help='Output the results in JSON format. Default is to print '
|
||||
'results in human readable table format.')
|
||||
|
||||
opt = cfg.SubCommandOpt('command', handler=add_parsers)
|
||||
conf.register_cli_opt(opt)
|
||||
@ -194,6 +217,7 @@ def main(conf, project, upgrade_command,
|
||||
the search behavior in oslo.config.
|
||||
|
||||
"""
|
||||
global CONF
|
||||
register_cli_options(conf, upgrade_command)
|
||||
|
||||
conf(
|
||||
@ -201,5 +225,5 @@ def main(conf, project, upgrade_command,
|
||||
project=project,
|
||||
default_config_files=default_config_files,
|
||||
)
|
||||
|
||||
CONF = conf
|
||||
return run(conf)
|
||||
|
7
releasenotes/notes/json-output-78a9e19588b7b1e1.yaml
Normal file
7
releasenotes/notes/json-output-78a9e19588b7b1e1.yaml
Normal file
@ -0,0 +1,7 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
oslo.upgradecheck now supports the command line flag ``--json`` to have
|
||||
the upgrade check results output in a compact, machine readable JSON
|
||||
format. The default output without this flag remains a human readable
|
||||
table of the results.
|
Loading…
Reference in New Issue
Block a user