Skip to content

Commit fdf93e0

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Revert "Remove marker and loop from "image list" command""
2 parents 83675e9 + 42f3343 commit fdf93e0

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
@@ -486,7 +486,6 @@ def take_action(self, parsed_args):
486486
if parsed_args.marker:
487487
kwargs['marker'] = utils.find_resource(image_client.images,
488488
parsed_args.marker).id
489-
490489
if parsed_args.long:
491490
columns = (
492491
'ID',
@@ -519,7 +518,19 @@ def take_action(self, parsed_args):
519518
column_headers = columns
520519

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

524535
if parsed_args.property:
525536
# 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)