Whamcloud - gitweb
LU-814 test: automate NFS over lustre testing
[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 -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     TEST_DISTRO=$(release)
92     LUSTRE_VERSION=$(lctl lustre_build_version | awk '/Lustre version:/ {print $3}')
93     LUSTRE_BUILD=${LUSTRE_BUILD_SOURCE:-$(sed 's/-.*//' <<<$LUSTRE_VERSION)}
94
95 cat <<EOF
96     lbats_build_id: $LBATS_ID
97     lbats_build_name: $LBATS_NAME
98     architecture: $(uname -m)
99     os: $(uname -o)
100     os_distribution: $TEST_DISTRO
101     lustre_version: $LUSTRE_VERSION
102     lustre_build: $LUSTRE_BUILD
103     kernel_version: $(uname -r)
104 EOF
105 }
106
107 yml_node_info()
108 {
109     mem=$(awk '/MemTotal:/ {print $2 " " $3}' /proc/meminfo)
110 cat <<EOF
111     node_name: $(hostname -s)
112     mem_size: $mem
113     architecture: $(uname -m)
114     networks:
115 EOF
116     for nw in $(lctl list_nids | grep -v @lo | cut -f 2 -d '@' | uniq); do
117         printf "        - $nw\n"
118     done
119 }
120
121 yml_entity() {
122     cat<<EOF
123 -
124     node_type: $1
125     node_name: $2
126 EOF
127 }
128
129 yml_entities() {
130     local host
131     for num in $(seq $MDSCOUNT); do
132         host=$(short_hostname $(facet_active_host mds$num))
133         yml_entity "MDS $num" $host >> $logdir/node.$host.yml
134     done
135
136     for num in $(seq $OSTCOUNT); do
137         host=$(short_hostname $(facet_active_host ost$num))
138         yml_entity "OST $num" $host >> $logdir/node.$host.yml
139     done
140
141     i=1
142     for host in ${CLIENTS//,/ }; do
143         host=$(short_hostname $host)
144         yml_entity "Client $i" $host >> $logdir/node.$host.yml
145         i=$((i+1))
146     done
147 }
148
149 yml_log_test() {
150     if [ $1 != "FINISHED" ]; then
151         cat <<EOF
152 -
153         name: $1
154         description: $TESTSUITE $1
155         submission: $(date)
156         report_version: 2
157         SubTests:
158 EOF
159     fi
160 }
161
162 yml_log_test_status() {
163     cat <<EOF
164         duration: $1
165         status: $2
166 EOF
167 }
168
169 yml_log_sub_test_begin() {
170     cat <<EOF
171         -
172             name: $1
173 EOF
174 }
175
176 yml_log_sub_test_end() {
177     cat <<EOF
178             status: $1
179             duration: $2
180             return_code: $3
181 EOF
182     shift 3
183     if [ -z "$*" ]; then
184         printf '            error:\n'
185     else
186         printf '            error: "%q"\n' "$*"
187     fi
188 }
189
190 yml_log_sub_test_log() {
191     cat <<EOF
192         -
193             name: $1
194             type: $2
195             location: $3
196 EOF
197 }