From f523e6e59326cabb7fc98ca7c6becb0f0ccb6759 Mon Sep 17 00:00:00 2001 From: liyingjun Date: Thu, 7 Aug 2014 05:58:17 +0800 Subject: [PATCH] Add filter to volume transfer REST api The transfer api supports filter param, https://github.com/openstack/cinder/blob/master/cinder/transfer/api.py#L72 But the transfer REST api didn't pass the filter params when calling get_all. Change-Id: I1e29614a3368296571378b4a80a5cfa29b16754e Closes-bug: 1351084 --- cinder/api/contrib/volume_transfer.py | 3 +- .../tests/api/contrib/test_volume_transfer.py | 29 +++++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/cinder/api/contrib/volume_transfer.py b/cinder/api/contrib/volume_transfer.py index 05daea215..23c82cda0 100644 --- a/cinder/api/contrib/volume_transfer.py +++ b/cinder/api/contrib/volume_transfer.py @@ -128,8 +128,9 @@ class VolumeTransferController(wsgi.Controller): def _get_transfers(self, req, is_detail): """Returns a list of transfers, transformed through view builder.""" context = req.environ['cinder.context'] + filters = req.params.copy() LOG.debug('Listing volume transfers') - transfers = self.transfer_api.get_all(context) + transfers = self.transfer_api.get_all(context, filters=filters) limited_list = common.limited(transfers, req) if is_detail: diff --git a/cinder/tests/api/contrib/test_volume_transfer.py b/cinder/tests/api/contrib/test_volume_transfer.py index f1d5b6d68..9ba455f9f 100644 --- a/cinder/tests/api/contrib/test_volume_transfer.py +++ b/cinder/tests/api/contrib/test_volume_transfer.py @@ -22,6 +22,7 @@ from xml.dom import minidom import webob +from cinder.api.contrib import volume_transfer from cinder import context from cinder import db from cinder import exception @@ -41,6 +42,7 @@ class VolumeTransferAPITestCase(test.TestCase): def setUp(self): super(VolumeTransferAPITestCase, self).setUp() self.volume_transfer_api = API() + self.controller = volume_transfer.VolumeTransferController() def _create_transfer(self, volume_id=1, display_name='test_transfer'): @@ -53,13 +55,14 @@ class VolumeTransferAPITestCase(test.TestCase): def _create_volume(display_name='test_volume', display_description='this is a test volume', status='available', - size=1): + size=1, + project_id='fake'): """Create a volume object.""" vol = {} vol['host'] = 'fake_host' vol['size'] = size vol['user_id'] = 'fake' - vol['project_id'] = 'fake' + vol['project_id'] = project_id vol['status'] = status vol['display_name'] = display_name vol['display_description'] = display_description @@ -233,6 +236,28 @@ class VolumeTransferAPITestCase(test.TestCase): db.volume_destroy(context.get_admin_context(), volume_id_2) db.volume_destroy(context.get_admin_context(), volume_id_1) + def test_list_transfers_with_all_tenants(self): + volume_id_1 = self._create_volume(size=5) + volume_id_2 = self._create_volume(size=5, project_id='fake1') + transfer1 = self._create_transfer(volume_id_1) + transfer2 = self._create_transfer(volume_id_2) + + req = fakes.HTTPRequest.blank('/v2/fake/os-volume-transfer?' + 'all_tenants=1', + use_admin_context=True) + res_dict = self.controller.index(req) + + expected = [(transfer1['id'], 'test_transfer'), + (transfer2['id'], 'test_transfer')] + ret = [] + for item in res_dict['transfers']: + ret.append((item['id'], item['name'])) + self.assertEqual(set(expected), set(ret)) + + db.transfer_destroy(context.get_admin_context(), transfer2['id']) + db.transfer_destroy(context.get_admin_context(), transfer1['id']) + db.volume_destroy(context.get_admin_context(), volume_id_1) + def test_create_transfer_json(self): volume_id = self._create_volume(status='available', size=5) body = {"transfer": {"display_name": "transfer1", -- 2.45.2