87f9ec8db51e6dec9477518e40a0267dc2d7214c
[releng.git] / jjb / xci / xci-deploy.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/openstack-ansible /opt/stack /opt/releng /opt/functest
42
43 # Fix up permissions
44 fix_ownership
45
46 # openstack-ansible enables strict host key checking by default
47 export ANSIBLE_HOST_KEY_CHECKING=False
48
49 # ensure the versions to checkout are set
50 export OPENSTACK_OSA_VERSION=${OPENSTACK_OSA_VERSION:-master}
51 export OPNFV_RELENG_VERSION=${OPNFV_RELENG_VERSION:-master}
52
53 # log some info
54 echo -e "\n"
55 echo "***********************************************************************"
56 echo "*                                                                     *"
57 echo "*                         Deploy OpenStack                            *"
58 echo "*                                                                     *"
59 echo "                 openstack-ansible version: $OPENSTACK_OSA_VERSION"
60 echo "                       releng version: $OPNFV_RELENG_VERSION"
61 echo "*                                                                     *"
62 echo "***********************************************************************"
63 echo -e "\n"
64 # clone releng repo
65 sudo git clone --quiet https://gerrit.opnfv.org/gerrit/releng /opt/releng
66 cd /opt/releng && sudo git checkout --quiet $OPNFV_RELENG_VERSION
67 echo "xci: using openstack-ansible commit"
68 git show --oneline -s --pretty=format:'%h - %s (%cr) <%an>'
69
70 # display the nodes
71 echo "xci: OpenStack nodes"
72 cd /opt/bifrost
73 source env-vars
74 ironic node-list
75
76 # this script will be reused for promoting openstack-ansible versions and using
77 # promoted openstack-ansible versions as part of xci daily.
78 USE_PROMOTED_VERSIONS=${USE_PROMOTED_VERSIONS:-false}
79 if [ $USE_PROMOTED_VERSIONS = "true" ]; then
80     echo "TBD: Will use the promoted versions of openstack/opnfv projects"
81 fi
82
83 cd /opt/releng/prototypes/openstack-ansible/scripts
84 sudo -E ./osa-deploy.sh
85
86 # log some info
87 echo -e "\n"
88 echo "***********************************************************************"
89 echo "*                                                                     *"
90 echo "*                OpenStack deployment is completed!                   *"
91 echo "*                                                                     *"
92 echo "***********************************************************************"
93 echo -e "\n"