api requests not returned in language specified in accept-language header

Bug #1214102 reported by Nicholas Goracke on 2013-08-19
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Cinder
Undecided
Luis A. Garcia

Bug Description

Update cinder.po file
cat /usr/lib/python2.6/site-packages/cinder/locale/ja/LC_MESSAGES/cinder.po
...
#: cinder/exception.py:620
#, python-format
msgid "Backup %(backup_id)s could not be found."
msgstr "Nick %(backup_id)s put this message here."
...

Compile new .mo file, install
msgfmt -o cinder.mo /usr/lib/python2.6/site-packages/cinder/locale/ja/LC_MESSAGES/cinder.po
cp cinder.mo /usr/share/locale/ja_JP/LC_MESSAGES/
cp cinder.mo /usr/share/locale/ja/LC_MESSAGES/

Restart cinder services
service openstack-cinder-volume restart
service openstack-cinder-scheduler restart
service openstack-cinder-api restart

API call to trigger translated message
curl -i http://127.0.0.1:8776/v1/1aaa0b70c70d43318230b926febd0da6/backups/blah -X GET -H "X-Auth-Project-Id: service" -H "User-Agent: python-cinderclient" -H "Accept: application/json" -H "X-Auth-Token: MIIMVwYJKoZIhvcNAQcCoIIMSDCCDEQCAQExCTAHBgUrDgMCGjCCCq0GCSqGSIb3DQEHAaCCCp4EggqaeyJhY2Nlc3MiOiB7InRva2VuIjogeyJpc3N1ZWRfYXQiOiAiMjAxMy0wOC0xOVQxNTo0NzoxMi45NDQxMTgiLCAiZXhwaXJlcyI6ICIyMDEzLTA4LTIwVDE1OjQ3OjEyWiIsICJpZCI6ICJwbGFjZWhvbGRlciIsICJ0ZW5hbnQiOiB7ImRlc2NyaXB0aW9uIjogIlNlcnZpY2UgVGVuYW50IiwgImVuYWJsZWQiOiB0cnVlLCAiaWQiOiAiMWFhYTBiNzBjNzBkNDMzMTgyMzBiOTI2ZmViZDBkYTYiLCAibmFtZSI6ICJzZXJ2aWNlIn19LCAic2VydmljZUNhdGFsb2ciOiBbeyJlbmRwb2ludHMiOiBbeyJhZG1pblVSTCI6ICJodHRwOi8vMTI3LjAuMC4xOjg3NzQvdjIvMWFhYTBiNzBj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BgNVBAYTAlVTMQ4wDAYDVQQIDAVVbnNldDEOMAwGA1UEBwwFVW5zZXQxDjAMBgNVBAoMBVVuc2V0MRgwFgYDVQQDDA93d3cuZXhhbXBsZS5jb20CAQEwBwYFKw4DAhowDQYJKoZIhvcNAQEBBQAEggEAtXHdf9GR-2xMG9I36aHp0wcVT85mqBKBqYrC5HWnb9zpH0yEc4b5OTWJJz-D7Mfgk9S9mZjy12I--aCQc8lSSCRmGTbxi4SxmuyAWMTI1dca059PXP-Z3p6lx477h+L5XmXtoAfY8tx2UBtvvQuZ7ovwj98s2po8R73b1ii2z9WSGaUoRe3LNiEcY1IPEB9KCzYkCM5PNknS--wEGBynbrx-dA2ZWkirpw+GUuX2So5nelVrCur3PYotK1xJGmxdvj0QmKq-hfwP2WuATzLOhVK8AAD+WRv8LYu72TBJt-18ZUam2+W+n2Cn1V12OMDLolnf-ywlfol06onM3YiHoA==" -H "Accept-Language: ja"

Response still in "english'
HTTP/1.1 404 Not Found
Content-Length: 77
Content-Type: application/json; charset=UTF-8
X-Compute-Request-Id: req-b996b5ab-37d2-4e36-87b5-79a8a7b8be89
Date: Mon, 19 Aug 2013 15:58:59 GMT

{"itemNotFound": {"message": "Backup blah could not be found.", "code": 404}}

Update system locale to make sure error message is properly translated (ie, didn't mess up the installation piece)
cat /etc/sysconfig/i18n
LANG="ja_JP.UTF-8"
#LANG="en_US.UTF-8"
SYSFONT="latarcyrheb-sun16"

Restart servers
service openstack-cinder-volume restart
service openstack-cinder-scheduler restart
service openstack-cinder-api restart

Response is "translated"
curl -i http://127.0.0.1:8776/v1/1aaa0b70c70d43318230b926febd0da6/backups/blah -X GET -H "X-Auth-Project-Id: service" -H "User-Agent: python-cinderclient" -H "Accept: application/json" -H "X-Auth-Token: MIIMVwYJKoZIhvcNAQcCoIIMSDCCDEQCAQExCTAHBgUrDgMCGjCCCq0GCSqGSIb3DQEHAaCCCp4EggqaeyJhY2Nlc3MiOiB7InRva2VuIjogeyJpc3N1ZWRfYXQ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b25lIn1dLCAidXNlciI6IHsidXNlcm5hbWUiOiAiYWRtaW4iLCAicm9sZXNfbGlua3MiOiBbXSwgImlkIjogIjk2ZWVlZTg5YzQzYzQ5ZGI4NmM3YTVmMjdmMWFmZDE4IiwgInJvbGVzIjogW3sibmFtZSI6ICJhZG1pbiJ9LCB7Im5hbWUiOiAiX21lbWJlcl8ifV0sICJuYW1lIjogImFkbWluIn0sICJtZXRhZGF0YSI6IHsiaXNfYWRtaW4iOiAwLCAicm9sZXMiOiBbIjNmZjljOTQ4OTRiMTQ0NTI5MjJjYjE3ZWU3MTllNGFhIiwgIjlmZTJmZjllZTQzODRiMTg5NGE5MDg3OGQzZTkyYmFiIl19fX0xggGBMIIBfQIBATBcMFcxCzAJBgNVBAYTAlVTMQ4wDAYDVQQIDAVVbnNldDEOMAwGA1UEBwwFVW5zZXQxDjAMBgNVBAoMBVVuc2V0MRgwFgYDVQQDDA93d3cuZXhhbXBsZS5jb20CAQEwBwYFKw4DAhowDQYJKoZIhvcNAQEBBQAEggEAtXHdf9GR-2xMG9I36aHp0wcVT85mqBKBqYrC5HWnb9zpH0yEc4b5OTWJJz-D7Mfgk9S9mZjy12I--aCQc8lSSCRmGTbxi4SxmuyAWMTI1dca059PXP-Z3p6lx477h+L5XmXtoAfY8tx2UBtvvQuZ7ovwj98s2po8R73b1ii2z9WSGaUoRe3LNiEcY1IPEB9KCzYkCM5PNknS--wEGBynbrx-dA2ZWkirpw+GUuX2So5nelVrCur3PYotK1xJGmxdvj0QmKq-hfwP2WuATzLOhVK8AAD+WRv8LYu72TBJt-18ZUam2+W+n2Cn1V12OMDLolnf-ywlfol06onM3YiHoA==" -H 'Accept-Language: ja'
HTTP/1.1 404 Not Found
Content-Length: 78
Content-Type: application/json; charset=UTF-8
X-Compute-Request-Id: req-16e980c6-8e6d-46b7-ade0-f5bf363a73f6
Date: Mon, 19 Aug 2013 16:03:57 GMT

{"itemNotFound": {"message": "Nick blah put this message here.", "code": 404}}

Luis A. Garcia (luisg-8) on 2013-08-19
Changed in cinder:
assignee: nobody → Luis A. Garcia (luisg-8)

Fix proposed to branch: master
Review: https://review.openstack.org/42726

Changed in cinder:
status: New → In Progress

Reviewed: https://review.openstack.org/42726
Committed: http://github.com/openstack/cinder/commit/2bec15e185e844dff757e09fa72a3b61d91e5f96
Submitter: Jenkins
Branch: master

commit 2bec15e185e844dff757e09fa72a3b61d91e5f96
Author: Luis A. Garcia <email address hidden>
Date: Mon Aug 19 20:19:57 2013 +0000

    Avoid serializing CinderExceptions before they are translated

    CinderExceptions were being unicode()'d when being wrapped in an
    HTTPException, and this was causing the delayed translation to fail for
    those errors.

    Also, CinderExceptions have a 'message' class attribute that holds the
    generic error message template, e.g. "Backup %(backup_id)s is not
    found", unfortunately, because the names are the same, it was
    overshadowing the actual exception instance 'message', e.g. "Backup 1 is
    not found", when translating. This patch puts the exception's actual
    message in a new field called 'msg'.

    Fixes Bug: #1214102

    Change-Id: Ied9abcc3d05454852c0a5891432eb181220a744e

Changed in cinder:
status: In Progress → Fix Committed
Thierry Carrez (ttx) on 2013-09-05
Changed in cinder:
milestone: none → havana-3
status: Fix Committed → Fix Released
Thierry Carrez (ttx) on 2013-10-17
Changed in cinder:
milestone: havana-3 → 2013.2
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers