Merge "xci: Enable VM provisioning using bifrost for daily runs"
[releng.git] / jjb / xci / xci-provision.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 fix_ownership() {
17     if [ -z "${JOB_URL+x}" ]; then
18         echo "Not running as part of Jenkins. Handle the logs manually."
19     else
20         # Make sure cache exists
21         [[ ! -d ${HOME}/.cache ]] && mkdir ${HOME}/.cache
22
23         sudo chown -R jenkins:jenkins $WORKSPACE
24         sudo chown -R jenkins:jenkins ${HOME}/.cache
25     fi
26 }
27
28 function cleanup_and_upload() {
29     original_exit=$?
30     fix_ownership
31     exit $original_exit
32 }
33
34 # check distro to see if we support it
35 if [[ ! "$DISTRO" =~ (xenial|centos7|suse) ]]; then
36     echo "Distro $DISTRO is not supported!"
37     exit 1
38 fi
39
40 # remove previously cloned repos
41 sudo /bin/rm -rf /opt/bifrost /opt/openstack-ansible /opt/stack /opt/releng /opt/functest
42
43 # Fix up permissions
44 fix_ownership
45
46 # clone all the repos first and checkout the patch afterwards
47 OPENSTACK_BRANCH=${OPENSTACK_BRANCH:-master}
48 OPNFV_BRANCH=${OPNFV_BRANCH:-master}
49 sudo git clone -b $OPENSTACK_BRANCH https://git.openstack.org/openstack/bifrost /opt/bifrost
50 sudo git clone -b $OPNFV_BRANCH https://gerrit.opnfv.org/gerrit/releng /opt/releng
51
52 # this script will be reused for promoting bifrost versions and using
53 # promoted bifrost versions as part of xci daily.
54 USE_PROMOTED_VERSIONS=${USE_PROMOTED_VERSIONS:-false}
55 if [ $USE_PROMOTED_VERSIONS = "true" ]; then
56     echo "TBD: Will use the promoted versions of openstack/opnfv projects"
57 fi
58
59 # combine opnfv and upstream scripts/playbooks
60 sudo /bin/cp -rf /opt/releng/prototypes/bifrost/* /opt/bifrost/
61
62 # cleanup remnants of previous deployment
63 cd /opt/bifrost
64 sudo -E ./scripts/destroy-env.sh
65
66 # provision 6 VMs; jumphost, controller00, controller01, controller02, compute00, and compute01
67 cd /opt/bifrost
68 sudo -E ./scripts/osa-bifrost-deployment.sh
69
70 # list the provisioned VMs
71 cd /opt/bifrost
72 source env-vars
73 ironic node-list
74 virsh list