summaryrefslogtreecommitdiff
path: root/openstackclient
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2016-09-11 05:22:58 +0000
committerGerrit Code Review <review@openstack.org>2016-09-11 05:22:58 +0000
commitcc5379b55cc74740b2451b9445bb752d6230862e (patch)
treeb056841d5efc58966a90d4bdf0efde890e84fd7a /openstackclient
parentf5c09fe24650626686c03426103a01e59ba7aa3d (diff)
parent6986a32e1cd6d0c0bdf973e5d4e4bcb3d1f45235 (diff)
downloadpython-openstackclient-cc5379b55cc74740b2451b9445bb752d6230862e.tar.gz
Merge "Add "--limit" and "--marker" options to "volume list" command"
Diffstat (limited to 'openstackclient')
-rw-r--r--openstackclient/tests/unit/volume/v1/test_volume.py41
-rw-r--r--openstackclient/tests/unit/volume/v2/test_volume.py71
-rw-r--r--openstackclient/volume/v1/volume.py12
-rw-r--r--openstackclient/volume/v2/volume.py18
4 files changed, 140 insertions, 2 deletions
diff --git a/openstackclient/tests/unit/volume/v1/test_volume.py b/openstackclient/tests/unit/volume/v1/test_volume.py
index 6a860fd0..54ec9e7e 100644
--- a/openstackclient/tests/unit/volume/v1/test_volume.py
+++ b/openstackclient/tests/unit/volume/v1/test_volume.py
@@ -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):
diff --git a/openstackclient/tests/unit/volume/v2/test_volume.py b/openstackclient/tests/unit/volume/v2/test_volume.py
index 66f8f74d..de059b1b 100644
--- a/openstackclient/tests/unit/volume/v2/test_volume.py
+++ b/openstackclient/tests/unit/volume/v2/test_volume.py
@@ -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):
diff --git a/openstackclient/volume/v1/volume.py b/openstackclient/volume/v1/volume.py
index 83158b97..16f0d6db 100644
--- a/openstackclient/volume/v1/volume.py
+++ b/openstackclient/volume/v1/volume.py
@@ -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(
diff --git a/openstackclient/volume/v2/volume.py b/openstackclient/volume/v2/volume.py
index bd201e00..28946a5f 100644
--- a/openstackclient/volume/v2/volume.py
+++ b/openstackclient/volume/v2/volume.py
@@ -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(