Merge pull request #1020 from dachary/wip-ceph-disk-override

ceph-disk: prepare --data-dir must not override files

Reviewed-by: Sage Weil <sage@inktank.com>
This commit is contained in:
Sage Weil 2014-01-01 18:00:43 -08:00
commit 906f973e26
2 changed files with 31 additions and 2 deletions

View File

@ -1048,7 +1048,12 @@ def prepare_dir(
journal_uuid,
journal_dmcrypt = None,
):
LOG.debug('Preparing osd data dir %s', path)
if os.path.exists(os.path.join(path, 'magic')):
LOG.debug('Data dir %s already exists', path)
return
else:
LOG.debug('Preparing osd data dir %s', path)
if osd_uuid is None:
osd_uuid = str(uuid.uuid4())
@ -1067,12 +1072,14 @@ def prepare_dir(
write_one_line(path, 'ceph_fsid', cluster_uuid)
write_one_line(path, 'fsid', osd_uuid)
write_one_line(path, 'magic', CEPH_OSD_ONDISK_MAGIC)
if journal_uuid is not None:
# i.e., journal is a tagged partition
write_one_line(path, 'journal_uuid', journal_uuid)
write_one_line(path, 'magic', CEPH_OSD_ONDISK_MAGIC)
def prepare_dev(
data,
journal,

View File

@ -0,0 +1,22 @@
$ uuid=$(uuidgen)
$ export CEPH_CONF=$TESTDIR/ceph.conf
$ echo "[global]\nfsid = $uuid\nosd_data = $TESTDIR/osd-data\n" > $CEPH_CONF
$ osd_data=$(ceph-conf osd_data)
$ mkdir $osd_data
# a failure to create the fsid file implies the magic file is not created
$ mkdir $osd_data/fsid
$ ceph-disk --verbose prepare $osd_data 2>&1 | grep 'Is a directory'
OSError: [Errno 21] Is a directory
$ ! [ -f $osd_data/magic ]
$ rmdir $osd_data/fsid
# successfully prepare the OSD
$ ceph-disk --verbose prepare $osd_data
DEBUG:ceph-disk:Preparing osd data dir .* (re)
$ grep $uuid $osd_data/ceph_fsid > /dev/null
$ [ -f $osd_data/magic ]
# will not override an existing OSD
$ echo "[global]\nfsid = $(uuidgen)\nosd_data = $TESTDIR/osd-data\n" > $CEPH_CONF
$ ceph-disk --verbose prepare $osd_data
DEBUG:ceph-disk:Data dir .* already exists (re)
$ grep $uuid $osd_data/ceph_fsid > /dev/null
$ rm -fr $osd_data $TESTDIR/ceph.conf