Skip to content

Commit

Permalink
Merge pull request #10625 from dachary/wip-16969-jewel
Browse files Browse the repository at this point in the history
jewel: src/script/subman fails with KeyError: 'nband'

Reviewed-by: Kefu Chai <kchai@redhat.com>
  • Loading branch information
Loic Dachary committed Aug 9, 2016
2 parents 954e978 + 5ae0e43 commit aacb793
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/script/subman
@@ -1,6 +1,7 @@
#!/usr/bin/env python -B
#!/usr/bin/env python

import json
import os
import re
import subprocess

Expand All @@ -13,8 +14,9 @@ for disk in disks:
df = subprocess.check_output("df --output=used " + partition['path'], shell=True)
used += int(re.findall('\d+', df)[0])

open("/etc/rhsm/facts/ceph_usage.facts", 'w').write("""
facts_file = os.environ.get("CEPH_FACTS_FILE", "/etc/rhsm/facts/ceph_usage.facts")
open(facts_file, 'w').write("""\
{
"band.storage.usage": {used}
}
""".format(used=used/(1024*1024*1024)))
""".replace('{used}', str(int(used/(1024*1024*1024)))))
1 change: 1 addition & 0 deletions src/test/CMakeLists.txt
Expand Up @@ -490,6 +490,7 @@ add_ceph_test(run-rbd-unit-tests.sh ${CMAKE_CURRENT_SOURCE_DIR}/run-rbd-unit-tes
add_ceph_test(run-cli-tests ${CMAKE_CURRENT_SOURCE_DIR}/run-cli-tests)
add_ceph_test(test_objectstore_memstore.sh ${CMAKE_CURRENT_SOURCE_DIR}/test_objectstore_memstore.sh)
add_ceph_test(test_pidfile.sh ${CMAKE_CURRENT_SOURCE_DIR}/test_pidfile.sh)
add_ceph_test(test_subman.sh ${CMAKE_CURRENT_SOURCE_DIR}/test_subman.sh)
add_ceph_test(unittest_bufferlist.sh ${CMAKE_SOURCE_DIR}/src/unittest_bufferlist.sh)

add_test(NAME run-tox-ceph-disk COMMAND bash ${CMAKE_SOURCE_DIR}/src/ceph-disk/run-tox.sh WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/src)
Expand Down
3 changes: 2 additions & 1 deletion src/test/Makefile.am
Expand Up @@ -93,7 +93,8 @@ check_SCRIPTS += \
test/mon/mon-handle-forward.sh \
test/libradosstriper/rados-striper.sh \
test/test_objectstore_memstore.sh \
test/test_pidfile.sh
test/test_pidfile.sh \
test/test_subman.sh

EXTRA_DIST += \
$(srcdir)/test/python/brag-client/setup.py \
Expand Down
28 changes: 28 additions & 0 deletions src/test/detect-build-env-vars.sh
@@ -0,0 +1,28 @@
#!/bin/bash

if [ -n "$CEPH_BUILD_DIR" ] && [ -n "$CEPH_ROOT" ] && [ -n "$CEPH_BIN" ] && [ -n "$CEPH_LIB" ]; then
echo "Enivronment Variables Already Set"
elif [ -e CMakeCache.txt ]; then
echo "Environment Variables Not All Set, Detected Build System CMake"
echo "Setting Environment Variables"
export CEPH_ROOT=`grep Ceph_SOURCE_DIR CMakeCache.txt | cut -d "=" -f 2`
export CEPH_BUILD_DIR=`pwd`
export CEPH_BIN=$CEPH_BUILD_DIR/bin
export CEPH_LIB=$CEPH_BUILD_DIR/lib
export PATH=$CEPH_BIN:$PATH
export LD_LIBRARY_PATH=$CEPH_LIB
elif [ -e .libs ]; then
echo "Environment Variables Not All Set, Detected Build System Autotools"
echo "Setting Environment Variables"
export CEPH_ROOT=".."
export CEPH_BUILD_DIR="."
export CEPH_BIN="."
export CEPH_LIB=".libs"
export PATH=.:$PATH
export LD_LIBRARY_PATH=".libs"
else
echo "Please execute this command out of the proper directory"
exit 1
fi


28 changes: 28 additions & 0 deletions src/test/test_subman.sh
@@ -0,0 +1,28 @@
#!/bin/bash -e

source $(dirname $0)/detect-build-env-vars.sh

TMP=$(mktemp --tmpdir -d)
trap "rm -fr $TMP" EXIT

export PATH=$TMP:$PATH

cat > $TMP/ceph-disk <<EOF
echo '[{"partition":[{"type":"data","path":"/dev/foo/bar"}]}]'
EOF
chmod +x $TMP/ceph-disk

cat > $TMP/df <<EOF
echo Used
echo $((2 * 1024 * 1024 * 1024))
EOF
chmod +x $TMP/df

cat > $TMP/expected <<EOF
{
"band.storage.usage": 2
}
EOF
export CEPH_FACTS_FILE=$TMP/facts
$CEPH_ROOT/src/script/subman
diff -u $CEPH_FACTS_FILE $TMP/expected

0 comments on commit aacb793

Please sign in to comment.