]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/nfs/export: use tool_exec() instead of private _exec() 43743/head
authorSage Weil <sage@newdream.net>
Fri, 29 Oct 2021 15:27:50 +0000 (11:27 -0400)
committerMichael Fritch <mfritch@suse.com>
Fri, 29 Oct 2021 20:03:22 +0000 (14:03 -0600)
Fixes: https://tracker.ceph.com/issues/53096
Signed-off-by: Sage Weil <sage@newdream.net>
Signed-off-by: Michael Fritch <mfritch@suse.com>
src/pybind/mgr/nfs/export.py
src/pybind/mgr/nfs/tests/test_nfs.py

index 7c2666bf19550a10f448b29a0b27a928652292e8..b23a95e04632d35cea368cfc3f2bbdc74011984e 100644 (file)
@@ -1,7 +1,6 @@
 import errno
 import json
 import logging
-import subprocess
 from typing import List, Any, Dict, Tuple, Optional, TYPE_CHECKING, TypeVar, Callable, cast
 from os.path import normpath
 
@@ -134,26 +133,6 @@ class ExportMgr:
         except TimedOut:
             log.exception("Ganesha timed out")
 
-    def _exec(self, args: List[str]) -> Tuple[int, str, str]:
-        try:
-            util = args.pop(0)
-            cmd = [
-                util,
-                '-k', str(self.mgr.get_ceph_option('keyring')),
-                '-n', f'mgr.{self.mgr.get_mgr_id()}',
-            ] + args
-            log.debug('exec: ' + ' '.join(cmd))
-            p = subprocess.run(
-                cmd,
-                stdout=subprocess.PIPE, stderr=subprocess.PIPE,
-                timeout=10,
-            )
-        except subprocess.CalledProcessError as ex:
-            log.error('Error executing <<%s>>: %s', ex.cmd, ex.output)
-        except subprocess.TimeoutExpired:
-            log.error('timeout (10s) executing <<%s>>', cmd)
-        return p.returncode, p.stdout.decode(), p.stderr.decode()
-
     @property
     def exports(self) -> Dict[str, List[Export]]:
         if self._exports is None:
@@ -226,14 +205,15 @@ class ExportMgr:
 
         elif isinstance(export.fsal, RGWFSAL):
             rgwfsal = cast(RGWFSAL, export.fsal)
-            ret, out, err = self._exec(['radosgw-admin', 'bucket', 'stats', '--bucket',
-                                        export.path])
+            ret, out, err = self.mgr.tool_exec(
+                ['radosgw-admin', 'bucket', 'stats', '--bucket', export.path]
+            )
             if ret:
                 raise NFSException(f'Failed to fetch owner for bucket {export.path}')
             j = json.loads(out)
             owner = j.get('owner', '')
             rgwfsal.user_id = owner
-            ret, out, err = self._exec([
+            ret, out, err = self.mgr.tool_exec([
                 'radosgw-admin', 'user', 'info', '--uid', owner
             ])
             if ret:
@@ -585,7 +565,8 @@ class ExportMgr:
         ex_dict["cluster_id"] = cluster_id
         export = Export.from_dict(ex_id, ex_dict)
         export.validate(self.mgr)
-        log.debug("Successfully created %s export-%s from dict for cluster %s", fsal_type, ex_id, cluster_id)
+        log.debug("Successfully created %s export-%s from dict for cluster %s",
+                  fsal_type, ex_id, cluster_id)
         return export
 
     def create_cephfs_export(self,
index d6f73ae456e65f7b08194abe933e14617f693c56..6fc4246e95880d4904a245aeb7a4ee1561701abe 100644 (file)
@@ -6,7 +6,7 @@ from typing import Optional, Tuple, Iterator, List, Any
 from contextlib import contextmanager
 from unittest import mock
 from unittest.mock import MagicMock
-from mgr_module import NFS_POOL_NAME
+from mgr_module import MgrModule, NFS_POOL_NAME
 
 from rados import ObjectNotFound
 
@@ -222,7 +222,7 @@ EXPORT {
                            return_value=[self.cluster_id]), \
                 mock.patch('nfs.export.restart_nfs_service'), \
                 mock.patch('nfs.cluster.restart_nfs_service'), \
-                mock.patch('nfs.export.ExportMgr._exec', mock_exec), \
+                mock.patch.object(MgrModule, 'tool_exec', mock_exec), \
                 mock.patch('nfs.export.check_fs', return_value=True), \
                 mock.patch('nfs.export_utils.check_fs', return_value=True), \
                 mock.patch('nfs.export.ExportMgr._create_user_key',