mirror of
https://github.com/ceph/ceph
synced 2025-01-29 14:34:40 +00:00
Merge pull request #3872 from dachary/wip-7334-partx-test
ceph-disk: test activate on the second journal Reviewed-by: Alfredo Deza <adeza@redhat.com>
This commit is contained in:
commit
0a76aa5e70
@ -964,6 +964,9 @@ def unmount(
|
||||
|
||||
###########################################
|
||||
|
||||
def extract_parted_partition_numbers(partitions):
|
||||
numbers_as_strings = re.findall('^\d+', partitions, re.MULTILINE)
|
||||
return map(int, numbers_as_strings)
|
||||
|
||||
def get_free_partition_index(dev):
|
||||
"""
|
||||
@ -988,31 +991,19 @@ def get_free_partition_index(dev):
|
||||
|
||||
if not lines:
|
||||
raise Error('parted failed to output anything')
|
||||
lines = str(lines).splitlines(True)
|
||||
|
||||
# work around buggy libreadline(?) library in rhel/centos.
|
||||
idiot_prefix = '\x1b\x5b\x3f\x31\x30\x33\x34\x68'
|
||||
if lines[0].startswith(idiot_prefix):
|
||||
lines[0] = lines[0][8:]
|
||||
|
||||
if lines[0] not in ['CHS;\n', 'CYL;\n', 'BYT;\n']:
|
||||
raise Error('weird parted units', lines[0])
|
||||
del lines[0]
|
||||
|
||||
if not lines[0].startswith('/dev/'):
|
||||
raise Error('weird parted disk entry', lines[0])
|
||||
del lines[0]
|
||||
|
||||
seen = set()
|
||||
for line in lines:
|
||||
idx, _ = line.split(':', 1)
|
||||
idx = int(idx)
|
||||
seen.add(idx)
|
||||
|
||||
num = 1
|
||||
while num in seen:
|
||||
num += 1
|
||||
return num
|
||||
if ('CHS;' not in lines and
|
||||
'CYL;' not in lines and
|
||||
'BYT;' not in lines):
|
||||
raise Error('parted output expected to contain one of ' +
|
||||
'CHH; CYL; or BYT; : ' + lines)
|
||||
if dev not in lines:
|
||||
raise Error('parted output expected to contain ' + dev + ': ' + lines)
|
||||
_, partitions = lines.split(dev)
|
||||
partition_numbers = extract_parted_partition_numbers(partitions)
|
||||
if partition_numbers:
|
||||
return max(partition_numbers) + 1
|
||||
else:
|
||||
return 1
|
||||
|
||||
|
||||
def update_partition(action, dev, description):
|
||||
|
@ -1,7 +1,7 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Copyright (C) 2014 Cloudwatt <libre.licensing@cloudwatt.com>
|
||||
# Copyright (C) 2014 Red Hat <contact@redhat.com>
|
||||
# Copyright (C) 2014, 2015 Red Hat <contact@redhat.com>
|
||||
#
|
||||
# Author: Loic Dachary <loic@dachary.org>
|
||||
#
|
||||
@ -31,6 +31,7 @@ FSID=$(uuidgen)
|
||||
export CEPH_CONF=$DIR/ceph.conf
|
||||
export CEPH_ARGS="--fsid $FSID"
|
||||
CEPH_ARGS+=" --chdir="
|
||||
CEPH_ARGS+=" --journal-dio=false"
|
||||
CEPH_ARGS+=" --run-dir=$DIR"
|
||||
CEPH_ARGS+=" --osd-failsafe-full-ratio=.99"
|
||||
CEPH_ARGS+=" --mon-host=$MONA"
|
||||
@ -51,6 +52,7 @@ timeout=$(which timeout)
|
||||
diff=$(which diff)
|
||||
mkdir=$(which mkdir)
|
||||
rm=$(which rm)
|
||||
uuidgen=$(which uuidgen)
|
||||
|
||||
function setup() {
|
||||
teardown
|
||||
@ -170,7 +172,7 @@ function test_no_path() {
|
||||
# ceph-disk prepare returns immediately on success if the magic file
|
||||
# exists in the --osd-data directory.
|
||||
function test_activate_dir_magic() {
|
||||
local uuid=$(uuidgen)
|
||||
local uuid=$($uuidgen)
|
||||
local osd_data=$DIR/osd
|
||||
|
||||
echo a failure to create the fsid file implies the magic file is not created
|
||||
@ -192,7 +194,7 @@ function test_activate_dir_magic() {
|
||||
|
||||
echo will not override an existing OSD
|
||||
|
||||
CEPH_ARGS="--fsid $(uuidgen)" \
|
||||
CEPH_ARGS="--fsid $($uuidgen)" \
|
||||
./ceph-disk $CEPH_DISK_ARGS prepare $osd_data 2>&1 | tee $DIR/out
|
||||
grep --quiet 'ceph-disk:Data dir .* already exists' $DIR/out || return 1
|
||||
grep --quiet $uuid $osd_data/ceph_fsid || return 1
|
||||
@ -202,11 +204,12 @@ function test_activate() {
|
||||
local to_prepare=$1
|
||||
local to_activate=$2
|
||||
local journal=$3
|
||||
local osd_uuid=$($uuidgen)
|
||||
|
||||
$mkdir -p $OSD_DATA
|
||||
|
||||
./ceph-disk $CEPH_DISK_ARGS \
|
||||
prepare $to_prepare $journal || return 1
|
||||
prepare --osd-uuid $osd_uuid $to_prepare $journal || return 1
|
||||
|
||||
$timeout $TIMEOUT ./ceph-disk $CEPH_DISK_ARGS \
|
||||
activate \
|
||||
@ -214,7 +217,7 @@ function test_activate() {
|
||||
$to_activate || return 1
|
||||
$timeout $TIMEOUT ./ceph osd pool set $TEST_POOL size 1 || return 1
|
||||
|
||||
local id=$($cat $OSD_DATA/ceph-?/whoami || $cat $to_activate/whoami)
|
||||
local id=$(ceph osd create $osd_uuid)
|
||||
local weight=1
|
||||
./ceph osd crush add osd.$id $weight root=default host=localhost || return 1
|
||||
echo FOO > $DIR/BAR
|
||||
@ -296,25 +299,99 @@ function test_activate_dir() {
|
||||
$rm -fr $osd_data
|
||||
}
|
||||
|
||||
function loop_sanity_check_body() {
|
||||
local dev=$1
|
||||
local guid=$2
|
||||
|
||||
#
|
||||
# Check if /dev/loop is configured with max_part > 0 to handle
|
||||
# partition tables and expose the partition devices in /dev
|
||||
#
|
||||
sgdisk --largest-new=1 --partition-guid=1:$guid $dev
|
||||
if ! test -e ${dev}p1 ; then
|
||||
if grep loop.max_part /proc/cmdline ; then
|
||||
echo "the loop module max_part parameter is configured but when"
|
||||
echo "creating a new partition on $dev, it the expected node"
|
||||
echo "${dev}p1 does not exist"
|
||||
return 1
|
||||
fi
|
||||
perl -pi -e 's/$/ loop.max_part=16/ if(/kernel/ && !/max_part/)' /boot/grub/grub.conf
|
||||
echo "the loop.max_part=16 was added to the kernel in /boot/grub/grub.conf"
|
||||
cat /boot/grub/grub.conf
|
||||
echo "you need to reboot for it to be taken into account"
|
||||
return 1
|
||||
fi
|
||||
|
||||
#
|
||||
# Install the minimal files supporting the maintenance of /dev/disk/by-partuuid
|
||||
#
|
||||
udevadm trigger --sysname-match=$(basename $dev)
|
||||
udevadm settle
|
||||
if test ! -e /dev/disk/by-partuuid/$guid ; then
|
||||
cp -a ../udev/95-ceph-osd-alt.rules /lib/udev/rules.d/95-ceph-osd.rules
|
||||
cp -a ceph-disk ceph-disk-udev /usr/sbin
|
||||
udevadm trigger --sysname-match=$(basename $dev)
|
||||
if test ! -e /dev/disk/by-partuuid/$guid ; then
|
||||
echo "/dev/disk/by-partuuid/$guid not found although the"
|
||||
echo "following support files are installed: "
|
||||
ls -l /lib/udev/rules.d/95-ceph-osd.rules /usr/sbin/ceph-disk{,-udev}
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
function loop_sanity_check() {
|
||||
local id=$(lsb_release -si)
|
||||
local major=$(lsb_release -rs | cut -f1 -d.)
|
||||
if test $major != 6 || test $id != CentOS -a $id != RedHatEnterpriseServer ; then
|
||||
echo "/dev/loop is assumed to be configured with max_part > 0"
|
||||
echo "and /dev/disk/by-partuuid to be populated by udev"
|
||||
return 0
|
||||
fi
|
||||
local name=$DIR/sanity.disk
|
||||
dd if=/dev/zero of=$name bs=1024k count=10 > /dev/null
|
||||
losetup --find $name
|
||||
local dev=$(losetup --associated $name | cut -f1 -d:)
|
||||
local guid=$($uuidgen)
|
||||
|
||||
loop_sanity_check_body $dev $guid
|
||||
status=$?
|
||||
|
||||
losetup --detach $dev
|
||||
rm $name
|
||||
rm -f /dev/disk/by-partuuid/$guid
|
||||
|
||||
return $status
|
||||
}
|
||||
|
||||
function create_dev() {
|
||||
local name=$1
|
||||
|
||||
dd if=/dev/zero of=$name bs=1024k count=200
|
||||
set -x
|
||||
echo create_dev $name >&2
|
||||
dd if=/dev/zero of=$name bs=1024k count=400 > /dev/null
|
||||
losetup --find $name
|
||||
local dev=$(losetup --associated $name | cut -f1 -d:)
|
||||
ceph-disk zap $dev > /dev/null 2>&1
|
||||
echo $dev
|
||||
set +x
|
||||
}
|
||||
|
||||
function destroy_dev() {
|
||||
local name=$1
|
||||
local dev=$2
|
||||
|
||||
set -x
|
||||
echo destroy_dev $name $dev >&2
|
||||
for partition in 1 2 3 4 ; do
|
||||
umount ${dev}p${partition} || true
|
||||
umount ${dev}p${partition} > /dev/null 2>&1 || true
|
||||
done
|
||||
ceph-disk zap $dev > /dev/null 2>&1
|
||||
losetup --detach $dev
|
||||
rm $name
|
||||
set +x
|
||||
}
|
||||
|
||||
function activate_dev_body() {
|
||||
@ -324,17 +401,45 @@ function activate_dev_body() {
|
||||
|
||||
setup
|
||||
run_mon
|
||||
#
|
||||
# Create an OSD with data on a disk, journal on another
|
||||
#
|
||||
test_activate $disk ${disk}p1 $journal || return 1
|
||||
kill_daemons
|
||||
umount ${disk}p1 || return 1
|
||||
teardown
|
||||
|
||||
# reuse the journal partition
|
||||
setup
|
||||
run_mon
|
||||
#
|
||||
# Create an OSD with data on a disk, journal on another
|
||||
# This will add a new partition to $journal, the previous
|
||||
# one will remain.
|
||||
#
|
||||
ceph-disk zap $disk || return 1
|
||||
test_activate $disk ${disk}p1 $journal || return 1
|
||||
kill_daemons
|
||||
umount ${disk}p1 || return 1
|
||||
teardown
|
||||
|
||||
setup
|
||||
run_mon
|
||||
#
|
||||
# Create an OSD and reuse an existing journal partition
|
||||
#
|
||||
test_activate $newdisk ${newdisk}p1 ${journal}p1 || return 1
|
||||
#
|
||||
# Create an OSD and get a journal partition from a disk that
|
||||
# already contains a journal partition which is in use. Updates of
|
||||
# the kernel partition table may behave differently when a
|
||||
# partition is in use. See http://tracker.ceph.com/issues/7334 for
|
||||
# more information.
|
||||
#
|
||||
ceph-disk zap $disk || return 1
|
||||
test_activate $disk ${disk}p1 $journal || return 1
|
||||
kill_daemons
|
||||
umount ${newdisk}p1 || return 1
|
||||
umount ${disk}p1 || return 1
|
||||
teardown
|
||||
}
|
||||
|
||||
@ -344,12 +449,15 @@ function test_activate_dev() {
|
||||
return 0
|
||||
fi
|
||||
|
||||
loop_sanity_check || return 1
|
||||
|
||||
local disk=$(create_dev vdf.disk)
|
||||
local journal=$(create_dev vdg.disk)
|
||||
local newdisk=$(create_dev vdh.disk)
|
||||
|
||||
activate_dev_body $disk $journal $newdisk
|
||||
status=$?
|
||||
test $status != 0 && teardown
|
||||
|
||||
destroy_dev vdf.disk $disk
|
||||
destroy_dev vdg.disk $journal
|
||||
@ -376,8 +484,8 @@ function activate_dmcrypt_dev_body() {
|
||||
local disk=$1
|
||||
local journal=$2
|
||||
local newdisk=$3
|
||||
local uuid=$(uuidgen)
|
||||
local juuid=$(uuidgen)
|
||||
local uuid=$($uuidgen)
|
||||
local juuid=$($uuidgen)
|
||||
|
||||
setup
|
||||
run_mon
|
||||
@ -393,12 +501,15 @@ function test_activate_dmcrypt_dev() {
|
||||
return 0
|
||||
fi
|
||||
|
||||
loop_sanity_check || return 1
|
||||
|
||||
local disk=$(create_dev vdf.disk)
|
||||
local journal=$(create_dev vdg.disk)
|
||||
local newdisk=$(create_dev vdh.disk)
|
||||
|
||||
activate_dmcrypt_dev_body $disk $journal $newdisk
|
||||
status=$?
|
||||
test $status != 0 && teardown
|
||||
|
||||
destroy_dmcrypt_dev vdf.disk $disk
|
||||
destroy_dmcrypt_dev vdg.disk $journal
|
||||
@ -411,8 +522,8 @@ function activate_dmcrypt_plain_dev_body() {
|
||||
local disk=$1
|
||||
local journal=$2
|
||||
local newdisk=$3
|
||||
local uuid=$(uuidgen)
|
||||
local juuid=$(uuidgen)
|
||||
local uuid=$($uuidgen)
|
||||
local juuid=$($uuidgen)
|
||||
|
||||
setup
|
||||
run_mon
|
||||
|
Loading…
Reference in New Issue
Block a user