From ad515bfec34378aa7c922f746fb1fbe063dc5c2f Mon Sep 17 00:00:00 2001 From: Loic Dachary Date: Wed, 29 Jan 2014 11:00:08 +0100 Subject: [PATCH] ceph-disk: support and test the absence of PATH Although this is not exactly the context in which ceph-disk is run when invoked by udev, it makes sure there is at least one sensible way of using it when PATH is undefined. Also make src/ceph.in not fail if PATH is not defined. Signed-off-by: Loic Dachary --- src/ceph-disk | 2 +- src/ceph.in | 2 +- src/test/ceph-disk.sh | 21 +++++++++++++++------ 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/ceph-disk b/src/ceph-disk index 96295e2f203e3..53e0afd986d88 100755 --- a/src/ceph-disk +++ b/src/ceph-disk @@ -2479,7 +2479,7 @@ def main(): ) if args.prepend_to_path != '': - path = os.environ.get('PATH', '') + path = os.environ.get('PATH', os.defpath) os.environ['PATH'] = args.prepend_to_path + ":" + path setup_statedir(args.statedir) diff --git a/src/ceph.in b/src/ceph.in index 57816d35b422c..c1f5a84c48e95 100755 --- a/src/ceph.in +++ b/src/ceph.in @@ -44,7 +44,7 @@ if MYDIR.endswith('src') and \ print >> sys.stderr, DEVMODEMSG os.execvp('python', ['python'] + sys.argv) sys.path.insert(0, os.path.join(MYDIR, 'pybind')) - if MYDIR not in os.environ['PATH']: + if os.environ.has_key('PATH') and MYDIR not in os.environ['PATH']: os.environ['PATH'] += ':' + MYDIR import argparse diff --git a/src/test/ceph-disk.sh b/src/test/ceph-disk.sh index a8a365ff250c5..35e2702669681 100755 --- a/src/test/ceph-disk.sh +++ b/src/test/ceph-disk.sh @@ -37,6 +37,10 @@ CEPH_DISK_ARGS+=" --prepend-to-path=" CEPH_DISK_ARGS+=" --verbose" TIMEOUT=360 +cat=$(which cat) +timeout=$(which timeout) +diff=$(which diff) + function setup() { teardown mkdir $DIR @@ -139,6 +143,10 @@ function test_path() { tweak_path use_path || return 1 } +function test_no_path() { + ( unset PATH ; test_activate_dir ) || return 1 +} + # ceph-disk prepare returns immediately on success if the magic file # exists on the --osd-data directory. function test_activate_dir_magic() { @@ -179,18 +187,18 @@ function test_activate_dir() { prepare $osd_data || return 1 CEPH_ARGS="$CEPH_ARGS --osd-journal-size=100 --osd-data=$osd_data" \ - timeout $TIMEOUT ./ceph-disk $CEPH_DISK_ARGS \ + $timeout $TIMEOUT ./ceph-disk $CEPH_DISK_ARGS \ activate \ --mark-init=none \ $osd_data || return 1 - timeout $TIMEOUT ./ceph osd pool set data size 1 || return 1 - local id=$(cat $osd_data/whoami) + $timeout $TIMEOUT ./ceph osd pool set data size 1 || return 1 + local id=$($cat $osd_data/whoami) local weight=1 ./ceph osd crush add osd.$id $weight root=default host=localhost || return 1 echo FOO > $DIR/BAR - timeout $TIMEOUT ./rados --pool data put BAR $DIR/BAR || return 1 - timeout $TIMEOUT ./rados --pool data get BAR $DIR/BAR.copy || return 1 - diff $DIR/BAR $DIR/BAR.copy || return 1 + $timeout $TIMEOUT ./rados --pool data put BAR $DIR/BAR || return 1 + $timeout $TIMEOUT ./rados --pool data get BAR $DIR/BAR.copy || return 1 + $diff $DIR/BAR $DIR/BAR.copy || return 1 } function test_find_cluster_by_uuid() { @@ -209,6 +217,7 @@ function test_find_cluster_by_uuid() { function run() { local default_actions default_actions+="test_path " + default_actions+="test_no_path " default_actions+="test_find_cluster_by_uuid " default_actions+="test_prepend_to_path " default_actions+="test_activate_dir_magic "