Merge "Adds parameter interpolation for Tempest config"
diff --git a/exercise.sh b/exercise.sh
index 15f264f..a0349ce 100755
--- a/exercise.sh
+++ b/exercise.sh
@@ -5,6 +5,9 @@
 # Keep track of the current devstack directory.
 TOP_DIR=$(cd $(dirname "$0") && pwd)
 
+# Import common functions
+source $TOP_DIR/functions
+
 # Load local configuration
 source $TOP_DIR/stackrc
 
diff --git a/files/apts/general b/files/apts/general
index 971a5ff..3fa07a7 100644
--- a/files/apts/general
+++ b/files/apts/general
@@ -18,4 +18,4 @@
 tcpdump
 euca2ools # only for testing client
 tar
-python-cmd2
+python-cmd2 # dist:precise
diff --git a/lib/cinder b/lib/cinder
index 0e42600..49ad4af 100644
--- a/lib/cinder
+++ b/lib/cinder
@@ -142,6 +142,8 @@
             if ! sudo vgs $VOLUME_GROUP; then sudo vgcreate $VOLUME_GROUP $DEV; fi
         fi
 
+        mkdir -p $CINDER_DIR/volumes
+
         if sudo vgs $VOLUME_GROUP; then
             if [[ "$os_PACKAGE" = "rpm" ]]; then
                 # RPM doesn't start the service
@@ -171,6 +173,9 @@
 function start_cinder() {
     if is_service_enabled c-vol; then
         if [[ "$os_PACKAGE" = "deb" ]]; then
+            if [[ ! -f /etc/tgt/conf.d/cinder.conf ]]; then
+               echo "include $CINDER_DIR/volumes/*" | sudo tee /etc/tgt/conf.d/cinder.conf
+            fi
             # tgt in oneiric doesn't restart properly if tgtd isn't running
             # do it in two steps
             sudo stop tgt || true
diff --git a/samples/local.sh b/samples/local.sh
index 83637f9..2c54b10 100755
--- a/samples/local.sh
+++ b/samples/local.sh
@@ -13,6 +13,9 @@
 # Keep track of the devstack directory
 TOP_DIR=$(cd $(dirname "$0") && pwd)
 
+# Import common functions
+source $TOP_DIR/functions
+
 # Use openrc + stackrc + localrc for settings
 source $TOP_DIR/stackrc
 
diff --git a/stack.sh b/stack.sh
index 0fbb957..19803bb 100755
--- a/stack.sh
+++ b/stack.sh
@@ -1075,17 +1075,9 @@
     Q_API_PASTE_FILE=/etc/quantum/api-paste.ini
     Q_POLICY_FILE=/etc/quantum/policy.json
 
-    if [[ -e $QUANTUM_DIR/etc/quantum.conf ]]; then
-      sudo cp $QUANTUM_DIR/etc/quantum.conf $Q_CONF_FILE
-    fi
-
-    if [[ -e $QUANTUM_DIR/etc/api-paste.ini ]]; then
-      sudo cp $QUANTUM_DIR/etc/api-paste.ini $Q_API_PASTE_FILE
-    fi
-
-    if [[ -e $QUANTUM_DIR/etc/policy.json ]]; then
-      sudo cp $QUANTUM_DIR/etc/policy.json $Q_POLICY_FILE
-    fi
+    cp $QUANTUM_DIR/etc/quantum.conf $Q_CONF_FILE
+    cp $QUANTUM_DIR/etc/api-paste.ini $Q_API_PASTE_FILE
+    cp $QUANTUM_DIR/etc/policy.json $Q_POLICY_FILE
 
     if is_service_enabled mysql; then
             mysql -u$MYSQL_USER -p$MYSQL_PASSWORD -e "DROP DATABASE IF EXISTS $Q_DB_NAME;"
@@ -1096,7 +1088,16 @@
     fi
 
     # Update either configuration file with plugin
-    sudo sed -i -e "s/^core_plugin =.*$/core_plugin = $Q_PLUGIN_CLASS/g" $Q_CONF_FILE
+    iniset $Q_CONF_FILE DEFAULT core_plugin $Q_PLUGIN_CLASS
+
+    iniset $Q_CONF_FILE DEFAULT auth_strategy $Q_AUTH_STRATEGY
+    iniset $Q_API_PASTE_FILE filter:authtoken auth_host $KEYSTONE_SERVICE_HOST
+    iniset $Q_API_PASTE_FILE filter:authtoken auth_port $KEYSTONE_AUTH_PORT
+    iniset $Q_API_PASTE_FILE filter:authtoken auth_protocol $KEYSTONE_SERVICE_PROTOCOL
+    iniset $Q_API_PASTE_FILE filter:authtoken admin_tenant_name $SERVICE_TENANT_NAME
+    iniset $Q_API_PASTE_FILE filter:authtoken admin_user $Q_ADMIN_USERNAME
+    iniset $Q_API_PASTE_FILE filter:authtoken admin_password $SERVICE_PASSWORD
+
     screen_it q-svc "cd $QUANTUM_DIR && python $QUANTUM_DIR/bin/quantum-server --config-file $Q_CONF_FILE --config-file /$Q_PLUGIN_CONF_FILE"
 fi
 
@@ -1699,6 +1700,9 @@
             start_service tgtd
         fi
 
+        # Setup tgtd configuration files
+        mkdir -p $NOVA_DIR/volumes
+
         # Remove nova iscsi targets
         sudo tgtadm --op show --mode target | grep $VOLUME_NAME_PREFIX | grep Target | cut -f3 -d ' ' | sudo xargs -n1 tgt-admin --delete || true
         # Clean out existing volumes
@@ -1711,6 +1715,12 @@
     fi
 
     if [[ "$os_PACKAGE" = "deb" ]]; then
+
+        # Setup the tgt configuration file
+        if [[ ! -f /etc/tgt/conf.d/nova.conf ]]; then
+           echo "include $NOVA_DIR/volumes/*" | sudo tee /etc/tgt/conf.d/nova.conf
+        fi
+
         # tgt in oneiric doesn't restart properly if tgtd isn't running
         # do it in two steps
         sudo stop tgt || true
@@ -2069,10 +2079,10 @@
         TENANT_ID=$(keystone tenant-list | grep " demo " | get_field 1)
 
         # Create a small network
-        NET_ID=$(quantum net-create --os_token $Q_ADMIN_USERNAME --os_url http://$Q_HOST:$Q_PORT --tenant_id $TENANT_ID net1 | grep ' id ' | get_field 2)
-
-        # Create a subnet
-        quantum subnet-create --os_token $Q_ADMIN_USERNAME --os_url http://$Q_HOST:$Q_PORT --tenant_id $TENANT_ID --ip_version 4 --gateway  $NETWORK_GATEWAY $NET_ID $FIXED_RANGE
+        # Since quantum command is executed in admin context at this point,
+        # --tenant_id needs to be specified.
+        NET_ID=$(quantum net-create --tenant_id $TENANT_ID net1 | grep ' id ' | get_field 2)
+        quantum subnet-create --tenant_id $TENANT_ID --ip_version 4 --gateway $NETWORK_GATEWAY $NET_ID $FIXED_RANGE
     fi
 fi
 
diff --git a/stackrc b/stackrc
index 9ac17ac..0a26508 100644
--- a/stackrc
+++ b/stackrc
@@ -1,6 +1,9 @@
 # Find the other rc files
 RC_DIR=$(cd $(dirname "$BASH_SOURCE") && pwd)
 
+# Destination path for installation
+DEST=/opt/stack
+
 # Specify which services to launch.  These generally correspond to
 # screen tabs. If you like to add other services that are not enabled
 # by default you can append them in your ENABLED_SERVICES variable in
diff --git a/tools/build_bm.sh b/tools/build_bm.sh
index b2d4c36..ab0ba0e 100755
--- a/tools/build_bm.sh
+++ b/tools/build_bm.sh
@@ -5,6 +5,13 @@
 # Build an OpenStack install on a bare metal machine.
 set +x
 
+# Keep track of the current directory
+TOOLS_DIR=$(cd $(dirname "$0") && pwd)
+TOP_DIR=$(cd $TOOLS_DIR/..; pwd)
+
+# Import common functions
+source $TOP_DIR/functions
+
 # Source params
 source ./stackrc