Skip to content

Commit

Permalink
ceph-disk: support and test the absence of PATH
Browse files Browse the repository at this point in the history
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 <loic@dachary.org>
  • Loading branch information
Loic Dachary committed Jan 30, 2014
1 parent 3f5e4f5 commit ad515bf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/ceph-disk
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/ceph.in
Expand Up @@ -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
Expand Down
21 changes: 15 additions & 6 deletions src/test/ceph-disk.sh
Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand All @@ -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 "
Expand Down

0 comments on commit ad515bf

Please sign in to comment.