]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-deploy.git/commitdiff
Merge branch 'master' into RM-15016
authorOleh Prypin <oleh@pryp.in>
Thu, 9 Jun 2016 12:34:19 +0000 (15:34 +0300)
committerOleh Prypin <oleh@pryp.in>
Thu, 9 Jun 2016 12:34:19 +0000 (15:34 +0300)
1  2 
ceph_deploy/gatherkeys.py

index fcd0ec88520c8172d4d2502ae32974a080eae824,a7d0981d902e29a551979001edb7f53e749cc8f4..2eb800ed74a480f8a1f1cc5c144037c719c82dfb
@@@ -30,52 -205,49 +205,49 @@@ def gatherkeys_with_mon(args, host, des
  
  
  def gatherkeys(args):
 -    oldmask = os.umask(077)
+     """
+     Gather keys from any mon and store in current working directory.
+     Backs up keys from previous installs and stores new keys.
+     """
 +    oldmask = os.umask(0o77)
      try:
-         # client.admin
-         keyring = '/etc/ceph/{cluster}.client.admin.keyring'.format(
-             cluster=args.cluster)
-         r = fetch_file(
-             args=args,
-             frompath=keyring,
-             topath='{cluster}.client.admin.keyring'.format(
-                 cluster=args.cluster),
-             _hosts=args.mon,
-             )
-         if not r:
-             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=keyring,
-             topath='{cluster}.mon.keyring'.format(cluster=args.cluster),
-             _hosts=args.mon,
-             )
-         if not r:
-             raise exc.KeyNotFoundError(keyring, args.mon)
-         # bootstrap
-         for what in ['osd', 'mds', 'rgw']:
-             keyring = '/var/lib/ceph/bootstrap-{what}/{cluster}.keyring'.format(
-                 what=what,
-                 cluster=args.cluster)
-             r = fetch_file(
-                 args=args,
-                 frompath=keyring,
-                 topath='{cluster}.bootstrap-{what}.keyring'.format(
-                     cluster=args.cluster,
-                     what=what),
-                 _hosts=args.mon,
-                 )
-             if not r:
-                 if what in ['osd', 'mds']:
-                     raise exc.KeyNotFoundError(keyring, args.mon)
-                 else:
-                     LOG.warning(("No RGW bootstrap key found. Will not be able to "
-                                  "deploy RGW daemons"))
+         try:
+             tmpd = tempfile.mkdtemp()
+             LOG.info("Storing keys in temp directory %s", tmpd)
+             sucess = False
+             for host in args.mon:
+                 sucess = gatherkeys_with_mon(args, host, tmpd)
+                 if sucess:
+                     break
+             if not sucess:
+                 LOG.error("Failed to connect to host:%s" ,', '.join(args.mon))
+                 raise RuntimeError('Failed to connect any mon')
+             had_error = False
+             date_string = time.strftime("%Y%m%d%H%M%S")
+             for keytype in ["admin", "mds", "mon", "osd", "rgw"]:
+                 filename = keytype_path_to(args, keytype)
+                 tmp_path = os.path.join(tmpd, filename)
+                 if not os.path.exists(tmp_path):
+                     LOG.error("No key retrived for '%s'" , keytype)
+                     had_error = True
+                     continue
+                 if not os.path.exists(filename):
+                     LOG.info("Storing %s" % (filename))
+                     shutil.move(tmp_path, filename)
+                     continue
+                 if _keyring_equivalent(tmp_path, filename):
+                     LOG.info("keyring '%s' already exists" , filename)
+                     continue
+                 backup_keyring = "%s-%s" % (filename, date_string)
+                 LOG.info("Replacing '%s' and backing up old key as '%s'", filename, backup_keyring)
+                 shutil.copy(filename, backup_keyring)
+                 shutil.move(tmp_path, filename)
+             if had_error:
+                 raise RuntimeError('Failed to get all key types')
+         finally:
+             LOG.info("Destroy temp directory %s" %(tmpd))
+             shutil.rmtree(tmpd)
      finally:
          os.umask(oldmask)