fixing PR_NUMBER evaluation when there is no opnfv-tht-pr in the commit message
[apex.git] / build / undercloud.sh
1 #!/bin/sh
2 ##############################################################################
3 # Copyright (c) 2015 Tim Rozet (Red Hat), Dan Radez (Red Hat) and others.
4 #
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 -e
11 source ./cache.sh
12 source ./variables.sh
13
14 populate_cache "$rdo_images_uri/undercloud.qcow2"
15 if [ ! -d images ]; then mkdir images/; fi
16 cp -f cache/undercloud.qcow2 images/
17
18 #Adding OpenStack packages to undercloud
19 pushd images > /dev/null
20
21 # install the packages above and enabling ceph to live on the controller
22 # OpenWSMan package update supports the AMT Ironic driver for the TealBox
23 LIBGUESTFS_BACKEND=direct virt-customize \
24     --run-command "sed -i '/ControllerEnableCephStorage/c\\  ControllerEnableCephStorage: true' /usr/share/openstack-tripleo-heat-templates/environments/storage-environment.yaml" \
25     --run-command "sed -i '/  \$enable_ceph = /c\\  \$enable_ceph = true' /usr/share/openstack-tripleo-heat-templates/puppet/manifests/overcloud_controller_pacemaker.pp" \
26     --run-command "sed -i '/  \$enable_ceph = /c\\  \$enable_ceph = true' /usr/share/openstack-tripleo-heat-templates/puppet/manifests/overcloud_controller.pp" \
27     --run-command "curl http://download.opensuse.org/repositories/Openwsman/CentOS_CentOS-7/Openwsman.repo > /etc/yum.repos.d/wsman.repo" \
28     --run-command "yum update -y openwsman*" \
29     --run-command "cp /usr/share/instack-undercloud/undercloud.conf.sample /home/stack/undercloud.conf && chown stack:stack /home/stack/undercloud.conf" \
30     --upload ../opnfv-environment.yaml:/home/stack/ \
31     -a undercloud.qcow2
32
33 # Use apex tripleo-heat-templates fork
34 PR_NUMBER=""
35 REF="stable/colorado"
36 REPO="https://github.com/trozet/opnfv-tht"
37
38 if git log -1 | grep 'opnfv-tht-pr:' | grep -o '[0-9]*'; then
39   PR_NUMBER=$(git log -1 | grep 'opnfv-tht-pr:' | grep -o '[0-9]*')
40 fi
41
42 if [ "$PR_NUMBER" != "" ]; then
43   echo "Using pull request $PR_NUMBER from $REPO"
44   # Source credentials since we are rate limited to 60/day
45   GHCREDS=""
46   if [ -f ~/.githubcreds ]; then
47     source ~/.githubcreds
48     GHCREDS=" -u $GHUSERNAME:$GHACCESSTOKEN"
49   fi
50
51   PR=$(curl $GHCREDS https://api.github.com/repos/trozet/opnfv-tht/pulls/$PR_NUMBER)
52
53   # Do not pull from merged branches
54   MERGED=$(echo $PR | python -c "import sys,json; print json.load(sys.stdin)['head']['merged']")
55   if [ "$MERGED" == false ]; then
56     REF=$(echo $PR | python -c "import sys,json; print json.load(sys.stdin)['head']['ref']")
57     REPO=$(echo $PR | python -c "import sys,json; print json.load(sys.stdin)['head']['repo']['git_url']")
58   fi
59 fi
60
61 rm -rf opnfv-tht
62 git clone $REPO -b $REF opnfv-tht
63
64 pushd opnfv-tht > /dev/null
65 git archive --format=tar.gz --prefix=openstack-tripleo-heat-templates/ HEAD > ../opnfv-tht.tar.gz
66 popd > /dev/null
67 LIBGUESTFS_BACKEND=direct virt-customize --upload opnfv-tht.tar.gz:/usr/share \
68                                          --run-command "cd /usr/share && rm -rf openstack-tripleo-heat-templates && tar xzf opnfv-tht.tar.gz" \
69                                          -a undercloud.qcow2
70
71 popd > /dev/null
72