]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: CephFS class issues with strings 29353/head
authorVolker Theile <vtheile@suse.com>
Fri, 26 Jul 2019 13:02:57 +0000 (15:02 +0200)
committerVolker Theile <vtheile@suse.com>
Fri, 30 Aug 2019 08:52:00 +0000 (10:52 +0200)
Fixes: https://tracker.ceph.com/issues/40981
Signed-off-by: Volker Theile <vtheile@suse.com>
src/pybind/cephfs/cephfs.pyx
src/pybind/mgr/dashboard/controllers/nfsganesha.py
src/pybind/mgr/dashboard/services/cephfs.py

index 146c4bfe7d585dfb03d9c6dcecda00a5dddcb42a..cbe31e1d913cc095d9bffa99b314df12121f89bf 100644 (file)
@@ -607,6 +607,8 @@ cdef class LibCephFS(object):
         # Configure which filesystem to mount if one was specified
         if filesystem_name is None:
             filesystem_name = b""
+        else:
+            filesystem_name = cstr(filesystem_name, 'filesystem_name')
         cdef:
             char *_filesystem_name = filesystem_name
         if filesystem_name:
index 83d04a8bb28bdee4daca8e75529ef438c87a89eb..e10006c8784cd74a09bf3f25911d8080cfa34a36 100644 (file)
@@ -285,16 +285,16 @@ class NFSGaneshaUi(BaseController):
             logger.warning("[NFS] Limiting depth to maximum value of 5: "
                            "input depth=%s", depth)
             depth = 5
-        root_dir = '{}/'.format(root_dir) \
-                   if not root_dir.endswith('/') else root_dir
-
+        root_dir = '{}{}'.format(root_dir.rstrip('/'), '/')
         try:
             cfs = CephFS()
+            root_dir = root_dir.encode()
             paths = cfs.get_dir_list(root_dir, depth)
-            paths = [p[:-1] for p in paths if p != root_dir]
-            return {'paths': paths}
+            # Convert (bytes => string) and prettify paths (strip slashes).
+            paths = [p.decode().rstrip('/') for p in paths if p != root_dir]
         except (cephfs.ObjectNotFound, cephfs.PermissionError):
-            return {'paths': []}
+            paths = []
+        return {'paths': paths}
 
     @Endpoint('GET', '/cephfs/filesystems')
     def filesystems(self):
index bb75b4e2573a26e61a22a60386cce3c6a1c94e57..70935f76eb6b2575b85301fd92995e95a51dba43 100644 (file)
@@ -3,6 +3,7 @@ from __future__ import absolute_import
 
 from contextlib import contextmanager
 
+import six
 import cephfs
 
 from .. import mgr, logger
@@ -40,6 +41,16 @@ class CephFS(object):
                 self.cfs.closedir(d)
 
     def get_dir_list(self, dirpath, level):
+        """
+        :param dirpath: The root directory path.
+        :type dirpath: str | bytes
+        :param level: The number of steps to go down the directory tree.
+        :type level: int
+        :return: A list of directory paths (bytes encoded).
+        :rtype: list
+        """
+        if isinstance(dirpath, six.string_types):
+            dirpath = dirpath.encode()
         logger.debug("[CephFS] get_dir_list dirpath=%s level=%s", dirpath,
                      level)
         if level == 0:
@@ -50,12 +61,12 @@ class CephFS(object):
             paths = [dirpath]
             while dent:
                 logger.debug("[CephFS] found entry=%s", dent.d_name)
-                if dent.d_name in ['.', '..']:
+                if dent.d_name in [b'.', b'..']:
                     dent = self.cfs.readdir(d)
                     continue
                 if dent.is_dir():
                     logger.debug("[CephFS] found dir=%s", dent.d_name)
-                    subdirpath = '{}{}/'.format(dirpath, dent.d_name)
+                    subdirpath = b''.join([dirpath, dent.d_name, b'/'])
                     paths.extend(self.get_dir_list(subdirpath, level-1))
                 dent = self.cfs.readdir(d)
         return paths