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