Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tools: ceph-disk zap should ensure block device #5755

Merged
1 commit merged into from Sep 2, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/ceph-disk
Expand Up @@ -1039,6 +1039,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)

Expand Down Expand Up @@ -1501,10 +1504,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)
Expand Down
10 changes: 10 additions & 0 deletions src/test/ceph-disk.sh
Expand Up @@ -167,6 +167,15 @@ function test_no_path() {
( unset PATH ; test_activate_dir ) || return 1
}

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() {
Expand Down Expand Up @@ -470,6 +479,7 @@ function run() {
default_actions+="test_activate_dir_magic "
default_actions+="test_activate_dir "
default_actions+="test_keyring_path "
default_actions+="test_zap "
local actions=${@:-$default_actions}
for action in $actions ; do
setup
Expand Down