Add param for magnum baymodel-list
Support baymodel-list --limit --sort_key --sort_dir Change-Id: I5aebc66e2e969939199687720a046742ee836f72 Closes-Bug: #1549667
This commit is contained in:
@@ -248,6 +248,24 @@ class ShellTest(shell_test_base.TestCommandLineArgument):
|
|||||||
self._test_arg_success('baymodel-list')
|
self._test_arg_success('baymodel-list')
|
||||||
self.assertTrue(mock_list.called)
|
self.assertTrue(mock_list.called)
|
||||||
|
|
||||||
|
@mock.patch('magnumclient.v1.baymodels.BayModelManager.list')
|
||||||
|
def test_baymodel_list_success_with_arg(self, mock_list):
|
||||||
|
self._test_arg_success('baymodel-list '
|
||||||
|
'--limit 1 '
|
||||||
|
'--sort-dir asc '
|
||||||
|
'--sort-key uuid')
|
||||||
|
self.assertTrue(mock_list.called)
|
||||||
|
|
||||||
|
@mock.patch('magnumclient.v1.baymodels.BayModelManager.list')
|
||||||
|
def test_baymodel_list_failure_invalid_arg(self, mock_list):
|
||||||
|
_error_msg = [
|
||||||
|
'.*?^usage: magnum baymodel-list ',
|
||||||
|
'.*?^error: argument --sort-dir: invalid choice: ',
|
||||||
|
".*?^Try 'magnum help baymodel-list' for more information."
|
||||||
|
]
|
||||||
|
self._test_arg_failure('baymodel-list --sort-dir aaa', _error_msg)
|
||||||
|
self.assertFalse(mock_list.called)
|
||||||
|
|
||||||
@mock.patch('magnumclient.v1.baymodels.BayModelManager.list')
|
@mock.patch('magnumclient.v1.baymodels.BayModelManager.list')
|
||||||
def test_baymodel_list_failure(self, mock_list):
|
def test_baymodel_list_failure(self, mock_list):
|
||||||
self._test_arg_failure('baymodel-list --wrong',
|
self._test_arg_failure('baymodel-list --wrong',
|
||||||
|
|||||||
@@ -146,12 +146,26 @@ def do_baymodel_show(cs, args):
|
|||||||
_show_baymodel(baymodel)
|
_show_baymodel(baymodel)
|
||||||
|
|
||||||
|
|
||||||
|
@utils.arg('--limit',
|
||||||
|
metavar='<limit>',
|
||||||
|
type=int,
|
||||||
|
help='Maximum number of baymodels to return')
|
||||||
|
@utils.arg('--sort-key',
|
||||||
|
metavar='<sort-key>',
|
||||||
|
help='Column to sort results by')
|
||||||
|
@utils.arg('--sort-dir',
|
||||||
|
metavar='<sort-dir>',
|
||||||
|
choices=['desc', 'asc'],
|
||||||
|
help='Direction to sort. "asc" or "desc".')
|
||||||
def do_baymodel_list(cs, args):
|
def do_baymodel_list(cs, args):
|
||||||
"""Print a list of bay models."""
|
"""Print a list of bay models."""
|
||||||
nodes = cs.baymodels.list()
|
nodes = cs.baymodels.list(limit=args.limit,
|
||||||
|
sort_key=args.sort_key,
|
||||||
|
sort_dir=args.sort_dir)
|
||||||
columns = ('uuid', 'name')
|
columns = ('uuid', 'name')
|
||||||
utils.print_list(nodes, columns,
|
utils.print_list(nodes, columns,
|
||||||
{'versions': magnum_utils.print_list_field('versions')})
|
{'versions': magnum_utils.print_list_field('versions')},
|
||||||
|
sortby_index=None)
|
||||||
|
|
||||||
|
|
||||||
@utils.arg('baymodel', metavar='<baymodel>', help="UUID or name of baymodel")
|
@utils.arg('baymodel', metavar='<baymodel>', help="UUID or name of baymodel")
|
||||||
|
|||||||
Reference in New Issue
Block a user