blob: e902bf3e8390ffc0e73936b34029ee0fe006114c [file] [log] [blame]
Brian Freeman48d30542019-08-20 13:13:58 -05001#!/bin/bash
2
3if [ "$#" -ne 3 ]; then
4 echo "$0 <output.xml> <job> <build>"
5 exit 1
6fi
7ROBOT_OUTPUT=$1
8JOB=$2
9BUILD=$3
10
11INFLUX_ENDPOINT='http://10.145.123.16:8086/write?db=robot'
12
13TMP_XML=/tmp/output-$JOB-$BUILD.xml
14
15if [ ! -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
22fi
23
24
25TIMESTR=$(xmlstarlet sel -t -v "/robot/@generated" $TMP_XML)
26TIME=$(date -d "${TIMESTR}Z" +%s%N)
27
28POINTS_FILE=/tmp/points-$JOB-$BUILD.txt
29rm -f $POINTS_FILE
30
31# test
32xmlstarlet 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
44done
45
46# suite
47xmlstarlet 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
62done
63
64# tag
65xmlstarlet 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
70done
71
72curl -i $INFLUX_ENDPOINT --data-binary @$POINTS_FILE