From aeba18101cf193a38d2e006b2960efb973417ee6 Mon Sep 17 00:00:00 2001 From: Cao Shufeng Date: Fri, 26 Aug 2016 10:15:30 -0400 Subject: [PATCH] Do not pass unicode to str.isspace() when disabling a service When --reason is passed to "cinder service-disable", a "malformed" error is returend. This is because we are passing a unicode object to str.isspace() function. In this change, we use unicode/str objects' isspace() instead. Change-Id: I215293994ed4f2c38b5780f2748a16fbaef88b7a Closes-Bug: #1617272 --- cinder/tests/unit/api/contrib/test_services.py | 14 ++++++++++++++ cinder/utils.py | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/cinder/tests/unit/api/contrib/test_services.py b/cinder/tests/unit/api/contrib/test_services.py index 96dbf6d10..10bfc14fa 100644 --- a/cinder/tests/unit/api/contrib/test_services.py +++ b/cinder/tests/unit/api/contrib/test_services.py @@ -708,6 +708,20 @@ class ServicesTest(test.TestCase): self.assertEqual('disabled', res_dict['status']) self.assertEqual('test-reason', res_dict['disabled_reason']) + def test_services_disable_log_reason_unicode(self): + self.ext_mgr.extensions['os-extended-services'] = True + self.controller = services.ServiceController(self.ext_mgr) + req = ( + fakes.HTTPRequest.blank('v1/fake/os-services/disable-log-reason')) + body = {'host': 'host1', + 'binary': 'cinder-scheduler', + 'disabled_reason': u'test-reason', + } + res_dict = self.controller.update(req, "disable-log-reason", body) + + self.assertEqual('disabled', res_dict['status']) + self.assertEqual('test-reason', res_dict['disabled_reason']) + def test_services_disable_log_reason_none(self): self.ext_mgr.extensions['os-extended-services'] = True self.controller = services.ServiceController(self.ext_mgr) diff --git a/cinder/utils.py b/cinder/utils.py index 84864fd61..66a84a59e 100644 --- a/cinder/utils.py +++ b/cinder/utils.py @@ -661,7 +661,7 @@ def check_string_length(value, name, min_length=0, max_length=None, except(ValueError, TypeError) as exc: raise exception.InvalidInput(reason=exc) - if not allow_all_spaces and str.isspace(value): + if not allow_all_spaces and value.isspace(): msg = _('%(name)s cannot be all spaces.') raise exception.InvalidInput(reason=msg)