summaryrefslogtreecommitdiff
path: root/openstackclient
diff options
context:
space:
mode:
authorSteve Martinelli <s.martinelli@gmail.com>2016-12-02 16:14:42 +0000
committerFrode Nordahl <frode.nordahl@canonical.com>2016-12-05 10:35:00 +0100
commit42f33435ed36319552842674a96823b7c6e2164f (patch)
tree66d2942984fd9cceea902b21831d2c735a975d71 /openstackclient
parent307a847685a04de2e6df19722d3287e59e20d34d (diff)
downloadpython-openstackclient-42f33435ed36319552842674a96823b7c6e2164f.tar.gz
Revert "Remove marker and loop from "image list" command"
This reverts commit 0b6fdcbe4c3f3142fdd18bfd827653d894607941. Adapt "image list" to not loop when --marker is specified on command line. Update tests to work with current state of code. Change-Id: I8af58adf8637a9e34371c6280db40935d22bc3c3
Diffstat (limited to 'openstackclient')
-rw-r--r--openstackclient/image/v2/image.py15
-rw-r--r--openstackclient/tests/unit/image/v2/test_image.py21
2 files changed, 29 insertions, 7 deletions
diff --git a/openstackclient/image/v2/image.py b/openstackclient/image/v2/image.py
index 4031952b..ac29da9c 100644
--- a/openstackclient/image/v2/image.py
+++ b/openstackclient/image/v2/image.py
@@ -485,7 +485,6 @@ class ListImage(command.Lister):
if parsed_args.marker:
kwargs['marker'] = utils.find_resource(image_client.images,
parsed_args.marker).id
-
if parsed_args.long:
columns = (
'ID',
@@ -518,7 +517,19 @@ class ListImage(command.Lister):
column_headers = columns
# List of image data received
- data = image_client.api.image_list(**kwargs)
+ data = []
+ if 'marker' in kwargs:
+ data = image_client.api.image_list(**kwargs)
+ else:
+ # No pages received yet, so start the page marker at None.
+ marker = None
+ while True:
+ page = image_client.api.image_list(marker=marker, **kwargs)
+ if not page:
+ break
+ data.extend(page)
+ # Set the marker to the id of the last item we received
+ marker = page[-1]['id']
if parsed_args.property:
# NOTE(dtroyer): coerce to a list to subscript it in py3
diff --git a/openstackclient/tests/unit/image/v2/test_image.py b/openstackclient/tests/unit/image/v2/test_image.py
index 2f2212e4..a054e513 100644
--- a/openstackclient/tests/unit/image/v2/test_image.py
+++ b/openstackclient/tests/unit/image/v2/test_image.py
@@ -535,7 +535,9 @@ class TestImageList(TestImage):
# returns a tuple containing the column names and an iterable
# containing the data to be listed.
columns, data = self.cmd.take_action(parsed_args)
- self.api_mock.image_list.assert_called_with()
+ self.api_mock.image_list.assert_called_with(
+ marker=self._image.id,
+ )
self.assertEqual(self.columns, columns)
self.assertEqual(self.datalist, tuple(data))
@@ -558,6 +560,7 @@ class TestImageList(TestImage):
columns, data = self.cmd.take_action(parsed_args)
self.api_mock.image_list.assert_called_with(
public=True,
+ marker=self._image.id,
)
self.assertEqual(self.columns, columns)
@@ -581,6 +584,7 @@ class TestImageList(TestImage):
columns, data = self.cmd.take_action(parsed_args)
self.api_mock.image_list.assert_called_with(
private=True,
+ marker=self._image.id,
)
self.assertEqual(self.columns, columns)
@@ -604,6 +608,7 @@ class TestImageList(TestImage):
columns, data = self.cmd.take_action(parsed_args)
self.api_mock.image_list.assert_called_with(
shared=True,
+ marker=self._image.id,
)
self.assertEqual(self.columns, columns)
@@ -622,7 +627,9 @@ class TestImageList(TestImage):
# returns a tuple containing the column names and an iterable
# containing the data to be listed.
columns, data = self.cmd.take_action(parsed_args)
- self.api_mock.image_list.assert_called_with()
+ self.api_mock.image_list.assert_called_with(
+ marker=self._image.id,
+ )
collist = (
'ID',
@@ -670,7 +677,9 @@ class TestImageList(TestImage):
# returns a tuple containing the column names and an iterable
# containing the data to be listed.
columns, data = self.cmd.take_action(parsed_args)
- self.api_mock.image_list.assert_called_with()
+ self.api_mock.image_list.assert_called_with(
+ marker=self._image.id,
+ )
sf_mock.assert_called_with(
[self._image],
attr='a',
@@ -693,7 +702,9 @@ class TestImageList(TestImage):
# returns a tuple containing the column names and an iterable
# containing the data to be listed.
columns, data = self.cmd.take_action(parsed_args)
- self.api_mock.image_list.assert_called_with()
+ self.api_mock.image_list.assert_called_with(
+ marker=self._image.id,
+ )
si_mock.assert_called_with(
[self._image],
'name:asc'
@@ -712,7 +723,7 @@ class TestImageList(TestImage):
columns, data = self.cmd.take_action(parsed_args)
self.api_mock.image_list.assert_called_with(
- limit=1,
+ limit=1, marker=self._image.id
)
self.assertEqual(self.columns, columns)