Skip to content

Commit aaf73cb

Browse files
Radoslaw SmigielskiDean Troyer
authored andcommitted
Fix --limit option in image list sub-command
Client site fix of --limit option. This bugfix makes client "image list" command working again with "--limit" option. This option was ignored and even if user specified it, still list of all available images was returned. Story: 2004314 Change-Id: I30a78d65a644c9b7d23706a6637ce77bca2c2386 Depends-On: https://review.openstack.org/#/c/634776/
1 parent b90c780 commit aaf73cb

3 files changed

Lines changed: 15 additions & 4 deletions

File tree

openstackclient/image/v2/image.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,9 @@ def take_action(self, parsed_args):
630630

631631
# List of image data received
632632
data = []
633+
limit = None
634+
if 'limit' in kwargs:
635+
limit = kwargs['limit']
633636
if 'marker' in kwargs:
634637
data = image_client.api.image_list(**kwargs)
635638
else:
@@ -642,6 +645,8 @@ def take_action(self, parsed_args):
642645
data.extend(page)
643646
# Set the marker to the id of the last item we received
644647
marker = page[-1]['id']
648+
if limit:
649+
break
645650

646651
if parsed_args.property:
647652
for attr, value in parsed_args.property.items():

openstackclient/tests/unit/image/v2/test_image.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -744,21 +744,22 @@ def test_image_list_sort_option(self, si_mock):
744744
self.assertEqual(self.datalist, tuple(data))
745745

746746
def test_image_list_limit_option(self):
747+
ret_limit = 1
747748
arglist = [
748-
'--limit', str(1),
749+
'--limit', str(ret_limit),
749750
]
750751
verifylist = [
751-
('limit', 1),
752+
('limit', ret_limit),
752753
]
753754
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
754755

755756
columns, data = self.cmd.take_action(parsed_args)
756757
self.api_mock.image_list.assert_called_with(
757-
limit=1, marker=self._image.id
758+
limit=ret_limit, marker=None
758759
)
759760

760761
self.assertEqual(self.columns, columns)
761-
self.assertEqual(len(self.datalist), len(tuple(data)))
762+
self.assertEqual(ret_limit, len(tuple(data)))
762763

763764
@mock.patch('osc_lib.utils.find_resource')
764765
def test_image_list_marker_option(self, fr_mock):
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
fixes:
3+
- |
4+
The ``--limit`` option of the ``image list`` command was previously ignored.
5+
[Bug `https://storyboard.openstack.org/#!/story/2004314`]

0 commit comments

Comments
 (0)