Whamcloud - gitweb
4dbdfe74329ec7abd79c9fa8933684785bcab06a
[fs/lustre-release.git] / lustre / tests / yaml.sh
1 #!/bin/bash
2 # vim:expandtab: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).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     # Tests
35     printf "Tests:\n"
36 }
37
38 # Called on the node for which we the info is needed.
39 yml_node() {
40     local node=$(hostname)
41     logdir=$1
42
43     printf "Build:\n"
44     yml_build_info
45     printf "\n"
46
47     printf "Node:\n"
48     yml_node_info
49     printf "\n"
50
51     printf "LustreEntities:\n"
52 }
53
54 yml_test_group() {
55     TEST_GROUP=${TEST_GROUP:-"acc-sm-$(hostname)"}
56     TEST_HOST=${TEST_HOST:-$(hostname)}
57     TEST_USER=${TEST_USER:-$USER}
58
59     # TestGroup information
60     cat <<EOF
61 TestGroup:
62     test_group: $TEST_GROUP
63     testhost: $TEST_HOST
64     submission: $(date)
65     user_name: $TEST_USER
66
67 EOF
68 }
69
70 release() {
71    if [ -r /etc/lsb-release ]; then
72       dist=$(grep 'DISTRIB_ID' /etc/lsb-release | sed 's/DISTRIB_ID=//' | head -1)
73    elif [ -r /etc/redhat-release ]; then
74        dist=$(awk '/release/ { printf("%s %s %s", $1, $2, $3)}' /etc/redhat-release)
75    elif [ -r /etc/*-release ]; then
76        dist=$(find /etc/ -maxdepth 1 -name '*release' 2> /dev/null | \
77            sed -e 's/\/etc\///' -e 's/-release//' | head -1)
78    else
79        dist="UNKNOWN"
80    fi
81
82    echo $dist
83 }
84
85 yml_build_info() {
86     TEST_DISTRO=$(release)
87     LUSTRE_VERSION=$(lctl lustre_build_version | awk '/Lustre version:/ {print $3}')
88     LUSTRE_BUILD=$(sed 's/-.*//' <<<$LUSTRE_VERSION)
89
90 cat <<EOF
91     lbats_build_id: $LBATS_ID
92     lbats_build_name: $LBATS_NAME
93     architecture: $(uname -m)
94     os: $(uname -o)
95     os_distribution: $TEST_DISTRO
96     lustre_version: $LUSTRE_VERSION
97     lustre_build: $LUSTRE_BUILD
98     kernel_version: $(uname -r)
99 EOF
100 }
101
102 yml_node_info()
103 {
104     mem=$(awk '/MemTotal:/ {print $2 " " $3}' /proc/meminfo)
105 cat <<EOF
106     node_name: $(hostname)
107     mem_size: $mem
108     architecture: $(uname -m)
109     networks:
110 EOF
111     for nw in $(lctl list_nids | grep -v @lo | cut -f 2 -d '@' | uniq); do
112         printf "        - $nw\n"
113     done
114 }
115
116 yml_entity() {
117     cat<<EOF
118 -
119     node_type: $1
120     node_name: $2
121 EOF
122 }
123
124 yml_entities() {
125     local host
126     for num in $(seq $MDSCOUNT); do
127         host=$(facet_active_host mds$num)
128         yml_entity "MDS $num" $host >> $logdir/node.$host.yml
129     done
130
131     for num in $(seq $OSTCOUNT); do
132         host=$(facet_active_host ost$num)
133         yml_entity "OST $num" $host >> $logdir/node.$host.yml
134     done
135
136     i=1
137     for host in ${CLIENTS//,/ }; do
138         yml_entity "Client $i" $host >> $logdir/node.$host.yml
139         i=$((i+1))
140     done
141 }
142
143 yml_log_test() {
144     if [ $1 != "FINISHED" ]; then
145         cat <<EOF
146 -
147         name: $1
148         description: $TESTSUITE $1
149         submission: $(date)
150         SubTests:
151 EOF
152     fi
153 }
154
155 yml_log_test_status() {
156     cat <<EOF
157     duration: $1
158     status: $2
159 EOF
160 }
161
162 yml_log_sub_test_begin() {
163     cat <<EOF
164         -
165             name: $1
166 EOF
167 }
168
169 yml_log_sub_test_end() {
170     cat <<EOF
171             status: $1
172             duration: $2
173             return_code: $3
174 EOF
175     shift 3
176     if [ -z "$*" ]; then
177         printf '            error:\n'
178     else
179         printf '            error: "%q"\n' "$*"
180     fi
181 }
182
183 yml_log_sub_test_log() {
184     cat <<EOF
185         -
186             name: $1
187             type: $2
188             location: $3
189 EOF
190 }