Skip to content

Commit

Permalink
osd_volume_activate: fix osd_volume_lvm function
Browse files Browse the repository at this point in the history
90511a4 introduced a bug in
osd_volume_lvm function.
OSDs couldn't start because `$CEPH_VOLUME_LIST_JSON` is seen as an empty
variable when consumed in this function.
Since there's no need to have a separate function for detecting the
volume type, let's refact this part of the code so we can fix this
issue.

Signed-off-by: Guillaume Abrioux <gabrioux@redhat.com>
(cherry picked from commit bbf493d)
  • Loading branch information
guits authored and dsavineau committed Sep 30, 2019
1 parent d78cc20 commit ef37aca
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions src/daemon/osd_scenarios/osd_volume_activate.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
#!/bin/bash
set -e

function get_osd_volume_type {
CEPH_VOLUME_LIST_JSON="$(ceph-volume lvm list --format json)"
#shellcheck disable=SC2153
if echo "$CEPH_VOLUME_LIST_JSON" | $PYTHON -c "import sys, json; print(json.load(sys.stdin)['$OSD_ID'])" &> /dev/null; then
echo "lvm"
else
echo "simple"
fi
}

function osd_volume_simple {
# Find the devices used by ceph-disk
DEVICES=$(ceph-volume inventory --format json | $PYTHON -c 'import sys, json; print(" ".join([d.get("path") for d in json.load(sys.stdin) if "Used by ceph-disk" in d.get("rejected_reasons")]))')
Expand All @@ -26,6 +16,7 @@ function osd_volume_simple {
done

# Find the OSD json file associated to the ID
#shellcheck disable=SC2153
OSD_JSON=$(grep -l "whoami\": ${OSD_ID}$" /etc/ceph/osd/*.json)
if [ -z "${OSD_JSON}" ]; then
log "OSD id ${OSD_ID} does not exist"
Expand All @@ -46,10 +37,10 @@ function get_dmcrypt_uuids {

function osd_volume_lvm {
# Find the OSD FSID from the OSD ID
OSD_FSID="$(echo "$CEPH_VOLUME_LIST_JSON" | $PYTHON -c "import sys, json; print(json.load(sys.stdin)[\"$OSD_ID\"][0][\"tags\"][\"ceph.osd_fsid\"])")"
OSD_FSID="$(echo "$CEPH_VOLUME_LIST_JSON" | $PYTHON -c "import sys, json; print(json.load(sys.stdin)['$OSD_ID'][0]['tags']['ceph.osd_fsid'])")"

# Find the OSD type
OSD_TYPE="$(echo "$CEPH_VOLUME_LIST_JSON" | $PYTHON -c "import sys, json; print(json.load(sys.stdin)[\"$OSD_ID\"][0][\"type\"])")"
OSD_TYPE="$(echo "$CEPH_VOLUME_LIST_JSON" | $PYTHON -c "import sys, json; print(json.load(sys.stdin)['$OSD_ID'][0]['type'])")"

# Discover the objectstore
if [[ "data journal" =~ $OSD_TYPE ]]; then
Expand All @@ -72,7 +63,14 @@ function osd_volume_lvm {
function osd_volume_activate {
: "${OSD_ID:?Give me an OSD ID to activate, eg: -e OSD_ID=0}"

OSD_VOLUME_TYPE=$(get_osd_volume_type)
CEPH_VOLUME_LIST_JSON="$(ceph-volume lvm list --format json)"

#shellcheck disable=SC2153
if echo "$CEPH_VOLUME_LIST_JSON" | $PYTHON -c "import sys, json; print(json.load(sys.stdin)['$OSD_ID'])" &> /dev/null; then
OSD_VOLUME_TYPE=lvm
else
OSD_VOLUME_TYPE=simple
fi

if [[ "$OSD_VOLUME_TYPE" == "lvm" ]]; then
osd_volume_lvm
Expand Down

0 comments on commit ef37aca

Please sign in to comment.