Merge "Write selected env variables to .stackenv"
diff --git a/exerciserc b/exerciserc
index 82c74b7..c26ec2c 100644
--- a/exerciserc
+++ b/exerciserc
@@ -26,3 +26,7 @@
 
 # Max time to wait for a euca-delete command to propogate
 export VOLUME_DELETE_TIMEOUT=${SNAPSHOT_DELETE_TIMEOUT:-60}
+
+# The size of the volume we want to boot from; some storage back-ends
+# do not allow a disk resize, so it's important that this can be tuned
+export DEFAULT_VOLUME_SIZE=${DEFAULT_VOLUME_SIZE:-1}
diff --git a/exercises/aggregates.sh b/exercises/aggregates.sh
index adc3393..deb1a03 100755
--- a/exercises/aggregates.sh
+++ b/exercises/aggregates.sh
@@ -99,8 +99,8 @@
 META_DATA_2_KEY=foo
 META_DATA_3_KEY=bar
 
-#ensure no metadata is set
-nova aggregate-details $AGGREGATE_ID | grep {}
+#ensure no additional metadata is set
+nova aggregate-details $AGGREGATE_ID | egrep "{u'availability_zone': u'$AGGREGATE_A_ZONE'}|{}"
 
 nova aggregate-set-metadata $AGGREGATE_ID ${META_DATA_1_KEY}=123
 nova aggregate-details $AGGREGATE_ID | grep $META_DATA_1_KEY
@@ -117,7 +117,7 @@
 nova aggregate-details $AGGREGATE_ID | grep $META_DATA_2_KEY && die "ERROR metadata was not cleared"
 
 nova aggregate-set-metadata $AGGREGATE_ID $META_DATA_3_KEY $META_DATA_1_KEY
-nova aggregate-details $AGGREGATE_ID | grep {}
+nova aggregate-details $AGGREGATE_ID | egrep "{u'availability_zone': u'$AGGREGATE_A_ZONE'}|{}"
 
 
 # Test aggregate-add/remove-host
diff --git a/exercises/boot_from_volume.sh b/exercises/boot_from_volume.sh
index 5ebdecc..5ada237 100755
--- a/exercises/boot_from_volume.sh
+++ b/exercises/boot_from_volume.sh
@@ -117,7 +117,7 @@
 fi
 
 # Create the bootable volume
-cinder create --display_name=$VOL_NAME --image-id $IMAGE 1
+cinder create --display_name=$VOL_NAME --image-id $IMAGE $DEFAULT_VOLUME_SIZE
 
 # Wait for volume to activate
 if ! timeout $ACTIVE_TIMEOUT sh -c "while ! cinder list | grep $VOL_NAME | grep available; do sleep 1; done"; then
diff --git a/exercises/volumes.sh b/exercises/volumes.sh
index 42f9cb4..48a976e 100755
--- a/exercises/volumes.sh
+++ b/exercises/volumes.sh
@@ -142,7 +142,7 @@
 fi
 
 # Create a new volume
-cinder create --display_name $VOL_NAME --display_description "test volume: $VOL_NAME" 1
+cinder create --display_name $VOL_NAME --display_description "test volume: $VOL_NAME" $DEFAULT_VOLUME_SIZE
 if [[ $? != 0 ]]; then
     echo "Failure creating volume $VOL_NAME"
     exit 1
diff --git a/files/apts/tls-proxy b/files/apts/tls-proxy
index dce9c07..0a44015 100644
--- a/files/apts/tls-proxy
+++ b/files/apts/tls-proxy
@@ -1 +1 @@
-stud
+stud # only available in dist:precise,quantal
diff --git a/files/keystone_data.sh b/files/keystone_data.sh
index 17e8c59..71a8e5e 100755
--- a/files/keystone_data.sh
+++ b/files/keystone_data.sh
@@ -7,7 +7,6 @@
 # service              glance     admin
 # service              quantum    admin        # if enabled
 # service              swift      admin        # if enabled
-# service              cinder     admin        # if enabled
 # service              heat       admin        # if enabled
 # service              ceilometer admin        # if enabled
 # Tempest Only:
@@ -38,6 +37,7 @@
 # Lookups
 SERVICE_TENANT=$(keystone tenant-list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
 ADMIN_ROLE=$(keystone role-list | awk "/ admin / { print \$2 }")
+MEMBER_ROLE=$(keystone role-list | awk "/ Member / { print \$2 }")
 
 
 # Roles
@@ -49,6 +49,7 @@
 # role is also configurable in swift-proxy.conf
 RESELLER_ROLE=$(get_id keystone role-create --name=ResellerAdmin)
 
+
 # Services
 # --------
 
@@ -243,25 +244,3 @@
         --user_id $ALT_DEMO_USER \
         --role_id $MEMBER_ROLE
 fi
-
-if [[ "$ENABLED_SERVICES" =~ "c-api" ]]; then
-    CINDER_USER=$(get_id keystone user-create --name=cinder \
-                                              --pass="$SERVICE_PASSWORD" \
-                                              --tenant_id $SERVICE_TENANT \
-                                              --email=cinder@example.com)
-    keystone user-role-add --tenant_id $SERVICE_TENANT \
-                           --user_id $CINDER_USER \
-                           --role_id $ADMIN_ROLE
-    if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
-        CINDER_SERVICE=$(get_id keystone service-create \
-            --name=cinder \
-            --type=volume \
-            --description="Cinder Service")
-        keystone endpoint-create \
-            --region RegionOne \
-            --service_id $CINDER_SERVICE \
-            --publicurl "http://$SERVICE_HOST:8776/v1/\$(tenant_id)s" \
-            --adminurl "http://$SERVICE_HOST:8776/v1/\$(tenant_id)s" \
-            --internalurl "http://$SERVICE_HOST:8776/v1/\$(tenant_id)s"
-    fi
-fi
diff --git a/lib/cinder b/lib/cinder
index 16cbaf3..5477e26 100644
--- a/lib/cinder
+++ b/lib/cinder
@@ -31,9 +31,11 @@
 CINDER_DIR=$DEST/cinder
 CINDERCLIENT_DIR=$DEST/python-cinderclient
 CINDER_STATE_PATH=${CINDER_STATE_PATH:=$DATA_DIR/cinder}
+CINDER_AUTH_CACHE_DIR=${CINDER_AUTH_CACHE_DIR:-/var/cache/cinder}
+
 CINDER_CONF_DIR=/etc/cinder
 CINDER_CONF=$CINDER_CONF_DIR/cinder.conf
-CINDER_AUTH_CACHE_DIR=${CINDER_AUTH_CACHE_DIR:-/var/cache/cinder}
+CINDER_API_PASTE_INI=$CINDER_CONF_DIR/api-paste.ini
 
 # Support entry points installation of console scripts
 if [[ -d $CINDER_DIR/bin ]]; then
@@ -97,7 +99,6 @@
     sudo chown root:root $TEMPFILE
     sudo mv $TEMPFILE /etc/sudoers.d/cinder-rootwrap
 
-    CINDER_API_PASTE_INI=$CINDER_CONF_DIR/api-paste.ini
     cp $CINDER_DIR/etc/cinder/api-paste.ini $CINDER_API_PASTE_INI
     iniset $CINDER_API_PASTE_INI filter:authtoken auth_host $KEYSTONE_AUTH_HOST
     iniset $CINDER_API_PASTE_INI filter:authtoken auth_port $KEYSTONE_AUTH_PORT
@@ -159,6 +160,46 @@
     fi
 }
 
+# create_cinder_accounts() - Set up common required cinder accounts
+
+# Tenant               User       Roles
+# ------------------------------------------------------------------
+# service              cinder     admin        # if enabled
+
+# Migrated from keystone_data.sh
+create_cinder_accounts() {
+
+    SERVICE_TENANT=$(keystone tenant-list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
+    ADMIN_ROLE=$(keystone role-list | awk "/ admin / { print \$2 }")
+
+    # Cinder
+    if [[ "$ENABLED_SERVICES" =~ "c-api" ]]; then
+        CINDER_USER=$(keystone user-create \
+            --name=cinder \
+            --pass="$SERVICE_PASSWORD" \
+            --tenant_id $SERVICE_TENANT \
+            --email=cinder@example.com \
+            | grep " id " | get_field 2)
+        keystone user-role-add \
+            --tenant_id $SERVICE_TENANT \
+            --user_id $CINDER_USER \
+            --role_id $ADMIN_ROLE
+        if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
+            CINDER_SERVICE=$(keystone service-create \
+                --name=cinder \
+                --type=volume \
+                --description="Cinder Volume Service" \
+                | grep " id " | get_field 2)
+            keystone endpoint-create \
+                --region RegionOne \
+                --service_id $CINDER_SERVICE \
+                --publicurl "http://$SERVICE_HOST:8776/v1/\$(tenant_id)s" \
+                --adminurl "http://$SERVICE_HOST:8776/v1/\$(tenant_id)s" \
+                --internalurl "http://$SERVICE_HOST:8776/v1/\$(tenant_id)s"
+        fi
+    fi
+}
+
 # init_cinder() - Initialize database and volume group
 function init_cinder() {
     # Force nova volumes off
@@ -212,6 +253,7 @@
     # Create cache dir
     sudo mkdir -p $CINDER_AUTH_CACHE_DIR
     sudo chown `whoami` $CINDER_AUTH_CACHE_DIR
+    rm -f $CINDER_AUTH_CACHE_DIR/*
 }
 
 # install_cinder() - Collect source and prepare
diff --git a/lib/glance b/lib/glance
index 4f631b2..8ba04b3 100644
--- a/lib/glance
+++ b/lib/glance
@@ -162,8 +162,10 @@
     # Create cache dir
     sudo mkdir -p $GLANCE_AUTH_CACHE_DIR/api
     sudo chown `whoami` $GLANCE_AUTH_CACHE_DIR/api
+    rm -f $GLANCE_AUTH_CACHE_DIR/api/*
     sudo mkdir -p $GLANCE_AUTH_CACHE_DIR/registry
     sudo chown `whoami` $GLANCE_AUTH_CACHE_DIR/registry
+    rm -f $GLANCE_AUTH_CACHE_DIR/registry/*
 }
 
 # install_glanceclient() - Collect source and prepare
diff --git a/lib/heat b/lib/heat
index feaadec..43115cb 100644
--- a/lib/heat
+++ b/lib/heat
@@ -175,7 +175,7 @@
     # (re)create heat database
     recreate_database heat utf8
 
-    $HEAT_DIR/bin/heat-db-setup $os_PACKAGE -r $MYSQL_PASSWORD
+    $HEAT_DIR/bin/heat-db-setup $os_PACKAGE -r $DATABASE_PASSWORD
     $HEAT_DIR/tools/nova_create_flavors.sh
 }
 
diff --git a/lib/keystone b/lib/keystone
index 2d21c2c..7950fa9 100644
--- a/lib/keystone
+++ b/lib/keystone
@@ -81,8 +81,8 @@
 
     if [[ ! -d $KEYSTONE_CONF_DIR ]]; then
         sudo mkdir -p $KEYSTONE_CONF_DIR
-        sudo chown `whoami` $KEYSTONE_CONF_DIR
     fi
+    sudo chown `whoami` $KEYSTONE_CONF_DIR
 
     if [[ "$KEYSTONE_CONF_DIR" != "$KEYSTONE_DIR/etc" ]]; then
         cp -p $KEYSTONE_DIR/etc/keystone.conf.sample $KEYSTONE_CONF
@@ -259,11 +259,13 @@
 
     if [[ "$KEYSTONE_TOKEN_FORMAT" == "PKI" ]]; then
         # Set up certificates
+        rm -rf $KEYSTONE_CONF_DIR/ssl
         $KEYSTONE_DIR/bin/keystone-manage pki_setup
 
         # Create cache dir
         sudo mkdir -p $KEYSTONE_AUTH_CACHE_DIR
         sudo chown `whoami` $KEYSTONE_AUTH_CACHE_DIR
+        rm -f $KEYSTONE_AUTH_CACHE_DIR/*
     fi
 }
 
diff --git a/lib/nova b/lib/nova
index 840965e..e07e61c 100644
--- a/lib/nova
+++ b/lib/nova
@@ -435,6 +435,7 @@
     # Create cache dir
     sudo mkdir -p $NOVA_AUTH_CACHE_DIR
     sudo chown `whoami` $NOVA_AUTH_CACHE_DIR
+    rm -f $NOVA_AUTH_CACHE_DIR/*
 }
 
 # install_novaclient() - Collect source and prepare
diff --git a/lib/quantum b/lib/quantum
index 288a327..480aaa1 100644
--- a/lib/quantum
+++ b/lib/quantum
@@ -127,6 +127,7 @@
     # Create cache dir
     sudo mkdir -p $QUANTUM_AUTH_CACHE_DIR
     sudo chown `whoami` $QUANTUM_AUTH_CACHE_DIR
+    rm -f $QUANTUM_AUTH_CACHE_DIR/*
 }
 
 function quantum_setup_ovs_bridge() {
diff --git a/lib/tempest b/lib/tempest
index 7fa15df..1859921 100644
--- a/lib/tempest
+++ b/lib/tempest
@@ -63,6 +63,8 @@
     local flavors
     local flavors_ref
     local flavor_lines
+    local public_network_id
+    local tenant_networks_reachable
 
     #TODO(afazekas):
     # sudo python setup.py deploy
@@ -153,6 +155,17 @@
         flavor_ref_alt=${flavors[1]}
     fi
 
+    if [ "$Q_USE_NAMESPACE" != "False" ]; then
+        tenant_networks_reachable=false
+    else
+        tenant_networks_reachable=true
+    fi
+
+    if is_service_enabled q-l3; then
+        public_network_id=$(quantum net-list | grep $PUBLIC_NETWORK_NAME | \
+            awk '{print $2}')
+    fi
+
     # Timeouts
     iniset $TEMPEST_CONF compute build_timeout $BUILD_TIMEOUT
     iniset $TEMPEST_CONF volume build_timeout $BUILD_TIMEOUT
@@ -205,8 +218,14 @@
     # compute admin
     iniset $TEMPEST_CONF "compute-admin" password "$password"
 
+    # network admin
+    iniset $TEMPEST_CONF "network-admin" password "$password"
+
     # network
     iniset $TEMPEST_CONF network api_version 2.0
+    iniset $TEMPEST_CONF network password "$password"
+    iniset $TEMPEST_CONF network tenant_networks_reachable "$tenant_networks_reachable"
+    iniset $TEMPEST_CONF network public_network_id "$public_network_id"
 
     #boto
     iniset $TEMPEST_CONF boto ec2_url "http://$SERVICE_HOST:8773/services/Cloud"
diff --git a/stack.sh b/stack.sh
index 5002f8b..cf638e8 100755
--- a/stack.sh
+++ b/stack.sh
@@ -961,6 +961,7 @@
     export OS_SERVICE_ENDPOINT=$SERVICE_ENDPOINT
     create_keystone_accounts
     create_nova_accounts
+    create_cinder_accounts
 
     # ``keystone_data.sh`` creates services, admin and demo users, and roles.
     ADMIN_PASSWORD=$ADMIN_PASSWORD SERVICE_TENANT_NAME=$SERVICE_TENANT_NAME SERVICE_PASSWORD=$SERVICE_PASSWORD \
diff --git a/tools/configure_tempest.sh b/tools/configure_tempest.sh
deleted file mode 100755
index 0924180..0000000
--- a/tools/configure_tempest.sh
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/usr/bin/env bash
-
-echo "$0 is scheduled for delete!!" >&2