]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Bootable filter for listening volumes from CLI
authorSheel Rana <ranasheel2000@gmail.com>
Wed, 3 Feb 2016 18:30:11 +0000 (00:00 +0530)
committerSheel Rana <ranasheel2000@gmail.com>
Thu, 4 Feb 2016 05:04:02 +0000 (05:04 +0000)
Currently cinder treats all values passed to it as True
for bootable filter in volume GET call.

For ex, if bootable=invalid, it converts it into True being
bootable as boolean value in db table 'volume'.

Need to update filtering functionality in cinder to address
'True' and 'False' values seperately.

Existing behavior will be kept same.
Only True/False/true/false input handling is done to treat
true/false seperately
(In current behavior, whatever input is passed for boolean
parameter, cinder convetrs it to True)

Implements : blueprint select-volume-through-bootable-option

Closes-Bug: #1535749

Change-Id: I1f1ec20441b28e01bf07bc4f60d848b653e58d58

cinder/tests/unit/test_volume.py
cinder/volume/api.py

index d3a5a230cad38b8d8fdefdca7208c044f48983f2..f062451066892d7fb6e2fd1af1572513df0aadb4 100644 (file)
@@ -4158,6 +4158,39 @@ class VolumeTestCase(BaseVolumeTestCase):
                                fake_new_volume.id)
         self.assertIsNone(volume.migration_status)
 
+    def test_check_volume_filters_true(self):
+        """Test bootable as filter for true"""
+        volume_api = cinder.volume.api.API()
+        filters = {'bootable': 'TRUE'}
+
+        # To convert filter value to True or False
+        volume_api.check_volume_filters(filters)
+
+        # Confirming converted filter value against True
+        self.assertTrue(filters['bootable'])
+
+    def test_check_volume_filters_false(self):
+        """Test bootable as filter for false"""
+        volume_api = cinder.volume.api.API()
+        filters = {'bootable': 'false'}
+
+        # To convert filter value to True or False
+        volume_api.check_volume_filters(filters)
+
+        # Confirming converted filter value against False
+        self.assertEqual(False, filters['bootable'])
+
+    def test_check_volume_filters_invalid(self):
+        """Test bootable as filter"""
+        volume_api = cinder.volume.api.API()
+        filters = {'bootable': 'invalid'}
+
+        # To convert filter value to True or False
+        volume_api.check_volume_filters(filters)
+
+        # Confirming converted filter value against invalid value
+        self.assertTrue(filters['bootable'])
+
     def test_update_volume_readonly_flag(self):
         """Test volume readonly flag can be updated at API level."""
         # create a volume and assign to host
index 189e0473c57deb0aab829544f8bb42f05ed87c43..06fa9ef1f287ae01c4f17bff79b5c43977187e20 100644 (file)
@@ -1698,11 +1698,22 @@ class API(base.Base):
         return self.volume_rpcapi.list_replication_targets(ctxt, volume)
 
     def check_volume_filters(self, filters):
+        '''Sets the user filter value to accepted format'''
         booleans = self.db.get_booleans_for_table('volume')
+
+        # To translate any true/false equivalent to True/False
+        # which is only acceptable format in database queries.
+        accepted_true = ['True', 'true', 'TRUE']
+        accepted_false = ['False', 'false', 'FALSE']
         for k, v in filters.items():
             try:
                 if k in booleans:
-                    filters[k] = bool(v)
+                    if v in accepted_false:
+                        filters[k] = False
+                    elif v in accepted_true:
+                        filters[k] = True
+                    else:
+                        filters[k] = bool(v)
                 else:
                     filters[k] = ast.literal_eval(v)
             except (ValueError, SyntaxError):