Use goal name as strategy list filter
In this changeset, I updated the CLI to be able to use now the goal name as a filter parameter of the command strategy list. Change-Id: I507bb1c37c845f56db537735f00a6d82a696908e Partial-Bug: #1573582
This commit is contained in:
parent
bc572e70dc
commit
4c19084cb1
@ -29,6 +29,7 @@ STRATEGY_1 = {
|
||||
'name': 'basic',
|
||||
'display_name': 'Basic consolidation',
|
||||
'goal_uuid': 'fc087747-61be-4aad-8126-b701731ae836',
|
||||
'goal_name': 'SERVER_CONSOLIDATION',
|
||||
'created_at': datetime.datetime.now().isoformat(),
|
||||
'updated_at': None,
|
||||
'deleted_at': None,
|
||||
@ -39,6 +40,7 @@ STRATEGY_2 = {
|
||||
'name': 'dummy',
|
||||
'display_name': 'Dummy',
|
||||
'goal_uuid': '407b03b1-63c6-49b2-adaf-4df5c0090047',
|
||||
'goal_name': 'DUMMY',
|
||||
'created_at': datetime.datetime.now().isoformat(),
|
||||
'updated_at': None,
|
||||
'deleted_at': None,
|
||||
@ -102,13 +104,32 @@ class StrategyShellTest(base.CommandTestCase):
|
||||
|
||||
self.m_strategy_mgr.list.assert_called_once_with(detail=True)
|
||||
|
||||
def test_do_strategy_list_filter_by_goal(self):
|
||||
def test_do_strategy_list_filter_by_goal_name(self):
|
||||
strategy2 = resource.Strategy(mock.Mock(), STRATEGY_2)
|
||||
self.m_strategy_mgr.list.return_value = [strategy2]
|
||||
|
||||
exit_code, results = self.run_cmd(
|
||||
'strategy list --goal '
|
||||
'DUMMY')
|
||||
|
||||
self.assertEqual(0, exit_code)
|
||||
self.assertEqual(
|
||||
[self.resource_as_dict(strategy2, self.SHORT_LIST_FIELDS,
|
||||
self.SHORT_LIST_FIELD_LABELS)],
|
||||
results)
|
||||
|
||||
self.m_strategy_mgr.list.assert_called_once_with(
|
||||
detail=False,
|
||||
goal='DUMMY',
|
||||
)
|
||||
|
||||
def test_do_strategy_list_filter_by_goal_uuid(self):
|
||||
strategy1 = resource.Strategy(mock.Mock(), STRATEGY_1)
|
||||
self.m_strategy_mgr.list.return_value = [strategy1]
|
||||
|
||||
exit_code, results = self.run_cmd(
|
||||
'strategy list --goal-uuid '
|
||||
'770ef053-ecb3-48b0-85b5-d55a2dbc6588')
|
||||
'strategy list --goal '
|
||||
'fc087747-61be-4aad-8126-b701731ae836')
|
||||
|
||||
self.assertEqual(0, exit_code)
|
||||
self.assertEqual(
|
||||
@ -118,7 +139,7 @@ class StrategyShellTest(base.CommandTestCase):
|
||||
|
||||
self.m_strategy_mgr.list.assert_called_once_with(
|
||||
detail=False,
|
||||
goal_uuid='770ef053-ecb3-48b0-85b5-d55a2dbc6588',
|
||||
goal='fc087747-61be-4aad-8126-b701731ae836',
|
||||
)
|
||||
|
||||
def test_do_strategy_show_by_uuid(self):
|
||||
|
@ -33,11 +33,11 @@ class StrategyManager(base.Manager):
|
||||
return ('/v1/strategies/%s' % strategy
|
||||
if strategy else '/v1/strategies')
|
||||
|
||||
def list(self, goal_uuid=None, limit=None, sort_key=None,
|
||||
def list(self, goal=None, limit=None, sort_key=None,
|
||||
sort_dir=None, detail=False):
|
||||
"""Retrieve a list of strategy.
|
||||
|
||||
:param goal_uuid: The UUID of the goal to filter by
|
||||
:param goal: The UUID of the goal to filter by
|
||||
:param limit: The maximum number of results to return per
|
||||
request, if:
|
||||
|
||||
@ -63,8 +63,8 @@ class StrategyManager(base.Manager):
|
||||
|
||||
filters = utils.common_filters(limit, sort_key, sort_dir)
|
||||
|
||||
if goal_uuid:
|
||||
filters.append(parse.urlencode(dict(goal_uuid=goal_uuid)))
|
||||
if goal:
|
||||
filters.append(parse.urlencode(dict(goal=goal)))
|
||||
|
||||
path = ''
|
||||
if detail:
|
||||
|
@ -55,10 +55,10 @@ class ListStrategy(command.Lister):
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(ListStrategy, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
'--goal-uuid',
|
||||
metavar='<goal_uuid>',
|
||||
dest='goal_uuid',
|
||||
help=_('UUID of the goal'))
|
||||
'--goal',
|
||||
metavar='<goal>',
|
||||
dest='goal',
|
||||
help=_('UUID or name of the goal'))
|
||||
parser.add_argument(
|
||||
'--detail',
|
||||
dest='detail',
|
||||
@ -95,8 +95,8 @@ class ListStrategy(command.Lister):
|
||||
fields = res_fields.STRATEGY_SHORT_LIST_FIELDS
|
||||
field_labels = res_fields.STRATEGY_SHORT_LIST_FIELD_LABELS
|
||||
|
||||
if parsed_args.goal_uuid:
|
||||
params["goal_uuid"] = parsed_args.goal_uuid
|
||||
if parsed_args.goal:
|
||||
params["goal"] = parsed_args.goal
|
||||
|
||||
params.update(
|
||||
common_utils.common_params_for_list(
|
||||
|
Loading…
Reference in New Issue
Block a user