Fix OSC protectable instance formatting

Change-Id: Ib06abd01682c7194547332582c64b4c7ae7f5a05
This commit is contained in:
Yuval Brik 2017-08-14 13:26:27 +03:00
parent e1f7540bac
commit c14aea8079
2 changed files with 19 additions and 3 deletions

View File

@ -12,6 +12,8 @@
"""Data protection V1 protectables action implementations"""
import functools
import json
from osc_lib.command import command
from osc_lib import utils as osc_utils
from oslo_log import log as logging
@ -131,7 +133,15 @@ class ListProtectableInstances(command.Lister):
column_headers = ['Id', 'Type', 'Name', 'Dependent resources',
'Extra info']
return (column_headers, data)
json_dumps = functools.partial(json.dumps, indent=2, sort_keys=True)
formatters = {
"Extra info": json_dumps,
"Dependent resources": json_dumps,
}
return (column_headers,
(osc_utils.get_item_properties(
s, column_headers, formatters=formatters,
) for s in data))
class ShowProtectableInstance(command.ShowOne):
@ -173,5 +183,11 @@ class ShowProtectableInstance(command.ShowOne):
parsed_args.protectable_id,
search_opts=search_opts)
json_dumps = functools.partial(json.dumps, indent=2, sort_keys=True)
instance._info.pop("links", None)
for key in ('extra_info', 'dependent_resources'):
if key not in instance._info:
continue
instance._info[key] = json_dumps(instance._info[key])
return zip(*sorted(instance._info.items()))

View File

@ -118,8 +118,8 @@ class TestListProtectableInstances(TestProtectables):
def setUp(self):
super(TestListProtectableInstances, self).setUp()
pm = self.protectables_mock
pm.list_instances.return_value = protectables.Instances(
None, copy.deepcopy(PROTECTABLE_INSTANCE_LIST_INFO))
pm.list_instances.return_value = [protectables.Instances(
None, copy.deepcopy(PROTECTABLE_INSTANCE_LIST_INFO)), ]
# Command to test
self.cmd = osc_protectables.ListProtectableInstances(self.app, None)