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