]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Added 'bootable volume' filter for non-admin user
authorSheel Rana <ranasheel2000@gmail.com>
Fri, 15 Jan 2016 20:23:49 +0000 (01:53 +0530)
committerSheel Rana <ranasheel2000@gmail.com>
Tue, 19 Jan 2016 16:23:02 +0000 (16:23 +0000)
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

cinder/api/v2/volumes.py
cinder/tests/unit/api/v2/test_volumes.py

index 0f4b17edb650b31cc976336a5a756d995eddd26e..66f49452369a855251f929263d6b371dcc9d1d32 100644 (file)
@@ -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)
index 17ee2ab1c6d14eb503242a802f4a86f7a3dadc60..63271508c4b514d0da0bbb0173c3e482e19b0b67 100644 (file)
@@ -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())