Merge "Modify euca test to get zone using describe"
diff --git a/.gitignore b/.gitignore
index c5744b3..17cb38c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -9,3 +9,4 @@
 files/*.gz
 files/images
 stack-screenrc
+*.pem
diff --git a/functions b/functions
index 664cfa0..0cfffb8 100644
--- a/functions
+++ b/functions
@@ -792,7 +792,12 @@
         *.img)
             IMAGE="$FILES/$IMAGE_FNAME";
             IMAGE_NAME=$(basename "$IMAGE" ".img")
-            DISK_FORMAT=raw
+            format=$(qemu-img info ${IMAGE} | awk '/^file format/ { print $3; exit }')
+            if [[ ",qcow2,raw,vdi,vmdk,vpc," =~ ",$format," ]]; then
+                DISK_FORMAT=$format
+            else
+                DISK_FORMAT=raw
+            fi
             CONTAINER_FORMAT=bare
             ;;
         *.img.gz)
diff --git a/lib/ceilometer b/lib/ceilometer
index 0208753..35d2507 100644
--- a/lib/ceilometer
+++ b/lib/ceilometer
@@ -48,10 +48,10 @@
 function configure_ceilometer() {
     setup_develop $CEILOMETER_DIR
 
-    [ -d $CEILOMETER_CONF_DIR ] && sudo mkdir -m 755 -p $CEILOMETER_CONF_DIR
+    [ ! -d $CEILOMETER_CONF_DIR ] && sudo mkdir -m 755 -p $CEILOMETER_CONF_DIR
     sudo chown $USER $CEILOMETER_CONF_DIR
 
-    [ ! -d $CEILOMETER_API_LOG_DIR ] &&  sudo mkdir -m 755 -p $CEILOMETER_API_LOG_DIR 
+    [ ! -d $CEILOMETER_API_LOG_DIR ] &&  sudo mkdir -m 755 -p $CEILOMETER_API_LOG_DIR
     sudo chown $USER $CEILOMETER_API_LOG_DIR
 
     # ceilometer confs are copy of /etc/nova/nova.conf which must exist first
@@ -72,5 +72,13 @@
     screen_it ceilometer-api "cd $CEILOMETER_DIR && $CEILOMETER_BIN_DIR/ceilometer-api -d -v --log-dir=$CEILOMETER_API_LOG_DIR"
 }
 
+# stop_ceilometer() - Stop running processes
+function stop_ceilometer() {
+    # Kill the ceilometer screen windows
+    for serv in ceilometer-acompute ceilometer-acentral ceilometer-collector ceilometer-api; do
+        screen -S $SCREEN_NAME -p $serv -X kill
+    done
+}
+
 # Restore xtrace
 $XTRACE
diff --git a/lib/cinder b/lib/cinder
index de2debc..14c2df8 100644
--- a/lib/cinder
+++ b/lib/cinder
@@ -225,9 +225,12 @@
     screen_it c-sch "cd $CINDER_DIR && $CINDER_BIN_DIR/cinder-scheduler --config-file $CINDER_CONF"
 }
 
-# stop_cinder() - Stop running processes (non-screen)
+# stop_cinder() - Stop running processes
 function stop_cinder() {
-    # FIXME(dtroyer): stop only the cinder screen window?
+    # Kill the cinder screen windows
+    for serv in c-api c-sch c-vol; do
+        screen -S $SCREEN_NAME -p $serv -X kill
+    done
 
     if is_service_enabled c-vol; then
         stop_service tgt
diff --git a/lib/glance b/lib/glance
index 44990f1..4cc6253 100644
--- a/lib/glance
+++ b/lib/glance
@@ -169,7 +169,7 @@
     fi
 }
 
-# stop_glance() - Stop running processes (non-screen)
+# stop_glance() - Stop running processes
 function stop_glance() {
     # Kill the Glance screen windows
     screen -S $SCREEN_NAME -p g-api -X kill
diff --git a/lib/heat b/lib/heat
index e713b39..6e823f2 100644
--- a/lib/heat
+++ b/lib/heat
@@ -173,10 +173,12 @@
     screen_it h-meta "cd $HEAT_DIR; bin/heat-metadata --config-dir=$HEAT_CONF_DIR/heat-metadata.conf"
 }
 
-# stop_heat() - Stop running processes (non-screen)
+# stop_heat() - Stop running processes
 function stop_heat() {
-    # This function intentionally left blank
-    :
+    # Kill the cinder screen windows
+    for serv in h-eng h-api-cfn h-api-cw h-meta; do
+        screen -S $SCREEN_NAME -p $serv -X kill
+    done
 }
 
 # Restore xtrace
diff --git a/lib/n-vol b/lib/n-vol
index cc669cb..db53582 100644
--- a/lib/n-vol
+++ b/lib/n-vol
@@ -114,9 +114,10 @@
     screen_it n-vol "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-volume"
 }
 
-# stop_nvol() - Stop running processes (non-screen)
+# stop_nvol() - Stop running processes
 function stop_nvol() {
-    # FIXME(dtroyer): stop only the n-vol screen window?
+    # Kill the nova volume screen window
+    screen -S $SCREEN_NAME -p n-vol -X kill
 
     stop_service tgt
 }
diff --git a/stack.sh b/stack.sh
index 545c071..5ea1b9b 100755
--- a/stack.sh
+++ b/stack.sh
@@ -357,6 +357,7 @@
 Q_AUTH_STRATEGY=${Q_AUTH_STRATEGY:-keystone}
 # Use namespace or not
 Q_USE_NAMESPACE=${Q_USE_NAMESPACE:-True}
+Q_USE_ROOTWRAP=${Q_USE_ROOTWRAP=:-True}
 # Meta data IP
 Q_META_DATA_IP=${Q_META_DATA_IP:-}
 
@@ -584,10 +585,35 @@
 # Log files
 # ---------
 
+# Draw a spinner so the user knows something is happening
+function spinner()
+{
+    local delay=0.75
+    local spinstr='|/-\'
+    printf "..." >&3
+    while [ true ]; do
+        local temp=${spinstr#?}
+        printf "[%c]" "$spinstr" >&3
+        local spinstr=$temp${spinstr%"$temp"}
+        sleep $delay
+        printf "\b\b\b" >&3
+    done
+}
+
 # Echo text to the log file, summary log file and stdout
 # echo_summary "something to say"
 function echo_summary() {
-    echo $@ >&6
+    if [[ -t 3 && "$VERBOSE" != "True" ]]; then
+        kill >/dev/null 2>&1 $LAST_SPINNER_PID
+        if [ ! -z "$LAST_SPINNER_PID" ]; then
+            printf "\b\b\bdone\n" >&3
+        fi
+        echo -n $@ >&6
+        spinner &
+        LAST_SPINNER_PID=$!
+    else
+        echo $@ >&6
+    fi
 }
 
 # Echo text only to stdout, no log files
@@ -640,7 +666,7 @@
     # Set up output redirection without log files
     # Copy stdout to fd 3
     exec 3>&1
-    if [[ "$VERBOSE" != "yes" ]]; then
+    if [[ "$VERBOSE" != "True" ]]; then
         # Throw away stdout and stderr
         exec 1>/dev/null 2>&1
     fi
@@ -669,10 +695,20 @@
 # Set Up Script Execution
 # -----------------------
 
+# Kill background processes on exit
+trap clean EXIT
+clean() {
+    local r=$?
+    kill >/dev/null 2>&1 $(jobs -p)
+    exit $r
+}
+
+
 # Exit on any errors so that errors don't compound
 trap failed ERR
 failed() {
     local r=$?
+    kill >/dev/null 2>&1 $(jobs -p)
     set +o xtrace
     [ -n "$LOGFILE" ] && echo "${0##*/} failed: full log in $LOGFILE"
     exit $r
@@ -1233,6 +1269,11 @@
     Q_CONF_FILE=/etc/quantum/quantum.conf
     cp $QUANTUM_DIR/etc/quantum.conf $Q_CONF_FILE
     Q_RR_CONF_FILE=/etc/quantum/rootwrap.conf
+    if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
+        Q_RR_COMMAND="sudo"
+    else
+        Q_RR_COMMAND="sudo $QUANTUM_DIR/bin/quantum-rootwrap $Q_RR_CONF_FILE"
+    fi
     cp -p $QUANTUM_DIR/etc/rootwrap.conf $Q_RR_CONF_FILE
 
     # Copy over the config and filter bits
@@ -1345,8 +1386,6 @@
         if [[ "$OVS_BRIDGE_MAPPINGS" != "" ]]; then
             iniset /$Q_PLUGIN_CONF_FILE OVS bridge_mappings $OVS_BRIDGE_MAPPINGS
         fi
-        # Update config w/rootwrap
-        iniset /$Q_PLUGIN_CONF_FILE OVS root_helper #Q_RR_CONF_FILE
         AGENT_BINARY="$QUANTUM_DIR/bin/quantum-openvswitch-agent"
     elif [[ "$Q_PLUGIN" = "linuxbridge" ]]; then
         # Setup physical network interface mappings.  Override
@@ -1358,10 +1397,10 @@
         if [[ "$LB_INTERFACE_MAPPINGS" != "" ]]; then
             iniset /$Q_PLUGIN_CONF_FILE LINUX_BRIDGE physical_interface_mappings $LB_INTERFACE_MAPPINGS
         fi
-        # Update config w/rootwrap
-        iniset /$Q_PLUGIN_CONF_FILE LINUX_BRIDGE root_helper #Q_RR_CONF_FILE
         AGENT_BINARY="$QUANTUM_DIR/bin/quantum-linuxbridge-agent"
     fi
+    # Update config w/rootwrap
+    iniset /$Q_PLUGIN_CONF_FILE AGENT root_helper "$Q_RR_COMMAND"
 fi
 
 # Quantum DHCP
@@ -1381,7 +1420,7 @@
     quantum_setup_keystone $Q_DHCP_CONF_FILE DEFAULT set_auth_url
 
     # Update config w/rootwrap
-    iniset /$Q_DHCP_CONF_FILE DEFAULT root_helper #Q_RR_CONF_FILE
+    iniset $Q_DHCP_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND"
 
     if [[ "$Q_PLUGIN" = "openvswitch" ]]; then
         iniset $Q_DHCP_CONF_FILE DEFAULT interface_driver quantum.agent.linux.interface.OVSInterfaceDriver
@@ -1406,6 +1445,8 @@
     iniset $Q_L3_CONF_FILE DEFAULT metadata_ip $Q_META_DATA_IP
     iniset $Q_L3_CONF_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE
 
+    iniset $Q_L3_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND"
+
     quantum_setup_keystone $Q_L3_CONF_FILE DEFAULT set_auth_url
     if [[ "$Q_PLUGIN" == "openvswitch" ]]; then
         iniset $Q_L3_CONF_FILE DEFAULT interface_driver quantum.agent.linux.interface.OVSInterfaceDriver
@@ -2222,8 +2263,9 @@
     start_cinder
 fi
 if is_service_enabled ceilometer; then
-    echo_summary "Starting Ceilometer"
+    echo_summary "Configuring Ceilometer"
     configure_ceilometer
+    echo_summary "Starting Ceilometer"
     start_ceilometer
 fi
 screen_it horizon "cd $HORIZON_DIR && sudo tail -f /var/log/$APACHE_NAME/horizon_error.log"
@@ -2287,7 +2329,7 @@
 if [[ -n "$LOGFILE" ]]; then
     exec 1>&3
     # Force all output to stdout and logs now
-    exec 1> >( tee "${LOGFILE}" ) 2>&1
+    exec 1> >( tee -a "${LOGFILE}" ) 2>&1
 else
     # Force all output to stdout now
     exec 1>&3