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