From: Kefu Chai Date: Sun, 21 May 2017 08:33:53 +0000 (+0800) Subject: test: switch from xmlstartlet to jq X-Git-Tag: ses5-milestone6~8^2~19^2~34 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=46bf019cbede41a5b22fa564990da371af50ef41;p=ceph.git test: switch from xmlstartlet to jq Signed-off-by: Kefu Chai --- diff --git a/qa/workunits/ceph-helpers.sh b/qa/workunits/ceph-helpers.sh index 11d48290014..d8f69604145 100755 --- a/qa/workunits/ceph-helpers.sh +++ b/qa/workunits/ceph-helpers.sh @@ -761,8 +761,8 @@ function get_osds() { local poolname=$1 local objectname=$2 - local osds=$(ceph --format xml osd map $poolname $objectname 2>/dev/null | \ - $XMLSTARLET sel -t -m "//acting/osd" -v . -o ' ') + local osds=$(ceph --format json osd map $poolname $objectname 2>/dev/null | \ + jq '.acting | .[]') # get rid of the trailing space echo $osds } @@ -831,8 +831,7 @@ function get_pg() { local poolname=$1 local objectname=$2 - ceph --format xml osd map $poolname $objectname 2>/dev/null | \ - $XMLSTARLET sel -t -m "//pgid" -v . -n + ceph --format json osd map $poolname $objectname 2>/dev/null | jq -r '.pgid' } function test_get_pg() { @@ -865,9 +864,9 @@ function get_config() { local config=$3 CEPH_ARGS='' \ - ceph --format xml daemon $dir/ceph-$daemon.$id.asok \ + ceph --format json daemon $dir/ceph-$daemon.$id.asok \ config get $config 2> /dev/null | \ - $XMLSTARLET sel -t -m "//$config" -v . -n + jq -r ".$config" } function test_get_config() { @@ -901,10 +900,9 @@ function set_config() { local config=$3 local value=$4 - CEPH_ARGS='' \ - ceph --format xml daemon $dir/ceph-$daemon.$id.asok \ - config set $config $value 2> /dev/null | \ - $XMLSTARLET sel -Q -t -m "//success" -v . + test $(env CEPH_ARGS='' ceph --format json daemon $dir/ceph-$daemon.$id.asok \ + config set $config $value 2> /dev/null | \ + jq 'has("success")') == true } function test_set_config() { @@ -935,8 +933,8 @@ function get_primary() { local poolname=$1 local objectname=$2 - ceph --format xml osd map $poolname $objectname 2>/dev/null | \ - $XMLSTARLET sel -t -m "//acting_primary" -v . -n + ceph --format json osd map $poolname $objectname 2>/dev/null | \ + jq '.acting_primary' } function test_get_primary() { @@ -968,9 +966,8 @@ function get_not_primary() { local objectname=$2 local primary=$(get_primary $poolname $objectname) - ceph --format xml osd map $poolname $objectname 2>/dev/null | \ - $XMLSTARLET sel -t -m "//acting/osd[not(.='$primary')]" -v . -n | \ - head -1 + ceph --format json osd map $poolname $objectname 2>/dev/null | \ + jq ".acting | map(select (. != $primary)) | first" } function test_get_not_primary() { @@ -1058,12 +1055,13 @@ function test_objectstore_tool() { # @return 0 if recovery in progress, 1 otherwise # function get_is_making_recovery_progress() { - local progress=$(ceph --format xml status 2>/dev/null | \ - $XMLSTARLET sel \ - -t -m "//pgmap/recovering_keys_per_sec" -v . -o ' ' \ - -t -m "//pgmap/recovering_bytes_per_sec" -v . -o ' ' \ - -t -m "//pgmap/recovering_objects_per_sec" -v .) - test -n "$progress" + local recovery_progress + recovery_progress+=".recovering_keys_per_sec + " + recovery_progress+=".recovering_bytes_per_sec + " + recovery_progress+=".recovering_objects_per_sec" + local progress=$(ceph --format json status 2>/dev/null | \ + jq -r ".pgmap | $recovery_progress") + test "$progress" != null } function test_get_is_making_recovery_progress() { @@ -1087,17 +1085,11 @@ function test_get_is_making_recovery_progress() { # @return 0 on success, 1 on error # function get_num_active_clean() { - local expression="(" - expression+="contains(.,'active') and " - expression+="contains(.,'clean') and " - expression+="not(contains(.,'stale'))" - expression+=")" - # xmlstarlet 1.3.0 (which is on Ubuntu precise) - # add extra new lines that must be ignored with - # grep -v '^$' - ceph --format xml pg dump pgs 2>/dev/null | \ - $XMLSTARLET sel -t -m "//pg_stat/state[$expression]" -v . -n | \ - grep -cv '^$' + local expression + expression+="select(contains(\"active\") and contains(\"clean\")) | " + expression+="select(contains(\"stale\") | not)" + ceph --format json pg dump pgs 2>/dev/null | \ + jq "[.[] | .state | $expression] | length" } function test_get_num_active_clean() { @@ -1123,8 +1115,7 @@ function test_get_num_active_clean() { # @return 0 on success, 1 on error # function get_num_pgs() { - ceph --format xml status 2>/dev/null | \ - $XMLSTARLET sel -t -m "//pgmap/num_pgs" -v . + ceph --format json status 2>/dev/null | jq '.pgmap.num_pgs' } function test_get_num_pgs() { @@ -1154,8 +1145,8 @@ function test_get_num_pgs() { function get_last_scrub_stamp() { local pgid=$1 local sname=${2:-last_scrub_stamp} - ceph --format xml pg dump pgs 2>/dev/null | \ - $XMLSTARLET sel -t -m "//pg_stat[pgid='$pgid']/$sname" -v . + ceph --format json pg dump pgs 2>/dev/null | \ + jq -r ".[] | select(.pgid==\"$pgid\") | .$sname" } function test_get_last_scrub_stamp() { diff --git a/src/test/mon/misc.sh b/src/test/mon/misc.sh index 10984e31344..7daf378b80e 100755 --- a/src/test/mon/misc.sh +++ b/src/test/mon/misc.sh @@ -122,7 +122,7 @@ function TEST_mon_add_to_single_mon() { # wait for the quorum timeout 120 ceph -s > /dev/null || return 1 local num_mons - num_mons=$(ceph mon dump --format=xml 2>/dev/null | $XMLSTARLET sel -t -v "count(//mons/mon)") || return 1 + num_mons=$(ceph mon dump --format=json 2>/dev/null | jq ".mons | length") || return 1 [ $num_mons == 2 ] || return 1 # no reason to take more than 120 secs to get this submitted timeout 120 ceph mon add b $MONB || return 1 diff --git a/src/test/mon/osd-crush.sh b/src/test/mon/osd-crush.sh index 3a873eb60f4..f4ba7de99d9 100755 --- a/src/test/mon/osd-crush.sh +++ b/src/test/mon/osd-crush.sh @@ -63,11 +63,10 @@ function TEST_crush_rule_dump() { local ruleset=ruleset1 ceph osd crush rule create-erasure $ruleset || return 1 - local expected - expected="$ruleset" - ceph --format xml osd crush rule dump $ruleset | grep $expected || return 1 - expected='"rule_name": "'$ruleset'"' - ceph osd crush rule dump | grep "$expected" || return 1 + test $(ceph --format json osd crush rule dump $ruleset | \ + jq ".rule_name == \"$ruleset\"") == true || return 1 + test $(ceph --format json osd crush rule dump | \ + jq "map(select(.rule_name == \"$ruleset\")) | length == 1") == true || return 1 ! ceph osd crush rule dump non_existent_ruleset || return 1 ceph osd crush rule rm $ruleset || return 1 } @@ -275,15 +274,15 @@ function TEST_crush_repair_faulty_crushmap() { # should be an empty crush map without any buckets success=false for delay in 1 2 4 8 16 32 64 128 256 ; do - if ! test $(ceph osd crush dump --format=xml | \ - $XMLSTARLET sel -t -m "//buckets/bucket" -v .) ; then + if test $(ceph osd crush dump --format=json | \ + jq '.buckets | length == 0') == true ; then success=true break fi sleep $delay done if ! $success ; then - ceph osd crush dump --format=xml + ceph osd crush dump --format=json-pretty return 1 fi # bring them down, the "ceph" commands will try to hunt for other monitor in @@ -296,8 +295,8 @@ function TEST_crush_repair_faulty_crushmap() { run_mon $dir b --public-addr $MONB || return 1 run_mon $dir c --public-addr $MONC || return 1 # the buckets are back - test $(ceph osd crush dump --format=xml | \ - $XMLSTARLET sel -t -m "//buckets/bucket" -v .) || return 1 + test $(ceph osd crush dump --format=json | \ + jq '.buckets | length > 0') == true || return 1 CEPH_ARGS=$CEPH_ARGS_orig }