]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-disk: use ceph-detect-init instead of hard coded values 4532/head
authorLoic Dachary <ldachary@redhat.com>
Fri, 1 May 2015 14:46:48 +0000 (16:46 +0200)
committerLoic Dachary <ldachary@redhat.com>
Tue, 5 May 2015 23:54:36 +0000 (01:54 +0200)
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 <osynge@suse.com>
Signed-off-by: Loic Dachary <ldachary@redhat.com>
src/ceph-disk
src/test/ceph-disk.sh

index df05547e7029cc2b75ff6fc41c332b4e364f5539..207a5e7b87dff9735a85f4a3b15ac77049703233 100755 (executable)
@@ -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'):
index 27b78fec273ca394953493ba45bd47da5dab7552..dca322f9b070820ccd0079a5750a7655150c2418 100755 (executable)
@@ -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 $@