From: Loic Dachary Date: Fri, 1 May 2015 14:46:48 +0000 (+0200) Subject: ceph-disk: use ceph-detect-init instead of hard coded values X-Git-Tag: v9.0.2~221^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F4532%2Fhead;p=ceph.git ceph-disk: use ceph-detect-init instead of hard coded values The ceph-detect-init implements the same detection logic as ceph-deploy. It is better than the current hardcoded values that assume Ubuntu is upstart and all the rest is sysvinit. Signed-off-by: Owen Synge Signed-off-by: Loic Dachary --- diff --git a/src/ceph-disk b/src/ceph-disk index df05547e7029..207a5e7b87df 100755 --- a/src/ceph-disk +++ b/src/ceph-disk @@ -631,6 +631,20 @@ def write_one_line(parent, name, text): os.rename(tmp, path) +def init_get(): + """ + Get a init system using 'ceph-detect-init' + """ + init = _check_output( + args=[ + 'ceph-detect-init', + '--default', 'sysvinit', + ], + ) + init = must_be_one_line(init) + return init + + def check_osd_magic(path): """ Check that this path has the Ceph OSD magic. @@ -2155,11 +2169,7 @@ def activate( if conf_val is not None: init = conf_val else: - (distro, release, codename) = platform.dist() - if distro == 'Ubuntu': - init = 'upstart' - else: - init = 'sysvinit' + init = init_get() LOG.debug('Marking with init system %s', init) with file(os.path.join(path, init), 'w'): diff --git a/src/test/ceph-disk.sh b/src/test/ceph-disk.sh index 27b78fec273c..dca322f9b070 100755 --- a/src/test/ceph-disk.sh +++ b/src/test/ceph-disk.sh @@ -19,8 +19,16 @@ source test/test_btrfs_common.sh PS4='${FUNCNAME[0]}: $LINENO: ' -export PATH=:$PATH # make sure program from sources are prefered +export PATH=.:$PATH # make sure program from sources are prefered DIR=test-ceph-disk +virtualenv virtualenv-$DIR +. virtualenv-$DIR/bin/activate +( + if test -d ceph-detect-init/wheelhouse ; then + wheelhouse="--no-index --use-wheel --find-links=ceph-detect-init/wheelhouse" + fi + pip install $wheelhouse --editable ceph-detect-init +) OSD_DATA=$DIR/osd MON_ID=a MONA=127.0.0.1:7451 @@ -172,6 +180,46 @@ function test_no_path() { ( unset PATH ; test_activate_dir ) || return 1 } +function test_mark_init() { + run_mon + + local osd_data=$(pwd)/$DIR/dir + $mkdir -p $osd_data + + local osd_uuid=$($uuidgen) + + $mkdir -p $OSD_DATA + + ./ceph-disk $CEPH_DISK_ARGS \ + prepare --osd-uuid $osd_uuid $osd_data || return 1 + + $timeout $TIMEOUT ./ceph-disk $CEPH_DISK_ARGS \ + --verbose \ + activate \ + --mark-init=auto \ + --no-start-daemon \ + $osd_data || return 1 + + test -f $osd_data/$(ceph-detect-init) || return 1 + + if test systemd = $(ceph-detect-init) ; then + expected=sysvinit + else + expected=systemd + fi + $timeout $TIMEOUT ./ceph-disk $CEPH_DISK_ARGS \ + --verbose \ + activate \ + --mark-init=$expected \ + --no-start-daemon \ + $osd_data || return 1 + + ! test -f $osd_data/$(ceph-detect-init) || return 1 + test -f $osd_data/$expected || 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() { @@ -562,7 +610,9 @@ function run() { default_actions+="test_activate_dir_magic " default_actions+="test_activate_dir " default_actions+="test_keyring_path " + default_actions+="test_mark_init " local actions=${@:-$default_actions} + local status for action in $actions ; do setup set -x @@ -571,9 +621,11 @@ function run() { set +x teardown if test $status != 0 ; then - return $status + break fi done + rm -fr virtualenv-$DIR + return $status } run $@