]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/ssh: pipe ceph-daemon script to stdin of python3
authorSage Weil <sage@redhat.com>
Thu, 3 Oct 2019 21:13:47 +0000 (16:13 -0500)
committerSage Weil <sage@redhat.com>
Sat, 5 Oct 2019 01:33:35 +0000 (20:33 -0500)
This avoids any need for the script to be present on the remote host.

We introduce a config option to indicate where the script should be
read from, since the location varies between a vstart environment (source
dir) and a real install (/usr/sbin).

Signed-off-by: Sage Weil <sage@redhat.com>
src/common/options.cc
src/pybind/mgr/ssh/module.py
src/vstart.sh

index e24c1156ff37b4aea500af78a2ba37bd587053a4..53d87cba83c39f0fbf6af122a439c6cef8f833f2 100644 (file)
@@ -5428,6 +5428,11 @@ std::vector<Option> get_global_options() {
     .set_default(false)
     .set_description(""),
 
+    Option("ceph_daemon_path", Option::TYPE_STR, Option::LEVEL_ADVANCED)
+    .set_default("/usr/sbin/ceph-daemon")
+    .add_service("mgr")
+    .set_description("Path to ceph-daemon utility"),
+
     Option("mgr_module_path", Option::TYPE_STR, Option::LEVEL_ADVANCED)
     .set_default(CEPH_DATADIR "/mgr")
     .add_service("mgr")
index 7144d5062f21d768c056d0ab9239658dbe518e0d..86519810cc6459e85ec5d5fe023d0d23a4bed509 100644 (file)
@@ -130,6 +130,14 @@ class SSHOrchestrator(MgrModule, orchestrator.Orchestrator):
     def __init__(self, *args, **kwargs):
         super(SSHOrchestrator, self).__init__(*args, **kwargs)
         self._cluster_fsid = None
+
+        path = self.get_ceph_option('ceph_daemon_path')
+        try:
+            with open(path, 'r') as f:
+                self._ceph_daemon = f.read()
+        except:
+            raise RuntimeError("unable to read ceph-daemon at '%s'" % path)
+
         self._worker_pool = multiprocessing.pool.ThreadPool(1)
 
         self._reconfig_ssh()
@@ -345,7 +353,7 @@ class SSHOrchestrator(MgrModule, orchestrator.Orchestrator):
         nodes = [orchestrator.InventoryNode(host_name, []) for host_name in self.inventory_cache]
         return orchestrator.TrivialReadCompletion(nodes)
 
-    def _run_ceph_daemon(self, host, entity, command, args):
+    def _run_ceph_daemon(self, host, entity, command, args, stdin=None):
         """
         Run ceph-daemon on the remote host with the given command + args
         """
@@ -361,14 +369,24 @@ class SSHOrchestrator(MgrModule, orchestrator.Orchestrator):
             image = image.strip()
             self.log.debug('%s container image %s' % (entity, image))
 
-            command = [
-                '/home/sage/src/ceph5/src/ceph-daemon',
+            final_args = [
                 '--image', image,
                 command,
                 '--fsid', self.get('mon_map')['fsid'],
             ] + args
 
-            out, err, code = remoto.process.check(conn, command)
+            script = 'injected_argv = ' + json.dumps(final_args) + '\n'
+            if stdin:
+                script += 'injected_stdin = ' + json.dumps(stdin) + '\n'
+            script += self._ceph_daemon
+            #self.log.debug('script is %s' % script)
+
+            out, err, code = remoto.process.check(
+                conn,
+                ['/usr/bin/python3', '-u'],
+                stdin=script.encode('utf-8'))
+            if code:
+                self.log.debug('code %s, err %s' % (code, err))
             # ceph-daemon combines stdout and stderr, so ignore err.
             self.log.debug('code %s out %s' % (code, out))
             return out, code
@@ -450,25 +468,19 @@ class SSHOrchestrator(MgrModule, orchestrator.Orchestrator):
         })
         self.log.debug('j %s' % j)
 
-        # TODO FIXME
-        conn = self._get_connection(host)
-        conn.remote_module.write_file(
-            '/tmp/foo',
-            j,
-            0o600, None, 0, 0)
-
         devices = drive_group.data_devices.paths
         for device in devices:
             out, code = self._run_ceph_daemon(
                 host, 'osd', 'ceph-volume',
                 [
-                    '--config-and-keyring', '/tmp/foo',
+                    '--config-and-keyring', '-',
                     '--',
                     'lvm', 'prepare',
                     "--cluster-fsid", self._get_cluster_fsid(),
                     "--{}".format(drive_group.objectstore),
                     "--data", device,
-                ])
+                ],
+                stdin=j)
             self.log.debug('ceph-volume prepare: %s' % out)
 
         # check result
@@ -550,17 +562,13 @@ class SSHOrchestrator(MgrModule, orchestrator.Orchestrator):
             })
             self.log.debug('j %s' % j)
 
-            conn.remote_module.write_file(
-                '/tmp/foo',
-                j,
-                0o600, None, 0, 0)
-
             out, code = self._run_ceph_daemon(
                 host, name, 'deploy',
                 [
                     '--name', name,
-                    '--config-and-keyring', '/tmp/foo',
-                ] + extra_args)
+                    '--config-and-keyring', '-',
+                ] + extra_args,
+                stdin=j)
             self.log.debug('create_daemon code %s out %s' % (code, out))
 
             return "Created {} on host '{}'".format(name, host)
index af046cf6d7057a12f2af8e73bde09a51b5e64ff6..4b1014460d86dc64263d41026e72ca7dddd3bd12 100755 (executable)
@@ -692,6 +692,7 @@ $extra_conf
 [mgr]
         mgr data = $CEPH_DEV_DIR/mgr.\$id
         mgr module path = $MGR_PYTHON_PATH
+        ceph daemon path = $CEPH_ROOT/src/ceph-daemon
 $DAEMONOPTS
 $extra_conf
 [osd]