]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/cephadm: try various pythons for root mode _run_cephadm
authorSage Weil <sage@redhat.com>
Wed, 18 Dec 2019 16:02:23 +0000 (10:02 -0600)
committerSage Weil <sage@redhat.com>
Fri, 20 Dec 2019 22:20:22 +0000 (16:20 -0600)
Some distros don't have the /usr/bin/python link.

Signed-off-by: Sage Weil <sage@redhat.com>
src/pybind/mgr/cephadm/module.py
src/pybind/mgr/cephadm/remotes.py

index 0649736cbe12cef25b1c66f9e0fbda0484539043..a1e9cea1bc05b3314b2634b05db481820488fbd6 100644 (file)
@@ -582,9 +582,9 @@ class CephadmOrchestrator(MgrModule, orchestrator.Orchestrator):
             logger=self.log.getChild(n),
             ssh_options=self._ssh_options)
 
-        conn.import_module(remotes)
+        r = conn.import_module(remotes)
 
-        return conn
+        return conn, r
 
     def _executable_path(self, conn, executable):
         """
@@ -610,7 +610,7 @@ class CephadmOrchestrator(MgrModule, orchestrator.Orchestrator):
         """
         Run cephadm on the remote host with the given command + args
         """
-        conn = self._get_connection(host)
+        conn, connr = self._get_connection(host)
 
         try:
             if not image:
@@ -632,22 +632,36 @@ class CephadmOrchestrator(MgrModule, orchestrator.Orchestrator):
             final_args += args
 
             if self.mode == 'root':
-                self.log.debug('args: %s' % final_args)
+                self.log.debug('args: %s' % (' '.join(final_args)))
                 self.log.debug('stdin: %s' % stdin)
                 script = 'injected_argv = ' + json.dumps(final_args) + '\n'
                 if stdin:
                     script += 'injected_stdin = ' + json.dumps(stdin) + '\n'
                 script += self._cephadm
-                out, err, code = remoto.process.check(
-                    conn,
-                    ['/usr/bin/python', '-u'],
-                    stdin=script.encode('utf-8'))
+                python = connr.choose_python()
+                if not python:
+                    raise RuntimeError(
+                        'unable to find python on %s (tried %s in %s)' % (
+                            host, remotes.PYTHONS, remotes.PATH))
+                try:
+                    out, err, code = remoto.process.check(
+                        conn,
+                        [python, '-u'],
+                        stdin=script.encode('utf-8'))
+                except RuntimeError as e:
+                    if error_ok:
+                        return '', str(e), 1
+                    raise
             elif self.mode == 'cephadm-package':
-                out, err, code = remoto.process.check(
-                    conn,
-                    ['sudo', '/usr/bin/cephadm'] + final_args,
-                    stdin=stdin)
-            self.log.debug('exit code %s out %s err %s' % (code, out, err))
+                try:
+                    out, err, code = remoto.process.check(
+                        conn,
+                        ['sudo', '/usr/bin/cephadm'] + final_args,
+                        stdin=stdin)
+                except RuntimeError as e:
+                    if error_ok:
+                        return '', str(e), 1
+                    raise
             if code and not error_ok:
                 raise RuntimeError(
                     'cephadm exited with an error code: %d, stderr:%s' % (
index 94f978dd2c0f28b5de0d45732138555f9336974b..aad5481c62948000f58b6edd16f31aba88d74eb7 100644 (file)
@@ -4,6 +4,24 @@ import errno
 import tempfile
 import shutil
 
+PYTHONS = ['python3', 'python2', 'python']
+PATH = [
+    '/usr/bin',
+    '/usr/local/bin',
+    '/bin',
+    '/usr/sbin',
+    '/usr/local/sbin',
+    '/sbin',
+]
+
+def choose_python():
+    for e in PYTHONS:
+        for b in PATH:
+            p = os.path.join(b, e)
+            if os.path.exists(p):
+                return p
+    return None
+
 def safe_makedirs(path, uid=-1, gid=-1):
     """ create path recursively if it doesn't exist """
     try: