diff --git a/manila/api/views/share_instance.py b/manila/api/views/share_instance.py index 4b319cc108..09eb4bb6ed 100644 --- a/manila/api/views/share_instance.py +++ b/manila/api/views/share_instance.py @@ -17,6 +17,7 @@ class ViewBuilder(common.ViewBuilder): """Model a server API response as a python dictionary.""" _collection_name = 'share_instances' + _collection_links = 'share_instances_links' _detail_version_modifiers = [ "remove_export_locations", @@ -60,7 +61,7 @@ class ViewBuilder(common.ViewBuilder): instances_dict = {self._collection_name: instances_list} if instances_links: - instances_dict[self._collection_name] = instances_links + instances_dict[self._collection_links] = instances_links return instances_dict diff --git a/manila/tests/api/v2/test_share_instances.py b/manila/tests/api/v2/test_share_instances.py index 5af1c810e6..688c0711bd 100644 --- a/manila/tests/api/v2/test_share_instances.py +++ b/manila/tests/api/v2/test_share_instances.py @@ -59,7 +59,7 @@ class ShareInstancesAPITest(test.TestCase): def _get_request(self, uri, context=None, version="2.3"): if context is None: context = self.admin_context - req = fakes.HTTPRequest.blank('/shares', version=version) + req = fakes.HTTPRequest.blank(uri, version=version) req.environ['manila.context'] = context return req @@ -84,6 +84,33 @@ class ShareInstancesAPITest(test.TestCase): self.mock_policy_check.assert_called_once_with( 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): test_instance = db_utils.create_share(size=1).instance id = test_instance['id'] diff --git a/releasenotes/notes/fix-share-instance-list-with-limit-db7b5b99138e22ee.yaml b/releasenotes/notes/fix-share-instance-list-with-limit-db7b5b99138e22ee.yaml new file mode 100644 index 0000000000..7e3a3fe96a --- /dev/null +++ b/releasenotes/notes/fix-share-instance-list-with-limit-db7b5b99138e22ee.yaml @@ -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.