From: Alfonso Martínez Date: Fri, 9 Apr 2021 08:51:21 +0000 (+0200) Subject: mgr/dashboard: fix errors when creating NFS export. X-Git-Tag: v16.2.2~30^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F40822%2Fhead;p=ceph.git mgr/dashboard: fix errors when creating NFS export. - Fix daemon raw config parsing. - Handle error when no rgw daemons found. Fixes: https://tracker.ceph.com/issues/49925 Signed-off-by: Alfonso Martínez (cherry picked from commit 8bad7360ef23fa154622d0bee7823092b9440ca6) --- diff --git a/src/pybind/mgr/dashboard/services/ganesha.py b/src/pybind/mgr/dashboard/services/ganesha.py index ba2ad7144d63..b4af48f415d1 100644 --- a/src/pybind/mgr/dashboard/services/ganesha.py +++ b/src/pybind/mgr/dashboard/services/ganesha.py @@ -154,7 +154,7 @@ class Ganesha(object): if RgwClient.admin_instance().is_service_online() and \ RgwClient.admin_instance().is_system_user(): result.append("RGW") - except (NoCredentialsException, RequestException, LookupError): + except (DashboardException, NoCredentialsException, RequestException, LookupError): pass return result @@ -212,9 +212,9 @@ class GaneshaConfParser(object): return block_name def parse_block_or_section(self): - if self.stream().startswith("%url "): + if self.stream().startswith("%url"): # section line - self.pos += 5 + self.pos += self.stream().find('rados://') idx = self.stream().find('\n') if idx == -1: value = self.stream() diff --git a/src/pybind/mgr/dashboard/tests/test_ganesha.py b/src/pybind/mgr/dashboard/tests/test_ganesha.py index 258bd9da6dd3..90f45471e8d4 100644 --- a/src/pybind/mgr/dashboard/tests/test_ganesha.py +++ b/src/pybind/mgr/dashboard/tests/test_ganesha.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +# pylint: disable=too-many-lines from __future__ import absolute_import import unittest @@ -18,6 +19,38 @@ from . import KVStoreMockMixin # pylint: disable=no-name-in-module class GaneshaConfTest(unittest.TestCase, KVStoreMockMixin): + daemon_raw_config = """ +NFS_CORE_PARAM { + Enable_NLM = false; + Enable_RQUOTA = false; + Protocols = 4; + NFS_Port = 14000; + } + + MDCACHE { + Dir_Chunk = 0; + } + + NFSv4 { + RecoveryBackend = rados_cluster; + Minor_Versions = 1, 2; + } + + RADOS_KV { + pool = nfs-ganesha; + namespace = vstart; + UserId = vstart; + nodeid = a; + } + + RADOS_URLS { + Userid = vstart; + watch_url = 'rados://nfs-ganesha/vstart/conf-nfs.vstart'; + } + + %url rados://nfs-ganesha/vstart/conf-nfs.vstart +""" + export_1 = """ EXPORT { Export_ID=1; @@ -231,6 +264,44 @@ EXPORT ganesha.GaneshaConfOrchestrator._get_orch_nfs_instances = Mock( side_effect=_get_nfs_instances) + def test_parse_daemon_raw_config(self): + expected_daemon_config = [ + { + "block_name": "NFS_CORE_PARAM", + "enable_nlm": False, + "enable_rquota": False, + "protocols": 4, + "nfs_port": 14000 + }, + { + "block_name": "MDCACHE", + "dir_chunk": 0 + }, + { + "block_name": "NFSV4", + "recoverybackend": "rados_cluster", + "minor_versions": [1, 2] + }, + { + "block_name": "RADOS_KV", + "pool": "nfs-ganesha", + "namespace": "vstart", + "userid": "vstart", + "nodeid": "a" + }, + { + "block_name": "RADOS_URLS", + "userid": "vstart", + "watch_url": "'rados://nfs-ganesha/vstart/conf-nfs.vstart'" + }, + { + "block_name": "%url", + "value": "rados://nfs-ganesha/vstart/conf-nfs.vstart" + } + ] + daemon_config = GaneshaConfParser(self.daemon_raw_config).parse() + self.assertEqual(daemon_config, expected_daemon_config) + def test_export_parser_1(self): blocks = GaneshaConfParser(self.export_1).parse() self.assertIsInstance(blocks, list)