Merge "Fix OSC scheduledoperations commands formatting"

This commit is contained in:
Jenkins
2017-08-20 08:41:20 +00:00
committed by Gerrit Code Review
2 changed files with 34 additions and 19 deletions

View File

@@ -12,6 +12,8 @@
"""Data protection V1 scheduled_operations action implementations""" """Data protection V1 scheduled_operations action implementations"""
import functools
import json
import six import six
from oslo_utils import uuidutils from oslo_utils import uuidutils
@@ -24,6 +26,15 @@ from karborclient.common.apiclient import exceptions
from karborclient.i18n import _ from karborclient.i18n import _
def format_scheduledoperation(scheduledoperation_info):
for key in ('operation_definition', ):
if key not in scheduledoperation_info:
continue
scheduledoperation_info[key] = json.dumps(scheduledoperation_info[key],
indent=2, sort_keys=True)
scheduledoperation_info.pop("links", None)
class ListScheduledOperations(command.Lister): class ListScheduledOperations(command.Lister):
_description = _("List scheduled_operations.") _description = _("List scheduled_operations.")
@@ -104,16 +115,17 @@ class ListScheduledOperations(command.Lister):
search_opts=search_opts, marker=parsed_args.marker, search_opts=search_opts, marker=parsed_args.marker,
limit=parsed_args.limit, sort=parsed_args.sort) limit=parsed_args.limit, sort=parsed_args.sort)
column_headers = ['Id', 'Name', 'OperationType', 'TriggerId', column_headers = ['Id', 'Name', 'Operation Type', 'Trigger Id',
'OperationDefinition'] 'Operation Definition']
scheduled_operations = [] json_dumps = functools.partial(json.dumps, indent=2, sort_keys=True)
for s in data: formatters = {
scheduled_operation = (s.id, s.name, s.operation_type, "Operation Definition": json_dumps,
s.trigger_id, s.operation_definition) }
scheduled_operations.append(scheduled_operation) return (column_headers,
list(osc_utils.get_item_properties(
return (column_headers, scheduled_operations) s, column_headers, formatters=formatters,
) for s in data))
class ShowScheduledOperation(command.ShowOne): class ShowScheduledOperation(command.ShowOne):
@@ -133,7 +145,7 @@ class ShowScheduledOperation(command.ShowOne):
so = osc_utils.find_resource(client.scheduled_operations, so = osc_utils.find_resource(client.scheduled_operations,
parsed_args.scheduledoperation) parsed_args.scheduledoperation)
so._info.pop("links", None) format_scheduledoperation(so._info)
return zip(*sorted(six.iteritems(so._info))) return zip(*sorted(six.iteritems(so._info)))
@@ -173,7 +185,7 @@ class CreateScheduledOperation(command.ShowOne):
parsed_args.name, parsed_args.operation_type, parsed_args.name, parsed_args.operation_type,
parsed_args.trigger_id, parsed_args.operation_definition) parsed_args.trigger_id, parsed_args.operation_definition)
so._info.pop("links", None) format_scheduledoperation(so._info)
return zip(*sorted(six.iteritems(so._info))) return zip(*sorted(six.iteritems(so._info)))

View File

@@ -12,6 +12,7 @@
# limitations under the License. # limitations under the License.
import copy import copy
import json
from karborclient.osc.v1 import scheduled_operations as osc_so from karborclient.osc.v1 import scheduled_operations as osc_so
from karborclient.tests.unit.osc.v1 import fakes from karborclient.tests.unit.osc.v1 import fakes
@@ -61,21 +62,23 @@ class TestListScheduledOperations(TestScheduledOperations):
# Check that columns are correct # Check that columns are correct
expected_columns = ( expected_columns = (
['Id', 'Name', 'OperationType', 'TriggerId', ['Id', 'Name', 'Operation Type', 'Trigger Id',
'OperationDefinition']) 'Operation Definition'])
self.assertEqual(expected_columns, columns) self.assertEqual(expected_columns, columns)
operation_definition = {
"provider_id": "2a9ce1f3-cc1a-4516-9435-0ebb13caa399",
"plan_id": "2a9ce1f3-cc1a-4516-9435-0ebb13caa398"
}
# Check that data is correct # Check that data is correct
expected_data = [("1a2c0c3d-f402-4cd8-b5db-82e85cb51fad", expected_data = [("1a2c0c3d-f402-4cd8-b5db-82e85cb51fad",
"My scheduled operation", "My scheduled operation",
"protect", "protect",
"23902b02-5666-4ee6-8dfe-962ac09c3995", "23902b02-5666-4ee6-8dfe-962ac09c3995",
{ json.dumps(operation_definition,
"provider_id": indent=2, sort_keys=True)
"2a9ce1f3-cc1a-4516-9435-0ebb13caa399", # noqa )]
"plan_id":
"2a9ce1f3-cc1a-4516-9435-0ebb13caa398"
})]
self.assertEqual(expected_data, data) self.assertEqual(expected_data, data)