Merge "Add support for Fedora 20"
diff --git a/functions b/functions
index e79e1d5..6f09685 100644
--- a/functions
+++ b/functions
@@ -1364,11 +1364,11 @@
     if [[ $image_url != file* ]]; then
         # Downloads the image (uec ami+aki style), then extracts it.
         if [[ ! -f $FILES/$IMAGE_FNAME || "$(stat -c "%s" $FILES/$IMAGE_FNAME)" = "0" ]]; then
-             wget -c $image_url -O $FILES/$IMAGE_FNAME
-             if [[ $? -ne 0 ]]; then
-                 echo "Not found: $image_url"
-                 return
-             fi
+            wget -c $image_url -O $FILES/$IMAGE_FNAME
+            if [[ $? -ne 0 ]]; then
+                echo "Not found: $image_url"
+                return
+            fi
         fi
         IMAGE="$FILES/${IMAGE_FNAME}"
     else
@@ -1420,7 +1420,7 @@
         vmdk_create_type="${vmdk_create_type%?}"
 
         descriptor_data_pair_msg="Monolithic flat and VMFS disks "`
-                                 `"should use a descriptor-data pair."
+                                    `"should use a descriptor-data pair."
         if [[ "$vmdk_create_type" = "monolithicSparse" ]]; then
             vmdk_disktype="sparse"
         elif [[ "$vmdk_create_type" = "monolithicFlat" || \
@@ -1435,7 +1435,7 @@
             path_len=`expr ${#image_url} - ${#IMAGE_FNAME}`
             flat_url="${image_url:0:$path_len}$flat_fname"
             warn $LINENO "$descriptor_data_pair_msg"`
-                         `" Attempt to retrieve the *-flat.vmdk: $flat_url"
+                            `" Attempt to retrieve the *-flat.vmdk: $flat_url"
             if [[ $flat_url != file* ]]; then
                 if [[ ! -f $FILES/$flat_fname || \
                 "$(stat -c "%s" $FILES/$flat_fname)" = "0" ]]; then
@@ -1474,7 +1474,7 @@
                 flat_path="${image_url:0:$path_len}"
                 descriptor_url=$flat_path$descriptor_fname
                 warn $LINENO "$descriptor_data_pair_msg"`
-                             `" Attempt to retrieve the descriptor *.vmdk: $descriptor_url"
+                                `" Attempt to retrieve the descriptor *.vmdk: $descriptor_url"
                 if [[ $flat_path != file* ]]; then
                     if [[ ! -f $FILES/$descriptor_fname || \
                     "$(stat -c "%s" $FILES/$descriptor_fname)" = "0" ]]; then
@@ -1489,8 +1489,8 @@
                     descriptor_url=$(echo $descriptor_url | sed "s/^file:\/\///g")
                     if [[ ! -f $descriptor_url || \
                     "$(stat -c "%s" $descriptor_url)" == "0" ]]; then
-                         warn $LINENO "Descriptor not found $descriptor_url"
-                         descriptor_found=false
+                        warn $LINENO "Descriptor not found $descriptor_url"
+                        descriptor_found=false
                     fi
                 fi
                 if $descriptor_found; then
@@ -1498,10 +1498,10 @@
                     `"grep -a -F -m 1 'ddb.adapterType =' $descriptor_url)"
                     vmdk_adapter_type="${vmdk_adapter_type#*\"}"
                     vmdk_adapter_type="${vmdk_adapter_type%?}"
-                 fi
-             fi
-             #TODO(alegendre): handle streamOptimized once supported by the VMware driver.
-             vmdk_disktype="preallocated"
+                fi
+            fi
+            #TODO(alegendre): handle streamOptimized once supported by the VMware driver.
+            vmdk_disktype="preallocated"
         else
             #TODO(alegendre): handle streamOptimized once supported by the VMware driver.
             vmdk_disktype="preallocated"
diff --git a/lib/databases/postgresql b/lib/databases/postgresql
index 519479a..60e5a33 100644
--- a/lib/databases/postgresql
+++ b/lib/databases/postgresql
@@ -64,9 +64,13 @@
     sudo sed -i "/^host/s/all\s\+::1\/128\s\+ident/$DATABASE_USER\t::0\/0\tpassword/" $PG_HBA
     restart_service postgresql
 
-    # If creating the role fails, chances are it already existed. Try to alter it.
-    sudo -u root sudo -u postgres -i psql -c "CREATE ROLE $DATABASE_USER WITH SUPERUSER LOGIN PASSWORD '$DATABASE_PASSWORD'" || \
-    sudo -u root sudo -u postgres -i psql -c "ALTER ROLE $DATABASE_USER WITH SUPERUSER LOGIN PASSWORD '$DATABASE_PASSWORD'"
+    # Create the role if it's not here or else alter it.
+    root_roles=$(sudo -u root sudo -u postgres -i psql -t -c "SELECT 'HERE' from pg_roles where rolname='root'")
+    if [[ ${root_roles} == *HERE ]];then
+        sudo -u root sudo -u postgres -i psql -c "ALTER ROLE $DATABASE_USER WITH SUPERUSER LOGIN PASSWORD '$DATABASE_PASSWORD'"
+    else
+        sudo -u root sudo -u postgres -i psql -c "CREATE ROLE $DATABASE_USER WITH SUPERUSER LOGIN PASSWORD '$DATABASE_PASSWORD'"
+    fi
 }
 
 function install_database_postgresql {
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 b/lib/nova
index e754341..39685a8 100644
--- a/lib/nova
+++ b/lib/nova
@@ -377,6 +377,7 @@
     iniset $NOVA_CONF DEFAULT osapi_compute_workers "4"
     iniset $NOVA_CONF DEFAULT ec2_workers "4"
     iniset $NOVA_CONF DEFAULT metadata_workers "4"
+    iniset $NOVA_CONF conductor workers "4"
     iniset $NOVA_CONF DEFAULT sql_connection `database_connection_url nova`
     iniset $NOVA_CONF DEFAULT fatal_deprecations "True"
     iniset $NOVA_CONF DEFAULT instance_name_template "${INSTANCE_NAME_PREFIX}%08x"
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/oslo b/lib/oslo
index 816ae9a..f644ed7 100644
--- a/lib/oslo
+++ b/lib/oslo
@@ -22,6 +22,7 @@
 # --------
 OSLOCFG_DIR=$DEST/oslo.config
 OSLOMSG_DIR=$DEST/oslo.messaging
+OSLORWRAP_DIR=$DEST/oslo.rootwrap
 
 # Entry Points
 # ------------
@@ -37,6 +38,9 @@
 
     git_clone $OSLOMSG_REPO $OSLOMSG_DIR $OSLOMSG_BRANCH
     setup_develop $OSLOMSG_DIR
+
+    git_clone $OSLORWRAP_REPO $OSLORWRAP_DIR $OSLORWRAP_BRANCH
+    setup_develop $OSLORWRAP_DIR
 }
 
 # cleanup_oslo() - purge possibly old versions of oslo
diff --git a/lib/tempest b/lib/tempest
index 0969b2d..08c0553 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"
@@ -328,7 +329,7 @@
     iniset $TEMPEST_CONF network-feature-enabled api_extensions "${NETWORK_API_EXTENSIONS:-all}"
 
     # service_available
-    for service in nova cinder glance neutron swift heat horizon ceilometer ironic savanna; do
+    for service in nova cinder glance neutron swift heat horizon ceilometer ironic savanna trove; do
         if is_service_enabled $service ; then
             iniset $TEMPEST_CONF service_available $service "True"
         else
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 4e12c45..7c06571 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.
@@ -1104,10 +1111,7 @@
 
 if is_service_enabled q-svc; then
     echo_summary "Starting Neutron"
-
     start_neutron_service_and_check
-    create_neutron_initial_network
-    setup_neutron_debug
 elif is_service_enabled $DATABASE_BACKENDS && is_service_enabled n-net; then
     NM_CONF=${NOVA_CONF}
     if is_service_enabled n-cell; then
@@ -1127,6 +1131,12 @@
 if is_service_enabled neutron; then
     start_neutron_agents
 fi
+# Once neutron agents are started setup initial network elements
+if is_service_enabled q-svc; then
+    echo_summary "Creating initial neutron network elements"
+    create_neutron_initial_network
+    setup_neutron_debug
+fi
 if is_service_enabled nova; then
     echo_summary "Starting Nova"
     start_nova
diff --git a/stackrc b/stackrc
index 695bdb1..3fdc566 100644
--- a/stackrc
+++ b/stackrc
@@ -136,6 +136,10 @@
 OSLOMSG_REPO=${OSLOMSG_REPO:-${GIT_BASE}/openstack/oslo.messaging.git}
 OSLOMSG_BRANCH=${OSLOMSG_BRANCH:-master}
 
+# oslo.rootwrap
+OSLORWRAP_REPO=${OSLORWRAP_REPO:-${GIT_BASE}/openstack/oslo.rootwrap.git}
+OSLORWRAP_BRANCH=${OSLORWRAP_BRANCH:-master}
+
 # pbr drives the setuptools configs
 PBR_REPO=${PBR_REPO:-${GIT_BASE}/openstack-dev/pbr.git}
 PBR_BRANCH=${PBR_BRANCH:-master}
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