Adds --vars filter to cell-list command
Adds the ability to search cell by its defined variables. Allowed query: cell-list --vars='a:b' --vars='c:d' or cell-list --vars='a:b,c:d' Closes-Bug: 1669760 Change-Id: Iac4ec9dcb91280603f313223baf10b82916da8f1
This commit is contained in:
parent
4bd5bc647e
commit
a273796f6a
cratonclient
@ -84,9 +84,19 @@ def do_cell_show(cc, args):
|
||||
metavar='<marker>',
|
||||
default=None,
|
||||
help='ID of the cell to use to resume listing cells.')
|
||||
@cliutils.arg('--vars',
|
||||
metavar='<vars>',
|
||||
nargs='+',
|
||||
action='append',
|
||||
default=[],
|
||||
help='Variables to use as filter in the form of '
|
||||
'--vars="key:value" --vars="key2:value2"')
|
||||
def do_cell_list(cc, args):
|
||||
"""Print list of cells which are registered with the Craton service."""
|
||||
params = {}
|
||||
if args.vars:
|
||||
query_vars = ",".join([i[0] for i in args.vars])
|
||||
params['vars'] = query_vars
|
||||
if args.cloud is not None:
|
||||
params['cloud_id'] = args.cloud
|
||||
if args.limit is not None:
|
||||
|
@ -181,6 +181,30 @@ class TestCellsShell(base.ShellTestCase):
|
||||
)
|
||||
self.assertIn("invalid choice: 'invalid'", error)
|
||||
|
||||
@mock.patch('cratonclient.v1.cells.CellManager.list')
|
||||
def test_cell_list_with_vars_success(self, mock_list):
|
||||
"""Verify --vars arguments successfully passed to Client."""
|
||||
self.shell('cell-list --vars a:b')
|
||||
mock_list.assert_called_once_with(
|
||||
vars='a:b',
|
||||
marker=None,
|
||||
sort_dir='asc',
|
||||
autopaginate=False,
|
||||
)
|
||||
mock_list.reset_mock()
|
||||
|
||||
@mock.patch('cratonclient.v1.cells.CellManager.list')
|
||||
def test_cell_list_with_multiple_vars_success(self, mock_list):
|
||||
"""Verify multiple --vars arguments successfully passed to Client."""
|
||||
self.shell('cell-list --vars=a:b --vars=c:d')
|
||||
mock_list.assert_called_once_with(
|
||||
vars='a:b,c:d',
|
||||
marker=None,
|
||||
sort_dir='asc',
|
||||
autopaginate=False,
|
||||
)
|
||||
mock_list.reset_mock()
|
||||
|
||||
def test_cell_create_missing_required_args(self):
|
||||
"""Verify that missing required args results in error message."""
|
||||
expected_responses = [
|
||||
|
@ -56,6 +56,7 @@ class TestDoCellList(base.TestShellCommand):
|
||||
kwargs.setdefault('fields', cells_shell.DEFAULT_CELL_FIELDS)
|
||||
kwargs.setdefault('marker', None)
|
||||
kwargs.setdefault('all', False)
|
||||
kwargs.setdefault('vars', None)
|
||||
return super(TestDoCellList, self).args_for(**kwargs)
|
||||
|
||||
def test_with_defaults(self):
|
||||
@ -177,6 +178,19 @@ class TestDoCellList(base.TestShellCommand):
|
||||
self.assertRaisesCommandErrorWith(cells_shell.do_cell_list, args)
|
||||
self.assertNothingWasCalled()
|
||||
|
||||
def test_with_multiple_vars(self):
|
||||
"""Verify that we pass vars filters to cell list."""
|
||||
args = self.args_for(vars=[['a:b'], ['c:d']])
|
||||
cells_shell.do_cell_list(self.craton_client, args)
|
||||
self.craton_client.cells.list.assert_called_once_with(
|
||||
vars='a:b,c:d',
|
||||
region_id=123,
|
||||
marker=None,
|
||||
sort_dir='asc',
|
||||
autopaginate=False,
|
||||
)
|
||||
self.assertFieldsEqualTo(cells_shell.DEFAULT_CELL_FIELDS)
|
||||
|
||||
def test_autopaginate(self):
|
||||
"""Verify that autopagination works."""
|
||||
args = self.args_for(all=True)
|
||||
|
Loading…
x
Reference in New Issue
Block a user