]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/cephadm: remove remotes.py, replace old _write_remote_file in serve.py with write...
authorMelissa <li.melissa.kun@gmail.com>
Wed, 21 Jul 2021 02:43:38 +0000 (22:43 -0400)
committerMelissa Li <li.melissa.kun@gmail.com>
Fri, 20 Aug 2021 18:27:45 +0000 (14:27 -0400)
remove remotes.py because it is specific to execnet/remoto.
_write_remote_file in ssh.py now fulfills the function of write_file in remotes.py and the old _write_remote_file in serve.py

Fixes: https://tracker.ceph.com/issues/44676
Signed-off-by: Melissa Li <li.melissa.kun@gmail.com>
src/pybind/mgr/cephadm/module.py
src/pybind/mgr/cephadm/remotes.py [deleted file]
src/pybind/mgr/cephadm/serve.py

index 43b1ee050e98f60b9b79863628d003111799f2ec..87a76debfabde76f70649916f0e28889a25e3a2b 100644 (file)
@@ -41,7 +41,6 @@ from orchestrator import OrchestratorError, OrchestratorValidationError, HostSpe
 from orchestrator._interface import GenericSpec
 from orchestrator._interface import daemon_type_to_service
 
-from . import remotes
 from . import utils
 from . import ssh
 from .migrations import Migrations
diff --git a/src/pybind/mgr/cephadm/remotes.py b/src/pybind/mgr/cephadm/remotes.py
deleted file mode 100644 (file)
index e1ecf2d..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-# ceph-deploy ftw
-import os
-try:
-    from typing import Optional
-except ImportError:
-    pass
-
-PYTHONS = ['python3', 'python2', 'python']
-PATH = [
-    '/usr/bin',
-    '/usr/local/bin',
-    '/bin',
-    '/usr/sbin',
-    '/usr/local/sbin',
-    '/sbin',
-]
-
-
-def choose_python():
-    # type: () -> Optional[str]
-    for e in PYTHONS:
-        for b in PATH:
-            p = os.path.join(b, e)
-            if os.path.exists(p):
-                return p
-    return None
-
-
-def write_file(path: str, content: bytes, mode: int, uid: int, gid: int,
-               mkdir_p: bool = True) -> Optional[str]:
-    try:
-        if mkdir_p:
-            dirname = os.path.dirname(path)
-            if not os.path.exists(dirname):
-                os.makedirs(dirname)
-        tmp_path = path + '.new'
-        with open(tmp_path, 'wb') as f:
-            os.fchown(f.fileno(), uid, gid)
-            os.fchmod(f.fileno(), mode)
-            f.write(content)
-            os.fsync(f.fileno())
-        os.rename(tmp_path, path)
-    except Exception as e:
-        return str(e)
-    return None
-
-
-if __name__ == '__channelexec__':
-    for item in channel:  # type: ignore # noqa: F821
-        channel.send(eval(item))  # type: ignore # noqa: F821
index 071dd4cbef3c29f3a085fc6408841aa3f32018b6..f09e8a033a6837d755aea1118c0ed8379dc3002a 100644 (file)
@@ -5,9 +5,6 @@ import uuid
 from collections import defaultdict
 from contextlib import contextmanager
 from typing import TYPE_CHECKING, Optional, List, cast, Dict, Any, Union, Tuple, Iterator
-
-from cephadm import remotes
-
 try:
     import remoto
     import execnet.gateway_bootstrap
@@ -34,7 +31,6 @@ from . import utils
 
 if TYPE_CHECKING:
     from cephadm.module import CephadmOrchestrator
-    from remoto.backends import BaseConnection
 
 logger = logging.getLogger(__name__)
 
@@ -310,16 +306,13 @@ class CephadmServe:
                     if match:
                         continue
                 self.log.info(f'Updating {host}:{path}')
-                self._write_remote_file(host, path, content, mode, uid, gid)
+                self.mgr.ssh.write_remote_file(host, path, content, mode, uid, gid)
                 self.mgr.cache.update_client_file(host, path, digest, mode, uid, gid)
                 updated_files = True
             for path in old_files.keys():
                 self.log.info(f'Removing {host}:{path}')
-                with self._remote_connection(host) as tpl:
-                    conn, connr = tpl
-                    out, err, code = remoto.process.check(
-                        conn,
-                        ['rm', '-f', path])
+                cmd = ['rm', '-f', path]
+                self.mgr.ssh.check_execute_command(host, cmd)
                 updated_files = True
                 self.mgr.cache.removed_client_file(host, path)
             if updated_files:
@@ -1321,25 +1314,6 @@ class CephadmServe:
             msg = f"Unable to deploy the cephadm binary to {host}: {_err}"
             self.log.warning(msg)
             raise OrchestratorError(msg)
-
-    def _write_remote_file(self,
-                           host: str,
-                           path: str,
-                           content: bytes,
-                           mode: int,
-                           uid: int,
-                           gid: int) -> None:
-        with self._remote_connection(host) as tpl:
-            conn, connr = tpl
-            try:
-                errmsg = connr.write_file(path, content, mode, uid, gid)
-                if errmsg is not None:
-                    raise OrchestratorError(errmsg)
-            except Exception as e:
-                msg = f"Unable to write {host}:{path}: {e}"
-                self.log.warning(msg)
-                raise OrchestratorError(msg)
-
     @contextmanager
     def _remote_connection(self,
                            host: str,