From aa9d1a65f67e1d63fe53d62812428b69e6180895 Mon Sep 17 00:00:00 2001
From: licanwei
Date: Tue, 14 Nov 2017 18:24:06 -0800
Subject: [PATCH] Add --marker for 'watcher actionplan list'
Change-Id: I88bb986d484198add967cdd953f46e341bf6f9ac
Closes-Bug: #1731826
---
watcherclient/common/utils.py | 8 +++++++-
watcherclient/tests/unit/test_utils.py | 10 +++++++++-
.../tests/unit/v1/test_action_plan.py | 20 +++++++++++++++++++
watcherclient/v1/action_plan.py | 7 +++++--
watcherclient/v1/action_plan_shell.py | 5 +++++
5 files changed, 46 insertions(+), 4 deletions(-)
diff --git a/watcherclient/common/utils.py b/watcherclient/common/utils.py
index 943ba87..50a4855 100644
--- a/watcherclient/common/utils.py
+++ b/watcherclient/common/utils.py
@@ -161,17 +161,21 @@ def common_params_for_list(args, fields, field_labels):
args.sort_dir)
params['sort_dir'] = args.sort_dir
+ marker = getattr(args, 'marker', None)
+ if marker is not None:
+ params['marker'] = marker
params['detail'] = args.detail
return params
-def common_filters(limit=None, sort_key=None, sort_dir=None):
+def common_filters(limit=None, sort_key=None, sort_dir=None, marker=None):
"""Generate common filters for any list request.
:param limit: maximum number of entities to return.
:param sort_key: field to use for sorting.
:param sort_dir: direction of sorting: 'asc' or 'desc'.
+ :param marker: The last actionplan UUID of the previous page.
:returns: list of string filters.
"""
filters = []
@@ -181,6 +185,8 @@ def common_filters(limit=None, sort_key=None, sort_dir=None):
filters.append('sort_key=%s' % sort_key)
if sort_dir is not None:
filters.append('sort_dir=%s' % sort_dir)
+ if marker is not None:
+ filters.append('marker=%s' % marker)
return filters
diff --git a/watcherclient/tests/unit/test_utils.py b/watcherclient/tests/unit/test_utils.py
index badcdcd..2c143dd 100644
--- a/watcherclient/tests/unit/test_utils.py
+++ b/watcherclient/tests/unit/test_utils.py
@@ -97,7 +97,8 @@ class UtilsTest(test_utils.BaseTestCase):
class CommonParamsForListTest(test_utils.BaseTestCase):
def setUp(self):
super(CommonParamsForListTest, self).setUp()
- self.args = mock.Mock(limit=None, sort_key=None, sort_dir=None)
+ self.args = mock.Mock(limit=None, marker=None,
+ sort_key=None, sort_dir=None)
self.args.detail = False
self.expected_params = {'detail': False}
@@ -117,6 +118,13 @@ class CommonParamsForListTest(test_utils.BaseTestCase):
utils.common_params_for_list,
self.args, [], [])
+ def test_marker(self):
+ self.args.marker = 'e420a881-d7df-4de2-bbf3-378cc13d9b3a'
+ self.expected_params.update(
+ {'marker': 'e420a881-d7df-4de2-bbf3-378cc13d9b3a'})
+ self.assertEqual(self.expected_params,
+ utils.common_params_for_list(self.args, [], []))
+
def test_sort_key_and_sort_dir(self):
self.args.sort_key = 'field'
self.args.sort_dir = 'desc'
diff --git a/watcherclient/tests/unit/v1/test_action_plan.py b/watcherclient/tests/unit/v1/test_action_plan.py
index 8049e83..87569df 100644
--- a/watcherclient/tests/unit/v1/test_action_plan.py
+++ b/watcherclient/tests/unit/v1/test_action_plan.py
@@ -94,6 +94,13 @@ fake_responses_pagination = {
{"action_plans": [ACTION_PLAN2]}
),
},
+ '/v1/action_plans/?marker=f8e47706-efcf-49a4-a5c4-af604eb492f2':
+ {
+ 'GET': (
+ {},
+ {"action_plans": [ACTION_PLAN2]}
+ ),
+ },
}
fake_responses_sorting = {
@@ -158,6 +165,19 @@ class ActionPlanManagerTest(testtools.TestCase):
self.assertEqual(expect, self.api.calls)
self.assertThat(action_plans, matchers.HasLength(2))
+ def test_action_plans_list_marker(self):
+ self.api = utils.FakeAPI(fake_responses_pagination)
+ self.mgr = watcherclient.v1.action_plan.ActionPlanManager(self.api)
+ action_plans = self.mgr.list(
+ marker='f8e47706-efcf-49a4-a5c4-af604eb492f2')
+ expect = [
+ ('GET', '/v1/action_plans/?'
+ 'marker=f8e47706-efcf-49a4-a5c4-af604eb492f2',
+ {}, None),
+ ]
+ self.assertEqual(expect, self.api.calls)
+ self.assertThat(action_plans, matchers.HasLength(1))
+
def test_action_plans_list_sort_key(self):
self.api = utils.FakeAPI(fake_responses_sorting)
self.mgr = watcherclient.v1.action_plan.ActionPlanManager(self.api)
diff --git a/watcherclient/v1/action_plan.py b/watcherclient/v1/action_plan.py
index 3caa8c1..be16189 100644
--- a/watcherclient/v1/action_plan.py
+++ b/watcherclient/v1/action_plan.py
@@ -31,7 +31,7 @@ class ActionPlanManager(base.Manager):
return '/v1/action_plans/%s' % id if id else '/v1/action_plans'
def list(self, audit=None, limit=None, sort_key=None,
- sort_dir=None, detail=False):
+ sort_dir=None, detail=False, marker=None):
"""Retrieve a list of action plan.
:param audit: Name of the audit
@@ -52,13 +52,16 @@ class ActionPlanManager(base.Manager):
:param detail: Optional, boolean whether to return detailed information
about action plans.
+ :param marker: The last actionplan UUID of the previous page;
+ displays list of actionplans after "marker".
+
:returns: A list of action plans.
"""
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 audit is not None:
filters.append('audit_uuid=%s' % audit)
diff --git a/watcherclient/v1/action_plan_shell.py b/watcherclient/v1/action_plan_shell.py
index 5f5af88..31db2ff 100644
--- a/watcherclient/v1/action_plan_shell.py
+++ b/watcherclient/v1/action_plan_shell.py
@@ -113,6 +113,11 @@ class ListActionPlan(command.Lister):
help=_('Maximum number of action plans to return per request, '
'0 for no limit. Default is the maximum number used '
'by the Watcher API Service.'))
+ parser.add_argument(
+ '--marker',
+ metavar='',
+ help=_('The last actionplan UUID of the previous page; '
+ 'displays list of actionplans after "marker".'))
parser.add_argument(
'--sort-key',
metavar='',