From 0e1c650075af0b684726d556ba1069414dd72ce0 Mon Sep 17 00:00:00 2001 From: Kiefer Chang Date: Tue, 15 Sep 2020 16:27:44 +0800 Subject: [PATCH] mgr/dashboard: fix the error when exporting CephFS path "/" in NFS exports Fixes: https://tracker.ceph.com/issues/47397 Signed-off-by: Kiefer Chang (cherry picked from commit 5d0d7f89285c43d70d0918a0ae71e77f602809cd) --- qa/tasks/mgr/dashboard/test_ganesha.py | 18 ++++++++++++------ src/pybind/mgr/dashboard/services/ganesha.py | 3 +++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/qa/tasks/mgr/dashboard/test_ganesha.py b/qa/tasks/mgr/dashboard/test_ganesha.py index c99e3651ff144..d02e4f6edac31 100644 --- a/qa/tasks/mgr/dashboard/test_ganesha.py +++ b/qa/tasks/mgr/dashboard/test_ganesha.py @@ -68,7 +68,7 @@ class GaneshaTest(DashboardTestCase): @classmethod def create_export(cls, path, cluster_id, daemons, fsal, sec_label_xattr=None): if fsal == 'CEPH': - fsal = {"name": "CEPH", "user_id":"admin", "fs_name": None, "sec_label_xattr": sec_label_xattr} + fsal = {"name": "CEPH", "user_id": "admin", "fs_name": None, "sec_label_xattr": sec_label_xattr} pseudo = "/cephfs{}".format(path) else: fsal = {"name": "RGW", "rgw_user_id": "admin"} @@ -86,7 +86,7 @@ class GaneshaTest(DashboardTestCase): "protocols": [4], "transports": ["TCP"], "clients": [{ - "addresses":["10.0.0.0/8"], + "addresses": ["10.0.0.0/8"], "access_type": "RO", "squash": "root" }] @@ -103,19 +103,25 @@ class GaneshaTest(DashboardTestCase): self._task_delete("/api/nfs-ganesha/export/{}/{}" .format(exp['cluster_id'], exp['export_id'])) - def test_create_export(self): + def _test_create_export(self, cephfs_path): exports = self._get("/api/nfs-ganesha/export") self.assertEqual(len(exports), 0) - data = self.create_export("/foo", 'cluster1', ['node1', 'node2'], 'CEPH', "security.selinux") + data = self.create_export(cephfs_path, 'cluster1', ['node1', 'node2'], 'CEPH', "security.selinux") exports = self._get("/api/nfs-ganesha/export") self.assertEqual(len(exports), 1) self.assertDictEqual(exports[0], data) return data + def test_create_export(self): + self._test_create_export('/foo') + + def test_create_export_for_cephfs_root(self): + self._test_create_export('/') + def test_update_export(self): - export = self.test_create_export() + export = self._test_create_export('/foo') export['access_type'] = 'RO' export['daemons'] = ['node1', 'node3'] export['security_label'] = True @@ -129,7 +135,7 @@ class GaneshaTest(DashboardTestCase): self.assertEqual(exports[0]['security_label'], True) def test_delete_export(self): - export = self.test_create_export() + export = self._test_create_export('/foo') self._task_delete("/api/nfs-ganesha/export/{}/{}" .format(export['cluster_id'], export['export_id'])) self.assertStatus(204) diff --git a/src/pybind/mgr/dashboard/services/ganesha.py b/src/pybind/mgr/dashboard/services/ganesha.py index e9144db406edd..773b4a3a8e0de 100644 --- a/src/pybind/mgr/dashboard/services/ganesha.py +++ b/src/pybind/mgr/dashboard/services/ganesha.py @@ -3,6 +3,7 @@ from __future__ import absolute_import import logging +import os import re from orchestrator import OrchestratorError @@ -491,6 +492,8 @@ class CephFSFSal(FSal): def create_path(self, path): cfs = CephFS(self.fs_name) + if path == os.sep: + return cfs.mk_dirs(path) @classmethod -- 2.47.3