Whamcloud - gitweb
844099664b4ac82f70b30b368b4a45a134832b11
[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     TEST_PROJECT=${TEST_PROJECT:-"LUSTRE"}
61
62     # TestGroup information
63     cat <<EOF
64 TestGroup:
65     test_group: $TEST_GROUP
66     testhost: $TEST_HOST
67     submission: $(date)
68     user_name: $TEST_USER
69 project: $TEST_PROJECT
70 EOF
71 }
72
73 yml_code_review() {
74     echo -e $CODE_REVIEW_YAML
75 }
76
77 release() {
78         rhel_pat=".*release \([[:digit:]]\+\.[[:digit:]]\+\).*"
79
80         if [ -r /etc/centos-release ]; then
81                 name=$(sed -n -e "s/^\([A-Za-z]\+\).*/\1/p" /etc/centos-release)
82                 version=$(sed -n -e "s/${rhel_pat}/\1/p" /etc/centos-release)
83                 dist="${name} ${version}"
84         elif [ -r /etc/redhat-release ]; then
85                 version=$(sed -n -e "s/${rhel_pat}/\1/p" /etc/redhat-release)
86                 dist="RHEL ${version}"
87         elif [ -r /etc/os-release ]; then
88                 name=$(sed -n -e 's/"//g' -e 's/ [A-Za-z]*$//' \
89                         -e 's/^NAME=//p' /etc/os-release)
90                 version=$(sed -n -e 's/"//g' -e 's/^VERSION_ID=//p' \
91                 /etc/os-release)
92                 dist="${name} ${version}"
93         else
94                 dist="UNKNOWN"
95         fi
96
97         echo $dist
98 }
99
100 yml_build_info() {
101         local TEST_DISTRO=$(release)
102         local LUSTRE_VERSION=$(lustre_build_version)
103         local LUSTRE_BUILD=${LUSTRE_BUILD_SOURCE:-$LUSTRE_VERSION}
104         local FILE_SYSTEM=$(node_fstypes $(hostname -s))
105
106 cat <<EOF
107     lbats_build_id: $LBATS_ID
108     lbats_build_name: $LBATS_NAME
109     architecture: $(uname -m)
110     os: $(uname -o)
111     os_distribution: $TEST_DISTRO
112     version: $LUSTRE_VERSION
113     build: $LUSTRE_BUILD
114     branch: $LUSTRE_BRANCH
115     revision: $LUSTRE_REVISION
116     kernel_version: $(uname -r)
117     file_system: ${FILE_SYSTEM:-"NA"}
118 EOF
119 }
120
121 yml_node_info()
122 {
123     mem=$(awk '/MemTotal:/ {print $2 " " $3}' /proc/meminfo)
124 cat <<EOF
125     node_name: $(hostname -s)
126     mem_size: $mem
127     architecture: $(uname -m)
128     networks:
129 EOF
130     for nw in $(lctl list_nids | grep -v @lo | cut -f 2 -d '@' | uniq); do
131         printf "        - $nw\n"
132     done
133 }
134
135 yml_entity() {
136     cat<<EOF
137 -
138     node_type: $1
139     node_name: $2
140 EOF
141 }
142
143 yml_entities() {
144         local host
145         local f_host
146         local i
147
148         if ! combined_mgs_mds; then
149                 host=$(short_hostname $(facet_active_host mgs))
150                 f_host=$(short_hostname $(facet_passive_host mgs))
151
152                 yml_entity "MGS" $host >> $logdir/node.$host.yml
153                 [[ -n $f_host ]] &&
154                         yml_entity "MGS" $f_host >> $logdir/node.$f_host.yml
155         fi
156
157         for i in $(seq $MDSCOUNT); do
158                 host=$(short_hostname $(facet_active_host mds$i))
159                 f_host=$(short_hostname $(facet_passive_host mds$i))
160
161                 yml_entity "MDS $i" $host >> $logdir/node.$host.yml
162                 [[ -n $f_host ]] &&
163                         yml_entity "MDS $i" $f_host >> $logdir/node.$f_host.yml
164         done
165
166         for i in $(seq $OSTCOUNT); do
167                 host=$(short_hostname $(facet_active_host ost$i))
168                 f_host=$(short_hostname $(facet_passive_host ost$i))
169
170                 yml_entity "OST $i" $host >> $logdir/node.$host.yml
171                 [[ -n $f_host ]] &&
172                         yml_entity "OST $i" $f_host >> $logdir/node.$f_host.yml
173         done
174
175         i=1
176         for host in ${CLIENTS//,/ }; do
177                 host=$(short_hostname $host)
178                 yml_entity "Client $i" $host >> $logdir/node.$host.yml
179                 i=$((i+1))
180         done
181 }
182
183 yml_log_test() {
184     if [ $1 != "FINISHED" ]; then
185         cat <<EOF
186 -
187         name: $1
188         description: $TESTSUITE $1
189         submission: $(date)
190         report_version: 2
191         SubTests:
192 EOF
193     fi
194 }
195
196 yml_log_test_status() {
197     cat <<EOF
198         duration: $1
199         status: $2
200 EOF
201 }
202
203 yml_log_sub_test_begin() {
204     cat <<EOF
205         -
206             name: $1
207 EOF
208 }
209
210 yml_log_sub_test_end() {
211     cat <<EOF
212             status: $1
213             duration: $2
214             return_code: $3
215 EOF
216     shift 3
217     if [ -z "$*" ]; then
218         printf '            error:\n'
219     else
220         printf '            error: "%q"\n' "$*"
221     fi
222 }
223
224 yml_log_sub_test_log() {
225     cat <<EOF
226         -
227             name: $1
228             type: $2
229             location: $3
230 EOF
231 }