Create pagination for the mistral client
Adding the ability to use pagination from the mistral client for list executions Change-Id: Ie8cd3e3b10da0fc198553903341570d69fbb31b8 Implements: blueprint pagination-execution-mitralclient
This commit is contained in:
@@ -68,8 +68,45 @@ class List(base.MistralLister):
|
|||||||
def _get_format_function(self):
|
def _get_format_function(self):
|
||||||
return format_list
|
return format_list
|
||||||
|
|
||||||
|
def get_parser(self, parsed_args):
|
||||||
|
parser = super(List, self).get_parser(parsed_args)
|
||||||
|
|
||||||
|
parser.add_argument('--marker',
|
||||||
|
type=str,
|
||||||
|
help='Pagination marker for large data sets('
|
||||||
|
'workflow execution id).'
|
||||||
|
'Example: mistral execution-list --marker '
|
||||||
|
'workflow_execution_id ',
|
||||||
|
default='',
|
||||||
|
nargs='?')
|
||||||
|
parser.add_argument('--limit',
|
||||||
|
type=int,
|
||||||
|
help='Maximum number of resources to '
|
||||||
|
'return in a single result.'
|
||||||
|
'Example: mistral execution-list --limit 5',
|
||||||
|
nargs='?')
|
||||||
|
parser.add_argument('--sort_keys',
|
||||||
|
help='Columns to sort results by.'
|
||||||
|
' Default: created_at.'
|
||||||
|
'Example : mistral execution-list '
|
||||||
|
'--sort_keys=id,Description',
|
||||||
|
default='created_at', nargs='?')
|
||||||
|
parser.add_argument('--sort_dirs',
|
||||||
|
help='Sorting Directions (asc/desc)'
|
||||||
|
'Default:asc.'
|
||||||
|
'Example : mistral execution-list '
|
||||||
|
'--sort_keys=id --sort_dirs=desc',
|
||||||
|
default='asc', nargs='?')
|
||||||
|
|
||||||
|
return parser
|
||||||
|
|
||||||
def _get_resources(self, parsed_args):
|
def _get_resources(self, parsed_args):
|
||||||
return executions.ExecutionManager(self.app.client).list()
|
return executions.ExecutionManager(self.app.client).list(
|
||||||
|
marker=parsed_args.marker,
|
||||||
|
limit=parsed_args.limit,
|
||||||
|
sort_keys=parsed_args.sort_keys,
|
||||||
|
sort_dirs=parsed_args.sort_dirs
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class Get(show.ShowOne):
|
class Get(show.ShowOne):
|
||||||
|
|||||||
@@ -435,6 +435,74 @@ class ExecutionCLITests(base_v2.MistralClientTestBase):
|
|||||||
|
|
||||||
self.assertEqual([], ex_output)
|
self.assertEqual([], ex_output)
|
||||||
|
|
||||||
|
def test_executions_list_with_pagination(self):
|
||||||
|
|
||||||
|
execution1 = self.mistral_admin(
|
||||||
|
'execution-create',
|
||||||
|
params='{0} -d "a"'.format(self.direct_wf['Name'])
|
||||||
|
)
|
||||||
|
|
||||||
|
execution2 = self.mistral_admin(
|
||||||
|
'execution-create',
|
||||||
|
params='{0} -d "b"'.format(self.direct_wf['Name'])
|
||||||
|
)
|
||||||
|
|
||||||
|
executions = self.mistral_cli(
|
||||||
|
True,
|
||||||
|
'execution-list',
|
||||||
|
params="--limit 1"
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(1, len(executions))
|
||||||
|
|
||||||
|
exec_id_1 = self.get_value_of_field(execution1, 'ID')
|
||||||
|
exec_id_2 = self.get_value_of_field(execution2, 'ID')
|
||||||
|
executions = self.mistral_cli(
|
||||||
|
True,
|
||||||
|
'execution-list',
|
||||||
|
params="--marker %s" % exec_id_1
|
||||||
|
)
|
||||||
|
self.assertNotIn(exec_id_1, [ex['ID'] for ex in executions])
|
||||||
|
self.assertIn(exec_id_2, [ex['ID'] for ex in executions])
|
||||||
|
|
||||||
|
executions = self.mistral_cli(
|
||||||
|
True,
|
||||||
|
'execution-list',
|
||||||
|
params="--sort_keys Description"
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertIn(exec_id_1, [ex['ID'] for ex in executions])
|
||||||
|
self.assertIn(exec_id_2, [ex['ID'] for ex in executions])
|
||||||
|
|
||||||
|
ex1_index = -1
|
||||||
|
ex2_index = -1
|
||||||
|
for idx, ex in enumerate(executions):
|
||||||
|
if ex['ID'] == exec_id_1:
|
||||||
|
ex1_index = idx
|
||||||
|
elif ex['ID'] == exec_id_2:
|
||||||
|
ex2_index = idx
|
||||||
|
|
||||||
|
self.assertTrue(ex1_index < ex2_index)
|
||||||
|
|
||||||
|
executions = self.mistral_cli(
|
||||||
|
True,
|
||||||
|
'execution-list',
|
||||||
|
params="--sort_keys Description --sort_dirs=desc"
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertIn(exec_id_1, [ex['ID'] for ex in executions])
|
||||||
|
self.assertIn(exec_id_2, [ex['ID'] for ex in executions])
|
||||||
|
|
||||||
|
ex1_index = -1
|
||||||
|
ex2_index = -1
|
||||||
|
for idx, ex in enumerate(executions):
|
||||||
|
if ex['ID'] == exec_id_1:
|
||||||
|
ex1_index = idx
|
||||||
|
elif ex['ID'] == exec_id_2:
|
||||||
|
ex2_index = idx
|
||||||
|
|
||||||
|
self.assertTrue(ex1_index > ex2_index)
|
||||||
|
|
||||||
|
|
||||||
class CronTriggerCLITests(base_v2.MistralClientTestBase):
|
class CronTriggerCLITests(base_v2.MistralClientTestBase):
|
||||||
"""Test suite checks commands to work with cron-triggers."""
|
"""Test suite checks commands to work with cron-triggers."""
|
||||||
|
|||||||
@@ -83,6 +83,23 @@ class TestCLIExecutionsV2(base.BaseCommandTest):
|
|||||||
self.assertEqual([('123', 'some', '', 'RUNNING', None,
|
self.assertEqual([('123', 'some', '', 'RUNNING', None,
|
||||||
'1', '1')], result[1])
|
'1', '1')], result[1])
|
||||||
|
|
||||||
|
@mock.patch('mistralclient.api.v2.executions.ExecutionManager.list')
|
||||||
|
def test_list_with_pagination(self, mock):
|
||||||
|
|
||||||
|
self.call(execution_cmd.List)
|
||||||
|
mock.assert_called_once_with(limit=None, marker='',
|
||||||
|
sort_dirs='asc',
|
||||||
|
sort_keys='created_at')
|
||||||
|
|
||||||
|
self.call(execution_cmd.List, app_args=['--limit', '5',
|
||||||
|
'--sort_dirs', 'id, Workflow',
|
||||||
|
'--sort_keys', 'desc',
|
||||||
|
'--marker', 'abc'])
|
||||||
|
|
||||||
|
mock.assert_called_with(limit=5, marker='abc',
|
||||||
|
sort_dirs='id, Workflow',
|
||||||
|
sort_keys='desc')
|
||||||
|
|
||||||
@mock.patch('mistralclient.api.v2.executions.ExecutionManager.get')
|
@mock.patch('mistralclient.api.v2.executions.ExecutionManager.get')
|
||||||
def test_get(self, mock):
|
def test_get(self, mock):
|
||||||
mock.return_value = EXECUTION
|
mock.return_value = EXECUTION
|
||||||
|
|||||||
Reference in New Issue
Block a user