blob: 79f6ead0e5692dd3143538a104242ebb73841310 [file] [log] [blame]
Dean Troyerfda65b82011-11-02 12:13:33 -05001#!/usr/bin/env bash
2#
Dean Troyerf79cc422011-12-01 10:21:42 -06003# build_ci_config.sh - Build a config.ini for tempest (openstack-integration-tests)
4# (https://github.com/openstack/tempest.git)
Dean Troyerfda65b82011-11-02 12:13:33 -05005
6function usage {
Dean Troyerf79cc422011-12-01 10:21:42 -06007 echo "$0 - Build config.ini for tempest"
Dean Troyerfda65b82011-11-02 12:13:33 -05008 echo ""
Dean Troyer44d8f8f2011-11-23 23:21:06 -06009 echo "Usage: $0 [configdir]"
Dean Troyerfda65b82011-11-02 12:13:33 -050010 exit 1
11}
12
Dean Troyer44d8f8f2011-11-23 23:21:06 -060013if [ "$1" = "-h" ]; then
Dean Troyerfda65b82011-11-02 12:13:33 -050014 usage
15fi
16
Dean Troyerfda65b82011-11-02 12:13:33 -050017# Clean up any resources that may be in use
18cleanup() {
19 set +o errexit
20
21 # Mop up temporary files
Jesse Andrewsd7326d22011-11-20 10:02:26 -080022 if [ -n "$CONFIG_CONF_TMP" -a -e "$CONFIG_CONF_TMP" ]; then
23 rm -f $CONFIG_CONF_TMP
24 fi
25 if [ -n "$CONFIG_INI_TMP" -a -e "$CONFIG_INI_TMP" ]; then
26 rm -f $CONFIG_INI_TMP
Dean Troyerfda65b82011-11-02 12:13:33 -050027 fi
28
29 # Kill ourselves to signal any calling process
30 trap 2; kill -2 $$
31}
32
Jesse Andrewsd7326d22011-11-20 10:02:26 -080033trap cleanup SIGHUP SIGINT SIGTERM SIGQUIT EXIT
Dean Troyerfda65b82011-11-02 12:13:33 -050034
35# Keep track of the current directory
36TOOLS_DIR=$(cd $(dirname "$0") && pwd)
37TOP_DIR=`cd $TOOLS_DIR/..; pwd`
38
39# Abort if localrc is not set
40if [ ! -e $TOP_DIR/localrc ]; then
41 echo "You must have a localrc with ALL necessary passwords and configuration defined before proceeding."
42 echo "See stack.sh for required passwords."
43 exit 1
44fi
45
46# Source params
47source ./stackrc
48
49# Where Openstack code lives
50DEST=${DEST:-/opt/stack}
51
Dean Troyerf79cc422011-12-01 10:21:42 -060052CITEST_DIR=$DEST/tempest
Dean Troyer44d8f8f2011-11-23 23:21:06 -060053
54CONFIG_DIR=${1:-$CITEST_DIR/etc}
55CONFIG_CONF=$CONFIG_DIR/storm.conf
56CONFIG_INI=$CONFIG_DIR/config.ini
57
Dean Troyer39c2efc2011-11-07 16:40:35 -060058DIST_NAME=${DIST_NAME:-oneiric}
Dean Troyerb0e57cf2011-11-04 12:13:43 -050059
Dean Troyer44d8f8f2011-11-23 23:21:06 -060060# git clone only if directory doesn't exist already. Since ``DEST`` might not
61# be owned by the installation user, we create the directory and change the
62# ownership to the proper user.
63function git_clone {
64
65 GIT_REMOTE=$1
66 GIT_DEST=$2
67 GIT_BRANCH=$3
68
69 # do a full clone only if the directory doesn't exist
70 if [ ! -d $GIT_DEST ]; then
71 git clone $GIT_REMOTE $GIT_DEST
72 cd $2
73 # This checkout syntax works for both branches and tags
74 git checkout $GIT_BRANCH
75 elif [[ "$RECLONE" == "yes" ]]; then
76 # if it does exist then simulate what clone does if asked to RECLONE
77 cd $GIT_DEST
78 # set the url to pull from and fetch
79 git remote set-url origin $GIT_REMOTE
80 git fetch origin
81 # remove the existing ignored files (like pyc) as they cause breakage
82 # (due to the py files having older timestamps than our pyc, so python
83 # thinks the pyc files are correct using them)
84 find $GIT_DEST -name '*.pyc' -delete
85 git checkout -f origin/$GIT_BRANCH
86 # a local branch might not exist
87 git branch -D $GIT_BRANCH || true
88 git checkout -b $GIT_BRANCH
89 fi
90}
91
92# Install tests and prerequisites
Dean Troyerf79cc422011-12-01 10:21:42 -060093sudo PIP_DOWNLOAD_CACHE=/var/cache/pip pip install --use-mirrors `cat $TOP_DIR/files/pips/tempest`
Dean Troyer44d8f8f2011-11-23 23:21:06 -060094
95git_clone $CITEST_REPO $CITEST_DIR $CITEST_BRANCH
96
Jesse Andrewsd7326d22011-11-20 10:02:26 -080097if [ ! -f $DEST/.ramdisk ]; then
98 # Process network configuration vars
99 GUEST_NETWORK=${GUEST_NETWORK:-1}
100 GUEST_RECREATE_NET=${GUEST_RECREATE_NET:-yes}
Dean Troyerfda65b82011-11-02 12:13:33 -0500101
Jesse Andrewsd7326d22011-11-20 10:02:26 -0800102 GUEST_IP=${GUEST_IP:-192.168.$GUEST_NETWORK.50}
103 GUEST_CIDR=${GUEST_CIDR:-$GUEST_IP/24}
104 GUEST_NETMASK=${GUEST_NETMASK:-255.255.255.0}
105 GUEST_GATEWAY=${GUEST_GATEWAY:-192.168.$GUEST_NETWORK.1}
106 GUEST_MAC=${GUEST_MAC:-"02:16:3e:07:69:`printf '%02X' $GUEST_NETWORK`"}
107 GUEST_RAM=${GUEST_RAM:-1524288}
108 GUEST_CORES=${GUEST_CORES:-1}
109fi
Dean Troyerfda65b82011-11-02 12:13:33 -0500110
111# Use the GUEST_IP unless an explicit IP is set by ``HOST_IP``
112HOST_IP=${HOST_IP:-$GUEST_IP}
113# Use the first IP if HOST_IP still is not set
114if [ ! -n "$HOST_IP" ]; then
115 HOST_IP=`LC_ALL=C /sbin/ifconfig | grep -m 1 'inet addr:'| cut -d: -f2 | awk '{print $1}'`
116fi
117
118RABBIT_HOST=${RABBIT_HOST:-localhost}
119
120# Glance connection info. Note the port must be specified.
121GLANCE_HOSTPORT=${GLANCE_HOSTPORT:-$HOST_IP:9292}
122set `echo $GLANCE_HOSTPORT | tr ':' ' '`
123GLANCE_HOST=$1
124GLANCE_PORT=$2
125
Dean Troyer3320c552011-11-23 23:19:10 -0600126# Set up downloaded images
127# Defaults to use first image
128
129IMAGE_DIR=""
130for imagedir in $TOP_DIR/files/images/*; do
131 KERNEL=""
132 RAMDISK=""
133 IMAGE=""
134 IMAGE_RAMDISK=""
135 KERNEL=$(for f in "$imagedir/"*-vmlinuz*; do
136 [ -f "$f" ] && echo "$f" && break; done; true)
137 [ -n "$KERNEL" ] && ln -sf $KERNEL $imagedir/kernel
138 RAMDISK=$(for f in "$imagedir/"*-initrd*; do
139 [ -f "$f" ] && echo "$f" && break; done; true)
140 [ -n "$RAMDISK" ] && ln -sf $RAMDISK $imagedir/ramdisk && \
141 IMAGE_RAMDISK="ari_location = $imagedir/ramdisk"
142 IMAGE=$(for f in "$imagedir/"*.img; do
143 [ -f "$f" ] && echo "$f" && break; done; true)
144 if [ -n "$IMAGE" ]; then
145 ln -sf $IMAGE $imagedir/disk
146 # Save the first image directory that contains a disk image link
147 if [ -z "$IMAGE_DIR" ]; then
148 IMAGE_DIR=$imagedir
149 fi
150 fi
151done
152
Jesse Andrewsd7326d22011-11-20 10:02:26 -0800153# Create storm.conf
154
155CONFIG_CONF_TMP=$(mktemp $CONFIG_CONF.XXXXXX)
156 cat >$CONFIG_CONF_TMP <<EOF
157[nova]
158auth_url=http://$HOST_IP:5000/v2.0/tokens
159user=admin
160api_key=$ADMIN_PASSWORD
161tenant_name=admin
162ssh_timeout=300
163build_interval=10
164build_timeout=600
165
166[environment]
167image_ref=3
168image_ref_alt=4
169flavor_ref=1
170flavor_ref_alt=2
171create_image_enabled=true
172resize_available=true
173authentication=keystone_v2
174EOF
175mv $CONFIG_CONF_TMP $CONFIG_CONF
176CONFIG_CONF_TMP=""
177
178# Create config.ini
179
180CONFIG_INI_TMP=$(mktemp $CONFIG_INI.XXXXXX)
Dean Troyerff0ed1d2011-11-05 16:15:11 -0500181if [ "$UPLOAD_LEGACY_TTY" ]; then
Jesse Andrewsd7326d22011-11-20 10:02:26 -0800182 cat >$CONFIG_INI_TMP <<EOF
Dean Troyerff0ed1d2011-11-05 16:15:11 -0500183[environment]
Dean Troyer3320c552011-11-23 23:19:10 -0600184aki_location = $TOP_DIR/files/images/aki-tty/image
185ari_location = $TOP_DIR/files/images/ari-tty/image
186ami_location = $TOP_DIR/files/images/ami-tty/image
Jesse Andrewsd7326d22011-11-20 10:02:26 -0800187image_ref = 3
188image_ref_alt = 3
Dean Troyerff0ed1d2011-11-05 16:15:11 -0500189flavor_ref = 1
Jesse Andrewsd7326d22011-11-20 10:02:26 -0800190flavor_ref_alt = 2
191
192[glance]
193host = $GLANCE_HOST
194apiver = v1
195port = $GLANCE_PORT
196image_id = 3
197image_id_alt = 3
198tenant_id = 1
Dean Troyerff0ed1d2011-11-05 16:15:11 -0500199EOF
200else
Jesse Andrewsd7326d22011-11-20 10:02:26 -0800201 cat >$CONFIG_INI_TMP <<EOF
Dean Troyerfda65b82011-11-02 12:13:33 -0500202[environment]
Dean Troyer3320c552011-11-23 23:19:10 -0600203aki_location = $IMAGE_DIR/kernel
204ami_location = $IMAGE_DIR/disk
205$IMAGE_RAMDISK
Jesse Andrewsd7326d22011-11-20 10:02:26 -0800206image_ref = 2
207image_ref_alt = 2
Dean Troyerff0ed1d2011-11-05 16:15:11 -0500208flavor_ref = 1
Jesse Andrewsd7326d22011-11-20 10:02:26 -0800209flavor_ref_alt = 2
Dean Troyerfda65b82011-11-02 12:13:33 -0500210
211[glance]
212host = $GLANCE_HOST
Dean Troyera0e29482011-11-04 19:44:06 -0500213apiver = v1
Dean Troyerfda65b82011-11-02 12:13:33 -0500214port = $GLANCE_PORT
Dean Troyer3320c552011-11-23 23:19:10 -0600215image_id = 2
216image_id_alt = 2
Dean Troyera0e29482011-11-04 19:44:06 -0500217tenant_id = 1
Jesse Andrewsd7326d22011-11-20 10:02:26 -0800218EOF
219fi
220
221cat >>$CONFIG_INI_TMP <<EOF
Dean Troyerfda65b82011-11-02 12:13:33 -0500222
223[keystone]
224service_host = $HOST_IP
225service_port = 5000
Dean Troyer5db287c2011-11-02 21:21:36 -0500226apiver = v2.0
Dean Troyerfda65b82011-11-02 12:13:33 -0500227user = admin
228password = $ADMIN_PASSWORD
Dolph Mathews50e32292011-12-15 16:04:49 -0600229tenant_name = admin
Dean Troyerfda65b82011-11-02 12:13:33 -0500230
231[nova]
232host = $HOST_IP
233port = 8774
234apiver = v1.1
235project = admin
236user = admin
Dean Troyerb0e57cf2011-11-04 12:13:43 -0500237key = $ADMIN_PASSWORD
Dean Troyerfda65b82011-11-02 12:13:33 -0500238ssh_timeout = 300
239build_timeout = 300
240flavor_ref = 1
241flavor_ref_alt = 2
Jesse Andrewsd7326d22011-11-20 10:02:26 -0800242multi_node = no
Dean Troyerfda65b82011-11-02 12:13:33 -0500243
244[rabbitmq]
245host = $RABBIT_HOST
246user = guest
247password = $RABBIT_PASSWORD
248
249[swift]
250auth_host = $HOST_IP
251auth_port = 443
252auth_prefix = /auth/
253auth_ssl = yes
254account = system
255username = root
256password = password
257
258EOF
Jesse Andrewsd7326d22011-11-20 10:02:26 -0800259mv $CONFIG_INI_TMP $CONFIG_INI
260CONFIG_INI_TMP=""
261
262trap - SIGHUP SIGINT SIGTERM SIGQUIT EXIT