Dean Troyer | fda65b8 | 2011-11-02 12:13:33 -0500 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | # |
Dean Troyer | 608bb12 | 2012-01-10 14:43:17 -0600 | [diff] [blame^] | 3 | # configure_tempest.sh - Build a tempest configuration file from devstack |
Dean Troyer | fda65b8 | 2011-11-02 12:13:33 -0500 | [diff] [blame] | 4 | |
| 5 | function usage { |
Dean Troyer | 608bb12 | 2012-01-10 14:43:17 -0600 | [diff] [blame^] | 6 | echo "$0 - Build tempest.conf" |
Dean Troyer | fda65b8 | 2011-11-02 12:13:33 -0500 | [diff] [blame] | 7 | echo "" |
Dean Troyer | 44d8f8f | 2011-11-23 23:21:06 -0600 | [diff] [blame] | 8 | echo "Usage: $0 [configdir]" |
Dean Troyer | fda65b8 | 2011-11-02 12:13:33 -0500 | [diff] [blame] | 9 | exit 1 |
| 10 | } |
| 11 | |
Dean Troyer | 44d8f8f | 2011-11-23 23:21:06 -0600 | [diff] [blame] | 12 | if [ "$1" = "-h" ]; then |
Dean Troyer | fda65b8 | 2011-11-02 12:13:33 -0500 | [diff] [blame] | 13 | usage |
| 14 | fi |
| 15 | |
Dean Troyer | fda65b8 | 2011-11-02 12:13:33 -0500 | [diff] [blame] | 16 | # Clean up any resources that may be in use |
| 17 | cleanup() { |
| 18 | set +o errexit |
| 19 | |
| 20 | # Mop up temporary files |
Jesse Andrews | d7326d2 | 2011-11-20 10:02:26 -0800 | [diff] [blame] | 21 | if [ -n "$CONFIG_INI_TMP" -a -e "$CONFIG_INI_TMP" ]; then |
| 22 | rm -f $CONFIG_INI_TMP |
Dean Troyer | fda65b8 | 2011-11-02 12:13:33 -0500 | [diff] [blame] | 23 | fi |
| 24 | |
| 25 | # Kill ourselves to signal any calling process |
| 26 | trap 2; kill -2 $$ |
| 27 | } |
| 28 | |
Jesse Andrews | d7326d2 | 2011-11-20 10:02:26 -0800 | [diff] [blame] | 29 | trap cleanup SIGHUP SIGINT SIGTERM SIGQUIT EXIT |
Dean Troyer | fda65b8 | 2011-11-02 12:13:33 -0500 | [diff] [blame] | 30 | |
| 31 | # Keep track of the current directory |
| 32 | TOOLS_DIR=$(cd $(dirname "$0") && pwd) |
| 33 | TOP_DIR=`cd $TOOLS_DIR/..; pwd` |
| 34 | |
| 35 | # Abort if localrc is not set |
| 36 | if [ ! -e $TOP_DIR/localrc ]; then |
| 37 | echo "You must have a localrc with ALL necessary passwords and configuration defined before proceeding." |
| 38 | echo "See stack.sh for required passwords." |
| 39 | exit 1 |
| 40 | fi |
| 41 | |
| 42 | # Source params |
| 43 | source ./stackrc |
| 44 | |
Dean Troyer | 608bb12 | 2012-01-10 14:43:17 -0600 | [diff] [blame^] | 45 | # Set defaults not configured by stackrc |
| 46 | TENANT=${TENANT:-admin} |
| 47 | USERNAME=${USERNAME:-admin} |
| 48 | IDENTITY_HOST=${IDENTITY_HOST:-$HOST_IP} |
| 49 | IDENTITY_PORT=${IDENTITY_PORT:-5000} |
| 50 | IDENTITY_API_VERSION=${IDENTITY_API_VERSION:-2.0} |
| 51 | |
Dean Troyer | fda65b8 | 2011-11-02 12:13:33 -0500 | [diff] [blame] | 52 | # Where Openstack code lives |
| 53 | DEST=${DEST:-/opt/stack} |
| 54 | |
Dean Troyer | 608bb12 | 2012-01-10 14:43:17 -0600 | [diff] [blame^] | 55 | TEMPEST_DIR=$DEST/tempest |
Dean Troyer | 44d8f8f | 2011-11-23 23:21:06 -0600 | [diff] [blame] | 56 | |
Dean Troyer | 608bb12 | 2012-01-10 14:43:17 -0600 | [diff] [blame^] | 57 | CONFIG_DIR=${1:-$TEMPEST_DIR/etc} |
Dean Troyer | 44d8f8f | 2011-11-23 23:21:06 -0600 | [diff] [blame] | 58 | CONFIG_INI=$CONFIG_DIR/config.ini |
Dean Troyer | 608bb12 | 2012-01-10 14:43:17 -0600 | [diff] [blame^] | 59 | TEMPEST_CONF=$CONFIG_DIR/tempest.conf |
Dean Troyer | 44d8f8f | 2011-11-23 23:21:06 -0600 | [diff] [blame] | 60 | |
Jesse Andrews | d7326d2 | 2011-11-20 10:02:26 -0800 | [diff] [blame] | 61 | if [ ! -f $DEST/.ramdisk ]; then |
| 62 | # Process network configuration vars |
| 63 | GUEST_NETWORK=${GUEST_NETWORK:-1} |
| 64 | GUEST_RECREATE_NET=${GUEST_RECREATE_NET:-yes} |
Dean Troyer | fda65b8 | 2011-11-02 12:13:33 -0500 | [diff] [blame] | 65 | |
Jesse Andrews | d7326d2 | 2011-11-20 10:02:26 -0800 | [diff] [blame] | 66 | GUEST_IP=${GUEST_IP:-192.168.$GUEST_NETWORK.50} |
| 67 | GUEST_CIDR=${GUEST_CIDR:-$GUEST_IP/24} |
| 68 | GUEST_NETMASK=${GUEST_NETMASK:-255.255.255.0} |
| 69 | GUEST_GATEWAY=${GUEST_GATEWAY:-192.168.$GUEST_NETWORK.1} |
| 70 | GUEST_MAC=${GUEST_MAC:-"02:16:3e:07:69:`printf '%02X' $GUEST_NETWORK`"} |
| 71 | GUEST_RAM=${GUEST_RAM:-1524288} |
| 72 | GUEST_CORES=${GUEST_CORES:-1} |
| 73 | fi |
Dean Troyer | fda65b8 | 2011-11-02 12:13:33 -0500 | [diff] [blame] | 74 | |
| 75 | # Use the GUEST_IP unless an explicit IP is set by ``HOST_IP`` |
| 76 | HOST_IP=${HOST_IP:-$GUEST_IP} |
| 77 | # Use the first IP if HOST_IP still is not set |
| 78 | if [ ! -n "$HOST_IP" ]; then |
| 79 | HOST_IP=`LC_ALL=C /sbin/ifconfig | grep -m 1 'inet addr:'| cut -d: -f2 | awk '{print $1}'` |
| 80 | fi |
| 81 | |
| 82 | RABBIT_HOST=${RABBIT_HOST:-localhost} |
| 83 | |
| 84 | # Glance connection info. Note the port must be specified. |
| 85 | GLANCE_HOSTPORT=${GLANCE_HOSTPORT:-$HOST_IP:9292} |
| 86 | set `echo $GLANCE_HOSTPORT | tr ':' ' '` |
| 87 | GLANCE_HOST=$1 |
| 88 | GLANCE_PORT=$2 |
| 89 | |
Dean Troyer | 3320c55 | 2011-11-23 23:19:10 -0600 | [diff] [blame] | 90 | # Set up downloaded images |
| 91 | # Defaults to use first image |
| 92 | |
| 93 | IMAGE_DIR="" |
Dean Troyer | 608bb12 | 2012-01-10 14:43:17 -0600 | [diff] [blame^] | 94 | IMAGE_NAME="" |
Dean Troyer | 3320c55 | 2011-11-23 23:19:10 -0600 | [diff] [blame] | 95 | for imagedir in $TOP_DIR/files/images/*; do |
| 96 | KERNEL="" |
| 97 | RAMDISK="" |
| 98 | IMAGE="" |
| 99 | IMAGE_RAMDISK="" |
| 100 | KERNEL=$(for f in "$imagedir/"*-vmlinuz*; do |
| 101 | [ -f "$f" ] && echo "$f" && break; done; true) |
| 102 | [ -n "$KERNEL" ] && ln -sf $KERNEL $imagedir/kernel |
| 103 | RAMDISK=$(for f in "$imagedir/"*-initrd*; do |
| 104 | [ -f "$f" ] && echo "$f" && break; done; true) |
| 105 | [ -n "$RAMDISK" ] && ln -sf $RAMDISK $imagedir/ramdisk && \ |
| 106 | IMAGE_RAMDISK="ari_location = $imagedir/ramdisk" |
| 107 | IMAGE=$(for f in "$imagedir/"*.img; do |
| 108 | [ -f "$f" ] && echo "$f" && break; done; true) |
| 109 | if [ -n "$IMAGE" ]; then |
| 110 | ln -sf $IMAGE $imagedir/disk |
| 111 | # Save the first image directory that contains a disk image link |
| 112 | if [ -z "$IMAGE_DIR" ]; then |
| 113 | IMAGE_DIR=$imagedir |
Dean Troyer | 608bb12 | 2012-01-10 14:43:17 -0600 | [diff] [blame^] | 114 | IMAGE_NAME=$(basename ${IMAGE%.img}) |
Dean Troyer | 3320c55 | 2011-11-23 23:19:10 -0600 | [diff] [blame] | 115 | fi |
| 116 | fi |
| 117 | done |
Dean Troyer | 608bb12 | 2012-01-10 14:43:17 -0600 | [diff] [blame^] | 118 | if [[ -n "$IMAGE_NAME" ]]; then |
| 119 | # Get the image UUID |
| 120 | IMAGE_UUID=$(nova image-list | grep " $IMAGE_NAME " | cut -d'|' -f2) |
| 121 | # Strip spaces off |
| 122 | IMAGE_UUID=$(echo $IMAGE_UUID) |
| 123 | fi |
Dean Troyer | 3320c55 | 2011-11-23 23:19:10 -0600 | [diff] [blame] | 124 | |
Dean Troyer | 608bb12 | 2012-01-10 14:43:17 -0600 | [diff] [blame^] | 125 | # Create tempest.conf from tempest.conf.sample |
Jesse Andrews | d7326d2 | 2011-11-20 10:02:26 -0800 | [diff] [blame] | 126 | |
Dean Troyer | 608bb12 | 2012-01-10 14:43:17 -0600 | [diff] [blame^] | 127 | if [[ ! -r $TEMPEST_CONF ]]; then |
| 128 | cp $TEMPEST_CONF.sample $TEMPEST_CONF |
| 129 | fi |
Jesse Andrews | d7326d2 | 2011-11-20 10:02:26 -0800 | [diff] [blame] | 130 | |
Dean Troyer | 608bb12 | 2012-01-10 14:43:17 -0600 | [diff] [blame^] | 131 | sed -e " |
| 132 | /^api_key=/s|=.*\$|=$ADMIN_PASSWORD|; |
| 133 | /^auth_url=/s|=.*\$|=${OS_AUTH_URL%/}/tokens/|; |
| 134 | /^host=/s|=.*\$|=$HOST_IP|; |
| 135 | /^image_ref=/s|=.*\$|=$IMAGE_UUID|; |
| 136 | /^password=/s|=.*\$|=$ADMIN_PASSWORD|; |
| 137 | /^tenant=/s|=.*\$|=$TENANT|; |
| 138 | /^tenant_name=/s|=.*\$|=$TENANT|; |
| 139 | /^user=/s|=.*\$|=$USERNAME|; |
| 140 | /^username=/s|=.*\$|=$USERNAME|; |
| 141 | " -i $TEMPEST_CONF |
Jesse Andrews | d7326d2 | 2011-11-20 10:02:26 -0800 | [diff] [blame] | 142 | |
| 143 | # Create config.ini |
| 144 | |
| 145 | CONFIG_INI_TMP=$(mktemp $CONFIG_INI.XXXXXX) |
Dean Troyer | ff0ed1d | 2011-11-05 16:15:11 -0500 | [diff] [blame] | 146 | if [ "$UPLOAD_LEGACY_TTY" ]; then |
Jesse Andrews | d7326d2 | 2011-11-20 10:02:26 -0800 | [diff] [blame] | 147 | cat >$CONFIG_INI_TMP <<EOF |
Dean Troyer | ff0ed1d | 2011-11-05 16:15:11 -0500 | [diff] [blame] | 148 | [environment] |
Dean Troyer | 3320c55 | 2011-11-23 23:19:10 -0600 | [diff] [blame] | 149 | aki_location = $TOP_DIR/files/images/aki-tty/image |
| 150 | ari_location = $TOP_DIR/files/images/ari-tty/image |
| 151 | ami_location = $TOP_DIR/files/images/ami-tty/image |
Jesse Andrews | d7326d2 | 2011-11-20 10:02:26 -0800 | [diff] [blame] | 152 | image_ref = 3 |
| 153 | image_ref_alt = 3 |
Dean Troyer | ff0ed1d | 2011-11-05 16:15:11 -0500 | [diff] [blame] | 154 | flavor_ref = 1 |
Jesse Andrews | d7326d2 | 2011-11-20 10:02:26 -0800 | [diff] [blame] | 155 | flavor_ref_alt = 2 |
| 156 | |
| 157 | [glance] |
| 158 | host = $GLANCE_HOST |
| 159 | apiver = v1 |
| 160 | port = $GLANCE_PORT |
| 161 | image_id = 3 |
| 162 | image_id_alt = 3 |
| 163 | tenant_id = 1 |
Dean Troyer | ff0ed1d | 2011-11-05 16:15:11 -0500 | [diff] [blame] | 164 | EOF |
| 165 | else |
Jesse Andrews | d7326d2 | 2011-11-20 10:02:26 -0800 | [diff] [blame] | 166 | cat >$CONFIG_INI_TMP <<EOF |
Dean Troyer | fda65b8 | 2011-11-02 12:13:33 -0500 | [diff] [blame] | 167 | [environment] |
Dean Troyer | 3320c55 | 2011-11-23 23:19:10 -0600 | [diff] [blame] | 168 | aki_location = $IMAGE_DIR/kernel |
| 169 | ami_location = $IMAGE_DIR/disk |
| 170 | $IMAGE_RAMDISK |
Jesse Andrews | d7326d2 | 2011-11-20 10:02:26 -0800 | [diff] [blame] | 171 | image_ref = 2 |
| 172 | image_ref_alt = 2 |
Dean Troyer | ff0ed1d | 2011-11-05 16:15:11 -0500 | [diff] [blame] | 173 | flavor_ref = 1 |
Jesse Andrews | d7326d2 | 2011-11-20 10:02:26 -0800 | [diff] [blame] | 174 | flavor_ref_alt = 2 |
Dean Troyer | fda65b8 | 2011-11-02 12:13:33 -0500 | [diff] [blame] | 175 | |
| 176 | [glance] |
| 177 | host = $GLANCE_HOST |
Dean Troyer | a0e2948 | 2011-11-04 19:44:06 -0500 | [diff] [blame] | 178 | apiver = v1 |
Dean Troyer | fda65b8 | 2011-11-02 12:13:33 -0500 | [diff] [blame] | 179 | port = $GLANCE_PORT |
Dean Troyer | 3320c55 | 2011-11-23 23:19:10 -0600 | [diff] [blame] | 180 | image_id = 2 |
| 181 | image_id_alt = 2 |
Dean Troyer | a0e2948 | 2011-11-04 19:44:06 -0500 | [diff] [blame] | 182 | tenant_id = 1 |
Jesse Andrews | d7326d2 | 2011-11-20 10:02:26 -0800 | [diff] [blame] | 183 | EOF |
| 184 | fi |
| 185 | |
| 186 | cat >>$CONFIG_INI_TMP <<EOF |
Dean Troyer | fda65b8 | 2011-11-02 12:13:33 -0500 | [diff] [blame] | 187 | |
| 188 | [keystone] |
| 189 | service_host = $HOST_IP |
| 190 | service_port = 5000 |
Dean Troyer | 5db287c | 2011-11-02 21:21:36 -0500 | [diff] [blame] | 191 | apiver = v2.0 |
Dean Troyer | fda65b8 | 2011-11-02 12:13:33 -0500 | [diff] [blame] | 192 | user = admin |
| 193 | password = $ADMIN_PASSWORD |
Dolph Mathews | 50e3229 | 2011-12-15 16:04:49 -0600 | [diff] [blame] | 194 | tenant_name = admin |
Dean Troyer | fda65b8 | 2011-11-02 12:13:33 -0500 | [diff] [blame] | 195 | |
| 196 | [nova] |
| 197 | host = $HOST_IP |
| 198 | port = 8774 |
| 199 | apiver = v1.1 |
| 200 | project = admin |
| 201 | user = admin |
Dean Troyer | b0e57cf | 2011-11-04 12:13:43 -0500 | [diff] [blame] | 202 | key = $ADMIN_PASSWORD |
Dean Troyer | fda65b8 | 2011-11-02 12:13:33 -0500 | [diff] [blame] | 203 | ssh_timeout = 300 |
| 204 | build_timeout = 300 |
| 205 | flavor_ref = 1 |
| 206 | flavor_ref_alt = 2 |
Jesse Andrews | d7326d2 | 2011-11-20 10:02:26 -0800 | [diff] [blame] | 207 | multi_node = no |
Dean Troyer | fda65b8 | 2011-11-02 12:13:33 -0500 | [diff] [blame] | 208 | |
| 209 | [rabbitmq] |
| 210 | host = $RABBIT_HOST |
| 211 | user = guest |
| 212 | password = $RABBIT_PASSWORD |
| 213 | |
| 214 | [swift] |
| 215 | auth_host = $HOST_IP |
| 216 | auth_port = 443 |
| 217 | auth_prefix = /auth/ |
| 218 | auth_ssl = yes |
| 219 | account = system |
| 220 | username = root |
| 221 | password = password |
| 222 | |
| 223 | EOF |
Jesse Andrews | d7326d2 | 2011-11-20 10:02:26 -0800 | [diff] [blame] | 224 | mv $CONFIG_INI_TMP $CONFIG_INI |
| 225 | CONFIG_INI_TMP="" |
| 226 | |
| 227 | trap - SIGHUP SIGINT SIGTERM SIGQUIT EXIT |