Whamcloud - gitweb
LU-16500 utils: 'lfs migrate' should select new OSTs
[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 nid in $(lctl list_nids | grep -v @lo ); do
131         printf "        - ${nid##*@}\n"
132     done | sort -u
133     echo "    nids:"
134     for nid in $(lctl list_nids | grep -v @lo ); do
135         printf "        - $nid\n"
136     done
137 }
138
139 yml_entity() {
140     cat<<EOF
141 -
142     node_type: $1
143     node_name: $2
144 EOF
145 }
146
147 yml_entities() {
148         local host
149         local f_host
150         local i
151
152         if ! combined_mgs_mds; then
153                 host=$(short_hostname $(facet_active_host mgs))
154                 f_host=$(short_hostname $(facet_passive_host mgs))
155
156                 yml_entity "MGS" $host >> $logdir/node.$host.yml
157                 [[ -n $f_host ]] &&
158                         yml_entity "MGS" $f_host >> $logdir/node.$f_host.yml
159         fi
160
161         for i in $(seq $MDSCOUNT); do
162                 host=$(short_hostname $(facet_active_host mds$i))
163                 f_host=$(short_hostname $(facet_passive_host mds$i))
164
165                 yml_entity "MDS $i" $host >> $logdir/node.$host.yml
166                 [[ -n $f_host ]] &&
167                         yml_entity "MDS $i" $f_host >> $logdir/node.$f_host.yml
168         done
169
170         for i in $(seq $OSTCOUNT); do
171                 host=$(short_hostname $(facet_active_host ost$i))
172                 f_host=$(short_hostname $(facet_passive_host ost$i))
173
174                 yml_entity "OST $i" $host >> $logdir/node.$host.yml
175                 [[ -n $f_host ]] &&
176                         yml_entity "OST $i" $f_host >> $logdir/node.$f_host.yml
177         done
178
179         i=1
180         for host in ${CLIENTS//,/ }; do
181                 host=$(short_hostname $host)
182                 yml_entity "Client $i" $host >> $logdir/node.$host.yml
183                 i=$((i+1))
184         done
185 }
186
187 yml_log_test() {
188     if [ $1 != "FINISHED" ]; then
189         cat <<EOF
190 -
191         name: $1
192         description: $TESTSUITE $1
193         submission: $(date)
194         report_version: 2
195         SubTests:
196 EOF
197     fi
198 }
199
200 yml_log_test_status() {
201     cat <<EOF
202         duration: $1
203         status: $2
204 EOF
205 }
206
207 yml_log_sub_test_begin() {
208     cat <<EOF
209         -
210             name: $1
211 EOF
212 }
213
214 yml_log_sub_test_end() {
215     cat <<EOF
216             status: $1
217             duration: $2
218             return_code: $3
219 EOF
220     shift 3
221     if [ -z "$*" ]; then
222         printf '            error:\n'
223     else
224         printf '            error: "%q"\n' "$*"
225     fi
226 }
227
228 yml_log_sub_test_log() {
229     cat <<EOF
230         -
231             name: $1
232             type: $2
233             location: $3
234 EOF
235 }