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