Brian Freeman | 48d3054 | 2019-08-20 13:13:58 -0500 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | if [ "$#" -ne 3 ]; then |
| 4 | echo "$0 <output.xml> <job> <build>" |
| 5 | exit 1 |
| 6 | fi |
| 7 | ROBOT_OUTPUT=$1 |
| 8 | JOB=$2 |
| 9 | BUILD=$3 |
| 10 | |
| 11 | INFLUX_ENDPOINT='http://10.145.123.16:8086/write?db=robot' |
| 12 | |
| 13 | TMP_XML=/tmp/output-$JOB-$BUILD.xml |
| 14 | |
| 15 | if [ ! -f $TMP_XML ]; then |
| 16 | xmlstarlet ed -d '//kw' -d '//timeout' -d '//tags' $ROBOT_OUTPUT | tr -d '\n' > $TMP_XML |
| 17 | |
| 18 | # Canonicalize Robot suite names |
| 19 | sed -i 's/ONAP.Verify/ONAP_CI/g' $TMP_XML |
| 20 | sed -i 's/ONAP.Daily/ONAP_CI/g' $TMP_XML |
| 21 | sed -i 's/OpenECOMP.ETE/ONAP_CI/g' $TMP_XML |
| 22 | fi |
| 23 | |
| 24 | |
| 25 | TIMESTR=$(xmlstarlet sel -t -v "/robot/@generated" $TMP_XML) |
| 26 | TIME=$(date -d "${TIMESTR}Z" +%s%N) |
| 27 | |
| 28 | POINTS_FILE=/tmp/points-$JOB-$BUILD.txt |
| 29 | rm -f $POINTS_FILE |
| 30 | |
| 31 | # test |
| 32 | xmlstarlet sel -t -m "//test" -c "." -n $TMP_XML | while read test; do |
| 33 | NAME=$(echo "$test" | xmlstarlet sel -t -v "/test/@name" | tr ' ' '_' | xmlstarlet unesc) |
| 34 | if [ "PASS" = $(echo "$test" | xmlstarlet sel -t -v "/test/status/@status" ) ]; then |
| 35 | PASS=1 |
| 36 | FAIL=0 |
| 37 | else |
| 38 | PASS=0 |
| 39 | FAIL=1 |
| 40 | fi |
| 41 | STARTTIME=$(date -d "$(echo $test | xmlstarlet sel -t -v "/test/status/@starttime")Z" +%s%N) |
| 42 | ENDTIME=$(date -d "$(echo $test | xmlstarlet sel -t -v "/test/status/@endtime")Z" +%s%N) |
| 43 | echo test,job=$JOB,name=$NAME build=$BUILD,pass=$PASS,fail=$FAIL,starttime=$STARTTIME,endtime=$ENDTIME $TIME | tee -a $POINTS_FILE |
| 44 | done |
| 45 | |
| 46 | # suite |
| 47 | xmlstarlet sel -t -m "/robot/statistics/suite/stat" -c "." -n $TMP_XML | while read suite; do |
| 48 | ID=$(echo "$suite" | xmlstarlet sel -t -v "/stat/@id" ) |
| 49 | STATUS=$(xmlstarlet sel -t -m "//suite[@id=\"$ID\"]/status" -c "." -n $TMP_XML) |
| 50 | STARTTIMESTR=$(echo $STATUS | xmlstarlet sel -t -v "/status/@starttime") |
| 51 | ENDTIMESTR=$(echo $STATUS | xmlstarlet sel -t -v "/status/@endtime") |
| 52 | NAME=$(echo "$suite" | xmlstarlet sel -t -m "/stat" -v . | tr ' ' '_' | xmlstarlet unesc) |
| 53 | PASS=$(echo "$suite" | xmlstarlet sel -t -v "/stat/@pass" ) |
| 54 | FAIL=$(echo "$suite" | xmlstarlet sel -t -v "/stat/@fail" ) |
| 55 | if [ "$STARTTIMESTR" != "N/A" ] && [ "$ENDTIMESTR" != "N/A" ]; then |
| 56 | STARTTIME=$(date -d "${STARTTIMESTR}Z" +%s%N) |
| 57 | ENDTIME=$(date -d "${ENDTIMESTR}Z" +%s%N) |
| 58 | echo suite,job=$JOB,name=$NAME build=$BUILD,pass=$PASS,fail=$FAIL,starttime=$STARTTIME,endtime=$ENDTIME $TIME | tee -a $POINTS_FILE |
| 59 | else |
| 60 | echo suite,job=$JOB,name=$NAME build=$BUILD,pass=$PASS,fail=$FAIL $TIME | tee -a $POINTS_FILE |
| 61 | fi |
| 62 | done |
| 63 | |
| 64 | # tag |
| 65 | xmlstarlet sel -t -m "/robot/statistics/tag/stat" -c "." -n $TMP_XML | while read tag; do |
| 66 | NAME=$(echo "$tag" | xmlstarlet sel -t -m "/stat" -v . | tr ' ' '_' | xmlstarlet unesc) |
| 67 | PASS=$(echo "$tag" | xmlstarlet sel -t -v "/stat/@pass" ) |
| 68 | FAIL=$(echo "$tag" | xmlstarlet sel -t -v "/stat/@fail" ) |
| 69 | echo tag,job=$JOB,name=$NAME build=$BUILD,pass=$PASS,fail=$FAIL $TIME | tee -a $POINTS_FILE |
| 70 | done |
| 71 | |
| 72 | curl -i $INFLUX_ENDPOINT --data-binary @$POINTS_FILE |