Merge "Handle more nicely when role root is already here"
diff --git a/lib/glance b/lib/glance
index b278796..135136d 100644
--- a/lib/glance
+++ b/lib/glance
@@ -176,7 +176,7 @@
     recreate_database glance utf8
 
     # Migrate glance database
-    $GLANCE_BIN_DIR/glance-manage db sync
+    $GLANCE_BIN_DIR/glance-manage db_sync
 
     create_glance_cache_dir
 }
diff --git a/lib/neutron b/lib/neutron
index dbc5843..a7519ad 100644
--- a/lib/neutron
+++ b/lib/neutron
@@ -757,6 +757,16 @@
 # Utility Functions
 #------------------
 
+# _neutron_service_plugin_class_add() - add service plugin class
+function _neutron_service_plugin_class_add() {
+    local service_plugin_class=$1
+    if [[ $Q_SERVICE_PLUGIN_CLASSES == '' ]]; then
+        Q_SERVICE_PLUGIN_CLASSES=$service_plugin_class
+    elif [[ ! ,${Q_SERVICE_PLUGIN_CLASSES}, =~ ,${service_plugin_class}, ]]; then
+        Q_SERVICE_PLUGIN_CLASSES="$Q_SERVICE_PLUGIN_CLASSES,$service_plugin_class"
+    fi
+}
+
 # _neutron_setup_rootwrap() - configure Neutron's rootwrap
 function _neutron_setup_rootwrap() {
     if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
diff --git a/lib/neutron_plugins/ml2 b/lib/neutron_plugins/ml2
index b5b1873..ab4e347 100644
--- a/lib/neutron_plugins/ml2
+++ b/lib/neutron_plugins/ml2
@@ -54,11 +54,7 @@
     Q_PLUGIN_CLASS="neutron.plugins.ml2.plugin.Ml2Plugin"
     # The ML2 plugin delegates L3 routing/NAT functionality to
     # the L3 service plugin which must therefore be specified.
-    if [[ $Q_SERVICE_PLUGIN_CLASSES == '' ]]; then
-        Q_SERVICE_PLUGIN_CLASSES=$ML2_L3_PLUGIN
-    else
-        Q_SERVICE_PLUGIN_CLASSES="$Q_SERVICE_PLUGIN_CLASSES,$ML2_L3_PLUGIN"
-    fi
+    _neutron_service_plugin_class_add $ML2_L3_PLUGIN
 }
 
 function neutron_plugin_configure_service() {
diff --git a/lib/neutron_plugins/services/firewall b/lib/neutron_plugins/services/firewall
index 580071f..8273e54 100644
--- a/lib/neutron_plugins/services/firewall
+++ b/lib/neutron_plugins/services/firewall
@@ -8,11 +8,7 @@
 FWAAS_PLUGIN=neutron.services.firewall.fwaas_plugin.FirewallPlugin
 
 function neutron_fwaas_configure_common() {
-    if [[ $Q_SERVICE_PLUGIN_CLASSES == '' ]]; then
-        Q_SERVICE_PLUGIN_CLASSES=$FWAAS_PLUGIN
-    else
-        Q_SERVICE_PLUGIN_CLASSES="$Q_SERVICE_PLUGIN_CLASSES,$FWAAS_PLUGIN"
-    fi
+    _neutron_service_plugin_class_add $FWAAS_PLUGIN
 }
 
 function neutron_fwaas_configure_driver() {
diff --git a/lib/neutron_plugins/services/loadbalancer b/lib/neutron_plugins/services/loadbalancer
index 2699a9b..5d7a94e 100644
--- a/lib/neutron_plugins/services/loadbalancer
+++ b/lib/neutron_plugins/services/loadbalancer
@@ -19,11 +19,7 @@
 }
 
 function neutron_agent_lbaas_configure_common() {
-    if [[ $Q_SERVICE_PLUGIN_CLASSES == '' ]]; then
-        Q_SERVICE_PLUGIN_CLASSES=$LBAAS_PLUGIN
-    else
-        Q_SERVICE_PLUGIN_CLASSES="$Q_SERVICE_PLUGIN_CLASSES,$LBAAS_PLUGIN"
-    fi
+    _neutron_service_plugin_class_add $LBAAS_PLUGIN
 }
 
 function neutron_agent_lbaas_configure_agent() {
diff --git a/lib/neutron_plugins/services/metering b/lib/neutron_plugins/services/metering
index b105429..37952bb 100644
--- a/lib/neutron_plugins/services/metering
+++ b/lib/neutron_plugins/services/metering
@@ -10,11 +10,7 @@
 METERING_PLUGIN="neutron.services.metering.metering_plugin.MeteringPlugin"
 
 function neutron_agent_metering_configure_common() {
-    if [[ $Q_SERVICE_PLUGIN_CLASSES == '' ]]; then
-        Q_SERVICE_PLUGIN_CLASSES=$METERING_PLUGIN
-    else
-        Q_SERVICE_PLUGIN_CLASSES="$Q_SERVICE_PLUGIN_CLASSES,$METERING_PLUGIN"
-    fi
+    _neutron_service_plugin_class_add $METERING_PLUGIN
 }
 
 function neutron_agent_metering_configure_agent() {
diff --git a/lib/neutron_plugins/services/vpn b/lib/neutron_plugins/services/vpn
index 55d0a76..02370e7 100644
--- a/lib/neutron_plugins/services/vpn
+++ b/lib/neutron_plugins/services/vpn
@@ -15,11 +15,7 @@
 }
 
 function neutron_vpn_configure_common() {
-    if [[ $Q_SERVICE_PLUGIN_CLASSES == '' ]]; then
-        Q_SERVICE_PLUGIN_CLASSES=$VPN_PLUGIN
-    else
-        Q_SERVICE_PLUGIN_CLASSES="$Q_SERVICE_PLUGIN_CLASSES,$VPN_PLUGIN"
-    fi
+    _neutron_service_plugin_class_add $VPN_PLUGIN
 }
 
 function neutron_vpn_stop() {
diff --git a/lib/nova_plugins/hypervisor-libvirt b/lib/nova_plugins/hypervisor-libvirt
index 6f90f4a..ef40e7a 100644
--- a/lib/nova_plugins/hypervisor-libvirt
+++ b/lib/nova_plugins/hypervisor-libvirt
@@ -93,6 +93,9 @@
         fi
     fi
 
+    # Change the libvirtd log level to DEBUG.
+    sudo sed -i s/"#log_level = 3"/"log_level = 1"/ /etc/libvirt/libvirtd.conf
+
     # The user that nova runs as needs to be member of **libvirtd** group otherwise
     # nova-compute will be unable to use libvirt.
     if ! getent group $LIBVIRT_GROUP >/dev/null; then
diff --git a/lib/tempest b/lib/tempest
index 0969b2d..95b300c 100644
--- a/lib/tempest
+++ b/lib/tempest
@@ -283,6 +283,7 @@
     iniset $TEMPEST_CONF network tenant_networks_reachable "$tenant_networks_reachable"
     iniset $TEMPEST_CONF network public_network_id "$public_network_id"
     iniset $TEMPEST_CONF network public_router_id "$public_router_id"
+    iniset $TEMPEST_CONF network default_network "$FIXED_RANGE"
 
     # boto
     iniset $TEMPEST_CONF boto ec2_url "http://$SERVICE_HOST:8773/services/Cloud"
diff --git a/lib/trove b/lib/trove
index 6d5a56e..f8e3edd 100644
--- a/lib/trove
+++ b/lib/trove
@@ -30,7 +30,13 @@
 TROVE_CONF_DIR=/etc/trove
 TROVE_LOCAL_CONF_DIR=$TROVE_DIR/etc/trove
 TROVE_AUTH_CACHE_DIR=${TROVE_AUTH_CACHE_DIR:-/var/cache/trove}
-TROVE_BIN_DIR=/usr/local/bin
+
+# Support entry points installation of console scripts
+if [[ -d $TROVE_DIR/bin ]]; then
+    TROVE_BIN_DIR=$TROVE_DIR/bin
+else
+    TROVE_BIN_DIR=$(get_python_exec_prefix)
+fi
 
 # setup_trove_logging() - Adds logging configuration to conf files
 function setup_trove_logging() {
@@ -178,14 +184,14 @@
     recreate_database trove utf8
 
     #Initialize the trove database
-    $TROVE_DIR/bin/trove-manage db_sync
+    $TROVE_BIN_DIR/trove-manage db_sync
 }
 
 # start_trove() - Start running processes, including screen
 function start_trove() {
-    screen_it tr-api "cd $TROVE_DIR; bin/trove-api --config-file=$TROVE_CONF_DIR/trove.conf --debug 2>&1"
-    screen_it tr-tmgr "cd $TROVE_DIR; bin/trove-taskmanager --config-file=$TROVE_CONF_DIR/trove-taskmanager.conf --debug 2>&1"
-    screen_it tr-cond "cd $TROVE_DIR; bin/trove-conductor --config-file=$TROVE_CONF_DIR/trove-conductor.conf --debug 2>&1"
+    screen_it tr-api "cd $TROVE_DIR; $TROVE_BIN_DIR/trove-api --config-file=$TROVE_CONF_DIR/trove.conf --debug 2>&1"
+    screen_it tr-tmgr "cd $TROVE_DIR; $TROVE_BIN_DIR/trove-taskmanager --config-file=$TROVE_CONF_DIR/trove-taskmanager.conf --debug 2>&1"
+    screen_it tr-cond "cd $TROVE_DIR; $TROVE_BIN_DIR/trove-conductor --config-file=$TROVE_CONF_DIR/trove-conductor.conf --debug 2>&1"
 }
 
 # stop_trove() - Stop running processes
diff --git a/stack.sh b/stack.sh
index d54a652..2438f9f 100755
--- a/stack.sh
+++ b/stack.sh
@@ -234,6 +234,13 @@
 # a basic test for $DEST path permissions (fatal on error unless skipped)
 check_path_perm_sanity ${DEST}
 
+# Certain services such as rabbitmq require that the local hostname resolves
+# correctly.  Make sure it exists in /etc/hosts so that is always true.
+LOCAL_HOSTNAME=`hostname -s`
+if [ -z "`grep ^127.0.0.1 /etc/hosts | grep $LOCAL_HOSTNAME`" ]; then
+    sudo sed -i "s/\(^127.0.0.1.*\)/\1 $LOCAL_HOSTNAME/" /etc/hosts
+fi
+
 # Set ``OFFLINE`` to ``True`` to configure ``stack.sh`` to run cleanly without
 # Internet access. ``stack.sh`` must have been previously run with Internet
 # access to install prerequisites and fetch repositories.
diff --git a/tools/docker/install_docker.sh b/tools/docker/install_docker.sh
index 2e5b510..375cfe9 100755
--- a/tools/docker/install_docker.sh
+++ b/tools/docker/install_docker.sh
@@ -45,7 +45,7 @@
 
 echo "Waiting for docker daemon to start..."
 DOCKER_GROUP=$(groups | cut -d' ' -f1)
-CONFIGURE_CMD="while ! /bin/echo -e 'GET /v1.3/version HTTP/1.0\n\n' | socat - unix-connect:$DOCKER_UNIX_SOCKET | grep -q '200 OK'; do
+CONFIGURE_CMD="while ! /bin/echo -e 'GET /v1.3/version HTTP/1.0\n\n' | socat - unix-connect:$DOCKER_UNIX_SOCKET 2>/dev/null | grep -q '200 OK'; do
     # Set the right group on docker unix socket before retrying
     sudo chgrp $DOCKER_GROUP $DOCKER_UNIX_SOCKET
     sudo chmod g+rw $DOCKER_UNIX_SOCKET
diff --git a/tools/xen/prepare_guest_template.sh b/tools/xen/prepare_guest_template.sh
index 6ea6f63..546ac99 100755
--- a/tools/xen/prepare_guest_template.sh
+++ b/tools/xen/prepare_guest_template.sh
@@ -79,3 +79,7 @@
     "$GUEST_PASSWORD" "$XS_TOOLS_PATH" "$STACK_USER" \\
     > /opt/stack/prepare_guest.log 2>&1
 EOF
+
+# Need to set barrier=0 to avoid a Xen bug
+# https://bugs.launchpad.net/ubuntu/+source/linux/+bug/824089
+sed -i -e 's/errors=/barrier=0,errors=/' $STAGING_DIR/etc/fstab