Update table headers in the reporting page
[releng.git] / jjb / xci / bifrost-verify.sh
1 #!/bin/bash
2 # SPDX-license-identifier: Apache-2.0
3 ##############################################################################
4 # Copyright (c) 2016 Ericsson AB 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 -o errexit
11 set -o nounset
12 set -o pipefail
13
14 trap cleanup_and_upload EXIT
15
16 function upload_logs() {
17     BIFROST_CONSOLE_LOG="${BUILD_URL}/consoleText"
18     BIFROST_GS_URL=${BIFROST_LOG_URL/http:/gs:}
19
20     # Make sure the old landing page is gone in case
21     # we break later on. We don't want to publish
22     # stale information.
23     # TODO: Maybe cleanup the entire $BIFROST_GS_URL directory
24     # before we upload the new data.
25     gsutil -q rm ${BIFROST_GS_URL}/index.html || true
26
27     echo "Uploading collected bifrost build logs to ${BIFROST_LOG_URL}"
28
29     if [[ -d ${WORKSPACE}/logs ]]; then
30         pushd ${WORKSPACE}/logs &> /dev/null
31         for x in *.log; do
32             echo "Compressing and uploading $x"
33             gsutil -q cp -Z ${x} ${BIFROST_GS_URL}/${x}
34         done
35         popd &> /dev/null
36     fi
37
38     echo "Generating the ${BIFROST_LOG_URL}/index.html landing page"
39     cat > ${WORKSPACE}/index.html <<EOF
40 <html>
41 <h1>Build results for <a href=https://$GERRIT_NAME/#/c/$GERRIT_CHANGE_NUMBER/$GERRIT_PATCHSET_NUMBER>$GERRIT_NAME/$GERRIT_CHANGE_NUMBER/$GERRIT_PATCHSET_NUMBER</a></h1>
42 <h2>Job: <a href=${BUILD_URL}>$JOB_NAME</a></h2>
43 <ul>
44 <li><a href=${BIFROST_LOG_URL}/build_log.txt>build_log.txt</a></li>
45 EOF
46
47     if [[ -d ${WORKSPACE}/logs ]]; then
48         pushd ${WORKSPACE}/logs &> /dev/null
49         for x in *.log; do
50             echo "<li><a href=${BIFROST_LOG_URL}/${x}>${x}</a></li>" >> ${WORKSPACE}/index.html
51         done
52         popd &> /dev/null
53     fi
54
55     cat >> ${WORKSPACE}/index.html << EOF
56 </ul>
57 </html>
58 EOF
59
60     # Upload landing page
61     echo "Uploading the landing page"
62     gsutil -q cp ${WORKSPACE}/index.html ${BIFROST_GS_URL}/index.html
63     rm -f ${WORKSPACE}/index.html
64
65     # Finally, download and upload the entire build log so we can retain
66     # as much build information as possible
67     echo "Uploading the final console output"
68     curl -s -L ${BIFROST_CONSOLE_LOG} > ${WORKSPACE}/build_log.txt
69     gsutil -q cp -Z ${WORKSPACE}/build_log.txt ${BIFROST_GS_URL}/build_log.txt
70     rm -f ${WORKSPACE}/build_log.txt
71 }
72
73 function fix_ownership() {
74     if [ -z "${JOB_URL+x}" ]; then
75         echo "Not running as part of Jenkins. Handle the logs manually."
76     else
77         # Make sure cache exists
78         [[ ! -d ${HOME}/.cache ]] && mkdir ${HOME}/.cache
79
80         sudo chown -R jenkins:jenkins $WORKSPACE
81         sudo chown -R jenkins:jenkins ${HOME}/.cache
82     fi
83 }
84
85 function cleanup_and_upload() {
86     original_exit=$?
87     echo "Job exit code: $original_exit"
88     # Turn off errexit
89     set +o errexit
90     fix_ownership
91     upload_logs
92     exit $original_exit
93 }
94
95 # check distro to see if we support it
96 if [[ ! "$DISTRO" =~ (xenial|centos7|suse) ]]; then
97     echo "Distro $DISTRO is not supported!"
98     exit 1
99 fi
100
101 # remove previously cloned repos
102 /bin/rm -rf $WORKSPACE/bifrost $WORKSPACE/releng-xci
103
104 # Fix up permissions
105 fix_ownership
106
107 # clone all the repos first and checkout the patch afterwards
108 git clone https://git.openstack.org/openstack/bifrost $WORKSPACE/bifrost
109 git clone https://gerrit.opnfv.org/gerrit/releng-xci $WORKSPACE/releng-xci
110
111 # checkout the patch
112 cd $CLONE_LOCATION
113 git fetch $PROJECT_REPO $GERRIT_REFSPEC && sudo git checkout FETCH_HEAD
114
115 # combine opnfv and upstream scripts/playbooks
116 /bin/cp -rf $WORKSPACE/releng-xci/bifrost/* $WORKSPACE/bifrost/
117
118 # cleanup remnants of previous deployment
119 cd $WORKSPACE/bifrost
120 sudo -H -E ./scripts/destroy-env.sh
121
122 # provision 3 VMs; xcimaster, controller, and compute
123 cd $WORKSPACE/bifrost
124 ./scripts/bifrost-provision.sh
125
126 # list the provisioned VMs
127 cd $WORKSPACE/bifrost
128 source env-vars
129 ironic node-list
130 sudo -H -E virsh list