]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-disk: always check zap is applied on a full device 4818/head
authorLoic Dachary <ldachary@redhat.com>
Sun, 31 May 2015 17:42:45 +0000 (19:42 +0200)
committerLoic Dachary <ldachary@redhat.com>
Sun, 31 May 2015 17:42:45 +0000 (19:42 +0200)
zap only makes sense on a full device and this is verified for

    ceph-disk prepare --zap-disk

but not for

    ceph-disk zap

Unify the two and add a test to check that it fails as expected when
trying to zap a directory.

http://tracker.ceph.com/issues/11272 Fixes: #11272

Signed-off-by: Loic Dachary <ldachary@redhat.com>
src/ceph-disk
src/test/ceph-disk.sh

index e1b12c503dfb3dd45c0517a2c3dd44e5317cbfc2..1d90f024f9f7a40ff61d9987bc9eab0e3ab36c73 100755 (executable)
@@ -1055,6 +1055,9 @@ def zap(dev):
     """
     Destroy the partition table and content of a given disk.
     """
+    dmode = os.stat(dev).st_mode
+    if not stat.S_ISBLK(dmode) or is_partition(dev):
+        raise Error('not full block device; cannot zap', dev)
     try:
         LOG.debug('Zapping partition table on %s', dev)
 
@@ -1540,10 +1543,7 @@ def main_prepare(args):
                 verify_not_in_use(args.journal, False)
 
         if args.zap_disk is not None:
-            if stat.S_ISBLK(dmode) and not is_partition(args.data):
-                zap(args.data)
-            else:
-                raise Error('not full block device; cannot zap', args.data)
+            zap(args.data)
 
         if args.cluster_uuid is None:
             args.cluster_uuid = get_fsid(cluster=args.cluster)
index c6bb4d5ff2fcc440036e6607eda36a32e46f260e..9cbbb00c48d9f3e116a69d0927a93b50fdf0d6c5 100755 (executable)
@@ -220,6 +220,15 @@ function test_mark_init() {
     $rm -fr $osd_data
 }
 
+function test_zap() {
+    local osd_data=$DIR/dir
+    $mkdir -p $osd_data
+
+    ./ceph-disk $CEPH_DISK_ARGS zap $osd_data 2>&1 | grep 'not full block device' || return 1
+
+    $rm -fr $osd_data
+}
+
 # ceph-disk prepare returns immediately on success if the magic file
 # exists in the --osd-data directory.
 function test_activate_dir_magic() {
@@ -613,6 +622,7 @@ function run() {
     default_actions+="test_activate_dir "
     default_actions+="test_keyring_path "
     default_actions+="test_mark_init "
+    default_actions+="test_zap "
     local actions=${@:-$default_actions}
     local status
     for action in $actions  ; do