]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-daemon: user-friendly exception/error messages
authorSage Weil <sage@redhat.com>
Tue, 26 Nov 2019 14:08:07 +0000 (08:08 -0600)
committerSage Weil <sage@redhat.com>
Tue, 26 Nov 2019 14:08:07 +0000 (08:08 -0600)
We don't want tracebacks for most error conditions in ceph-daemon.

Signed-off-by: Sage Weil <sage@redhat.com>
src/ceph-daemon/ceph-daemon

index 37bb1f9465baa3c508d64fd132c799cebe2dc12f..a700dceb85c9aa33c370b23c8d5ee47a136710e9 100755 (executable)
@@ -66,6 +66,9 @@ from glob import glob
 
 container_path = None
 
+class CDError(Exception):
+    pass
+
 ##################################
 # Popen wrappers, lifted from ceph-volume
 
@@ -230,7 +233,7 @@ def infer_fsid(func):
             return func()
 
         if len(fsid_list) > 1:
-            raise RuntimeError('Cannot infer fsid, must specify --fsid')
+            raise CDError('cannot infer fsid, must specify --fsid')
 
         logger.info('Inferring fsid %s' % fsid_list[0])
         args.fsid = fsid_list[0]
@@ -406,7 +409,7 @@ def get_config_and_keyring():
             with open(args.keyring, 'r') as f:
                 keyring = f.read()
         else:
-            raise RuntimeError('no keyring')
+            raise CDError('no keyring provided')
         with open(args.config, 'r') as f:
             config = f.read()
     return (config, keyring)
@@ -431,7 +434,7 @@ def get_config_and_both_keyrings():
             with open(args.keyring, 'r') as f:
                 keyring = f.read()
         else:
-            raise RuntimeError('no keyring')
+            raise CDError('no keyring provided')
         crash_keyring = None
         if args.crash_keyring:
             with open(args.crash_keyring, 'r') as f:
@@ -873,8 +876,8 @@ def command_bootstrap():
     if not args.allow_overwrite:
         for f in [args.output_config, args.output_keyring, args.output_pub_ssh_key]:
             if os.path.exists(f):
-                raise RuntimeError('%s already exists; delete or pass '
-                                   '--allow-overwrite to overwrite' % f)
+                raise CDError('%s already exists; delete or pass '
+                              '--allow-overwrite to overwrite' % f)
 
     # initial vars
     fsid = args.fsid or make_fsid()
@@ -894,7 +897,7 @@ def command_bootstrap():
         addr_arg = args.mon_addrv
         mon_ip = args.mon_addrv.split(':')[1]
     else:
-        raise RuntimeError('must specify --mon-ip or --mon-addrv')
+        raise CDError('must specify --mon-ip or --mon-addrv')
     if not cp.has_section('global'):
         cp.add_section('global')
     cp.set('global', 'fsid', fsid);
@@ -908,7 +911,7 @@ def command_bootstrap():
         logger.info('Verifying we can ping mon IP %s...' % mon_ip)
         _, _, ret = call(['timeout', '5', 'ping', mon_ip, '-c', '1'], 'ping')
         if ret:
-            raise RuntimeError('Failed to ping %s' % mon_ip)
+            raise CDError('failed to ping %s' % mon_ip)
 
     if not args.skip_pull:
         logger.info('Pulling latest %s container...' % args.image)
@@ -1205,7 +1208,7 @@ def command_deploy():
     # type: () -> None
     (daemon_type, daemon_id) = args.name.split('.', 1)
     if daemon_type not in ['mon', 'mgr', 'mds', 'osd', 'rgw', 'rbd-mirror']:
-        raise RuntimeError('daemon type %s not recognized' % daemon_type)
+        raise CDError('daemon type %s not recognized' % daemon_type)
     (config, keyring, crash_keyring) = get_config_and_both_keyrings()
     if daemon_type == 'mon':
         if args.mon_ip:
@@ -1217,7 +1220,7 @@ def command_deploy():
             config += '[mon.%s]\n\tpublic_network = %s\n' % (daemon_id,
                                                              args.mon_network)
         else:
-            raise RuntimeError('must specify --mon-ip or --mon-network')
+            raise CDError('must specify --mon-ip or --mon-network')
     (uid, gid) = extract_uid_gid()
     c = get_container(args.fsid, daemon_type, daemon_id)
     deploy_daemon(args.fsid, daemon_type, daemon_id, c, uid, gid,
@@ -1282,7 +1285,7 @@ def command_shell():
 def command_enter():
     # type: () -> int
     if not args.fsid:
-        raise RuntimeError('must pass --fsid to specify cluster')
+        raise CDError('must pass --fsid to specify cluster')
     (daemon_type, daemon_id) = args.name.split('.', 1)
     container_args = [] # type: List[str]
     if args.command:
@@ -1350,7 +1353,7 @@ def command_ceph_volume():
 def command_unit():
     # type: () -> None
     if not args.fsid:
-        raise RuntimeError('must pass --fsid to specify cluster')
+        raise CDError('must pass --fsid to specify cluster')
     (daemon_type, daemon_id) = args.name.split('.', 1)
     unit_name = get_unit_name(args.fsid, daemon_type, daemon_id)
     call_throws([
@@ -1364,7 +1367,7 @@ def command_unit():
 def command_logs():
     # type: () -> None
     if not args.fsid:
-        raise RuntimeError('must pass --fsid to specify cluster')
+        raise CDError('must pass --fsid to specify cluster')
     cmd = [str(container_path), 'logs'] # type: List[str]
     if args.follow:
         cmd.append('-f')
@@ -1482,7 +1485,7 @@ def command_adopt():
                                       daemon_id,
                                       legacy_dir=args.legacy_dir)
         if not fsid:
-            raise RuntimeError('could not detect fsid; add fsid = to ceph.conf')
+            raise CDError('could not detect legacy fsid; set fsid in ceph.conf')
 
         # NOTE: implicit assumption here that the units correspond to the
         # cluster we are adopting based on the /etc/{defaults,sysconfig}/ceph
@@ -1542,8 +1545,8 @@ def command_rm_daemon():
     # type: () -> None
     (daemon_type, daemon_id) = args.name.split('.', 1)
     if daemon_type in ['mon', 'osd'] and not args.force:
-        raise RuntimeError('must pass --force to proceed: '
-                           'this command may destroy precious data!')
+        raise CDError('must pass --force to proceed: '
+                      'this command may destroy precious data!')
     unit_name = get_unit_name(args.fsid, daemon_type, daemon_id)
     call(['systemctl', 'stop', unit_name],
          verbose_on_failure=False)
@@ -1559,8 +1562,8 @@ def command_rm_daemon():
 def command_rm_cluster():
     # type: () -> None
     if not args.force:
-        raise RuntimeError('must pass --force to proceed: '
-                           'this command may destroy precious data!')
+        raise CDError('must pass --force to proceed: '
+                      'this command may destroy precious data!')
 
     # stop + disable individual daemon units
     for d in list_daemons(detail=False):
@@ -1936,12 +1939,16 @@ if __name__ == "__main__":
             except Exception as e:
                 logger.debug('could not locate %s: %s' % (i, e))
         if not container_path:
-            raise RuntimeError('unable to locate any of %s' % CONTAINER_PREFERENCE)
+            raise CDError('unable to locate any of %s' % CONTAINER_PREFERENCE)
 
     if 'func' not in args:
         sys.stderr.write('No command specified; pass -h or --help for usage\n')
         sys.exit(1)
-    r = args.func()
+    try:
+        r = args.func()
+    except CDError as e:
+        sys.stderr.write('ERROR: %s' % e)
+        sys.exit(1)
     if not r:
         r = 0
     sys.exit(r)