blob: aa44766ae819857195e5b54a645a8d7f578ada64 [file] [log] [blame]
Dean Troyer608bb122012-01-10 14:43:17 -06001#!/usr/bin/env bash
2#
3# build_tempest.sh - Checkout and prepare a Tempest repo
4# (https://github.com/openstack/tempest.git)
5
6function usage {
7 echo "$0 - Check out and prepare a Tempest repo"
8 echo ""
9 echo "Usage: $0"
10 exit 1
11}
12
13if [ "$1" = "-h" ]; then
14 usage
15fi
16
17# Clean up any resources that may be in use
18cleanup() {
19 set +o errexit
20
21 # Kill ourselves to signal any calling process
22 trap 2; kill -2 $$
23}
24
25trap cleanup SIGHUP SIGINT SIGTERM SIGQUIT EXIT
26
27# Keep track of the current directory
28TOOLS_DIR=$(cd $(dirname "$0") && pwd)
29TOP_DIR=`cd $TOOLS_DIR/..; pwd`
30
31# Abort if localrc is not set
32if [ ! -e $TOP_DIR/localrc ]; then
33 echo "You must have a localrc with ALL necessary passwords and configuration defined before proceeding."
34 echo "See stack.sh for required passwords."
35 exit 1
36fi
37
38# Source params
39source ./stackrc
40
41# Where Openstack code lives
42DEST=${DEST:-/opt/stack}
43
44TEMPEST_DIR=$DEST/tempest
45
46DIST_NAME=${DIST_NAME:-oneiric}
47
48# git clone only if directory doesn't exist already. Since ``DEST`` might not
49# be owned by the installation user, we create the directory and change the
50# ownership to the proper user.
51function git_clone {
52
53 GIT_REMOTE=$1
54 GIT_DEST=$2
55 GIT_BRANCH=$3
56
57 # do a full clone only if the directory doesn't exist
58 if [ ! -d $GIT_DEST ]; then
59 git clone $GIT_REMOTE $GIT_DEST
60 cd $2
61 # This checkout syntax works for both branches and tags
62 git checkout $GIT_BRANCH
63 elif [[ "$RECLONE" == "yes" ]]; then
64 # if it does exist then simulate what clone does if asked to RECLONE
65 cd $GIT_DEST
66 # set the url to pull from and fetch
67 git remote set-url origin $GIT_REMOTE
68 git fetch origin
69 # remove the existing ignored files (like pyc) as they cause breakage
70 # (due to the py files having older timestamps than our pyc, so python
71 # thinks the pyc files are correct using them)
72 find $GIT_DEST -name '*.pyc' -delete
73 git checkout -f origin/$GIT_BRANCH
74 # a local branch might not exist
75 git branch -D $GIT_BRANCH || true
76 git checkout -b $GIT_BRANCH
77 fi
78}
79
80# Install tests and prerequisites
81sudo PIP_DOWNLOAD_CACHE=/var/cache/pip pip install --use-mirrors `cat $TOP_DIR/files/pips/tempest`
82
83git_clone $TEMPEST_REPO $TEMPEST_DIR $TEMPEST_BRANCH
84
85trap - SIGHUP SIGINT SIGTERM SIGQUIT EXIT