From 61b9d9fe2d0c6c99d5e77361111f02a19d169782 Mon Sep 17 00:00:00 2001 From: Huanxuan Ao Date: Fri, 22 Jul 2016 13:23:30 +0800 Subject: [PATCH] Add "--marker" and "--limit" options to "snapshot list" Add "--marker" and "--limit" options to "snapshot list" command in volume v2 (v2 only). Change-Id: Ib60840b9b83dfe5e599e4037e8ec308844a9448b Closes-Bug: #1605475 --- doc/source/command-objects/snapshot.rst | 15 ++++++++ .../tests/volume/v2/test_snapshot.py | 34 +++++++++++++++++-- openstackclient/volume/v2/snapshot.py | 17 +++++++++- .../notes/bug-1605475-84e649fb8c675737.yaml | 5 +++ 4 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 releasenotes/notes/bug-1605475-84e649fb8c675737.yaml diff --git a/doc/source/command-objects/snapshot.rst b/doc/source/command-objects/snapshot.rst index 8ac0b6b869..ce2d9c8eab 100644 --- a/doc/source/command-objects/snapshot.rst +++ b/doc/source/command-objects/snapshot.rst @@ -68,6 +68,9 @@ List snapshots os snapshot list [--all-projects] + [--long] + [--limit ] + [--marker ] .. option:: --all-projects @@ -77,6 +80,18 @@ List snapshots List additional fields in output +.. option:: --limit + + Maximum number of snapshots to display + + *Volume version 2 only* + +.. option:: --marker + + The last snapshot ID of the previous page + + *Volume version 2 only* + snapshot set ------------ diff --git a/openstackclient/tests/volume/v2/test_snapshot.py b/openstackclient/tests/volume/v2/test_snapshot.py index 04e0285eda..3eb740ba6c 100644 --- a/openstackclient/tests/volume/v2/test_snapshot.py +++ b/openstackclient/tests/volume/v2/test_snapshot.py @@ -12,6 +12,7 @@ # under the License. # +import argparse import mock from mock import call @@ -260,16 +261,33 @@ class TestSnapshotList(TestSnapshot): parsed_args = self.check_parser(self.cmd, arglist, verifylist) columns, data = self.cmd.take_action(parsed_args) + + self.snapshots_mock.list.assert_called_once_with( + limit=None, marker=None, search_opts={'all_tenants': False}) self.assertEqual(self.columns, columns) self.assertEqual(self.data, list(data)) def test_snapshot_list_with_options(self): - arglist = ["--long"] - verifylist = [("long", True), ('all_projects', False)] + arglist = [ + "--long", + "--limit", "2", + "--marker", self.snapshots[0].id, + ] + verifylist = [ + ("long", True), + ("limit", 2), + ("marker", self.snapshots[0].id), + ('all_projects', False), + ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) columns, data = self.cmd.take_action(parsed_args) + self.snapshots_mock.list.assert_called_once_with( + limit=2, + marker=self.snapshots[0].id, + search_opts={'all_tenants': False} + ) self.assertEqual(self.columns_long, columns) self.assertEqual(self.data_long, list(data)) @@ -285,9 +303,21 @@ class TestSnapshotList(TestSnapshot): columns, data = self.cmd.take_action(parsed_args) + self.snapshots_mock.list.assert_called_once_with( + limit=None, marker=None, search_opts={'all_tenants': True}) self.assertEqual(self.columns, columns) self.assertEqual(self.data, list(data)) + def test_snapshot_list_negative_limit(self): + arglist = [ + "--limit", "-2", + ] + verifylist = [ + ("limit", -2), + ] + self.assertRaises(argparse.ArgumentTypeError, self.check_parser, + self.cmd, arglist, verifylist) + class TestSnapshotSet(TestSnapshot): diff --git a/openstackclient/volume/v2/snapshot.py b/openstackclient/volume/v2/snapshot.py index ba692074a2..8304a5eb46 100644 --- a/openstackclient/volume/v2/snapshot.py +++ b/openstackclient/volume/v2/snapshot.py @@ -134,6 +134,18 @@ class ListSnapshot(command.Lister): default=False, help=_('List additional fields in output'), ) + parser.add_argument( + '--marker', + metavar='', + help=_('The last snapshot ID of the previous page'), + ) + parser.add_argument( + '--limit', + type=int, + action=parseractions.NonNegativeAction, + metavar='', + help=_('Maximum number of snapshots to display'), + ) return parser def take_action(self, parsed_args): @@ -174,7 +186,10 @@ class ListSnapshot(command.Lister): } data = self.app.client_manager.volume.volume_snapshots.list( - search_opts=search_opts) + search_opts=search_opts, + marker=parsed_args.marker, + limit=parsed_args.limit, + ) return (column_headers, (utils.get_item_properties( s, columns, diff --git a/releasenotes/notes/bug-1605475-84e649fb8c675737.yaml b/releasenotes/notes/bug-1605475-84e649fb8c675737.yaml new file mode 100644 index 0000000000..f9362bc3a9 --- /dev/null +++ b/releasenotes/notes/bug-1605475-84e649fb8c675737.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + Add ``--limit`` and ``--marker`` options to ``snapshot list`` command. + [Bug `1605475 `_]