Merge "jjb: infra: bifrost-verify.sh: Always create the landing page"
[releng.git] / jjb / infra / 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     echo "Uploading build logs to ${BIFROST_LOG_URL}"
21
22     echo "Uploading console output"
23     curl -s -L ${BIFROST_CONSOLE_LOG} > ${WORKSPACE}/build_log.txt
24     gsutil -q cp -Z ${WORKSPACE}/build_log.txt ${BIFROST_GS_URL}/build_log.txt
25     rm ${WORKSPACE}/build_log.txt
26
27     if [[ -d ${WORKSPACE}/logs ]]; then
28         pushd ${WORKSPACE}/logs &> /dev/null
29         for x in *.log; do
30             echo "Compressing and uploading $x"
31             gsutil -q cp -Z ${x} ${BIFROST_GS_URL}/${x}
32         done
33         popd &> /dev/null
34     fi
35
36     echo "Generating the landing page"
37     cat > ${WORKSPACE}/index.html <<EOF
38 <html>
39 <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>
40 <h2>Job: $JOB_NAME</h2>
41 <ul>
42 <li><a href=${BIFROST_LOG_URL}/build_log.txt>build_log.txt</a></li>
43 EOF
44
45     if [[ -d ${WORKSPACE}/logs ]]; then
46         pushd ${WORKSPACE}/logs &> /dev/null
47         for x in *.log; do
48             echo "<li><a href=${BIFROST_LOG_URL}/${x}>${x}</a></li>" >> ${WORKSPACE}/index.html
49         done
50         popd &> /dev/null
51     fi
52
53     cat >> ${WORKSPACE}/index.html << EOF
54 </ul>
55 </html>
56 EOF
57
58     gsutil -q cp ${WORKSPACE}/index.html ${BIFROST_GS_URL}/index.html
59
60     rm ${WORKSPACE}/index.html
61 }
62
63 function fix_ownership() {
64     if [ -z "${JOB_URL+x}" ]; then
65         echo "Not running as part of Jenkins. Handle the logs manually."
66     else
67         # Make sure cache exists
68         [[ ! -d ${HOME}/.cache ]] && mkdir ${HOME}/.cache
69
70         sudo chown -R jenkins:jenkins $WORKSPACE
71         sudo chown -R jenkins:jenkins ${HOME}/.cache
72     fi
73 }
74
75 function cleanup_and_upload() {
76     original_exit=$?
77     fix_ownership
78     upload_logs
79     exit $original_exit
80 }
81
82 # check distro to see if we support it
83 if [[ ! "$DISTRO" =~ (trusty|centos7|suse) ]]; then
84     echo "Distro $DISTRO is not supported!"
85     exit 1
86 fi
87
88 # remove previously cloned repos
89 sudo /bin/rm -rf /opt/bifrost /opt/puppet-infracloud /opt/stack /opt/releng
90
91 # Fix up permissions
92 fix_ownership
93
94 # clone all the repos first and checkout the patch afterwards
95 sudo git clone https://git.openstack.org/openstack/bifrost /opt/bifrost
96 sudo git clone https://git.openstack.org/openstack-infra/puppet-infracloud /opt/puppet-infracloud
97 sudo git clone https://gerrit.opnfv.org/gerrit/releng /opt/releng
98
99 # checkout the patch
100 cd $CLONE_LOCATION
101 sudo git fetch $PROJECT_REPO $GERRIT_REFSPEC && sudo git checkout FETCH_HEAD
102
103 # combine opnfv and upstream scripts/playbooks
104 sudo /bin/cp -rf /opt/releng/prototypes/bifrost/* /opt/bifrost/
105
106 # place bridge creation file on the right path
107 sudo mkdir -p /opt/puppet-infracloud/files/elements/infra-cloud-bridge/static/opt
108 sudo cp /opt/puppet-infracloud/templates/bifrost/create_bridge.py.erb /opt/puppet-infracloud/files/elements/infra-cloud-bridge/static/opt/create_bridge.py
109
110 # replace bridge name
111 sudo sed -i s/"<%= @bridge_name -%>"/br_opnfv/g /opt/puppet-infracloud/files/elements/infra-cloud-bridge/static/opt/create_bridge.py
112
113 # cleanup remnants of previous deployment
114 cd /opt/bifrost
115 sudo -E ./scripts/destroy-env.sh
116
117 # provision 3 VMs; jumphost, controller, and compute
118 cd /opt/bifrost
119 sudo -E ./scripts/test-bifrost-deployment.sh
120
121 # list the provisioned VMs
122 cd /opt/bifrost
123 source env-vars
124 ironic node-list
125 virsh list