]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-deploy.git/commitdiff
Return non-zero when gatherkeys fails 250/head
authorTravis Rhoden <trhoden@redhat.com>
Tue, 18 Nov 2014 20:21:37 +0000 (20:21 +0000)
committerTravis Rhoden <trhoden@redhat.com>
Tue, 2 Dec 2014 16:41:16 +0000 (16:41 +0000)
Immediately abort and exit when a needed key cannot be found
on the list of given hosts.

Define a new exception, KeyNotFoundError, and raise that from
gatherkeys() when the requested file does not exist on any of
the given hosts to try.  Since we now raise an exception on
error, there is no longer any need to return a value from
gatherkeys().

Fixes: 10043
Signed-off-by: Travis Rhoden <trhoden@redhat.com>
ceph_deploy/exc.py
ceph_deploy/gatherkeys.py

index fdb1db6ee10a2b6ff15f00d49b1d4dd99f73ba09..a0ac09b53240f691bb04edd92eb2b5e86e56f82f 100644 (file)
@@ -95,3 +95,22 @@ class GenericError(DeployError):
 
     def __str__(self):
         return self.message
+
+
+class KeyNotFoundError(DeployError):
+    """
+    Could not find keyring file
+    """
+    def __init__(self, keyring, hosts):
+        self.keyring = keyring
+        self.hosts = hosts
+
+    def __str__(self):
+        return '{doc}: {keys}'.format(
+            doc=self.__doc__.strip(),
+            keys=', '.join(
+                [self.keyring.format(hostname=host) +
+                 " on host {hostname}".format(hostname=host)
+                 for host in self.hosts]
+            )
+        )
index 9b276bf20533dba936a7a499ac3ad89d036ba368..e3b355e160d71c5281ac7935557a84e9d48d8e01 100644 (file)
@@ -1,7 +1,7 @@
 import os.path
 import logging
 
-from ceph_deploy import hosts
+from ceph_deploy import hosts, exc
 from ceph_deploy.cliutil import priority
 
 
@@ -14,11 +14,10 @@ def fetch_file(args, frompath, topath, _hosts):
         return True
     else:
         for hostname in _hosts:
-            LOG.debug('Checking %s for %s', hostname, frompath)
+            filepath = frompath.format(hostname=hostname)
+            LOG.debug('Checking %s for %s', hostname, filepath)
             distro = hosts.get(hostname, username=args.username)
-            key = distro.conn.remote_module.get_file(
-                frompath.format(hostname=hostname)
-            )
+            key = distro.conn.remote_module.get_file(filepath)
 
             if key is not None:
                 LOG.debug('Got %s key from %s.', topath, hostname)
@@ -26,51 +25,51 @@ def fetch_file(args, frompath, topath, _hosts):
                     f.write(key)
                     return True
             distro.conn.exit()
-    LOG.warning('Unable to find %s on %s', frompath, _hosts)
+            LOG.warning('Unable to find %s on %s', filepath, hostname)
     return False
 
 
 def gatherkeys(args):
-    ret = 0
-
     # client.admin
+    keyring = '/etc/ceph/{cluster}.client.admin.keyring'.format(
+        cluster=args.cluster)
     r = fetch_file(
         args=args,
-        frompath='/etc/ceph/{cluster}.client.admin.keyring'.format(
-            cluster=args.cluster),
+        frompath=keyring,
         topath='{cluster}.client.admin.keyring'.format(
             cluster=args.cluster),
         _hosts=args.mon,
         )
     if not r:
-        ret = 1
+        raise exc.KeyNotFoundError(keyring, args.mon)
 
     # mon.
+    keyring = '/var/lib/ceph/mon/{cluster}-{{hostname}}/keyring'.format(
+        cluster=args.cluster)
     r = fetch_file(
         args=args,
-        frompath='/var/lib/ceph/mon/%s-{hostname}/keyring' % args.cluster,
+        frompath=keyring,
         topath='{cluster}.mon.keyring'.format(cluster=args.cluster),
         _hosts=args.mon,
         )
     if not r:
-        ret = 1
+        raise exc.KeyNotFoundError(keyring, args.mon)
 
     # bootstrap
     for what in ['osd', 'mds']:
+        keyring = '/var/lib/ceph/bootstrap-{what}/{cluster}.keyring'.format(
+            what=what,
+            cluster=args.cluster)
         r = fetch_file(
             args=args,
-            frompath='/var/lib/ceph/bootstrap-{what}/{cluster}.keyring'.format(
-                cluster=args.cluster,
-                what=what),
+            frompath=keyring,
             topath='{cluster}.bootstrap-{what}.keyring'.format(
                 cluster=args.cluster,
                 what=what),
             _hosts=args.mon,
             )
         if not r:
-            ret = 1
-
-    return ret
+            raise exc.KeyNotFoundError(keyring, args.mon)
 
 
 @priority(40)