Project

General

Profile

Actions

Bug #42651

closed

mgr/dashboard: error when editing rbd image whose name contains non-ASCII chars.

Added by Alfonso Martínez over 4 years ago. Updated about 3 years ago.

Status:
Resolved
Priority:
Normal
Assignee:
Category:
Component - RBD
Target version:
% Done:

0%

Source:
Tags:
Backport:
Regression:
No
Severity:
3 - minor
Reviewed:
Affected Versions:
ceph-qa-suite:
Pull request ID:
Crash signature (v1):
Crash signature (v2):

Description

Verified for this environment:
OS: CentOS 7
Python version: 2.7.5

After creating rbd image with name like "año" (non-ASCII chars: ñ),
if you try to edit image, you get an error:

2019-10-30T19:34:33.269+0000 7f8ca4be6700  0 mgr[dashboard] [30/Oct/2019:19:34:33]  Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/cherrypy/_cprequest.py", line 102, in run
    hook()
  File "/usr/lib/python2.7/site-packages/cherrypy/_cprequest.py", line 62, in __call__
    return self.callback(**self.kwargs)
  File "/ceph/src/pybind/mgr/dashboard/tools.py", line 53, in request_begin
    req.method, user, req.path_info)
  File "/usr/lib64/python2.7/logging/__init__.py", line 1137, in debug
    self._log(DEBUG, msg, args, **kwargs)
  File "/usr/lib64/python2.7/logging/__init__.py", line 1268, in _log
    self.handle(record)
  File "/usr/lib64/python2.7/logging/__init__.py", line 1278, in handle
    self.callHandlers(record)
  File "/usr/lib64/python2.7/logging/__init__.py", line 1318, in callHandlers
    hdlr.handle(record)
  File "/usr/lib64/python2.7/logging/__init__.py", line 749, in handle
    self.emit(record)
  File "/ceph/src/pybind/mgr/mgr_module.py", line 65, in emit
    self._module._ceph_log(ceph_level, self.format(record))
  File "/usr/lib64/python2.7/logging/__init__.py", line 724, in format
    return fmt.format(record)
  File "/usr/lib64/python2.7/logging/__init__.py", line 464, in format
    record.message = record.getMessage()
  File "/usr/lib64/python2.7/logging/__init__.py", line 328, in getMessage
    msg = msg % self.args
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 21: ordinal not in range(128)

It seems that this line is the origin:
https://github.com/ceph/ceph/blob/master/src/pybind/mgr/dashboard/tools.py#L52

logger.debug('[%s:%s] [%s] [%s] %s', req.remote.ip, req.remote.port,
                     req.method, user, req.path_info)

Actions #1

Updated by Ricardo Dias over 4 years ago

The issue can be reproduced with the following example:

from __future__ import unicode_literals
import logging

logging.basicConfig()
log = logging.getLogger()
log.setLevel(logging.DEBUG)

log.debug("%s", b"ñ")

And it can be fixed by changing the last line to:

log.debug("%s", b"ñ".decode('utf-8'))

This means that maybe we should add some `.decode('utf-8')` to the strings passed to that logger call.

AFAICT this issue only happens in python2, if octopus will only support python3 then we just need to fix the nautilus version.

Actions #2

Updated by Lenz Grimmer over 4 years ago

  • Assignee set to Kiefer Chang
Actions #3

Updated by Ernesto Puerta over 4 years ago

  • Assignee deleted (Kiefer Chang)
An extra couple of ideas:
Actions #4

Updated by Ernesto Puerta over 4 years ago

  • Assignee set to Kiefer Chang
Actions #5

Updated by Kiefer Chang over 4 years ago

AFAICT this issue only happens in python2, if octopus will only support python3 then we just need to fix the nautilus version.

Confirmed that this doesn't happen in python3.

Actions #6

Updated by Kiefer Chang over 4 years ago

(In python2)

With

diff --git a/src/pybind/mgr/dashboard/tools.py b/src/pybind/mgr/dashboard/tools.py
index 7eb23e535b..af03000b2a 100644
--- a/src/pybind/mgr/dashboard/tools.py
+++ b/src/pybind/mgr/dashboard/tools.py
@@ -44,7 +44,7 @@ class RequestLoggingTool(cherrypy.Tool):
         user = JwtManager.get_username()
         # Log the request.
         logger.debug('[%s:%s] [%s] [%s] %s', req.remote.ip, req.remote.port,
-                     req.method, user, req.path_info)
+                     req.method, user, req.path_info.decode('utf-8'))
         # Audit the request.
         if Settings.AUDIT_API_ENABLED and req.method not in ['GET']:
             url = build_url(req.remote.ip, scheme=req.scheme,

I'm getting encoding error:

2019-11-12 09:25:32.402 7faeec78a700  0 mgr[dashboard] [12/Nov/2019:09:25:32]
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/cherrypy/_cprequest.py", line 104, in run
    hook()
  File "/usr/lib/python2.7/site-packages/cherrypy/_cprequest.py", line 63, in __call__
    return self.callback(**self.kwargs)
  File "/ceph/src/pybind/mgr/dashboard/tools.py", line 47, in request_begin
    req.method, user, req.path_info.decode('utf-8'))
  File "/usr/lib64/python2.7/logging/__init__.py", line 1155, in debug
    self._log(DEBUG, msg, args, **kwargs)
  File "/usr/lib64/python2.7/logging/__init__.py", line 1286, in _log
    self.handle(record)
  File "/usr/lib64/python2.7/logging/__init__.py", line 1296, in handle
    self.callHandlers(record)
  File "/usr/lib64/python2.7/logging/__init__.py", line 1336, in callHandlers
    hdlr.handle(record)
  File "/usr/lib64/python2.7/logging/__init__.py", line 759, in handle
    self.emit(record)
  File "/ceph/src/pybind/mgr/mgr_module.py", line 65, in emit
    self._module._ceph_log(ceph_level, self.format(record))
UnicodeEncodeError: 'ascii' codec can't encode character u'\xf1' in position 59: ordinal not in range(128)

Start mgr daemon with PYTHONIOENCODING=utf-8 doesn't help either.

But with

diff --git a/src/pybind/mgr/dashboard/tools.py b/src/pybind/mgr/dashboard/tools.py
index 7eb23e535b..a5166e8a98 100644
--- a/src/pybind/mgr/dashboard/tools.py
+++ b/src/pybind/mgr/dashboard/tools.py
@@ -43,6 +43,8 @@ class RequestLoggingTool(cherrypy.Tool):
         req = cherrypy.request
         user = JwtManager.get_username()
         # Log the request.
+        if user is not None:
+            user = user.encode('utf-8')
         logger.debug('[%s:%s] [%s] [%s] %s', req.remote.ip, req.remote.port,
                      req.method, user, req.path_info)
         # Audit the request.

The exception is gone and the message is logged (but año becomes a\xc3\xb1o). The only variable in `unicode` type in this line is user, others are in `str`

Actions #7

Updated by Kiefer Chang over 4 years ago

  • Status changed from New to In Progress
Actions #8

Updated by Kiefer Chang over 4 years ago

  • Pull request ID set to 31586
Actions #9

Updated by Nathan Cutler over 4 years ago

Kiefer Chang wrote:

AFAICT this issue only happens in python2, if octopus will only support python3 then we just need to fix the nautilus version.

Confirmed that this doesn't happen in python3.

Please add this info to the actual commit message, so it's available in the git history.

Actions #10

Updated by Lenz Grimmer almost 4 years ago

  • Status changed from In Progress to Resolved
  • Target version changed from v15.0.0 to v14.2.10
Actions #11

Updated by Ernesto Puerta about 3 years ago

  • Project changed from mgr to Dashboard
  • Category changed from 139 to Component - RBD
Actions

Also available in: Atom PDF