Merge "Add "--limit" and "--marker" options to "volume list" command"

This commit is contained in:
Jenkins 2016-09-11 05:22:58 +00:00 committed by Gerrit Code Review
commit cc5379b55c
6 changed files with 159 additions and 2 deletions

View File

@ -121,6 +121,8 @@ List volumes
[--status <status>]
[--all-projects]
[--long]
[--limit <limit>]
[--marker <marker>]
.. option:: --project <project>
@ -166,6 +168,16 @@ List volumes
List additional fields in output
.. option:: --limit <limit>
Maximum number of volumes to display
.. option:: --marker <marker>
The last volume ID of the previous page
*Volume version 2 only*
volume set
----------

View File

@ -13,6 +13,7 @@
# under the License.
#
import argparse
import copy
import mock
from mock import call
@ -540,6 +541,7 @@ class TestVolumeList(TestVolume):
('all_projects', False),
('name', None),
('status', None),
('limit', None),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -557,6 +559,7 @@ class TestVolumeList(TestVolume):
('all_projects', False),
('name', volume_fakes.volume_name),
('status', None),
('limit', None),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -573,6 +576,7 @@ class TestVolumeList(TestVolume):
('all_projects', False),
('name', None),
('status', volume_fakes.volume_status),
('limit', None),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -589,6 +593,7 @@ class TestVolumeList(TestVolume):
('all_projects', True),
('name', None),
('status', None),
('limit', None),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -605,6 +610,7 @@ class TestVolumeList(TestVolume):
('all_projects', False),
('name', None),
('status', None),
('limit', None),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -635,6 +641,41 @@ class TestVolumeList(TestVolume):
), )
self.assertEqual(datalist, tuple(data))
def test_volume_list_with_limit(self):
arglist = [
'--limit', '2',
]
verifylist = [
('long', False),
('all_projects', False),
('name', None),
('status', None),
('limit', 2),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args)
self.volumes_mock.list.assert_called_once_with(
limit=2,
search_opts={
'status': None,
'display_name': None,
'all_tenants': False, }
)
self.assertEqual(self.columns, columns)
self.assertEqual(self.datalist, tuple(data))
def test_volume_list_negative_limit(self):
arglist = [
"--limit", "-2",
]
verifylist = [
("limit", -2),
]
self.assertRaises(argparse.ArgumentTypeError, self.check_parser,
self.cmd, arglist, verifylist)
class TestVolumeSet(TestVolume):

View File

@ -12,6 +12,7 @@
# under the License.
#
import argparse
import mock
from mock import call
@ -553,6 +554,8 @@ class TestVolumeList(TestVolume):
('all_projects', False),
('name', None),
('status', None),
('marker', None),
('limit', None),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -581,6 +584,8 @@ class TestVolumeList(TestVolume):
('long', False),
('all_projects', False),
('status', None),
('marker', None),
('limit', None),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -611,6 +616,8 @@ class TestVolumeList(TestVolume):
('long', False),
('all_projects', False),
('status', None),
('marker', None),
('limit', None),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -639,6 +646,8 @@ class TestVolumeList(TestVolume):
('long', False),
('all_projects', False),
('status', None),
('marker', None),
('limit', None),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -668,6 +677,8 @@ class TestVolumeList(TestVolume):
('long', False),
('all_projects', False),
('status', None),
('marker', None),
('limit', None),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -696,6 +707,8 @@ class TestVolumeList(TestVolume):
('all_projects', False),
('name', self.mock_volume.name),
('status', None),
('marker', None),
('limit', None),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -724,6 +737,8 @@ class TestVolumeList(TestVolume):
('all_projects', False),
('name', None),
('status', self.mock_volume.status),
('marker', None),
('limit', None),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -752,6 +767,8 @@ class TestVolumeList(TestVolume):
('all_projects', True),
('name', None),
('status', None),
('marker', None),
('limit', None),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -780,6 +797,8 @@ class TestVolumeList(TestVolume):
('all_projects', False),
('name', None),
('status', None),
('marker', None),
('limit', None),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -813,6 +832,58 @@ class TestVolumeList(TestVolume):
), )
self.assertEqual(datalist, tuple(data))
def test_volume_list_with_marker_and_limit(self):
arglist = [
"--marker", self.mock_volume.id,
"--limit", "2",
]
verifylist = [
('long', False),
('all_projects', False),
('name', None),
('status', None),
('marker', self.mock_volume.id),
('limit', 2),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args)
self.assertEqual(self.columns, columns)
server = self.mock_volume.attachments[0]['server_id']
device = self.mock_volume.attachments[0]['device']
msg = 'Attached to %s on %s ' % (server, device)
datalist = ((
self.mock_volume.id,
self.mock_volume.name,
self.mock_volume.status,
self.mock_volume.size,
msg,
), )
self.volumes_mock.list.assert_called_once_with(
marker=self.mock_volume.id,
limit=2,
search_opts={
'status': None,
'project_id': None,
'user_id': None,
'display_name': None,
'all_tenants': False, }
)
self.assertEqual(datalist, tuple(data))
def test_volume_list_negative_limit(self):
arglist = [
"--limit", "-2",
]
verifylist = [
("limit", -2),
]
self.assertRaises(argparse.ArgumentTypeError, self.check_parser,
self.cmd, arglist, verifylist)
class TestVolumeSet(TestVolume):

View File

@ -235,6 +235,13 @@ class ListVolume(command.Lister):
default=False,
help=_('List additional fields in output'),
)
parser.add_argument(
'--limit',
type=int,
action=parseractions.NonNegativeAction,
metavar='<limit>',
help=_('Maximum number of volumes to display'),
)
return parser
def take_action(self, parsed_args):
@ -310,7 +317,10 @@ class ListVolume(command.Lister):
'status': parsed_args.status,
}
data = volume_client.volumes.list(search_opts=search_opts)
data = volume_client.volumes.list(
search_opts=search_opts,
limit=parsed_args.limit,
)
return (column_headers,
(utils.get_item_properties(

View File

@ -246,6 +246,18 @@ class ListVolume(command.Lister):
default=False,
help=_('List additional fields in output'),
)
parser.add_argument(
'--marker',
metavar='<marker>',
help=_('The last volume ID of the previous page'),
)
parser.add_argument(
'--limit',
type=int,
action=parseractions.NonNegativeAction,
metavar='<limit>',
help=_('Maximum number of volumes to display'),
)
return parser
def take_action(self, parsed_args):
@ -328,7 +340,11 @@ class ListVolume(command.Lister):
'status': parsed_args.status,
}
data = volume_client.volumes.list(search_opts=search_opts)
data = volume_client.volumes.list(
search_opts=search_opts,
marker=parsed_args.marker,
limit=parsed_args.limit,
)
return (column_headers,
(utils.get_item_properties(

View File

@ -0,0 +1,7 @@
---
features:
- |
Add ``--limit`` option to ``volume list`` command in volume v1,
add ``--limit`` and ``--marker`` options to ``volume list``
command in volume v2.
[Bug `1612484 <https://bugs.launchpad.net/bugs/1612484>`_]