Browse Source

Merge "Fix issue of getting detail backups list info" into stable/train

changes/96/816596/1
Zuul 7 months ago committed by Gerrit Code Review
parent
commit
4fde5a3e05
  1. 8
      cinder/api/views/backups.py
  2. 39
      cinder/tests/unit/api/contrib/test_backups.py

8
cinder/api/views/backups.py

@ -31,7 +31,8 @@ class ViewBuilder(common.ViewBuilder):
def detail_list(self, request, backups, backup_count=None):
"""Detailed view of a list of backups ."""
return self._list_view(self.detail, request, backups, backup_count)
return self._list_view(self.detail, request, backups, backup_count,
self._collection_name + '/detail')
def summary(self, request, backup):
"""Generic, non-detailed view of a backup."""
@ -80,12 +81,13 @@ class ViewBuilder(common.ViewBuilder):
return backup_dict
def _list_view(self, func, request, backups, backup_count):
def _list_view(self, func, request, backups, backup_count,
coll_name=_collection_name):
"""Provide a view for a list of backups."""
backups_list = [func(request, backup)['backup'] for backup in backups]
backups_links = self._get_collection_links(request,
backups,
self._collection_name,
coll_name,
backup_count)
backups_dict = dict(backups=backups_list)

39
cinder/tests/unit/api/contrib/test_backups.py

@ -257,6 +257,45 @@ class BackupsAPITestCase(test.TestCase):
backup2.destroy()
backup1.destroy()
def test_list_all_backups_detail_json_over_limit(self):
self.override_config('osapi_max_limit', 2)
backup1 = utils.create_backup(self.context, availability_zone='az1',
container='volumebackups', size=1)
backup2 = utils.create_backup(self.context, availability_zone='az1',
container='volumebackups', size=1)
backup3 = utils.create_backup(self.context, availability_zone='az1',
container='volumebackups', size=1)
req = webob.Request.blank('/v2/%s/backups/detail' % fake.PROJECT_ID)
req.method = 'GET'
req.headers['Content-Type'] = 'application/json'
req.headers['Accept'] = 'application/json'
res = req.get_response(fakes.wsgi_app(
fake_auth_context=self.user_context))
res_dict = jsonutils.loads(res.body)
self.assertEqual(http_client.OK, res.status_int)
self.assertEqual(NUM_ELEMENTS_IN_BACKUP, len(res_dict['backups'][0]))
self.assertEqual(NUM_ELEMENTS_IN_BACKUP, len(res_dict['backups'][1]))
self.assertEqual(2, len(res_dict['backups']))
self.assertIn('backups_links', res_dict)
links = res_dict['backups_links']
next_url = links[0]['href']
req = webob.Request.blank(next_url)
req.method = 'GET'
req.headers['Content-Type'] = 'application/json'
req.headers['Accept'] = 'application/json'
res = req.get_response(fakes.wsgi_app(
fake_auth_context=self.user_context))
res_dict = jsonutils.loads(res.body)
self.assertEqual(NUM_ELEMENTS_IN_BACKUP, len(res_dict['backups'][0]))
backup3.destroy()
backup2.destroy()
backup1.destroy()
def test_list_backups_detail_json(self):
backup1 = utils.create_backup(self.context, availability_zone='az1',
container='volumebackups', size=1)

Loading…
Cancel
Save