From: liyuanyuan Date: Thu, 10 Sep 2015 05:52:00 +0000 (+0000) Subject: Change check method for 'all_tenants' X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=9080962d5d6060a9edac30bc3d2d898592b06dd2;p=openstack-build%2Fcinder-build.git Change check method for 'all_tenants' Replaced with calls to get_bool_param from utils, so it supports any boolean value like the rest of the API methods. APIImpact: The API will also allow to pass 'yes', 'no', 'y', 'n' as valid boolean strings in addition. Change-Id: I397b0dfb688e0e6278eac75978df28bf6f99d0a9 Closes-Bug: #1494130 --- diff --git a/cinder/tests/unit/test_volume.py b/cinder/tests/unit/test_volume.py index 48201640a..fce13c05f 100644 --- a/cinder/tests/unit/test_volume.py +++ b/cinder/tests/unit/test_volume.py @@ -1050,24 +1050,6 @@ class VolumeTestCase(BaseVolumeTestCase): self.context, limit="-1") - def test_get_all_tenants_value(self): - """Validate allowable values for --all_tenants - - Note: type of the value could be String, Boolean, or Int - """ - api = cinder.volume.api.API() - - self.assertTrue(api._get_all_tenants_value({'all_tenants': True})) - self.assertTrue(api._get_all_tenants_value({'all_tenants': 1})) - self.assertFalse(api._get_all_tenants_value({'all_tenants': 'False'})) - self.assertFalse(api._get_all_tenants_value({'all_tenants': '0'})) - self.assertRaises(exception.InvalidInput, - api._get_all_tenants_value, - {'all_tenants': 'No'}) - self.assertRaises(exception.InvalidInput, - api._get_all_tenants_value, - {'all_tenants': -1}) - def test_get_all_tenants_volume_list(self): """Validate when the volume list for all tenants is returned""" volume_api = cinder.volume.api.API() diff --git a/cinder/volume/api.py b/cinder/volume/api.py index 3b8cfece4..e41d03dae 100644 --- a/cinder/volume/api.py +++ b/cinder/volume/api.py @@ -446,26 +446,6 @@ class API(base.Base): LOG.info(_LI("Volume info retrieved successfully."), resource=rv) return volume - def _get_all_tenants_value(self, filters): - """Returns a Boolean for the value of filters['all_tenants']. - - False is returned if 'all_tenants' is not in the filters dictionary. - An InvalidInput exception is thrown for invalid values. - """ - - b = False - if 'all_tenants' in filters: - val = six.text_type(filters['all_tenants']).lower() - if val in ['true', '1']: - b = True - elif val in ['false', '0']: - b = False - else: - msg = _('all_tenants param must be 0 or 1') - raise exception.InvalidInput(reason=msg) - - return b - def get_all(self, context, marker=None, limit=None, sort_keys=None, sort_dirs=None, filters=None, viewable_admin_meta=False, offset=None): @@ -474,7 +454,7 @@ class API(base.Base): if filters is None: filters = {} - allTenants = self._get_all_tenants_value(filters) + allTenants = utils.get_bool_param('all_tenants', filters) try: if limit is not None: