From: Sheel Rana Date: Fri, 15 Jan 2016 20:23:49 +0000 (+0530) Subject: Added 'bootable volume' filter for non-admin user X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=7ac7413ae31f1298af3d50f5b3e017f2af572ecd;p=openstack-build%2Fcinder-build.git Added 'bootable volume' filter for non-admin user During launch instance from Horizon, if non-admin user selects volume as source for launching instance, drop down list for volumes will also show non-bootable volumes. It is wrong behaviour. To fix this, 'bootable volume' search filter is enabled so that only bootable volumes get displayed in drop down list of volume. APIImpact DocImpact:Need to add bootable against query_volume_filters in OpenStack Configuration Reference Closes-Bug: #1524450 Change-Id: If5bfbd73bbe02b13b76d7169ea16424493ac5fca --- diff --git a/cinder/api/v2/volumes.py b/cinder/api/v2/volumes.py index 0f4b17edb..66f494523 100644 --- a/cinder/api/v2/volumes.py +++ b/cinder/api/v2/volumes.py @@ -38,12 +38,14 @@ from cinder.volume import volume_types query_volume_filters_opt = cfg.ListOpt('query_volume_filters', default=['name', 'status', 'metadata', - 'availability_zone'], + 'availability_zone', + 'bootable'], help="Volume filter options which " "non-admin user could use to " "query volumes. Default values " "are: ['name', 'status', " - "'metadata', 'availability_zone']") + "'metadata', 'availability_zone'," + "'bootable']") CONF = cfg.CONF CONF.register_opt(query_volume_filters_opt) diff --git a/cinder/tests/unit/api/v2/test_volumes.py b/cinder/tests/unit/api/v2/test_volumes.py index 17ee2ab1c..63271508c 100644 --- a/cinder/tests/unit/api/v2/test_volumes.py +++ b/cinder/tests/unit/api/v2/test_volumes.py @@ -1472,6 +1472,20 @@ class VolumeApiTest(test.TestCase): filters={'availability_zone': 'nova'}, viewable_admin_meta=True, offset=0) + @mock.patch('cinder.volume.api.API.get_all') + def test_get_volumes_filter_with_bootable(self, get_all): + req = mock.MagicMock() + ctxt = context.RequestContext('fake', 'fake', auth_token=True) + req.environ = {'cinder.context': ctxt} + req.params = {'bootable': 1} + self.controller._view_builder.detail_list = mock.Mock() + self.controller._get_volumes(req, True) + get_all.assert_called_once_with( + ctxt, None, CONF.osapi_max_limit, + sort_keys=['created_at'], sort_dirs=['desc'], + filters={'bootable': True}, viewable_admin_meta=True, + offset=0) + @mock.patch('cinder.volume.api.API.get_all') def test_get_volumes_filter_with_invalid_filter(self, get_all): req = mock.MagicMock() @@ -1503,9 +1517,10 @@ class VolumeApiTest(test.TestCase): sort_keys=['display_name'], filters={}, offset=0) def test_get_volume_filter_options_using_config(self): - self.override_config('query_volume_filters', ['name', 'status', - 'metadata']) - self.assertEqual(['name', 'status', 'metadata'], + filter_list = ['name', 'status', 'metadata', 'bootable', + 'availability_zone'] + self.override_config('query_volume_filters', filter_list) + self.assertEqual(filter_list, self.controller._get_volume_filter_options())