Merge "Fix OSC scheduledoperations commands formatting"
This commit is contained in:
@@ -12,6 +12,8 @@
|
||||
|
||||
"""Data protection V1 scheduled_operations action implementations"""
|
||||
|
||||
import functools
|
||||
import json
|
||||
import six
|
||||
|
||||
from oslo_utils import uuidutils
|
||||
@@ -24,6 +26,15 @@ from karborclient.common.apiclient import exceptions
|
||||
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):
|
||||
_description = _("List scheduled_operations.")
|
||||
|
||||
@@ -104,16 +115,17 @@ class ListScheduledOperations(command.Lister):
|
||||
search_opts=search_opts, marker=parsed_args.marker,
|
||||
limit=parsed_args.limit, sort=parsed_args.sort)
|
||||
|
||||
column_headers = ['Id', 'Name', 'OperationType', 'TriggerId',
|
||||
'OperationDefinition']
|
||||
column_headers = ['Id', 'Name', 'Operation Type', 'Trigger Id',
|
||||
'Operation Definition']
|
||||
|
||||
scheduled_operations = []
|
||||
for s in data:
|
||||
scheduled_operation = (s.id, s.name, s.operation_type,
|
||||
s.trigger_id, s.operation_definition)
|
||||
scheduled_operations.append(scheduled_operation)
|
||||
|
||||
return (column_headers, scheduled_operations)
|
||||
json_dumps = functools.partial(json.dumps, indent=2, sort_keys=True)
|
||||
formatters = {
|
||||
"Operation Definition": json_dumps,
|
||||
}
|
||||
return (column_headers,
|
||||
list(osc_utils.get_item_properties(
|
||||
s, column_headers, formatters=formatters,
|
||||
) for s in data))
|
||||
|
||||
|
||||
class ShowScheduledOperation(command.ShowOne):
|
||||
@@ -133,7 +145,7 @@ class ShowScheduledOperation(command.ShowOne):
|
||||
so = osc_utils.find_resource(client.scheduled_operations,
|
||||
parsed_args.scheduledoperation)
|
||||
|
||||
so._info.pop("links", None)
|
||||
format_scheduledoperation(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.trigger_id, parsed_args.operation_definition)
|
||||
|
||||
so._info.pop("links", None)
|
||||
format_scheduledoperation(so._info)
|
||||
return zip(*sorted(six.iteritems(so._info)))
|
||||
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
# limitations under the License.
|
||||
|
||||
import copy
|
||||
import json
|
||||
|
||||
from karborclient.osc.v1 import scheduled_operations as osc_so
|
||||
from karborclient.tests.unit.osc.v1 import fakes
|
||||
@@ -61,21 +62,23 @@ class TestListScheduledOperations(TestScheduledOperations):
|
||||
|
||||
# Check that columns are correct
|
||||
expected_columns = (
|
||||
['Id', 'Name', 'OperationType', 'TriggerId',
|
||||
'OperationDefinition'])
|
||||
['Id', 'Name', 'Operation Type', 'Trigger Id',
|
||||
'Operation Definition'])
|
||||
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
|
||||
expected_data = [("1a2c0c3d-f402-4cd8-b5db-82e85cb51fad",
|
||||
"My scheduled operation",
|
||||
"protect",
|
||||
"23902b02-5666-4ee6-8dfe-962ac09c3995",
|
||||
{
|
||||
"provider_id":
|
||||
"2a9ce1f3-cc1a-4516-9435-0ebb13caa399", # noqa
|
||||
"plan_id":
|
||||
"2a9ce1f3-cc1a-4516-9435-0ebb13caa398"
|
||||
})]
|
||||
json.dumps(operation_definition,
|
||||
indent=2, sort_keys=True)
|
||||
)]
|
||||
self.assertEqual(expected_data, data)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user