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