From aaf73cbf6d51a4a3b25cc0a5f1b7c5fb0d462c57 Mon Sep 17 00:00:00 2001 From: Radoslaw Smigielski Date: Mon, 10 Dec 2018 19:18:05 +0100 Subject: [PATCH] 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/ --- openstackclient/image/v2/image.py | 5 +++++ openstackclient/tests/unit/image/v2/test_image.py | 9 +++++---- releasenotes/notes/bug-27882-402ced7ffe930058.yaml | 5 +++++ 3 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 releasenotes/notes/bug-27882-402ced7ffe930058.yaml diff --git a/openstackclient/image/v2/image.py b/openstackclient/image/v2/image.py index 06eebe984c..1464c7b85d 100644 --- a/openstackclient/image/v2/image.py +++ b/openstackclient/image/v2/image.py @@ -630,6 +630,9 @@ class ListImage(command.Lister): # List of image data received data = [] + limit = None + if 'limit' in kwargs: + limit = kwargs['limit'] if 'marker' in kwargs: data = image_client.api.image_list(**kwargs) else: @@ -642,6 +645,8 @@ class ListImage(command.Lister): data.extend(page) # Set the marker to the id of the last item we received marker = page[-1]['id'] + if limit: + break if parsed_args.property: for attr, value in parsed_args.property.items(): diff --git a/openstackclient/tests/unit/image/v2/test_image.py b/openstackclient/tests/unit/image/v2/test_image.py index 170a7f036b..a1a3035a65 100644 --- a/openstackclient/tests/unit/image/v2/test_image.py +++ b/openstackclient/tests/unit/image/v2/test_image.py @@ -744,21 +744,22 @@ class TestImageList(TestImage): self.assertEqual(self.datalist, tuple(data)) def test_image_list_limit_option(self): + ret_limit = 1 arglist = [ - '--limit', str(1), + '--limit', str(ret_limit), ] verifylist = [ - ('limit', 1), + ('limit', ret_limit), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) columns, data = self.cmd.take_action(parsed_args) self.api_mock.image_list.assert_called_with( - limit=1, marker=self._image.id + limit=ret_limit, marker=None ) self.assertEqual(self.columns, columns) - self.assertEqual(len(self.datalist), len(tuple(data))) + self.assertEqual(ret_limit, len(tuple(data))) @mock.patch('osc_lib.utils.find_resource') def test_image_list_marker_option(self, fr_mock): diff --git a/releasenotes/notes/bug-27882-402ced7ffe930058.yaml b/releasenotes/notes/bug-27882-402ced7ffe930058.yaml new file mode 100644 index 0000000000..6bd090aa5c --- /dev/null +++ b/releasenotes/notes/bug-27882-402ced7ffe930058.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - | + The ``--limit`` option of the ``image list`` command was previously ignored. + [Bug `https://storyboard.openstack.org/#!/story/2004314`]