xci: Create periodic bifrost jobs to find working version
[releng.git] / jjb / xci / bifrost-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/releng /opt/functest
42
43 # Fix up permissions
44 fix_ownership
45
46 # ensure the versions to checkout are set
47 export OPENSTACK_BIFROST_VERSION=${OPENSTACK_BIFROST_VERSION:-master}
48 export OPNFV_RELENG_VERSION=${OPNFV_RELENG_VERSION:-master}
49
50 # log some info
51 echo -e "\n"
52 echo "***********************************************************************"
53 echo "*                                                                     *"
54 echo "*                      Provision OpenStack Nodes                      *"
55 echo "*                                                                     *"
56 echo "                       bifrost version: $OPENSTACK_BIFROST_VERSION"
57 echo "                       releng version: $OPNFV_RELENG_VERSION"
58 echo "*                                                                     *"
59 echo "***********************************************************************"
60 echo -e "\n"
61
62 # clone the repos and checkout the versions
63 sudo git clone --quiet https://git.openstack.org/openstack/bifrost /opt/bifrost
64 cd /opt/bifrost && sudo git checkout --quiet $OPENSTACK_BIFROST_VERSION
65 echo "xci: using bifrost commit"
66 git show --oneline -s --pretty=format:'%h - %s (%cr) <%an>'
67
68 sudo git clone --quiet https://gerrit.opnfv.org/gerrit/releng /opt/releng
69 cd /opt/releng && sudo git checkout --quiet $OPNFV_RELENG_VERSION
70 echo "xci: using releng commit"
71 git show --oneline -s --pretty=format:'%h - %s (%cr) <%an>'
72
73 # combine opnfv and upstream scripts/playbooks
74 sudo /bin/cp -rf /opt/releng/prototypes/bifrost/* /opt/bifrost/
75
76 # cleanup remnants of previous deployment
77 cd /opt/bifrost
78 sudo -E ./scripts/destroy-env.sh
79
80 # provision 6 VMs; xcimaster, controller00, controller01, controller02, compute00, and compute01
81 cd /opt/bifrost
82 sudo -E ./scripts/bifrost-provision.sh
83
84 # list the provisioned VMs
85 cd /opt/bifrost
86 source env-vars
87 ironic node-list
88 virsh list
89
90
91 echo "OpenStack nodes are provisioned!"
92 # here we have to do something in order to capture what was the working sha1
93 # hardcoding stuff for the timebeing
94
95 cd /opt/bifrost
96 BIFROST_GIT_SHA1=$(git rev-parse HEAD)
97
98 # log some info
99 echo -e "\n"
100 echo "***********************************************************************"
101 echo "*                       BIFROST SHA1 TO PIN                           *"
102 echo "*                                                                     *"
103 echo "    $BIFROST_GIT_SHA1"
104 echo "*                                                                     *"
105 echo "***********************************************************************"
106
107 echo -e "\n"