Merge "Handle the pagination for image list"
This commit is contained in:
commit
e288e0194c
@ -405,7 +405,17 @@ class ListImage(lister.Lister):
|
|||||||
columns = ("ID", "Name")
|
columns = ("ID", "Name")
|
||||||
column_headers = columns
|
column_headers = columns
|
||||||
|
|
||||||
data = image_client.api.image_list(**kwargs)
|
# List of image data received
|
||||||
|
data = []
|
||||||
|
# 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:
|
if parsed_args.property:
|
||||||
# NOTE(dtroyer): coerce to a list to subscript it in py3
|
# NOTE(dtroyer): coerce to a list to subscript it in py3
|
||||||
|
@ -156,7 +156,17 @@ class ListImage(lister.Lister):
|
|||||||
columns = ("ID", "Name")
|
columns = ("ID", "Name")
|
||||||
column_headers = columns
|
column_headers = columns
|
||||||
|
|
||||||
data = image_client.api.image_list(**kwargs)
|
# List of image data received
|
||||||
|
data = []
|
||||||
|
# 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:
|
if parsed_args.property:
|
||||||
# NOTE(dtroyer): coerce to a list to subscript it in py3
|
# NOTE(dtroyer): coerce to a list to subscript it in py3
|
||||||
|
@ -306,8 +306,8 @@ class TestImageList(TestImage):
|
|||||||
super(TestImageList, self).setUp()
|
super(TestImageList, self).setUp()
|
||||||
|
|
||||||
self.api_mock = mock.Mock()
|
self.api_mock = mock.Mock()
|
||||||
self.api_mock.image_list.return_value = [
|
self.api_mock.image_list.side_effect = [
|
||||||
copy.deepcopy(image_fakes.IMAGE),
|
[copy.deepcopy(image_fakes.IMAGE)], [],
|
||||||
]
|
]
|
||||||
self.app.client_manager.image.api = self.api_mock
|
self.app.client_manager.image.api = self.api_mock
|
||||||
|
|
||||||
@ -327,6 +327,7 @@ class TestImageList(TestImage):
|
|||||||
columns, data = self.cmd.take_action(parsed_args)
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
self.api_mock.image_list.assert_called_with(
|
self.api_mock.image_list.assert_called_with(
|
||||||
detailed=False,
|
detailed=False,
|
||||||
|
marker=image_fakes.image_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
collist = ('ID', 'Name')
|
collist = ('ID', 'Name')
|
||||||
@ -354,6 +355,7 @@ class TestImageList(TestImage):
|
|||||||
self.api_mock.image_list.assert_called_with(
|
self.api_mock.image_list.assert_called_with(
|
||||||
detailed=False,
|
detailed=False,
|
||||||
public=True,
|
public=True,
|
||||||
|
marker=image_fakes.image_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
collist = ('ID', 'Name')
|
collist = ('ID', 'Name')
|
||||||
@ -381,6 +383,7 @@ class TestImageList(TestImage):
|
|||||||
self.api_mock.image_list.assert_called_with(
|
self.api_mock.image_list.assert_called_with(
|
||||||
detailed=False,
|
detailed=False,
|
||||||
private=True,
|
private=True,
|
||||||
|
marker=image_fakes.image_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
collist = ('ID', 'Name')
|
collist = ('ID', 'Name')
|
||||||
@ -405,6 +408,7 @@ class TestImageList(TestImage):
|
|||||||
columns, data = self.cmd.take_action(parsed_args)
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
self.api_mock.image_list.assert_called_with(
|
self.api_mock.image_list.assert_called_with(
|
||||||
detailed=True,
|
detailed=True,
|
||||||
|
marker=image_fakes.image_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
collist = (
|
collist = (
|
||||||
@ -437,8 +441,8 @@ class TestImageList(TestImage):
|
|||||||
|
|
||||||
@mock.patch('openstackclient.api.utils.simple_filter')
|
@mock.patch('openstackclient.api.utils.simple_filter')
|
||||||
def test_image_list_property_option(self, sf_mock):
|
def test_image_list_property_option(self, sf_mock):
|
||||||
sf_mock.return_value = [
|
sf_mock.side_effect = [
|
||||||
copy.deepcopy(image_fakes.IMAGE),
|
[copy.deepcopy(image_fakes.IMAGE)], [],
|
||||||
]
|
]
|
||||||
|
|
||||||
arglist = [
|
arglist = [
|
||||||
@ -453,6 +457,7 @@ class TestImageList(TestImage):
|
|||||||
columns, data = self.cmd.take_action(parsed_args)
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
self.api_mock.image_list.assert_called_with(
|
self.api_mock.image_list.assert_called_with(
|
||||||
detailed=True,
|
detailed=True,
|
||||||
|
marker=image_fakes.image_id,
|
||||||
)
|
)
|
||||||
sf_mock.assert_called_with(
|
sf_mock.assert_called_with(
|
||||||
[image_fakes.IMAGE],
|
[image_fakes.IMAGE],
|
||||||
@ -472,8 +477,8 @@ class TestImageList(TestImage):
|
|||||||
|
|
||||||
@mock.patch('openstackclient.common.utils.sort_items')
|
@mock.patch('openstackclient.common.utils.sort_items')
|
||||||
def test_image_list_sort_option(self, si_mock):
|
def test_image_list_sort_option(self, si_mock):
|
||||||
si_mock.return_value = [
|
si_mock.side_effect = [
|
||||||
copy.deepcopy(image_fakes.IMAGE)
|
[copy.deepcopy(image_fakes.IMAGE)], [],
|
||||||
]
|
]
|
||||||
|
|
||||||
arglist = ['--sort', 'name:asc']
|
arglist = ['--sort', 'name:asc']
|
||||||
@ -483,7 +488,8 @@ class TestImageList(TestImage):
|
|||||||
# DisplayCommandBase.take_action() returns two tuples
|
# DisplayCommandBase.take_action() returns two tuples
|
||||||
columns, data = self.cmd.take_action(parsed_args)
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
self.api_mock.image_list.assert_called_with(
|
self.api_mock.image_list.assert_called_with(
|
||||||
detailed=False
|
detailed=False,
|
||||||
|
marker=image_fakes.image_id,
|
||||||
)
|
)
|
||||||
si_mock.assert_called_with(
|
si_mock.assert_called_with(
|
||||||
[image_fakes.IMAGE],
|
[image_fakes.IMAGE],
|
||||||
|
@ -70,8 +70,8 @@ class TestImageList(TestImage):
|
|||||||
super(TestImageList, self).setUp()
|
super(TestImageList, self).setUp()
|
||||||
|
|
||||||
self.api_mock = mock.Mock()
|
self.api_mock = mock.Mock()
|
||||||
self.api_mock.image_list.return_value = [
|
self.api_mock.image_list.side_effect = [
|
||||||
copy.deepcopy(image_fakes.IMAGE),
|
[copy.deepcopy(image_fakes.IMAGE)], [],
|
||||||
]
|
]
|
||||||
self.app.client_manager.image.api = self.api_mock
|
self.app.client_manager.image.api = self.api_mock
|
||||||
|
|
||||||
@ -90,7 +90,9 @@ class TestImageList(TestImage):
|
|||||||
|
|
||||||
# DisplayCommandBase.take_action() returns two tuples
|
# DisplayCommandBase.take_action() returns two tuples
|
||||||
columns, data = self.cmd.take_action(parsed_args)
|
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=image_fakes.image_id,
|
||||||
|
)
|
||||||
|
|
||||||
collist = ('ID', 'Name')
|
collist = ('ID', 'Name')
|
||||||
|
|
||||||
@ -117,6 +119,7 @@ class TestImageList(TestImage):
|
|||||||
columns, data = self.cmd.take_action(parsed_args)
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
self.api_mock.image_list.assert_called_with(
|
self.api_mock.image_list.assert_called_with(
|
||||||
public=True,
|
public=True,
|
||||||
|
marker=image_fakes.image_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
collist = ('ID', 'Name')
|
collist = ('ID', 'Name')
|
||||||
@ -144,6 +147,7 @@ class TestImageList(TestImage):
|
|||||||
columns, data = self.cmd.take_action(parsed_args)
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
self.api_mock.image_list.assert_called_with(
|
self.api_mock.image_list.assert_called_with(
|
||||||
private=True,
|
private=True,
|
||||||
|
marker=image_fakes.image_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
collist = ('ID', 'Name')
|
collist = ('ID', 'Name')
|
||||||
@ -171,6 +175,7 @@ class TestImageList(TestImage):
|
|||||||
columns, data = self.cmd.take_action(parsed_args)
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
self.api_mock.image_list.assert_called_with(
|
self.api_mock.image_list.assert_called_with(
|
||||||
shared=True,
|
shared=True,
|
||||||
|
marker=image_fakes.image_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
collist = ('ID', 'Name')
|
collist = ('ID', 'Name')
|
||||||
@ -193,7 +198,9 @@ class TestImageList(TestImage):
|
|||||||
|
|
||||||
# DisplayCommandBase.take_action() returns two tuples
|
# DisplayCommandBase.take_action() returns two tuples
|
||||||
columns, data = self.cmd.take_action(parsed_args)
|
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=image_fakes.image_id,
|
||||||
|
)
|
||||||
|
|
||||||
collist = (
|
collist = (
|
||||||
'ID',
|
'ID',
|
||||||
@ -239,7 +246,9 @@ class TestImageList(TestImage):
|
|||||||
|
|
||||||
# DisplayCommandBase.take_action() returns two tuples
|
# DisplayCommandBase.take_action() returns two tuples
|
||||||
columns, data = self.cmd.take_action(parsed_args)
|
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=image_fakes.image_id,
|
||||||
|
)
|
||||||
sf_mock.assert_called_with(
|
sf_mock.assert_called_with(
|
||||||
[image_fakes.IMAGE],
|
[image_fakes.IMAGE],
|
||||||
attr='a',
|
attr='a',
|
||||||
@ -268,7 +277,9 @@ class TestImageList(TestImage):
|
|||||||
|
|
||||||
# DisplayCommandBase.take_action() returns two tuples
|
# DisplayCommandBase.take_action() returns two tuples
|
||||||
columns, data = self.cmd.take_action(parsed_args)
|
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=image_fakes.image_id,
|
||||||
|
)
|
||||||
si_mock.assert_called_with(
|
si_mock.assert_called_with(
|
||||||
[image_fakes.IMAGE],
|
[image_fakes.IMAGE],
|
||||||
'name:asc'
|
'name:asc'
|
||||||
|
Loading…
Reference in New Issue
Block a user