Add a --limit parameter to list operations
In v2, we use the link header during paginations to know when there are more images available in the server that could be returned in the same request. This way, it's possible to iterate over the generator returned by list and consume the images in the server. However, it's currently not possible to tell glanceclient the exact number of images we want, which basically means that it'll *always* go through the whole list of images in the server unless the limit is implemented by the consumer. DocImpact Change-Id: I9f65a40d4eafda6320e5c7d94d03fcd1bbc93e33 Closes-bug: #1415035
This commit is contained in:
committed by
Flavio Percoco
parent
363b170851
commit
93c9bc1fe0
@@ -78,6 +78,25 @@ data_fixtures = {
|
||||
]},
|
||||
),
|
||||
},
|
||||
'/v2/images?limit=2': {
|
||||
'GET': (
|
||||
{},
|
||||
{
|
||||
'images': [
|
||||
{
|
||||
'id': '3a4560a1-e585-443e-9b39-553b46ec92d1',
|
||||
'name': 'image-1',
|
||||
},
|
||||
{
|
||||
'id': '6f99bf80-2ee6-47cf-acfe-1f1fabb7e810',
|
||||
'name': 'image-2',
|
||||
},
|
||||
],
|
||||
'next': ('/v2/images?limit=2&'
|
||||
'marker=6f99bf80-2ee6-47cf-acfe-1f1fabb7e810'),
|
||||
},
|
||||
),
|
||||
},
|
||||
'/v2/images?limit=1': {
|
||||
'GET': (
|
||||
{},
|
||||
@@ -104,6 +123,17 @@ data_fixtures = {
|
||||
]},
|
||||
),
|
||||
},
|
||||
('/v2/images?limit=1&marker=6f99bf80-2ee6-47cf-acfe-1f1fabb7e810'): {
|
||||
'GET': (
|
||||
{},
|
||||
{'images': [
|
||||
{
|
||||
'id': '3f99bf80-2ee6-47cf-acfe-1f1fabb7e811',
|
||||
'name': 'image-3',
|
||||
},
|
||||
]},
|
||||
),
|
||||
},
|
||||
'/v2/images/3a4560a1-e585-443e-9b39-553b46ec92d1': {
|
||||
'GET': (
|
||||
{},
|
||||
@@ -420,6 +450,17 @@ class TestController(testtools.TestCase):
|
||||
self.assertEqual('6f99bf80-2ee6-47cf-acfe-1f1fabb7e810', images[1].id)
|
||||
self.assertEqual('image-2', images[1].name)
|
||||
|
||||
def test_list_images_paginated_with_limit(self):
|
||||
# NOTE(bcwaldon):cast to list since the controller returns a generator
|
||||
images = list(self.controller.list(limit=3, page_size=2))
|
||||
self.assertEqual('3a4560a1-e585-443e-9b39-553b46ec92d1', images[0].id)
|
||||
self.assertEqual('image-1', images[0].name)
|
||||
self.assertEqual('6f99bf80-2ee6-47cf-acfe-1f1fabb7e810', images[1].id)
|
||||
self.assertEqual('image-2', images[1].name)
|
||||
self.assertEqual('3f99bf80-2ee6-47cf-acfe-1f1fabb7e811', images[2].id)
|
||||
self.assertEqual('image-3', images[2].name)
|
||||
self.assertEqual(3, len(images))
|
||||
|
||||
def test_list_images_visibility_public(self):
|
||||
filters = {'filters': {'visibility': 'public'}}
|
||||
images = list(self.controller.list(**filters))
|
||||
|
||||
@@ -61,6 +61,7 @@ class ShellV2Test(testtools.TestCase):
|
||||
|
||||
def test_do_image_list(self):
|
||||
input = {
|
||||
'limit': None,
|
||||
'page_size': 18,
|
||||
'visibility': True,
|
||||
'member_status': 'Fake',
|
||||
@@ -88,6 +89,7 @@ class ShellV2Test(testtools.TestCase):
|
||||
|
||||
def test_do_image_list_with_property_filter(self):
|
||||
input = {
|
||||
'limit': None,
|
||||
'page_size': 1,
|
||||
'visibility': True,
|
||||
'member_status': 'Fake',
|
||||
|
||||
Reference in New Issue
Block a user