Skip to content

Commit 42f3343

Browse files
stevemarfnordahl
authored andcommitted
Revert "Remove marker and loop from "image list" command"
This reverts commit 0b6fdcb. 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
1 parent 307a847 commit 42f3343

2 files changed

Lines changed: 29 additions & 7 deletions

File tree

openstackclient/image/v2/image.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,6 @@ def take_action(self, parsed_args):
485485
if parsed_args.marker:
486486
kwargs['marker'] = utils.find_resource(image_client.images,
487487
parsed_args.marker).id
488-
489488
if parsed_args.long:
490489
columns = (
491490
'ID',
@@ -518,7 +517,19 @@ def take_action(self, parsed_args):
518517
column_headers = columns
519518

520519
# List of image data received
521-
data = image_client.api.image_list(**kwargs)
520+
data = []
521+
if 'marker' in kwargs:
522+
data = image_client.api.image_list(**kwargs)
523+
else:
524+
# No pages received yet, so start the page marker at None.
525+
marker = None
526+
while True:
527+
page = image_client.api.image_list(marker=marker, **kwargs)
528+
if not page:
529+
break
530+
data.extend(page)
531+
# Set the marker to the id of the last item we received
532+
marker = page[-1]['id']
522533

523534
if parsed_args.property:
524535
# NOTE(dtroyer): coerce to a list to subscript it in py3

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

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,9 @@ def test_image_list_no_options(self):
535535
# returns a tuple containing the column names and an iterable
536536
# containing the data to be listed.
537537
columns, data = self.cmd.take_action(parsed_args)
538-
self.api_mock.image_list.assert_called_with()
538+
self.api_mock.image_list.assert_called_with(
539+
marker=self._image.id,
540+
)
539541

540542
self.assertEqual(self.columns, columns)
541543
self.assertEqual(self.datalist, tuple(data))
@@ -558,6 +560,7 @@ def test_image_list_public_option(self):
558560
columns, data = self.cmd.take_action(parsed_args)
559561
self.api_mock.image_list.assert_called_with(
560562
public=True,
563+
marker=self._image.id,
561564
)
562565

563566
self.assertEqual(self.columns, columns)
@@ -581,6 +584,7 @@ def test_image_list_private_option(self):
581584
columns, data = self.cmd.take_action(parsed_args)
582585
self.api_mock.image_list.assert_called_with(
583586
private=True,
587+
marker=self._image.id,
584588
)
585589

586590
self.assertEqual(self.columns, columns)
@@ -604,6 +608,7 @@ def test_image_list_shared_option(self):
604608
columns, data = self.cmd.take_action(parsed_args)
605609
self.api_mock.image_list.assert_called_with(
606610
shared=True,
611+
marker=self._image.id,
607612
)
608613

609614
self.assertEqual(self.columns, columns)
@@ -622,7 +627,9 @@ def test_image_list_long_option(self):
622627
# returns a tuple containing the column names and an iterable
623628
# containing the data to be listed.
624629
columns, data = self.cmd.take_action(parsed_args)
625-
self.api_mock.image_list.assert_called_with()
630+
self.api_mock.image_list.assert_called_with(
631+
marker=self._image.id,
632+
)
626633

627634
collist = (
628635
'ID',
@@ -670,7 +677,9 @@ def test_image_list_property_option(self, sf_mock):
670677
# returns a tuple containing the column names and an iterable
671678
# containing the data to be listed.
672679
columns, data = self.cmd.take_action(parsed_args)
673-
self.api_mock.image_list.assert_called_with()
680+
self.api_mock.image_list.assert_called_with(
681+
marker=self._image.id,
682+
)
674683
sf_mock.assert_called_with(
675684
[self._image],
676685
attr='a',
@@ -693,7 +702,9 @@ def test_image_list_sort_option(self, si_mock):
693702
# returns a tuple containing the column names and an iterable
694703
# containing the data to be listed.
695704
columns, data = self.cmd.take_action(parsed_args)
696-
self.api_mock.image_list.assert_called_with()
705+
self.api_mock.image_list.assert_called_with(
706+
marker=self._image.id,
707+
)
697708
si_mock.assert_called_with(
698709
[self._image],
699710
'name:asc'
@@ -712,7 +723,7 @@ def test_image_list_limit_option(self):
712723

713724
columns, data = self.cmd.take_action(parsed_args)
714725
self.api_mock.image_list.assert_called_with(
715-
limit=1,
726+
limit=1, marker=self._image.id
716727
)
717728

718729
self.assertEqual(self.columns, columns)

0 commit comments

Comments
 (0)