Whamcloud - gitweb
b=22298 Buffalo should be able to detect test failures
[fs/lustre-release.git] / lustre / tests / yaml.sh
1 #!/bin/bash
2 # vim:expandtab:shiftwidth=4:softtabstop=4:tabstop=4:
3
4 #
5 # Shell routines for logging results to a yaml file.
6 #
7
8 split_output() {
9     while read line; do
10         host=${line%%:*};
11         echo "$line" | sed "s/^${host}: //" | sed "s/^${host}://" \
12             >> $logdir/node.$host.yml;
13     done
14 }
15
16 yml_nodes_file() {
17     export logdir=$1
18
19     if [ -f $logdir/shared ]; then
20         do_rpc_nodes $(comma_list $(nodes_list)) \
21             "yml_node >> $logdir/node.\\\$(hostname).yml"
22     else
23         do_rpc_nodes $(comma_list $(nodes_list)) yml_node | split_output
24     fi
25     yml_entities
26 }
27
28 yml_results_file() {
29     export logdir=$1
30
31     #TestGroup
32     yml_test_group
33
34     # Tests
35     printf "Tests:\n"
36 }
37
38 # Called on the node for which we the info is needed.
39 yml_node() {
40     local node=$(hostname)
41     logdir=$1
42
43     printf "Build:\n"
44     yml_build_info
45     printf "\n"
46
47     printf "Node:\n"
48     yml_node_info
49     printf "\n"
50
51     printf "LustreEntities:\n"
52 }
53
54 yml_test_group() {
55     TEST_GROUP=${TEST_GROUP:-"acc-sm-$(hostname)"}
56     TEST_HOST=${TEST_HOST:-$(hostname)}
57     TEST_USER=${TEST_USER:-$USER}
58
59     # TestGroup information
60     cat <<EOF
61 TestGroup:
62     test_group: $TEST_GROUP
63     testhost: $TEST_HOST
64     submission: $(date)
65     user_name: $TEST_USER
66
67 EOF
68 }
69
70 release() {
71    if [ -r /etc/lsb-release ]; then
72       dist=$(grep 'DISTRIB_ID' /etc/lsb-release | sed 's/DISTRIB_ID=//' | head -1)
73    elif [ -r /etc/redhat-release ]; then
74        dist=$(awk '/release/ { printf("%s %s %s", $1, $2, $3)}' /etc/redhat-release)
75    elif [ -r /etc/*-release ]; then
76        dist=$(find /etc/ -maxdepth 1 -name '*release' 2> /dev/null | \
77            sed -e 's/\/etc\///' -e 's/-release//' | head -1)
78    else
79        dist="UNKNOWN"
80    fi
81
82    echo $dist
83 }
84
85 yml_build_info() {
86     TEST_DISTRO=$(release)
87     LUSTRE_VERSION=$(lctl lustre_build_version | awk '/Lustre version:/ {print $3}')
88     LUSTRE_BUILD=$(sed 's/-.*//' <<<$LUSTRE_VERSION)
89
90 cat <<EOF
91     lbats_build_id: $LBATS_ID
92     lbats_build_name: $LBATS_NAME
93     architecture: $(uname -m)
94     os: $(uname -o)
95     os_distribution: $TEST_DISTRO
96     lustre_version: $LUSTRE_VERSION
97     lustre_build: $LUSTRE_BUILD
98     kernel_version: $(uname -r)
99 EOF
100 }
101
102 yml_node_info()
103 {
104     mem=$(awk '/MemTotal:/ {print $2 " " $3}' /proc/meminfo)
105 cat <<EOF
106     node_name: $(hostname)
107     mem_size: $mem
108     architecture: $(uname -m)
109     networks:
110 EOF
111     for nw in $(lctl list_nids | grep -v @lo | cut -f 2 -d '@' | uniq); do
112         printf "        - $nw\n"
113     done
114 }
115
116 yml_entity() {
117     cat<<EOF
118 -
119     node_type: $1
120     node_name: $2
121 EOF
122 }
123
124 yml_entities() {
125     local host
126     for num in $(seq $MDSCOUNT); do
127         host=$(facet_active_host mds$num)
128         yml_entity "MDS $num" $host >> $logdir/node.$host.yml
129     done
130
131     for num in $(seq $OSTCOUNT); do
132         host=$(facet_active_host ost$num)
133         yml_entity "OST $num" $host >> $logdir/node.$host.yml
134     done
135
136     i=1
137     for host in ${CLIENTS//,/ }; do
138         yml_entity "Client $i" $host >> $logdir/node.$host.yml
139         i=$((i+1))
140     done
141 }
142
143 yml_log_test() {
144     if [ $1 != "FINISHED" ]; then
145         cat <<EOF
146 -
147         name: $1
148         description: $TESTSUITE $1
149         submission: $(date)
150         report_version: 2
151         SubTests:
152 EOF
153     fi
154 }
155
156 yml_log_test_status() {
157     cat <<EOF
158         duration: $1
159         status: $2
160 EOF
161 }
162
163 yml_log_sub_test_begin() {
164     cat <<EOF
165         -
166             name: $1
167 EOF
168 }
169
170 yml_log_sub_test_end() {
171     cat <<EOF
172             status: $1
173             duration: $2
174             return_code: $3
175 EOF
176     shift 3
177     if [ -z "$*" ]; then
178         printf '            error:\n'
179     else
180         printf '            error: "%q"\n' "$*"
181     fi
182 }
183
184 yml_log_sub_test_log() {
185     cat <<EOF
186         -
187             name: $1
188             type: $2
189             location: $3
190 EOF
191 }