diff --git a/watcherclient/tests/unit/v1/test_action.py b/watcherclient/tests/unit/v1/test_action.py index 195f34e..9f0b53d 100644 --- a/watcherclient/tests/unit/v1/test_action.py +++ b/watcherclient/tests/unit/v1/test_action.py @@ -144,6 +144,16 @@ fake_responses_sorting = { }, } +fake_responses_marker = { + '/v1/actions/?marker=770ef053-ecb3-48b0-85b5-d55a2dbc6588': + { + 'GET': ( + {}, + {"actions": [ACTION2, ACTION3]} + ), + }, +} + class ActionManagerTest(testtools.TestCase): @@ -231,6 +241,20 @@ class ActionManagerTest(testtools.TestCase): self.assertEqual(expect, self.api.calls) self.assertEqual(3, len(actions)) + def test_actions_list_marker(self): + self.api = utils.FakeAPI(fake_responses_marker) + self.mgr = watcherclient.v1.action.ActionManager(self.api) + actions = self.mgr.list( + marker='770ef053-ecb3-48b0-85b5-d55a2dbc6588') + expect = [ + ('GET', + '/v1/actions/?marker=770ef053-ecb3-48b0-85b5-d55a2dbc6588', + {}, + None) + ] + self.assertEqual(expect, self.api.calls) + self.assertEqual(2, len(actions)) + def test_actions_show(self): action = self.mgr.get(ACTION1['uuid']) expect = [ diff --git a/watcherclient/tests/unit/v1/test_action_shell.py b/watcherclient/tests/unit/v1/test_action_shell.py old mode 100755 new mode 100644 index 3f06ac7..fafd84b --- a/watcherclient/tests/unit/v1/test_action_shell.py +++ b/watcherclient/tests/unit/v1/test_action_shell.py @@ -132,6 +132,27 @@ class ActionShellTest(base.CommandTestCase): self.m_action_mgr.list.assert_called_once_with(detail=True) + def test_do_action_list_marker(self): + action2 = resource.Action(mock.Mock(), ACTION_2) + action3 = resource.Action(mock.Mock(), ACTION_3) + self.m_action_mgr.list.return_value = [ + action2, action3] + + exit_code, results = self.run_cmd( + 'action list --marker 770ef053-ecb3-48b0-85b5-d55a2dbc6588') + + self.assertEqual(0, exit_code) + self.assertEqual( + [self.resource_as_dict(action2, self.SHORT_LIST_FIELDS, + self.SHORT_LIST_FIELD_LABELS), + self.resource_as_dict(action3, self.SHORT_LIST_FIELDS, + self.SHORT_LIST_FIELD_LABELS)], + results) + + self.m_action_mgr.list.assert_called_once_with( + detail=False, + marker='770ef053-ecb3-48b0-85b5-d55a2dbc6588') + def test_do_action_show_by_uuid(self): action = resource.Action(mock.Mock(), ACTION_1) self.m_action_mgr.get.return_value = action diff --git a/watcherclient/v1/action.py b/watcherclient/v1/action.py index 4448a3f..64dcb6f 100644 --- a/watcherclient/v1/action.py +++ b/watcherclient/v1/action.py @@ -30,7 +30,7 @@ class ActionManager(base.Manager): return '/v1/actions/%s' % id if id else '/v1/actions' def list(self, action_plan=None, audit=None, limit=None, sort_key=None, - sort_dir=None, detail=False): + sort_dir=None, detail=False, marker=None): """Retrieve a list of action. :param action_plan: UUID of the action plan @@ -52,13 +52,15 @@ class ActionManager(base.Manager): :param detail: Optional, boolean whether to return detailed information about actions. + :param marker: Optional, UUID of the last action in the previous page. + :returns: A list of actions. """ if limit is not None: limit = int(limit) - filters = utils.common_filters(limit, sort_key, sort_dir) + filters = utils.common_filters(limit, sort_key, sort_dir, marker) if action_plan is not None: filters.append('action_plan_uuid=%s' % action_plan) if audit is not None: diff --git a/watcherclient/v1/action_shell.py b/watcherclient/v1/action_shell.py index 2d200cf..87976af 100644 --- a/watcherclient/v1/action_shell.py +++ b/watcherclient/v1/action_shell.py @@ -83,6 +83,13 @@ class ListAction(command.Lister): metavar='', choices=['asc', 'desc'], help=_('Sort direction: "asc" (the default) or "desc".')) + parser.add_argument( + '--marker', + dest='marker', + metavar='', + default=None, + help=_('UUID of the last action in the previous page; ' + 'displays list of actions after "marker".')) return parser