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