Merge "heat had it's api split into two binaries (cfn & cloudwatch)"
diff --git a/AUTHORS b/AUTHORS
index 22d5f32..cd0acac 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -30,6 +30,7 @@
 Justin Shepherd <galstrom21@gmail.com>
 Ken Pepple <ken.pepple@rabbityard.com>
 Kiall Mac Innes <kiall@managedit.ie>
+Matt Joyce <matt.joyce@cloudscaling.com>
 Osamu Habuka <xiu.yushen@gmail.com>
 Russell Bryant <rbryant@redhat.com>
 Scott Moser <smoser@ubuntu.com>
diff --git a/exercises/client-args.sh b/exercises/client-args.sh
index 9cbb6a6..b3e2ad8 100755
--- a/exercises/client-args.sh
+++ b/exercises/client-args.sh
@@ -1,6 +1,6 @@
 #!/usr/bin/env bash
 
-**client-args.sh**
+# **client-args.sh**
 
 # Test OpenStack client authentication aguemnts handling
 
@@ -140,8 +140,10 @@
 report "Glance" $STATUS_GLANCE
 report "Swift" $STATUS_SWIFT
 
-echo "*********************************************************************"
-echo "SUCCESS: End DevStack Exercise: $0"
-echo "*********************************************************************"
+if (( $RETURN == 0 )); then
+    echo "*********************************************************************"
+    echo "SUCCESS: End DevStack Exercise: $0"
+    echo "*********************************************************************"
+fi
 
 exit $RETURN
diff --git a/exercises/client-env.sh b/exercises/client-env.sh
index 94f4a82..68c0e5a 100755
--- a/exercises/client-env.sh
+++ b/exercises/client-env.sh
@@ -1,6 +1,6 @@
 #!/usr/bin/env bash
 
-**client-env.sh**
+# **client-env.sh**
 
 # Test OpenStack client enviroment variable handling
 
@@ -149,8 +149,10 @@
 report "Glance" $STATUS_GLANCE
 report "Swift" $STATUS_SWIFT
 
-echo "*********************************************************************"
-echo "SUCCESS: End DevStack Exercise: $0"
-echo "*********************************************************************"
+if (( $RETURN == 0 )); then
+    echo "*********************************************************************"
+    echo "SUCCESS: End DevStack Exercise: $0"
+    echo "*********************************************************************"
+fi
 
 exit $RETURN
diff --git a/exercises/euca.sh b/exercises/euca.sh
index fb052dd..79405c2 100755
--- a/exercises/euca.sh
+++ b/exercises/euca.sh
@@ -72,6 +72,48 @@
     exit 1
 fi
 
+# Volumes
+# -------
+if [[ "$ENABLED_SERVICES" =~ "n-vol" || "$ENABLED_SERVICES" =~ "c-vol" ]]; then
+   VOLUME=`euca-create-volume -s 1 -z $VOLUME_ZONE | cut -f2`
+   die_if_not_set VOLUME "Failure to create volume"
+
+   # Test that volume has been created
+   VOLUME=`euca-describe-volumes | cut -f2`
+
+   # Test volume has become available
+   if ! timeout $ASSOCIATE_TIMEOUT sh -c "while ! euca-describe-volumes $VOLUME | grep -q available; do sleep 1; done"; then
+       echo "volume didnt become available within $RUNNING_TIMEOUT seconds"
+       exit 1
+   fi
+
+   # Attach volume to an instance
+   euca-attach-volume -i $INSTANCE -d $ATTACH_DEVICE $VOLUME || \
+       die "Failure attaching volume $VOLUME to $INSTANCE"
+   if ! timeout $ACTIVE_TIMEOUT sh -c "while ! euca-describe-volumes $VOLUME | grep -q in-use; do sleep 1; done"; then
+       echo "Could not attach $VOLUME to $INSTANCE"
+       exit 1
+   fi
+
+   # Detach volume from an instance
+   euca-detach-volume $VOLUME || \
+       die "Failure detaching volume $VOLUME to $INSTANCE"
+    if ! timeout $ACTIVE_TIMEOUT sh -c "while ! euca-describe-volumes $VOLUME | grep -q available; do sleep 1; done"; then
+        echo "Could not detach $VOLUME to $INSTANCE"
+        exit 1
+    fi
+
+    # Remove volume
+    euca-delete-volume $VOLUME || \
+        die "Failure to delete volume"
+    if ! timeout $ACTIVE_TIMEOUT sh -c "while euca-describe-volumes | grep $VOLUME; do sleep 1; done"; then
+       echo "Could not delete $VOLUME"
+       exit 1
+    fi
+else
+    echo "Volume Tests Skipped"
+fi
+
 # Allocate floating address
 FLOATING_IP=`euca-allocate-address | cut -f2`
 die_if_not_set FLOATING_IP "Failure allocating floating IP"
diff --git a/files/apts/horizon b/files/apts/horizon
index 53bddf0..2161ccd 100644
--- a/files/apts/horizon
+++ b/files/apts/horizon
@@ -21,3 +21,4 @@
 python-cherrypy3 # why?
 python-migrate
 nodejs
+python-netaddr
diff --git a/files/horizon_settings.py b/files/horizon_settings.py
index 487c06e..d18fd1a 100644
--- a/files/horizon_settings.py
+++ b/files/horizon_settings.py
@@ -41,7 +41,6 @@
 HORIZON_CONFIG = {
     'dashboards': ('nova', 'syspanel', 'settings',),
     'default_dashboard': 'nova',
-    'user_home': 'openstack_dashboard.views.user_home',
 }
 
 # TODO(tres): Remove these once Keystone has an API to identify auth backend.
diff --git a/files/rpms/horizon b/files/rpms/horizon
index 5e36820..12f75ba 100644
--- a/files/rpms/horizon
+++ b/files/rpms/horizon
@@ -15,6 +15,7 @@
 python-kombu
 python-migrate
 python-mox
+python-netaddr
 python-nose
 python-paste
 python-paste-deploy
diff --git a/functions b/functions
index 8ed9960..664cfa0 100644
--- a/functions
+++ b/functions
@@ -548,6 +548,26 @@
 }
 
 
+# Distro-agnostic function to tell if a package is installed
+# is_package_installed package [package ...]
+function is_package_installed() {
+    if [[ -z "$@" ]]; then
+        return 1
+    fi
+
+    if [[ -z "$os_PACKAGE" ]]; then
+        GetOSVersion
+    fi
+    if [[ "$os_PACKAGE" = "deb" ]]; then
+        dpkg -l "$@" > /dev/null
+        return $?
+    else
+        rpm --quiet -q "$@"
+        return $?
+    fi
+}
+
+
 # Test if the named environment variable is set and not zero length
 # is_set env-var
 function is_set() {
diff --git a/lib/cinder b/lib/cinder
index 5f0b255..ec491dd 100644
--- a/lib/cinder
+++ b/lib/cinder
@@ -189,10 +189,19 @@
     git_clone $CINDERCLIENT_REPO $CINDERCLIENT_DIR $CINDERCLIENT_BRANCH
 }
 
+# apply config.d approach (e.g. Oneiric does not have this)
+function _configure_tgt_for_config_d() {
+    if [[ ! -d /etc/tgt/conf.d/ ]]; then
+        sudo mkdir /etc/tgt/conf.d
+        echo "include /etc/tgt/conf.d/*.conf" | sudo tee -a /etc/tgt/targets.conf
+    fi
+}
+
 # start_cinder() - Start running processes, including screen
 function start_cinder() {
     if is_service_enabled c-vol; then
         if [[ "$os_PACKAGE" = "deb" ]]; then
+            _configure_tgt_for_config_d
             if [[ ! -f /etc/tgt/conf.d/cinder.conf ]]; then
                echo "include $CINDER_DIR/volumes/*" | sudo tee /etc/tgt/conf.d/cinder.conf
             fi
diff --git a/lib/keystone b/lib/keystone
index a0cc601..a6ab5a3 100644
--- a/lib/keystone
+++ b/lib/keystone
@@ -36,7 +36,7 @@
 KEYSTONECLIENT_DIR=$DEST/python-keystoneclient
 
 # Select the backend for Keystopne's service catalog
-KEYSTONE_CATALOG_BACKEND=${KEYSTONE_CATALOG_BACKEND:-template}
+KEYSTONE_CATALOG_BACKEND=${KEYSTONE_CATALOG_BACKEND:-sql}
 KEYSTONE_CATALOG=$KEYSTONE_CONF_DIR/default_catalog.templates
 
 # Set Keystone interface configuration
diff --git a/lib/n-vol b/lib/n-vol
index 30be0cd..a9d1c7d 100644
--- a/lib/n-vol
+++ b/lib/n-vol
@@ -5,6 +5,7 @@
 # - functions
 # - KEYSTONE_AUTH_* must be defined
 # SERVICE_{TENANT_NAME|PASSWORD} must be defined
+# _configure_tgt_for_config_d() from lib/cinder
 
 # stack.sh
 # ---------
@@ -94,6 +95,7 @@
 function start_nvol() {
     # Setup the tgt configuration file
     if [[ ! -f /etc/tgt/conf.d/nova.conf ]]; then
+        _configure_tgt_for_config_d
        sudo mkdir -p /etc/tgt/conf.d
        echo "include $NOVA_DIR/volumes/*" | sudo tee /etc/tgt/conf.d/nova.conf
     fi
diff --git a/samples/local.sh b/samples/local.sh
index eb9bc24..5901525 100755
--- a/samples/local.sh
+++ b/samples/local.sh
@@ -62,3 +62,6 @@
 # ----------
 
 # Add tcp/22 and icmp to default security group
+nova secgroup-add-rule default tcp 22 22 0.0.0.0/0
+nova secgroup-add-rule default icmp -1 -1 0.0.0.0/0
+
diff --git a/stack.sh b/stack.sh
index efbf38c..1151f7f 100755
--- a/stack.sh
+++ b/stack.sh
@@ -182,11 +182,7 @@
     sleep $ROOTSLEEP
 
     # Give the non-root user the ability to run as **root** via ``sudo``
-    if [[ "$os_PACKAGE" = "deb" ]]; then
-        dpkg -l sudo || install_package sudo
-    else
-        rpm -qa | grep sudo || install_package sudo
-    fi
+    is_package_installed sudo || install_package sudo
     if ! getent group stack >/dev/null; then
         echo "Creating a group called stack"
         groupadd stack
@@ -215,12 +211,7 @@
     exit 1
 else
     # We're not **root**, make sure ``sudo`` is available
-    if [[ "$os_PACKAGE" = "deb" ]]; then
-        CHECK_SUDO_CMD="dpkg -l sudo"
-    else
-        CHECK_SUDO_CMD="rpm -q sudo"
-    fi
-    $CHECK_SUDO_CMD || die "Sudo is required.  Re-run stack.sh as root ONE TIME ONLY to set up sudo."
+    is_package_installed sudo || die "Sudo is required.  Re-run stack.sh as root ONE TIME ONLY to set up sudo."
 
     # UEC images ``/etc/sudoers`` does not have a ``#includedir``, add one
     sudo grep -q "^#includedir.*/etc/sudoers.d" /etc/sudoers ||
@@ -1470,28 +1461,23 @@
 
 cp -p $NOVA_DIR/etc/nova/policy.json $NOVA_CONF_DIR
 
-# If Nova ships the new rootwrap filters files, deploy them
-# (owned by root) and add a parameter to ``$NOVA_ROOTWRAP``
-ROOTWRAP_SUDOER_CMD="$NOVA_ROOTWRAP"
-if [[ -d $NOVA_DIR/etc/nova/rootwrap.d ]]; then
-    # Wipe any existing rootwrap.d files first
-    if [[ -d $NOVA_CONF_DIR/rootwrap.d ]]; then
-        sudo rm -rf $NOVA_CONF_DIR/rootwrap.d
-    fi
-    # Deploy filters to /etc/nova/rootwrap.d
-    sudo mkdir -m 755 $NOVA_CONF_DIR/rootwrap.d
-    sudo cp $NOVA_DIR/etc/nova/rootwrap.d/*.filters $NOVA_CONF_DIR/rootwrap.d
-    sudo chown -R root:root $NOVA_CONF_DIR/rootwrap.d
-    sudo chmod 644 $NOVA_CONF_DIR/rootwrap.d/*
-    # Set up rootwrap.conf, pointing to /etc/nova/rootwrap.d
-    sudo cp $NOVA_DIR/etc/nova/rootwrap.conf $NOVA_CONF_DIR/
-    sudo sed -e "s:^filters_path=.*$:filters_path=$NOVA_CONF_DIR/rootwrap.d:" -i $NOVA_CONF_DIR/rootwrap.conf
-    sudo chown root:root $NOVA_CONF_DIR/rootwrap.conf
-    sudo chmod 0644 $NOVA_CONF_DIR/rootwrap.conf
-    # Specify rootwrap.conf as first parameter to nova-rootwrap
-    NOVA_ROOTWRAP="$NOVA_ROOTWRAP $NOVA_CONF_DIR/rootwrap.conf"
-    ROOTWRAP_SUDOER_CMD="$NOVA_ROOTWRAP *"
+# Deploy new rootwrap filters files (owned by root).
+# Wipe any existing rootwrap.d files first
+if [[ -d $NOVA_CONF_DIR/rootwrap.d ]]; then
+    sudo rm -rf $NOVA_CONF_DIR/rootwrap.d
 fi
+# Deploy filters to /etc/nova/rootwrap.d
+sudo mkdir -m 755 $NOVA_CONF_DIR/rootwrap.d
+sudo cp $NOVA_DIR/etc/nova/rootwrap.d/*.filters $NOVA_CONF_DIR/rootwrap.d
+sudo chown -R root:root $NOVA_CONF_DIR/rootwrap.d
+sudo chmod 644 $NOVA_CONF_DIR/rootwrap.d/*
+# Set up rootwrap.conf, pointing to /etc/nova/rootwrap.d
+sudo cp $NOVA_DIR/etc/nova/rootwrap.conf $NOVA_CONF_DIR/
+sudo sed -e "s:^filters_path=.*$:filters_path=$NOVA_CONF_DIR/rootwrap.d:" -i $NOVA_CONF_DIR/rootwrap.conf
+sudo chown root:root $NOVA_CONF_DIR/rootwrap.conf
+sudo chmod 0644 $NOVA_CONF_DIR/rootwrap.conf
+# Specify rootwrap.conf as first parameter to nova-rootwrap
+ROOTWRAP_SUDOER_CMD="$NOVA_ROOTWRAP $NOVA_CONF_DIR/rootwrap.conf *"
 
 # Set up the rootwrap sudoers for nova
 TEMPFILE=`mktemp`
@@ -1953,7 +1939,7 @@
 add_nova_opt "verbose=True"
 add_nova_opt "auth_strategy=keystone"
 add_nova_opt "allow_resize_to_same_host=True"
-add_nova_opt "root_helper=sudo $NOVA_ROOTWRAP"
+add_nova_opt "rootwrap_config=$NOVA_CONF_DIR/rootwrap.conf"
 add_nova_opt "compute_scheduler_driver=$SCHEDULER"
 add_nova_opt "dhcpbridge_flagfile=$NOVA_CONF_DIR/$NOVA_CONF"
 add_nova_opt "fixed_range=$FIXED_RANGE"
diff --git a/tests/functions.sh b/tests/functions.sh
index f111a48..3a0f319 100755
--- a/tests/functions.sh
+++ b/tests/functions.sh
@@ -239,3 +239,44 @@
 test_disable_negated_services 'b,a,-a' 'b'
 test_disable_negated_services 'a,b,-a' 'b'
 test_disable_negated_services 'a,-a,b' 'b'
+
+
+echo "Testing is_package_installed()"
+
+if [[ -z "$os_PACKAGE" ]]; then
+    GetOSVersion
+fi
+
+if [[ "$os_PACKAGE" = "deb" ]]; then
+    is_package_installed dpkg
+    VAL=$?
+else
+    is_package_installed rpm
+    VAL=$?
+fi
+if [[ "$VAL" -eq 0 ]]; then
+    echo "OK"
+else
+    echo "is_package_installed() on existing package failed"
+fi
+
+if [[ "$os_PACKAGE" = "deb" ]]; then
+    is_package_installed dpkg bash
+    VAL=$?
+else
+    is_package_installed rpm bash
+    VAL=$?
+fi
+if [[ "$VAL" -eq 0 ]]; then
+    echo "OK"
+else
+    echo "is_package_installed() on more than one existing package failed"
+fi
+
+is_package_installed zzzZZZzzz
+VAL=$?
+if [[ "$VAL" -ne 0 ]]; then
+    echo "OK"
+else
+    echo "is_package_installed() on non-existing package failed"
+fi
diff --git a/tools/xen/prepare_guest_template.sh b/tools/xen/prepare_guest_template.sh
index 60782d0..baf9c3a 100755
--- a/tools/xen/prepare_guest_template.sh
+++ b/tools/xen/prepare_guest_template.sh
@@ -49,7 +49,7 @@
 XS_TOOLS_FILE_NAME="xs-tools.deb"
 XS_TOOLS_PATH="/root/$XS_TOOLS_FILE_NAME"
 if [ -e "$ISO_DIR" ]; then
-    TOOLS_ISO=$(ls $ISO_DIR/xs-tools-*.iso)
+    TOOLS_ISO=$(ls -1 $ISO_DIR/xs-tools-*.iso | head -1)
     TMP_DIR=/tmp/temp.$RANDOM
     mkdir -p $TMP_DIR
     mount -o loop $TOOLS_ISO $TMP_DIR