]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-deploy.git/commitdiff
avoid overwriting a modified ceph.conf without --overwrite-conf
authorSage Weil <sage@inktank.com>
Thu, 7 Mar 2013 01:42:04 +0000 (17:42 -0800)
committerSage Weil <sage@inktank.com>
Thu, 7 Mar 2013 01:42:04 +0000 (17:42 -0800)
While we're at it, continue with mon/osd/mds creations if there is a
failure, but return an error at the end.

Signed-off-by: Sage Weil <sage@inktank.com>
ceph_deploy/cli.py
ceph_deploy/conf.py
ceph_deploy/mds.py
ceph_deploy/mon.py
ceph_deploy/osd.py

index 4d0bf957898e4ccc4a40b0bdfc51c9db4767711d..8961afe9c21433f8c4bf807814eea4ab0b046f3b 100644 (file)
@@ -31,6 +31,11 @@ def parse_args(args=None, namespace=None):
         action='store_true', dest='dry_run',
         help='do not perform any action, but report what would be done',
         )
+    parser.add_argument(
+        '--overwrite-conf',
+        action='store_true',
+        help='overwrite an existing conf file on remote host (if present)',
+        )
     parser.add_argument(
         '--cluster',
         metavar='NAME',
index fcd08e068f2c49f7111111accd58b1abc8074709..1b67cfe758ede058a915f14fd03caf31f13330cb 100644 (file)
@@ -36,3 +36,21 @@ def load(args):
     else:
         with contextlib.closing(f):
             return parse(f)
+
+
+def write_conf(cluster, conf, overwrite):
+    import os
+
+    path = '/etc/ceph/{cluster}.conf'.format(cluster=cluster)
+    tmp = '{path}.{pid}.tmp'.format(path=path, pid=os.getpid())
+
+    if os.path.exists(path):
+        with file(path, 'rb') as f:
+            old = f.read()
+            if old != conf and not overwrite:
+                raise RuntimeError('config file %s exists with different content; use --overwrite-conf to overwrite' % path)
+    with file(tmp, 'w') as f:
+        f.write(conf)
+        f.flush()
+        os.fsync(f)
+    os.rename(tmp, path)
index 08a54dd61ada940f856b14765837186648420035..98df2479b4c1bb857e15ab53cb0723b2def17f24 100644 (file)
@@ -25,19 +25,6 @@ def get_bootstrap_mds_key(cluster):
         raise RuntimeError('bootstrap-mds keyring not found; run \'gatherkeys\'')
 
 
-def write_conf(cluster, conf):
-    import os
-
-    path = '/etc/ceph/{cluster}.conf'.format(cluster=cluster)
-    tmp = '{path}.{pid}.tmp'.format(path=path, pid=os.getpid())
-
-    with file(tmp, 'w') as f:
-        f.write(conf)
-        f.flush()
-        os.fsync(f)
-    os.rename(tmp, path)
-
-
 def create_mds_bootstrap(cluster, key):
     """
     Run on mds node, writes the bootstrap key if not there yet.
@@ -155,46 +142,54 @@ def mds_create(args):
     key = get_bootstrap_mds_key(cluster=args.cluster)
 
     bootstrapped = set()
+    errors = 0
     for hostname, name in args.mds:
-
-        # TODO username
-        sudo = args.pushy('ssh+sudo:{hostname}'.format(hostname=hostname))
-
-        lsb_release_r = sudo.compile(lsb.lsb_release)
-        (distro, release, codename) = lsb_release_r()
-        init = lsb.choose_init(distro, codename)
-        log.debug('Distro %s codename %s, will use %s',
-                  distro, codename, init)
-
-        if hostname not in bootstrapped:
-            bootstrapped.add(hostname)
-            log.debug('Deploying mds bootstrap to %s', hostname)
-
-            write_conf_r = sudo.compile(write_conf)
-            conf_data = StringIO()
-            cfg.write(conf_data)
-            write_conf_r(
+        try:
+            # TODO username
+            sudo = args.pushy('ssh+sudo:{hostname}'.format(hostname=hostname))
+
+            lsb_release_r = sudo.compile(lsb.lsb_release)
+            (distro, release, codename) = lsb_release_r()
+            init = lsb.choose_init(distro, codename)
+            log.debug('Distro %s codename %s, will use %s',
+                      distro, codename, init)
+
+            if hostname not in bootstrapped:
+                bootstrapped.add(hostname)
+                log.debug('Deploying mds bootstrap to %s', hostname)
+
+                write_conf_r = sudo.compile(conf.write_conf)
+                conf_data = StringIO()
+                cfg.write(conf_data)
+                write_conf_r(
+                    cluster=args.cluster,
+                    conf=conf_data.getvalue(),
+                    overwrite=args.overwrite_conf,
+                    )
+
+                create_mds_bootstrap_r = sudo.compile(create_mds_bootstrap)
+                error = create_mds_bootstrap_r(
+                    cluster=args.cluster,
+                    key=key,
+                    )
+                if error is not None:
+                    raise exc.GenericError(error)
+                log.debug('Host %s is now ready for MDS use.', hostname)
+
+            # create an mds
+            log.debug('Deploying mds.%s to %s', name, hostname)
+            create_mds_r = sudo.compile(create_mds)
+            create_mds_r(
+                name=name,
                 cluster=args.cluster,
-                conf=conf_data.getvalue(),
+                init=init,
                 )
+        except RuntimeError as e:
+            log.error(e)
+            errors += 1
 
-            create_mds_bootstrap_r = sudo.compile(create_mds_bootstrap)
-            error = create_mds_bootstrap_r(
-                cluster=args.cluster,
-                key=key,
-                )
-            if error is not None:
-                raise exc.GenericError(error)
-            log.debug('Host %s is now ready for MDS use.', hostname)
-
-        # create an mds
-        log.debug('Deploying mds.%s to %s', name, hostname)
-        create_mds_r = sudo.compile(create_mds)
-        create_mds_r(
-            name=name,
-            cluster=args.cluster,
-            init=init,
-            )
+    if errors:
+        raise exc.GenericError('Failed to create %d MDSs' % errors)
 
 
 def mds(args):
index d3135f1dd544d96e24c8f6a97616112495b5ace6..9eb1a86173e855f4cad316f6fec2107623623e76 100644 (file)
@@ -13,19 +13,6 @@ from .cliutil import priority
 log = logging.getLogger(__name__)
 
 
-def write_conf(cluster, conf):
-    import os
-
-    path = '/etc/ceph/{cluster}.conf'.format(cluster=cluster)
-    tmp = '{path}.{pid}.tmp'.format(path=path, pid=os.getpid())
-
-    with file(tmp, 'w') as f:
-        f.write(conf)
-        f.flush()
-        os.fsync(f)
-    os.rename(tmp, path)
-
-
 def create_mon(cluster, monitor_keyring, init):
     import os
     import socket
@@ -120,34 +107,44 @@ def mon_create(args):
         ' '.join(args.mon),
         )
 
+    errors = 0
     for hostname in args.mon:
-        log.debug('Deploying mon to %s', hostname)
-
-        # TODO username
-        sudo = args.pushy('ssh+sudo:{hostname}'.format(hostname=hostname))
-
-        lsb_release_r = sudo.compile(lsb.lsb_release)
-        (distro, release, codename) = lsb_release_r()
-        init = lsb.choose_init(distro, codename)
-        log.debug('Distro %s codename %s, will use %s',
-                  distro, codename, init)
-
-        write_conf_r = sudo.compile(write_conf)
-        conf_data = StringIO()
-        cfg.write(conf_data)
-        write_conf_r(
-            cluster=args.cluster,
-            conf=conf_data.getvalue(),
-            )
-
-        create_mon_r = sudo.compile(create_mon)
-        create_mon_r(
-            cluster=args.cluster,
-            monitor_keyring=monitor_keyring,
-            init=init,
-            )
-
-        # TODO add_bootstrap_peer_hint
+        try:
+            log.debug('Deploying mon to %s', hostname)
+
+            # TODO username
+            sudo = args.pushy('ssh+sudo:{hostname}'.format(hostname=hostname))
+
+            lsb_release_r = sudo.compile(lsb.lsb_release)
+            (distro, release, codename) = lsb_release_r()
+            init = lsb.choose_init(distro, codename)
+            log.debug('Distro %s codename %s, will use %s',
+                      distro, codename, init)
+
+            write_conf_r = sudo.compile(conf.write_conf)
+            conf_data = StringIO()
+            cfg.write(conf_data)
+            write_conf_r(
+                cluster=args.cluster,
+                conf=conf_data.getvalue(),
+                overwrite=args.overwrite_conf,
+                )
+
+            create_mon_r = sudo.compile(create_mon)
+            create_mon_r(
+                cluster=args.cluster,
+                monitor_keyring=monitor_keyring,
+                init=init,
+                )
+
+            # TODO add_bootstrap_peer_hint
+
+        except RuntimeError as e:
+            log.error(e)
+            errors += 1
+
+    if errors:
+        raise exc.GenericError('Failed to create %d monitors' % errors)
 
 def mon(args):
     if args.subcommand == 'create':
index 38daaa290a0467c9c2e88de1dbea8c7d11a0316a..2bcb47da41522c37b9d31de96e54ff4ee73473b9 100644 (file)
@@ -26,19 +26,6 @@ def get_bootstrap_osd_key(cluster):
     except IOError:
         raise RuntimeError('bootstrap-osd keyring not found; run \'gatherkeys\'')
 
-def write_conf(cluster, conf):
-    import os
-
-    path = '/etc/ceph/{cluster}.conf'.format(cluster=cluster)
-    tmp = '{path}.{pid}.tmp'.format(path=path, pid=os.getpid())
-
-    with file(tmp, 'w') as f:
-        f.write(conf)
-        f.flush()
-        os.fsync(f)
-    os.rename(tmp, path)
-
-
 def create_osd(cluster, key):
     """
     Run on osd node, writes the bootstrap key if not there yet.
@@ -147,48 +134,56 @@ def prepare(args, cfg, activate):
     key = get_bootstrap_osd_key(cluster=args.cluster)
 
     bootstrapped = set()
+    errors = 0
     for hostname, disk, journal in args.disk:
-
-        # TODO username
-        sudo = args.pushy('ssh+sudo:{hostname}'.format(
-                hostname=hostname,
-                ))
-
-        if hostname not in bootstrapped:
-            bootstrapped.add(hostname)
-            log.debug('Deploying osd to %s', hostname)
-
-            write_conf_r = sudo.compile(write_conf)
-            conf_data = StringIO()
-            cfg.write(conf_data)
-            write_conf_r(
-                cluster=args.cluster,
-                conf=conf_data.getvalue(),
-                )
-
-            create_osd_r = sudo.compile(create_osd)
-            error = create_osd_r(
+        try:
+            # TODO username
+            sudo = args.pushy('ssh+sudo:{hostname}'.format(
+                    hostname=hostname,
+                    ))
+
+            if hostname not in bootstrapped:
+                bootstrapped.add(hostname)
+                log.debug('Deploying osd to %s', hostname)
+
+                write_conf_r = sudo.compile(conf.write_conf)
+                conf_data = StringIO()
+                cfg.write(conf_data)
+                write_conf_r(
+                    cluster=args.cluster,
+                    conf=conf_data.getvalue(),
+                    overwrite=args.overwrite_conf,
+                    )
+
+                create_osd_r = sudo.compile(create_osd)
+                error = create_osd_r(
+                    cluster=args.cluster,
+                    key=key,
+                    )
+                if error is not None:
+                    raise exc.GenericError(error)
+                log.debug('Host %s is now ready for osd use.', hostname)
+
+            log.debug('Preparing host %s disk %s journal %s activate %s',
+                      hostname, disk, journal, activate)
+
+            prepare_disk_r = sudo.compile(prepare_disk)
+            prepare_disk_r(
                 cluster=args.cluster,
-                key=key,
+                disk=disk,
+                journal=journal,
+                activate=activate,
+                zap=args.zap_disk,
+                dmcrypt=args.dmcrypt,
+                dmcrypt_dir=args.dmcrypt_key_dir,
                 )
-            if error is not None:
-                raise exc.GenericError(error)
-            log.debug('Host %s is now ready for osd use.', hostname)
 
-        log.debug('Preparing host %s disk %s journal %s activate %s',
-                  hostname, disk, journal, activate)
-
-        prepare_disk_r = sudo.compile(prepare_disk)
-        prepare_disk_r(
-            cluster=args.cluster,
-            disk=disk,
-            journal=journal,
-            activate=activate,
-            zap=args.zap_disk,
-            dmcrypt=args.dmcrypt,
-            dmcrypt_dir=args.dmcrypt_key_dir,
-            )
+        except RuntimeError as e:
+            log.error(e)
+            errors += 1
 
+    if errors:
+        raise exc.GenericError('Failed to create %d OSDs' % errors)
 
 def activate(args, cfg):
     log.debug(