Merge "Fix share instance list API display error"

This commit is contained in:
Jenkins 2017-05-26 23:04:08 +00:00 committed by Gerrit Code Review
commit a6a1cbcd96
3 changed files with 35 additions and 2 deletions

View File

@ -17,6 +17,7 @@ class ViewBuilder(common.ViewBuilder):
"""Model a server API response as a python dictionary.""" """Model a server API response as a python dictionary."""
_collection_name = 'share_instances' _collection_name = 'share_instances'
_collection_links = 'share_instances_links'
_detail_version_modifiers = [ _detail_version_modifiers = [
"remove_export_locations", "remove_export_locations",
@ -60,7 +61,7 @@ class ViewBuilder(common.ViewBuilder):
instances_dict = {self._collection_name: instances_list} instances_dict = {self._collection_name: instances_list}
if instances_links: if instances_links:
instances_dict[self._collection_name] = instances_links instances_dict[self._collection_links] = instances_links
return instances_dict return instances_dict

View File

@ -59,7 +59,7 @@ class ShareInstancesAPITest(test.TestCase):
def _get_request(self, uri, context=None, version="2.3"): def _get_request(self, uri, context=None, version="2.3"):
if context is None: if context is None:
context = self.admin_context context = self.admin_context
req = fakes.HTTPRequest.blank('/shares', version=version) req = fakes.HTTPRequest.blank(uri, version=version)
req.environ['manila.context'] = context req.environ['manila.context'] = context
return req return req
@ -84,6 +84,33 @@ class ShareInstancesAPITest(test.TestCase):
self.mock_policy_check.assert_called_once_with( self.mock_policy_check.assert_called_once_with(
req_context, self.resource_name, 'index') req_context, self.resource_name, 'index')
def test_index_with_limit(self):
req = self._get_request('/share_instances')
req_context = req.environ['manila.context']
share_instances_count = 3
test_instances = [
db_utils.create_share(size=s + 1).instance
for s in range(0, share_instances_count)
]
expect_links = [
{
'href': (
'http://localhost/v1/fake/share_instances?'
'limit=3&marker=%s' % test_instances[2]['id']),
'rel': 'next',
}
]
url = 'share_instances?limit=3'
req = self._get_request(url)
actual_result = self.controller.index(req)
self._validate_ids_in_share_instances_list(
test_instances, actual_result['share_instances'])
self.assertEqual(expect_links, actual_result['share_instances_links'])
self.mock_policy_check.assert_called_once_with(
req_context, self.resource_name, 'index')
def test_show(self): def test_show(self):
test_instance = db_utils.create_share(size=1).instance test_instance = db_utils.create_share(size=1).instance
id = test_instance['id'] id = test_instance['id']

View File

@ -0,0 +1,5 @@
---
fixes:
- Fixed share instance list with limit number API display error.
Change _collection_name to _collection_links when we want to
show instances_links.