From 2b455c306373aa467b8da38e2748389e4505306e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alfonso=20Mart=C3=ADnez?= Date: Fri, 9 Apr 2021 10:51:21 +0200 Subject: [PATCH] mgr/dashboard: fix errors when creating NFS export. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit - 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) --- src/pybind/mgr/dashboard/services/ganesha.py | 6 +- .../mgr/dashboard/tests/test_ganesha.py | 71 +++++++++++++++++++ 2 files changed, 74 insertions(+), 3 deletions(-) diff --git a/src/pybind/mgr/dashboard/services/ganesha.py b/src/pybind/mgr/dashboard/services/ganesha.py index ba2ad7144d63f..b4af48f415d18 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 258bd9da6dd35..90f45471e8d41 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) -- 2.39.5