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
This commit is contained in:
Cao Shufeng 2016-08-26 10:15:30 -04:00 committed by Cao ShuFeng
parent b4ef69d8ff
commit aeba18101c
2 changed files with 15 additions and 1 deletions

View File

@ -708,6 +708,20 @@ class ServicesTest(test.TestCase):
self.assertEqual('disabled', res_dict['status']) self.assertEqual('disabled', res_dict['status'])
self.assertEqual('test-reason', res_dict['disabled_reason']) 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): def test_services_disable_log_reason_none(self):
self.ext_mgr.extensions['os-extended-services'] = True self.ext_mgr.extensions['os-extended-services'] = True
self.controller = services.ServiceController(self.ext_mgr) self.controller = services.ServiceController(self.ext_mgr)

View File

@ -661,7 +661,7 @@ def check_string_length(value, name, min_length=0, max_length=None,
except(ValueError, TypeError) as exc: except(ValueError, TypeError) as exc:
raise exception.InvalidInput(reason=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.') msg = _('%(name)s cannot be all spaces.')
raise exception.InvalidInput(reason=msg) raise exception.InvalidInput(reason=msg)