eb57deb7bf40777271fc87899a32c3fea76aa421
[releng.git] / utils / push-test-logs.sh
1 #!/bin/bash
2 # SPDX-license-identifier: Apache-2.0
3 ##############################################################################
4 # Copyright (c) 2016 Orange and others.
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
10 set -e
11 set -o pipefail
12
13 export PATH=$PATH:/usr/local/bin/
14
15 git_sha1="$(git rev-parse HEAD)"
16 res_build_date=${1:-$(date -u +"%Y-%m-%d_%H-%M-%S")}
17 project=$PROJECT
18 branch=${BRANCH##*/}
19 testbed=$NODE_NAME
20 dir_result="${HOME}/opnfv/$project/results/${branch}"
21 # src: https://wiki.opnfv.org/display/INF/Hardware+Infrastructure
22 # + intel-pod12 (vsperf)
23 node_list=(\
24 'lf-pod1' 'lf-pod2' 'intel-pod2' 'intel-pod12' \
25 'lf-virtual2' 'lf-virtual3' \
26 'intel-pod5' 'intel-pod6' 'intel-pod7' 'intel-pod8' \
27 'ericsson-pod1' 'ericsson-pod2' \
28 'ericsson-virtual1' 'ericsson-virtual2'  'ericsson-virtual3' \
29 'ericsson-virtual4' 'ericsson-virtual5' 'ericsson-virtual12' \
30 'arm-pod1' 'arm-pod3' \
31 'huawei-pod1' 'huawei-pod2' 'huawei-pod3' 'huawei-pod4' 'huawei-pod5' \
32 'huawei-pod6' 'huawei-pod7' 'huawei-pod12' \
33 'huawei-virtual1' 'huawei-virtual2' 'huawei-virtual3' 'huawei-virtual4' \
34 'zte-pod2' \
35 'zte-virtual1')
36
37
38 if [[ ! " ${node_list[@]} " =~ " ${testbed} " ]]; then
39     echo "This is not a CI POD. Aborting pushing the logs to artifacts."
40     exit 0
41 fi
42
43 if [[ "$branch" == "master" ]]; then
44     project_artifact=logs/$project/$testbed/$res_build_date
45 else
46     project_artifact=logs/$project/$testbed/$branch/$res_build_date
47 fi
48
49 # create the folder to store the results
50 mkdir -p $dir_result
51
52 # copy folder to artifact
53 if [ -d "$dir_result" ]; then
54     if [ "$(ls -A $dir_result)" ]; then
55         set +e
56         gsutil&>/dev/null
57         if [ $? != 0 ]; then
58             echo "Not possible to push results to artifact: gsutil not installed";
59         else
60             gsutil ls gs://artifacts.opnfv.org/"$project"/ &>/dev/null
61             if [ $? != 0 ]; then
62                 echo "Not possible to push results to artifact: some error happened when using gsutil";
63             else
64                 echo "Uploading logs to artifact $project_artifact"
65                 gsutil -m cp -r "$dir_result"/* gs://artifacts.opnfv.org/"$project_artifact"/ >/dev/null 2>&1
66                 echo "Logs can be found in http://artifacts.opnfv.org/logs_${project}_${testbed}.html"
67                 cd $dir_result
68                 files=($(find . -name \* -print|sed 's/^\.//'|sed '/^\s*$/d'))
69                 for f in ${files[@]}; do
70                     echo "http://artifacts.opnfv.org/${project_artifact}${f}"
71                 done
72             fi
73         fi
74     else
75           echo "Result folder is empty"
76     fi
77 fi