Merge "Add pagination for snapshots, backups"
This commit is contained in:
@@ -115,12 +115,13 @@ class Manager(common_base.HookableMixin):
|
|||||||
# than osapi_max_limit, so we have to retrieve multiple times to
|
# than osapi_max_limit, so we have to retrieve multiple times to
|
||||||
# get the complete list.
|
# get the complete list.
|
||||||
next = None
|
next = None
|
||||||
if 'volumes_links' in body:
|
link_name = response_key + '_links'
|
||||||
volumes_links = body['volumes_links']
|
if link_name in body:
|
||||||
if volumes_links:
|
links = body[link_name]
|
||||||
for volumes_link in volumes_links:
|
if links:
|
||||||
if 'rel' in volumes_link and 'next' == volumes_link['rel']:
|
for link in links:
|
||||||
next = volumes_link['href']
|
if 'rel' in link and 'next' == link['rel']:
|
||||||
|
next = link['href']
|
||||||
break
|
break
|
||||||
if next:
|
if next:
|
||||||
# As long as the 'next' link is not empty, keep requesting it
|
# As long as the 'next' link is not empty, keep requesting it
|
||||||
|
@@ -126,6 +126,37 @@ class BaseTest(utils.TestCase):
|
|||||||
manager._build_list_url,
|
manager._build_list_url,
|
||||||
**arguments)
|
**arguments)
|
||||||
|
|
||||||
|
def test__list_no_link(self):
|
||||||
|
api = mock.Mock()
|
||||||
|
api.client.get.return_value = (mock.sentinel.resp,
|
||||||
|
{'resp_keys': [{'name': '1'}]})
|
||||||
|
manager = test_utils.FakeManager(api)
|
||||||
|
res = manager._list(mock.sentinel.url, 'resp_keys')
|
||||||
|
api.client.get.assert_called_once_with(mock.sentinel.url)
|
||||||
|
result = [r.name for r in res]
|
||||||
|
self.assertListEqual(['1'], result)
|
||||||
|
|
||||||
|
def test__list_with_link(self):
|
||||||
|
api = mock.Mock()
|
||||||
|
api.client.get.side_effect = [
|
||||||
|
(mock.sentinel.resp,
|
||||||
|
{'resp_keys': [{'name': '1'}],
|
||||||
|
'resp_keys_links': [{'rel': 'next', 'href': mock.sentinel.u2}]}),
|
||||||
|
(mock.sentinel.resp,
|
||||||
|
{'resp_keys': [{'name': '2'}],
|
||||||
|
'resp_keys_links': [{'rel': 'next', 'href': mock.sentinel.u3}]}),
|
||||||
|
(mock.sentinel.resp,
|
||||||
|
{'resp_keys': [{'name': '3'}],
|
||||||
|
'resp_keys_links': [{'rel': 'next', 'href': None}]}),
|
||||||
|
]
|
||||||
|
manager = test_utils.FakeManager(api)
|
||||||
|
res = manager._list(mock.sentinel.url, 'resp_keys')
|
||||||
|
api.client.get.assert_has_calls([mock.call(mock.sentinel.url),
|
||||||
|
mock.call(mock.sentinel.u2),
|
||||||
|
mock.call(mock.sentinel.u3)])
|
||||||
|
result = [r.name for r in res]
|
||||||
|
self.assertListEqual(['1', '2', '3'], result)
|
||||||
|
|
||||||
|
|
||||||
class ListWithMetaTest(utils.TestCase):
|
class ListWithMetaTest(utils.TestCase):
|
||||||
def test_list_with_meta(self):
|
def test_list_with_meta(self):
|
||||||
|
@@ -34,7 +34,7 @@ UUID = '8e8ec658-c7b0-4243-bdf8-6f7f2952c0d0'
|
|||||||
class FakeResource(object):
|
class FakeResource(object):
|
||||||
NAME_ATTR = 'name'
|
NAME_ATTR = 'name'
|
||||||
|
|
||||||
def __init__(self, _id, properties):
|
def __init__(self, _id, properties, **kwargs):
|
||||||
self.id = _id
|
self.id = _id
|
||||||
try:
|
try:
|
||||||
self.name = properties['name']
|
self.name = properties['name']
|
||||||
|
Reference in New Issue
Block a user