]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-crash: try to post as either client.crash[.$hostname] or client.admin 30844/head
authorSage Weil <sage@redhat.com>
Sat, 5 Oct 2019 18:30:21 +0000 (13:30 -0500)
committerSage Weil <sage@redhat.com>
Thu, 10 Oct 2019 12:51:35 +0000 (07:51 -0500)
Often/usually a client.admin isn't installed on hosts with ceph daemons
where we need to scrape crashes.  Try both client.crash (which can be
relatively unprivileged, but isn't historically present) and client.admin.

Signed-off-by: Sage Weil <sage@redhat.com>
(cherry picked from commit 885031296f36bda59baca168149432ba009cab7b)

src/ceph-crash.in

index f0d24dec644646b2f2bfe678e6ff97d7188c8eab..e5f08acb71a571a4ab68696bf13c9c033a2befef 100755 (executable)
@@ -5,6 +5,7 @@
 import argparse
 import logging
 import os
+import socket
 import subprocess
 import sys
 import time
@@ -12,6 +13,9 @@ import time
 logging.basicConfig(level=logging.INFO)
 log = logging.getLogger(__name__)
 
+auth_names = ['client.crash.%s' % socket.gethostname(),
+              'client.crash',
+              'client.admin']
 
 def parse_args():
     parser = argparse.ArgumentParser()
@@ -22,22 +26,31 @@ def parse_args():
         '-d', '--delay', default=10.0, type=float,
         help='minutes to delay between scans (0 to exit after one)',
     )
+    parser.add_argument(
+        '--name', '-n',
+        help='ceph name to authenticate as (default: try client.crash, client.admin)')
     return parser.parse_args()
 
 
 def post_crash(path):
-    pr = subprocess.Popen(
-        args=['timeout', '30', 'ceph', 'crash', 'post', '-i', '-'],
-        stdin=subprocess.PIPE,
-        stdout=subprocess.PIPE,
-        stderr=subprocess.PIPE,
-    )
-    f = open(os.path.join(path, 'meta'), 'rb')
-    stdout, stderr = pr.communicate(input=f.read())
-    rc = pr.wait()
-    f.close()
-    if rc != 0:
-        log.warning('post %s failed: %s' % (path, stderr))
+    rc = 0
+    for n in auth_names:
+        pr = subprocess.Popen(
+            args=['timeout', '30', 'ceph',
+                  '-n', n,
+                  'crash', 'post', '-i', '-'],
+            stdin=subprocess.PIPE,
+            stdout=subprocess.PIPE,
+            stderr=subprocess.PIPE,
+        )
+        f = open(os.path.join(path, 'meta'), 'rb')
+        stdout, stderr = pr.communicate(input=f.read())
+        rc = pr.wait()
+        f.close()
+        if rc != 0:
+            log.warning('post %s as %s failed: %s' % (path, n, stderr))
+        if rc == 0:
+            break
     return rc
 
 
@@ -66,6 +79,8 @@ def scrape_path(path):
 def main():
     args = parse_args()
     postdir = os.path.join(args.path, 'posted')
+    if args.name:
+        auth_names = [args.name]
 
     while not os.path.isdir(postdir):
         log.error("directory %s does not exist; please create" % postdir)