From 72b96ee9dfca05e75a23784e4b86c9947797aa3d Mon Sep 17 00:00:00 2001 From: Neha Alhat Date: Fri, 24 Nov 2017 14:56:24 +0530 Subject: [PATCH] Fix TypeError for workers cleanup api incase of invalid resource_type value Workers cleanup API fails to build exception message if invalid resource_type value other than ['snapshot', 'volume'] is passed and raises TypeError which gets wrapped into BadRequest at wsgi level. This patch modifies exception message to fix TypeError issue. Closes-Bug: #1734252 Change-Id: I5823547c88edb4a1cc9ea5a51c9bf301daf41257 --- cinder/api/v3/workers.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cinder/api/v3/workers.py b/cinder/api/v3/workers.py index f3f5c3dfffe..bfdd62bf365 100644 --- a/cinder/api/v3/workers.py +++ b/cinder/api/v3/workers.py @@ -59,9 +59,11 @@ class WorkerController(wsgi.Controller): resource_type = resource_type.title() types = cleanable.CinderCleanableObject.cleanable_resource_types if resource_type not in types: - msg = (_('Resource type %s not valid, must be ') % - resource_type) - msg = utils.build_or_str(types, msg + '%s.') + valid_types = utils.build_or_str(types) + msg = _('Resource type %(resource_type)s not valid,' + ' must be %(valid_types)s') + msg = msg % {"resource_type": resource_type, + "valid_types": valid_types} raise exception.InvalidInput(reason=msg) params['resource_type'] = resource_type