VersionedObject.__repr__ should return encoded string

Bug #1514325 reported by Liang Chen
52
This bug affects 7 people
Affects Status Importance Assigned to Milestone
Cinder
Invalid
Undecided
Liang Chen
oslo.versionedobjects
Fix Released
Undecided
Liang Chen
cinder (Ubuntu)
Fix Released
Medium
Liang Chen

Bug Description

[Impact]

 * Cinder snapshot display-description cannot contain non-ascii characters.

[Test Case]

 * cinder create 1
 * cinder snapshot-create --display-description "中文" <the volume ID>

[Regression Potential]

 * None

The following error is reported when creating a volume snapshot with non-ascii display-description, e.g. cinder snapshot-create --display-description "中文" my-2nd-volume.

2015-11-09 05:55:50.995 29937 ERROR oslo_messaging.rpc.dispatcher [req-81f48a02-b1ef-4aae-9e22-ac2ce1c75b2f 16818cbff07548889da69bf526558d97 7aac0111a39741f59513c05b2d83dd70 - - -] Exception during message handling: 'ascii' codec can't encode characters in position 111-117: ordinal not in range(128)
2015-11-09 05:55:50.995 29937 ERROR oslo_messaging.rpc.dispatcher Traceback (most recent call last):
2015-11-09 05:55:50.995 29937 ERROR oslo_messaging.rpc.dispatcher File "/usr/lib/python2.7/dist-packages/oslo_messaging/rpc/dispatcher.py", line 142, in _dispatch_and_reply
2015-11-09 05:55:50.995 29937 ERROR oslo_messaging.rpc.dispatcher executor_callback))
2015-11-09 05:55:50.995 29937 ERROR oslo_messaging.rpc.dispatcher File "/usr/lib/python2.7/dist-packages/oslo_messaging/rpc/dispatcher.py", line 186, in _dispatch
2015-11-09 05:55:50.995 29937 ERROR oslo_messaging.rpc.dispatcher executor_callback)
2015-11-09 05:55:50.995 29937 ERROR oslo_messaging.rpc.dispatcher File "/usr/lib/python2.7/dist-packages/oslo_messaging/rpc/dispatcher.py", line 129, in _do_dispatch
2015-11-09 05:55:50.995 29937 ERROR oslo_messaging.rpc.dispatcher result = func(ctxt, **new_args)
2015-11-09 05:55:50.995 29937 ERROR oslo_messaging.rpc.dispatcher File "/usr/lib/python2.7/dist-packages/osprofiler/profiler.py", line 102, in wrapper
2015-11-09 05:55:50.995 29937 ERROR oslo_messaging.rpc.dispatcher info["function"]["kwargs"] = str(kwargs)
2015-11-09 05:55:50.995 29937 ERROR oslo_messaging.rpc.dispatcher UnicodeEncodeError: 'ascii' codec can't encode characters in position 111-117: ordinal not in range(128)
2015-11-09 05:55:50.995 29937 ERROR oslo_messaging.rpc.dispatcher

Root cause is that profiler tries to get a string representation of the arguments (cinder.objects.snapshot.Snapshot) of the snapshot-create cinder-volume service api. As a result, VersionedObject.__repr__ is called to produce such a string representation with an attribute (display-description) containing non-ascii characters, thus returning an unicode object. However when __repr__ returns an unicode object, it's expected that the the returned string can be encoded by default encoding scheme which is ascii in general [1][2]. So __repr__ needs to make sure any unicode string it's going to return are properly encoded.

[1] trying to encode the returned string when it's an unicode object
https://github.com/python/cpython/blob/2.7/Objects/object.c#L387

[2] if encoding arg is left null, default encoding will be used
https://github.com/python/cpython/blob/2.7/Objects/unicodeobject.c#L1355

Tags: sts

Related branches

Liang Chen (cbjchen)
Changed in oslo.versionedobjects:
assignee: nobody → Liang Chen (cbjchen)
description: updated
Revision history for this message
Liang Chen (cbjchen) wrote :
Changed in oslo.versionedobjects:
status: New → In Progress
Liang Chen (cbjchen)
Changed in oslo.versionedobjects:
status: In Progress → Fix Committed
Liang Chen (cbjchen)
tags: added: sts
Changed in oslo.versionedobjects:
milestone: none → 0.13.0
status: Fix Committed → Fix Released
Liang Chen (cbjchen)
Changed in cinder:
assignee: nobody → Liang Chen (cbjchen)
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to cinder (stable/kilo)

Fix proposed to branch: stable/kilo
Review: https://review.openstack.org/246772

Revision history for this message
Liang Chen (cbjchen) wrote :

Fix proposed to branch: stable/liberty at https://review.openstack.org/#/c/246758/

Liang Chen (cbjchen)
description: updated
Changed in cinder (Ubuntu):
status: New → In Progress
assignee: nobody → Liang Chen (cbjchen)
Mathew Hodson (mhodson)
Changed in cinder (Ubuntu):
importance: Undecided → Medium
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Change abandoned on cinder (stable/kilo)

Change abandoned by Eric Harney (<email address hidden>) on branch: stable/kilo
Review: https://review.openstack.org/246772
Reason: -2 in November, and I agree with that, so cleaning this one out of the queue.

Revision history for this message
James Page (james-page) wrote :

Accepted into stable/liberty a while back, so Ubuntu + UCA with >= liberty will now have this fix.

Marking 'Fix Released'

Changed in cinder (Ubuntu):
status: In Progress → Fix Released
Matt Riedemann (mriedem)
Changed in cinder:
status: In Progress → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.