Whamcloud - gitweb
LU-913 test: Framework needs to record the test filesystem.
[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 $(nodes_list)) \
21             "yml_node >> $logdir/node.\\\$(hostname -s).yml"
22     else
23         do_rpc_nodes $(comma_list $(nodes_list)) 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     kernel_version: $(uname -r)
105     file_system: ${FILE_SYSTEM:-"NA"}
106 EOF
107 }
108
109 yml_node_info()
110 {
111     mem=$(awk '/MemTotal:/ {print $2 " " $3}' /proc/meminfo)
112 cat <<EOF
113     node_name: $(hostname -s)
114     mem_size: $mem
115     architecture: $(uname -m)
116     networks:
117 EOF
118     for nw in $(lctl list_nids | grep -v @lo | cut -f 2 -d '@' | uniq); do
119         printf "        - $nw\n"
120     done
121 }
122
123 yml_entity() {
124     cat<<EOF
125 -
126     node_type: $1
127     node_name: $2
128 EOF
129 }
130
131 yml_entities() {
132     local host
133     for num in $(seq $MDSCOUNT); do
134         host=$(short_hostname $(facet_active_host mds$num))
135         yml_entity "MDS $num" $host >> $logdir/node.$host.yml
136     done
137
138     for num in $(seq $OSTCOUNT); do
139         host=$(short_hostname $(facet_active_host ost$num))
140         yml_entity "OST $num" $host >> $logdir/node.$host.yml
141     done
142
143     i=1
144     for host in ${CLIENTS//,/ }; do
145         host=$(short_hostname $host)
146         yml_entity "Client $i" $host >> $logdir/node.$host.yml
147         i=$((i+1))
148     done
149 }
150
151 yml_log_test() {
152     if [ $1 != "FINISHED" ]; then
153         cat <<EOF
154 -
155         name: $1
156         description: $TESTSUITE $1
157         submission: $(date)
158         report_version: 2
159         SubTests:
160 EOF
161     fi
162 }
163
164 yml_log_test_status() {
165     cat <<EOF
166         duration: $1
167         status: $2
168 EOF
169 }
170
171 yml_log_sub_test_begin() {
172     cat <<EOF
173         -
174             name: $1
175 EOF
176 }
177
178 yml_log_sub_test_end() {
179     cat <<EOF
180             status: $1
181             duration: $2
182             return_code: $3
183 EOF
184     shift 3
185     if [ -z "$*" ]; then
186         printf '            error:\n'
187     else
188         printf '            error: "%q"\n' "$*"
189     fi
190 }
191
192 yml_log_sub_test_log() {
193     cat <<EOF
194         -
195             name: $1
196             type: $2
197             location: $3
198 EOF
199 }