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