ed4f2b345f2cdeae257df3b4eb8bb26a5139f4e4
[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 # Use apex tripleo-heat-templates fork
22 PR_NUMBER=""
23 REF="stable/colorado"
24 REPO="https://github.com/trozet/opnfv-tht"
25
26 if git log -1 | grep 'opnfv-tht-pr:' | grep -o '[0-9]*'; then
27   PR_NUMBER=$(git log -1 | grep 'opnfv-tht-pr:' | grep -o '[0-9]*')
28 fi
29
30 if [ "$PR_NUMBER" != "" ]; then
31   echo "Using pull request $PR_NUMBER from $REPO"
32   # Source credentials since we are rate limited to 60/day
33   GHCREDS=""
34   if [ -f ~/.githubcreds ]; then
35     source ~/.githubcreds
36     GHCREDS=" -u $GHUSERNAME:$GHACCESSTOKEN"
37   fi
38
39   PR=$(curl $GHCREDS https://api.github.com/repos/trozet/opnfv-tht/pulls/$PR_NUMBER)
40
41   # Do not pull from merged branches
42   MERGED=$(python -c "import json; print json.loads('''$PR'''.replace('\n', '').replace('\r', ''))['merged']")
43   if [ "$MERGED" == "False" ]; then
44     REF=$(python -c "import json; print json.loads('''$PR'''.replace('\n', '').replace('\r', ''))['head']['ref']")
45     echo "Setting GitHub Ref to: $REF"
46     REPO=$(python -c "import json; print json.loads('''$PR'''.replace('\n', '').replace('\r', ''))['head']['repo']['git_url']")
47     echo "Setting GitHub URL to: $REPO"
48   fi
49 fi
50
51 rm -rf opnfv-tht
52 git clone $REPO -b $REF opnfv-tht
53
54 pushd opnfv-tht > /dev/null
55 git archive --format=tar.gz --prefix=openstack-tripleo-heat-templates/ HEAD > ../opnfv-tht.tar.gz
56 popd > /dev/null
57 LIBGUESTFS_BACKEND=direct virt-customize --upload opnfv-tht.tar.gz:/usr/share \
58                                          --run-command "cd /usr/share && rm -rf openstack-tripleo-heat-templates && tar xzf opnfv-tht.tar.gz" \
59                                          -a undercloud.qcow2
60
61 # install the packages above and enabling ceph to live on the controller
62 # OpenWSMan package update supports the AMT Ironic driver for the TealBox
63 LIBGUESTFS_BACKEND=direct virt-customize \
64     --run-command "sed -i '/ControllerEnableCephStorage/c\\  ControllerEnableCephStorage: true' /usr/share/openstack-tripleo-heat-templates/environments/storage-environment.yaml" \
65     --run-command "sed -i '/ComputeEnableCephStorage/c\\  ComputeEnableCephStorage: true' /usr/share/openstack-tripleo-heat-templates/environments/storage-environment.yaml" \
66     --run-command "curl http://download.opensuse.org/repositories/Openwsman/CentOS_CentOS-7/Openwsman.repo > /etc/yum.repos.d/wsman.repo" \
67     --run-command "yum update -y openwsman*" \
68     --run-command "cp /usr/share/instack-undercloud/undercloud.conf.sample /home/stack/undercloud.conf && chown stack:stack /home/stack/undercloud.conf" \
69     --upload ../opnfv-environment.yaml:/home/stack/ \
70     --upload ../virtual-environment.yaml:/home/stack/ \
71     -a undercloud.qcow2
72
73 popd > /dev/null
74