From 47ec84182007024eba86b50de59a0bd5978b64a2 Mon Sep 17 00:00:00 2001 From: Sheel Rana Date: Thu, 4 Feb 2016 00:00:11 +0530 Subject: [PATCH] Bootable filter for listening volumes from CLI 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 | 33 ++++++++++++++++++++++++++++++++ cinder/volume/api.py | 13 ++++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/cinder/tests/unit/test_volume.py b/cinder/tests/unit/test_volume.py index d3a5a230c..f06245106 100644 --- a/cinder/tests/unit/test_volume.py +++ b/cinder/tests/unit/test_volume.py @@ -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 diff --git a/cinder/volume/api.py b/cinder/volume/api.py index 189e0473c..06fa9ef1f 100644 --- a/cinder/volume/api.py +++ b/cinder/volume/api.py @@ -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): -- 2.45.2