Whamcloud - gitweb
LU-7117 osp: set ptlrpc_request::rq_allow_replay properly
[fs/lustre-release.git] / lustre / tests / yaml.sh
1 #!/bin/bash
2 # vim: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 $(all_nodes)) \
21             "yml_node >> $logdir/node.\\\$(hostname -s).yml"
22     else
23         do_rpc_nodes $(comma_list $(all_nodes)) 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     #CodeReview
35     yml_code_review
36
37     # Tests
38     printf "Tests:\n"
39 }
40
41 # Called on the node for which we the info is needed.
42 yml_node() {
43     logdir=$1
44
45     printf "Build:\n"
46     yml_build_info
47     printf "\n"
48
49     printf "Node:\n"
50     yml_node_info
51     printf "\n"
52
53     printf "LustreEntities:\n"
54 }
55
56 yml_test_group() {
57     TEST_GROUP=${TEST_GROUP:-"acc-sm-$(hostname -s)"}
58     TEST_HOST=${TEST_HOST:-$(hostname -s)}
59     TEST_USER=${TEST_USER:-$USER}
60
61     # TestGroup information
62     cat <<EOF
63 TestGroup:
64     test_group: $TEST_GROUP
65     testhost: $TEST_HOST
66     submission: $(date)
67     user_name: $TEST_USER
68 EOF
69 }
70
71 yml_code_review() {
72     echo -e $CODE_REVIEW_YAML
73 }
74
75 release() {
76         if [ -r /etc/SuSE-release ]; then
77                 name=$(awk '/SUSE/ { printf("%s %s %s %s", $1, $2, $3, $4) }' \
78                         /etc/SuSE-release)
79                 version=$(sed -n -e 's/^VERSION = //p' /etc/SuSE-release)
80                 level=$(sed -n -e 's/^PATCHLEVEL = //p' /etc/SuSE-release)
81                 dist="${name} ${version}.${level}"
82         elif [ -r /etc/os-release ]; then
83                 name=$(sed -n -e 's/"//g' -e 's/^NAME=//p' /etc/os-release)
84                 version=$(sed -n -e 's/"//g' -e 's/^VERSION_ID=//p' \
85                         /etc/os-release)
86                 dist="${name} ${version}"
87         elif [ -r /etc/system-release ]; then
88                 dist=$(awk '/release/ \
89                         { printf("%s %s %s", $1, $2, $3) }' \
90                         /etc/system-release)
91         elif [ -r /etc/*-release ]; then
92                 dist=$(find /etc/ -maxdepth 1 -name '*release' 2> /dev/null | \
93                         sed -e 's/\/etc\///' -e 's/-release//' | head -n1)
94         else
95                 dist="UNKNOWN"
96         fi
97
98         echo $dist
99 }
100
101 yml_build_info() {
102         local TEST_DISTRO=$(release)
103         local LUSTRE_VERSION=$(lustre_build_version)
104         local LUSTRE_BUILD=${LUSTRE_BUILD_SOURCE:-$LUSTRE_VERSION}
105         local FILE_SYSTEM=$(node_fstypes $(hostname -s))
106
107 cat <<EOF
108     lbats_build_id: $LBATS_ID
109     lbats_build_name: $LBATS_NAME
110     architecture: $(uname -m)
111     os: $(uname -o)
112     os_distribution: $TEST_DISTRO
113     lustre_version: $LUSTRE_VERSION
114     lustre_build: $LUSTRE_BUILD
115     lustre_branch: $LUSTRE_BRANCH
116     lustre_revision: $LUSTRE_REVISION
117     kernel_version: $(uname -r)
118     file_system: ${FILE_SYSTEM:-"NA"}
119 EOF
120 }
121
122 yml_node_info()
123 {
124     mem=$(awk '/MemTotal:/ {print $2 " " $3}' /proc/meminfo)
125 cat <<EOF
126     node_name: $(hostname -s)
127     mem_size: $mem
128     architecture: $(uname -m)
129     networks:
130 EOF
131     for nw in $(lctl list_nids | grep -v @lo | cut -f 2 -d '@' | uniq); do
132         printf "        - $nw\n"
133     done
134 }
135
136 yml_entity() {
137     cat<<EOF
138 -
139     node_type: $1
140     node_name: $2
141 EOF
142 }
143
144 yml_entities() {
145         local host
146         local f_host
147         local i
148
149         if ! combined_mgs_mds; then
150                 host=$(short_hostname $(facet_active_host mgs))
151                 f_host=$(short_hostname $(facet_passive_host mgs))
152
153                 yml_entity "MGS" $host >> $logdir/node.$host.yml
154                 [[ -n $f_host ]] &&
155                         yml_entity "MGS" $f_host >> $logdir/node.$f_host.yml
156         fi
157
158         for i in $(seq $MDSCOUNT); do
159                 host=$(short_hostname $(facet_active_host mds$i))
160                 f_host=$(short_hostname $(facet_passive_host mds$i))
161
162                 yml_entity "MDS $i" $host >> $logdir/node.$host.yml
163                 [[ -n $f_host ]] &&
164                         yml_entity "MDS $i" $f_host >> $logdir/node.$f_host.yml
165         done
166
167         for i in $(seq $OSTCOUNT); do
168                 host=$(short_hostname $(facet_active_host ost$i))
169                 f_host=$(short_hostname $(facet_passive_host ost$i))
170
171                 yml_entity "OST $i" $host >> $logdir/node.$host.yml
172                 [[ -n $f_host ]] &&
173                         yml_entity "OST $i" $f_host >> $logdir/node.$f_host.yml
174         done
175
176         i=1
177         for host in ${CLIENTS//,/ }; do
178                 host=$(short_hostname $host)
179                 yml_entity "Client $i" $host >> $logdir/node.$host.yml
180                 i=$((i+1))
181         done
182 }
183
184 yml_log_test() {
185     if [ $1 != "FINISHED" ]; then
186         cat <<EOF
187 -
188         name: $1
189         description: $TESTSUITE $1
190         submission: $(date)
191         report_version: 2
192         SubTests:
193 EOF
194     fi
195 }
196
197 yml_log_test_status() {
198     cat <<EOF
199         duration: $1
200         status: $2
201 EOF
202 }
203
204 yml_log_sub_test_begin() {
205     cat <<EOF
206         -
207             name: $1
208 EOF
209 }
210
211 yml_log_sub_test_end() {
212     cat <<EOF
213             status: $1
214             duration: $2
215             return_code: $3
216 EOF
217     shift 3
218     if [ -z "$*" ]; then
219         printf '            error:\n'
220     else
221         printf '            error: "%q"\n' "$*"
222     fi
223 }
224
225 yml_log_sub_test_log() {
226     cat <<EOF
227         -
228             name: $1
229             type: $2
230             location: $3
231 EOF
232 }