Merge "Revert "Remove python-openstackclient.""
diff --git a/files/apts/horizon b/files/apts/horizon
index 2161ccd..2c2faf1 100644
--- a/files/apts/horizon
+++ b/files/apts/horizon
@@ -21,4 +21,5 @@
 python-cherrypy3 # why?
 python-migrate
 nodejs
+nodejs-legacy # dist:quantal
 python-netaddr
diff --git a/files/keystone_data.sh b/files/keystone_data.sh
index 71994a8..f75d24a 100755
--- a/files/keystone_data.sh
+++ b/files/keystone_data.sh
@@ -106,7 +106,7 @@
 fi
 
 # Nova
-if [[ "$ENABLED_SERVICES" =~ "n-cpu" ]]; then
+if [[ "$ENABLED_SERVICES" =~ "n-api" ]]; then
     NOVA_USER=$(get_id keystone user-create \
         --name=nova \
         --pass="$SERVICE_PASSWORD" \
diff --git a/lib/databases/postgresql b/lib/databases/postgresql
index 10ab721..d9c2f00 100644
--- a/lib/databases/postgresql
+++ b/lib/databases/postgresql
@@ -23,6 +23,7 @@
     if [[ "$os_PACKAGE" = "rpm" ]]; then
         PG_HBA=/var/lib/pgsql/data/pg_hba.conf
         PG_CONF=/var/lib/pgsql/data/postgresql.conf
+        sudo [ -e $PG_HBA ] || sudo postgresql-setup initdb
     else
         PG_DIR=`find /etc/postgresql -name pg_hba.conf|xargs dirname`
         PG_HBA=$PG_DIR/pg_hba.conf
diff --git a/lib/heat b/lib/heat
index efdcfad..396c8a0 100644
--- a/lib/heat
+++ b/lib/heat
@@ -125,6 +125,9 @@
     iniset $HEAT_ENGINE_CONF DEFAULT use_syslog $SYSLOG
     iniset $HEAT_ENGINE_CONF DEFAULT bind_host $HEAT_ENGINE_HOST
     iniset $HEAT_ENGINE_CONF DEFAULT bind_port $HEAT_ENGINE_PORT
+    iniset $HEAT_ENGINE_CONF DEFAULT heat_metadata_server_url http://$HEAT_API_CFN_HOST:$HEAT_API_CFN_PORT
+    iniset $HEAT_ENGINE_CONF DEFAULT heat_waitcondition_server_url http://$HEAT_METADATA_HOST:$HEAT_METADATA_PORT
+    iniset $HEAT_ENGINE_CONF DEFAULT heat_watch_server_url http://$HEAT_API_CW_HOST:$HEAT_API_CW_PORT
     local dburl
     database_connection_url dburl heat
     iniset $HEAT_ENGINE_CONF DEFAULT sql_connection $dburl
diff --git a/lib/horizon b/lib/horizon
new file mode 100644
index 0000000..c6c96da
--- /dev/null
+++ b/lib/horizon
@@ -0,0 +1,133 @@
+# lib/horizon
+# Functions to control the configuration and operation of the horizon service
+# <do not include this template file in ``stack.sh``!>
+
+# Dependencies:
+# ``functions`` file
+# ``SERVICE_{TENANT_NAME|PASSWORD}`` must be defined
+# <list other global vars that are assumed to be defined>
+
+# ``stack.sh`` calls the entry points in this order:
+#
+# install_horizon
+# configure_horizon
+# init_horizon
+# start_horizon
+# stop_horizon
+# cleanup_horizon
+
+# Save trace setting
+XTRACE=$(set +o | grep xtrace)
+set +o xtrace
+
+
+# Defaults
+# --------
+
+# <define global variables here that belong to this project>
+
+# Set up default directories
+HORIZON_DIR=$DEST/horizon
+
+# Allow overriding the default Apache user and group, default both to
+# current user.
+APACHE_USER=${APACHE_USER:-$USER}
+APACHE_GROUP=${APACHE_GROUP:-$APACHE_USER}
+
+
+# Entry Points
+# ------------
+
+# cleanup_horizon() - Remove residual data files, anything left over from previous
+# runs that a clean run would need to clean up
+function cleanup_horizon() {
+    # kill instances (nova)
+    # delete image files (glance)
+    # This function intentionally left blank
+    :
+}
+
+# configure_horizon() - Set config files, create data dirs, etc
+function configure_horizon() {
+    setup_develop $HORIZON_DIR
+}
+
+# init_horizon() - Initialize databases, etc.
+function init_horizon() {
+    # Remove stale session database.
+    rm -f $HORIZON_DIR/openstack_dashboard/local/dashboard_openstack.sqlite3
+
+    # ``local_settings.py`` is used to override horizon default settings.
+    local_settings=$HORIZON_DIR/openstack_dashboard/local/local_settings.py
+    cp $FILES/horizon_settings.py $local_settings
+
+    # Initialize the horizon database (it stores sessions and notices shown to
+    # users).  The user system is external (keystone).
+    cd $HORIZON_DIR
+    python manage.py syncdb --noinput
+    cd $TOP_DIR
+
+    # Create an empty directory that apache uses as docroot
+    sudo mkdir -p $HORIZON_DIR/.blackhole
+
+
+    if [[ "$os_PACKAGE" = "deb" ]]; then
+        APACHE_NAME=apache2
+        APACHE_CONF=sites-available/horizon
+        # Clean up the old config name
+        sudo rm -f /etc/apache2/sites-enabled/000-default
+        # Be a good citizen and use the distro tools here
+        sudo touch /etc/$APACHE_NAME/$APACHE_CONF
+        sudo a2ensite horizon
+    else
+        # Install httpd, which is NOPRIME'd
+        APACHE_NAME=httpd
+        APACHE_CONF=conf.d/horizon.conf
+        sudo sed '/^Listen/s/^.*$/Listen 0.0.0.0:80/' -i /etc/httpd/conf/httpd.conf
+    fi
+
+    # Configure apache to run horizon
+    sudo sh -c "sed -e \"
+        s,%USER%,$APACHE_USER,g;
+        s,%GROUP%,$APACHE_GROUP,g;
+        s,%HORIZON_DIR%,$HORIZON_DIR,g;
+        s,%APACHE_NAME%,$APACHE_NAME,g;
+        s,%DEST%,$DEST,g;
+    \" $FILES/apache-horizon.template >/etc/$APACHE_NAME/$APACHE_CONF"
+
+}
+
+# install_horizon() - Collect source and prepare
+function install_horizon() {
+    # Apache installation, because we mark it NOPRIME
+    if [[ "$os_PACKAGE" = "deb" ]]; then
+        # Install apache2, which is NOPRIME'd
+        install_package apache2 libapache2-mod-wsgi
+    else
+        sudo rm -f /etc/httpd/conf.d/000-*
+        install_package httpd mod_wsgi
+    fi
+
+    # NOTE(sdague) quantal changed the name of the node binary
+    if [[ "$os_PACKAGE" = "deb" ]]; then
+        if [[ ! -e "/usr/bin/node" ]]; then
+            install_package nodejs-legacy
+        fi
+    fi
+
+    git_clone $HORIZON_REPO $HORIZON_DIR $HORIZON_BRANCH $HORIZON_TAG
+}
+
+# start_horizon() - Start running processes, including screen
+function start_horizon() {
+    restart_service $APACHE_NAME
+    screen_it horizon "cd $HORIZON_DIR && sudo tail -f /var/log/$APACHE_NAME/horizon_error.log"
+}
+
+# stop_horizon() - Stop running processes (non-screen)
+function stop_horizon() {
+    stop_service apache2
+}
+
+# Restore xtrace
+$XTRACE
diff --git a/lib/nova b/lib/nova
index fbb5a01..3ea2f2a 100644
--- a/lib/nova
+++ b/lib/nova
@@ -432,14 +432,15 @@
     screen_it n-net "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-network"
     screen_it n-sch "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-scheduler"
     screen_it n-novnc "cd $NOVNC_DIR && ./utils/nova-novncproxy --config-file $NOVA_CONF --web ."
-    screen_it n-xvnc "cd $NOVA_DIR && ./bin/nova-xvpvncproxy --config-file $NOVA_CONF"
-    screen_it n-cauth "cd $NOVA_DIR && ./bin/nova-consoleauth"
+    screen_it n-xvnc "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-xvpvncproxy --config-file $NOVA_CONF"
+    screen_it n-cauth "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-consoleauth"
+    screen_it n-cond "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-conductor"
 }
 
 # stop_nova() - Stop running processes (non-screen)
 function stop_nova() {
     # Kill the nova screen windows
-    for serv in n-api n-cpu n-crt n-net n-sch n-novnc n-xvnc n-cauth; do
+    for serv in n-api n-cpu n-crt n-net n-sch n-novnc n-xvnc n-cauth n-cond; do
         screen -S $SCREEN_NAME -p $serv -X kill
     done
 }
diff --git a/stack.sh b/stack.sh
index ec10b11..570fc68 100755
--- a/stack.sh
+++ b/stack.sh
@@ -306,6 +306,7 @@
 # ==================
 
 # Get project function libraries
+source $TOP_DIR/lib/horizon
 source $TOP_DIR/lib/keystone
 source $TOP_DIR/lib/glance
 source $TOP_DIR/lib/nova
@@ -330,7 +331,7 @@
 # Default Quantum Port
 Q_PORT=${Q_PORT:-9696}
 # Default Quantum Host
-Q_HOST=${Q_HOST:-localhost}
+Q_HOST=${Q_HOST:-$HOST_IP}
 # Which Quantum API nova should use
 # Default admin username
 Q_ADMIN_USERNAME=${Q_ADMIN_USERNAME:-quantum}
@@ -569,15 +570,6 @@
 SERVICE_TENANT_NAME=${SERVICE_TENANT_NAME:-service}
 
 
-# Horizon
-# -------
-
-# Allow overriding the default Apache user and group, default both to
-# current user.
-APACHE_USER=${APACHE_USER:-$USER}
-APACHE_GROUP=${APACHE_GROUP:-$APACHE_USER}
-
-
 # Log files
 # ---------
 
@@ -757,16 +749,6 @@
     install_database
 fi
 
-if is_service_enabled horizon; then
-    if [[ "$os_PACKAGE" = "deb" ]]; then
-        # Install apache2, which is NOPRIME'd
-        install_package apache2 libapache2-mod-wsgi
-    else
-        sudo rm -f /etc/httpd/conf.d/000-*
-        install_package httpd mod_wsgi
-    fi
-fi
-
 if is_service_enabled q-agt; then
     if is_quantum_ovs_base_plugin "$Q_PLUGIN"; then
         # Install deps
@@ -844,8 +826,8 @@
     git_clone $NOVNC_REPO $NOVNC_DIR $NOVNC_BRANCH
 fi
 if is_service_enabled horizon; then
-    # django powered web control panel for openstack
-    git_clone $HORIZON_REPO $HORIZON_DIR $HORIZON_BRANCH $HORIZON_TAG
+    # dashboard
+    install_horizon
 fi
 if is_service_enabled quantum; then
     git_clone $QUANTUM_CLIENT_REPO $QUANTUM_CLIENT_DIR $QUANTUM_CLIENT_BRANCH
@@ -904,7 +886,7 @@
     configure_nova
 fi
 if is_service_enabled horizon; then
-    setup_develop $HORIZON_DIR
+    configure_horizon
 fi
 if is_service_enabled quantum; then
     setup_develop $QUANTUM_CLIENT_DIR
@@ -1040,48 +1022,8 @@
 
 if is_service_enabled horizon; then
     echo_summary "Configuring and starting Horizon"
-
-    # Remove stale session database.
-    rm -f $HORIZON_DIR/openstack_dashboard/local/dashboard_openstack.sqlite3
-
-    # ``local_settings.py`` is used to override horizon default settings.
-    local_settings=$HORIZON_DIR/openstack_dashboard/local/local_settings.py
-    cp $FILES/horizon_settings.py $local_settings
-
-    # Initialize the horizon database (it stores sessions and notices shown to
-    # users).  The user system is external (keystone).
-    cd $HORIZON_DIR
-    python manage.py syncdb --noinput
-    cd $TOP_DIR
-
-    # Create an empty directory that apache uses as docroot
-    sudo mkdir -p $HORIZON_DIR/.blackhole
-
-    if [[ "$os_PACKAGE" = "deb" ]]; then
-        APACHE_NAME=apache2
-        APACHE_CONF=sites-available/horizon
-        # Clean up the old config name
-        sudo rm -f /etc/apache2/sites-enabled/000-default
-        # Be a good citizen and use the distro tools here
-        sudo touch /etc/$APACHE_NAME/$APACHE_CONF
-        sudo a2ensite horizon
-    else
-        # Install httpd, which is NOPRIME'd
-        APACHE_NAME=httpd
-        APACHE_CONF=conf.d/horizon.conf
-        sudo sed '/^Listen/s/^.*$/Listen 0.0.0.0:80/' -i /etc/httpd/conf/httpd.conf
-    fi
-
-    # Configure apache to run horizon
-    sudo sh -c "sed -e \"
-        s,%USER%,$APACHE_USER,g;
-        s,%GROUP%,$APACHE_GROUP,g;
-        s,%HORIZON_DIR%,$HORIZON_DIR,g;
-        s,%APACHE_NAME%,$APACHE_NAME,g;
-        s,%DEST%,$DEST,g;
-    \" $FILES/apache-horizon.template >/etc/$APACHE_NAME/$APACHE_CONF"
-
-    restart_service $APACHE_NAME
+    init_horizon
+    start_horizon
 fi
 
 
@@ -1773,11 +1715,11 @@
         add_nova_opt "quantum_url=http://$Q_HOST:$Q_PORT"
 
         if [[ "$Q_PLUGIN" = "openvswitch" ]]; then
-            NOVA_VIF_DRIVER="nova.virt.libvirt.vif.LibvirtHybridOVSBridgeDriver"
+            NOVA_VIF_DRIVER=${NOVA_VIF_DRIVER:-"nova.virt.libvirt.vif.LibvirtHybridOVSBridgeDriver"}
         elif [[ "$Q_PLUGIN" = "linuxbridge" ]]; then
-            NOVA_VIF_DRIVER="nova.virt.libvirt.vif.QuantumLinuxBridgeVIFDriver"
+            NOVA_VIF_DRIVER=${NOVA_VIF_DRIVER:-"nova.virt.libvirt.vif.QuantumLinuxBridgeVIFDriver"}
         elif [[ "$Q_PLUGIN" = "ryu" ]]; then
-            NOVA_VIF_DRIVER="quantum.plugins.ryu.nova.vif.LibvirtOpenVswitchOFPRyuDriver"
+            NOVA_VIF_DRIVER=${NOVA_VIF_DRIVER:-"quantum.plugins.ryu.nova.vif.LibvirtOpenVswitchOFPRyuDriver"}
             add_nova_opt "libvirt_ovs_integration_bridge=$OVS_BRIDGE"
             add_nova_opt "linuxnet_ovs_ryu_api_host=$RYU_API_HOST:$RYU_API_PORT"
             add_nova_opt "libvirt_ovs_ryu_api_host=$RYU_API_HOST:$RYU_API_PORT"
@@ -1963,7 +1905,7 @@
     echo_summary "Starting Ceilometer"
     start_ceilometer
 fi
-screen_it horizon "cd $HORIZON_DIR && sudo tail -f /var/log/$APACHE_NAME/horizon_error.log"
+
 screen_it swift "cd $SWIFT_DIR && $SWIFT_DIR/bin/swift-proxy-server ${SWIFT_CONFIG_DIR}/proxy-server.conf -v"
 
 # Starting the nova-objectstore only if swift3 service is not enabled.
diff --git a/stackrc b/stackrc
index 01e9556..9588cf9 100644
--- a/stackrc
+++ b/stackrc
@@ -14,7 +14,7 @@
 # ``disable_service`` functions in ``localrc``.
 # For example, to enable Swift add this to ``localrc``:
 # enable_service swift
-ENABLED_SERVICES=g-api,g-reg,key,n-api,n-crt,n-obj,n-cpu,n-net,cinder,c-sch,c-api,c-vol,n-sch,n-novnc,n-xvnc,n-cauth,horizon,rabbit,$DATABASE_TYPE
+ENABLED_SERVICES=g-api,g-reg,key,n-api,n-crt,n-obj,n-cpu,n-net,n-cond,cinder,c-sch,c-api,c-vol,n-sch,n-novnc,n-xvnc,n-cauth,horizon,rabbit,$DATABASE_TYPE
 
 # Set the default Nova APIs to enable
 NOVA_ENABLED_APIS=ec2,osapi_compute,metadata
diff --git a/tools/configure_tempest.sh b/tools/configure_tempest.sh
index 6493822..9b543ab 100755
--- a/tools/configure_tempest.sh
+++ b/tools/configure_tempest.sh
@@ -209,6 +209,21 @@
 LIVE_MIGRATION_AVAILABLE=${LIVE_MIGRATION_AVAILABLE:-False}
 USE_BLOCK_MIGRATION_FOR_LIVE_MIGRATION=${USE_BLOCK_MIGRATION_FOR_LIVE_MIGRATION:-False}
 
+# EC2 and S3 test configuration
+BOTO_EC2_URL="http://$IDENTITY_HOST:8773/services/Cloud"
+BOTO_S3_URL="http://$IDENTITY_HOST:3333"
+BOTO_AWS_ACCESS=""  # Created in tempest...
+BOTO_AWS_SECRET=""  # Created in tempest...
+BOTO_AWS_REGION="RegionOne"
+BOTO_S3_MATERIALS_PATH=$DEST/devstack/files/images/s3-materials/cirros-0.3.0
+BOTO_ARI_MANIFEST=cirros-0.3.0-x86_64-initrd.manifest.xml
+BOTO_AMI_MANIFEST=cirros-0.3.0-x86_64-blank.img.manifest.xml
+BOTO_AKI_MANIFEST=cirros-0.3.0-x86_64-vmlinuz.manifest.xml
+BOTO_FLAVOR_NAME=m1.tiny
+BOTO_SOCKET_TIMEOUT=5
+BOTO_BUILD_TIMEOUT=${COMPUTE_BUILD_TIMEOUT:-400}
+BOTO_BUILD_INTERVAL=${COMPUTE_BUILD_INTERVAL:-3}
+
 sed -e "
     s,%IDENTITY_USE_SSL%,$IDENTITY_USE_SSL,g;
     s,%IDENTITY_HOST%,$IDENTITY_HOST,g;
@@ -266,6 +281,19 @@
     s,%VOLUME_BUILD_TIMEOUT%,$VOLUME_BUILD_TIMEOUT,g;
     s,%LIVE_MIGRATION_AVAILABLE%,$LIVE_MIGRATION_AVAILABLE,g;
     s,%USE_BLOCK_MIGRATION_FOR_LIVE_MIGRATION%,$USE_BLOCK_MIGRATION_FOR_LIVE_MIGRATION,g;
+    s,%BOTO_EC2_URL%,$BOTO_EC2_URL,g;
+    s,%BOTO_S3_URL%,$BOTO_S3_URL,g;
+    s,%BOTO_AWS_ACCESS%,$BOTO_AWS_ACCESS,g;
+    s,%BOTO_AWS_SECRET%,$BOTO_AWS_SECRET,g;
+    s,%BOTO_AWS_REGION%,$BOTO_AWS_REGION,g;
+    s,%BOTO_S3_MATERIALS_PATH%,$BOTO_S3_MATERIALS_PATH,g;
+    s,%BOTO_ARI_MANIFEST%,$BOTO_ARI_MANIFEST,g;
+    s,%BOTO_AMI_MANIFEST%,$BOTO_AMI_MANIFEST,g;
+    s,%BOTO_AKI_MANIFEST%,$BOTO_AKI_MANIFEST,g;
+    s,%BOTO_FLAVOR_NAME%,$BOTO_FLAVOR_NAME,g;
+    s,%BOTO_SOCKET_TIMEOUT%,$BOTO_SOCKET_TIMEOUT,g;
+    s,%BOTO_BUILD_TIMEOUT%,$BOTO_BUILD_TIMEOUT,g;
+    s,%BOTO_BUILD_INTERVAL%,$BOTO_BUILD_INTERVAL,g;
 " -i $TEMPEST_CONF
 
 echo "Created tempest configuration file:"
diff --git a/unstack.sh b/unstack.sh
index 1a2cad8..0040cf1 100755
--- a/unstack.sh
+++ b/unstack.sh
@@ -26,6 +26,7 @@
 
 # Get project function libraries
 source $TOP_DIR/lib/cinder
+source $TOP_DIR/lib/horizon
 
 # Determine what system we are running on.  This provides ``os_VENDOR``,
 # ``os_RELEASE``, ``os_UPDATE``, ``os_PACKAGE``, ``os_CODENAME``
@@ -51,7 +52,7 @@
 
 # Apache has the WSGI processes
 if is_service_enabled horizon; then
-    stop_service apache2
+    stop_horizon
 fi
 
 SCSI_PERSIST_DIR=$CINDER_STATE_PATH/volumes/*